11 #include "hugglefeedproviderwiki.hpp"
13 using namespace Huggle;
15 HuggleFeedProviderWiki::HuggleFeedProviderWiki()
17 Buffer =
new QList<WikiEdit*>();
21 LatestTime = QDateTime::currentDateTime().addDays(-1);
22 LastRefresh = QDateTime::currentDateTime().addDays(-1);
25 HuggleFeedProviderWiki::~HuggleFeedProviderWiki()
27 while (Buffer->count() > 0)
29 Buffer->at(0)->UnregisterConsumer(HUGGLECONSUMER_WIKIEDIT);
61 if (this->Buffer->size() == 0)
63 if (this->LastRefresh.addSecs(6) < QDateTime::currentDateTime())
66 this->LastRefresh = QDateTime::currentDateTime();
102 q->
Parameters =
"list=recentchanges&rcprop=" + QUrl::toPercentEncoding(
"user|userid|comment|flags|timestamp|title|ids|sizes") +
103 "&rcshow=" + QUrl::toPercentEncoding(
"!bot") +
"&rclimit=200";
104 q->
Target =
"Recent changes refresh";
112 if (this->Buffer->size() < 1)
116 WikiEdit *edit = this->Buffer->at(0);
117 this->Buffer->removeAt(0);
122 void HuggleFeedProviderWiki::Process(QString data)
127 QDomNodeList l = d.elementsByTagName(
"rc");
128 int CurrentNode = l.count();
131 Core::Log(
"Error, wiki provider returned: " + data);
135 QDateTime t = this->LatestTime;
136 bool Changed =
false;
137 while (CurrentNode > 0)
141 QDomElement item = l.at(CurrentNode).toElement();
143 if (item.nodeName() !=
"rc")
149 if (!item.attributes().contains(
"timestamp"))
151 Core::Log(
"RC Feed: Item was missing timestamp attribute: " + item.toElement().nodeName());
156 QDateTime time = QDateTime::fromString(item.attribute(
"timestamp"),
"yyyy-MM-ddThh:mm:ssZ");
169 if (!item.attributes().contains(
"type"))
171 Core::Log(
"RC Feed: Item was missing type attribute: " + item.text());
176 QString type = item.attribute(
"type");
178 if (type !=
"edit" && type !=
"new")
184 if (!item.attributes().contains(
"title"))
186 Core::Log(
"RC Feed: Item was missing title attribute: " + item.text());
199 if (item.attributes().contains(
"newlen") && item.attributes().contains(
"oldlen"))
201 edit->
Size = item.attribute(
"newlen").toInt() - item.attribute(
"oldlen").toInt();
204 if (item.attributes().contains(
"user"))
209 if (item.attributes().contains(
"comment"))
211 edit->
Summary = item.attribute(
"comment");
214 if (item.attributes().contains(
"bot"))
219 if (item.attributes().contains(
"anon"))
224 if (item.attributes().contains(
"revid"))
226 edit->
RevID = QString(item.attribute(
"revid")).toInt();
227 if (edit->
RevID == 0)
233 if (item.attributes().contains(
"minor"))
238 this->InsertEdit(edit);
244 this->LatestTime = t.addSecs(1);
248 void HuggleFeedProviderWiki::InsertEdit(
WikiEdit *edit)
252 if (
Core::Main->Queue1->CurrentFilter->Matches(edit))
258 this->Buffer->at(0)->UnregisterConsumer(HUGGLECONSUMER_WIKIEDIT);
259 this->Buffer->removeAt(0);
261 Core::Log(
"WARNING: insufficient space in irc cache, increase ProviderCache size, otherwise you will be loosing edits");
263 this->Buffer->append(edit);
bool IsManaged()
IsManaged Managed class is deleted by GC and must not be deleted by hand.
bool Start()
Start the feed engine.
static void Log(QString Message)
Write text to terminal as well as ring log.
bool NewPage
Edit is a new page.
QString Target
This is optional property which contains a label of target this query is for.
static void PostProcessEdit(WikiEdit *_e)
virtual bool Processed()
Returns true in case that query is processed.
void UnregisterConsumer(const int consumer)
This function will remove a string which prevent the object from being removed.
void Stop()
Stop the feed engine.
void RegisterConsumer(const int consumer)
Registers a consumer.
static void AppendQuery(Query *item)
Insert a query to internal list of running queries, so that they can be watched This will insert it t...
static double EditCounter
Number of edits made since you logged in.
QString Summary
Summary of edit.
static void PreProcessEdit(WikiEdit *_e)
static int ProviderCache
Size of feed.
void SetAction(const Action action)
Change the action type.
bool Minor
Edit is a minor edit.
virtual void Resume()
Resume edit parsing.
bool IsWorking()
Return true if this feed is operational or not.
WikiUser * User
User who changed the page.
bool ContainsEdit()
Check if feed is containing some edits in buffer.
QString ErrorMessage
If query is in error the reason for error is stored here.
QString Parameters
Parameters for action, for example page title.
int Size
Size of change of edit.
void ForceIP()
Change the IP property to true forcefully even if user isn't IP.
static MainWindow * Main
Pointer to main.
This class can be used to execute any kind of api query on any wiki.
WikiEdit * RetrieveEdit()
Return a last edit from cache or NULL.
bool Bot
Edit is a bot edit.
WikiPage * Page
Page that was changed by edit.
QString Data
Data retrieved by query.
QueryResult * Result
Result of query, see documentation of QueryResult for more.
virtual void Pause()
This is useful to stop parsing edits from irc and like in case that queue is full.