11 #include "wikiedit.hpp"
12 using namespace Huggle;
27 this->Status = StatusNone;
32 this->RollbackToken =
"";
33 this->PostProcessing =
false;
34 this->DifferenceQuery = NULL;
35 this->ProcessingQuery = NULL;
36 this->ProcessingDiff =
false;
37 this->ProcessingRevs =
false;
41 this->Previous = NULL;
42 this->Time = QDateTime::currentDateTime();
44 this->ProcessingByWorkerThread =
false;
45 this->ProcessedByWorkerThread =
false;
46 this->
RevID = WIKI_UNKNOWN_REVID;
59 if (this->ProcessedByWorkerThread)
64 if (this->ProcessingByWorkerThread)
69 if (!this->PostProcessing)
74 if (this->ProcessingRevs)
82 if (this->ProcessingQuery->
Result->Failed)
85 Core::Log(
"Unable to retrieve " + this->
User->
GetTalk() +
" warning level will not be scored by it");
90 d.setContent(this->ProcessingQuery->
Result->
Data);
91 QDomNodeList page = d.elementsByTagName(
"rev");
92 QDomNodeList code = d.elementsByTagName(
"page");
96 QDomElement e = code.at(0).toElement();
97 if (e.attributes().contains(
"missing"))
103 if (missing !=
true && page.count() > 0)
105 QDomElement e = page.at(0).toElement();
106 if (e.nodeName() ==
"rev")
112 Core::Log(
"Unable to retrieve " + this->
User->
GetTalk() +
" warning level will not be scored by it");
119 Core::Log(
"Unable to retrieve " + this->
User->
GetTalk() +
" warning level will not be scored by it");
124 this->ProcessingRevs =
false;
127 if (this->ProcessingDiff)
135 if (this->DifferenceQuery->
Result->Failed)
139 this->DifferenceQuery = NULL;
140 this->PostProcessing =
false;
146 d.setContent(this->DifferenceQuery->
Result->
Data);
147 QDomNodeList l = d.elementsByTagName(
"rev");
148 QDomNodeList diff = d.elementsByTagName(
"diff");
152 QDomElement e = l.at(0).toElement();
153 if (e.nodeName() ==
"rev")
157 this->
Page->Contents = e.text();
160 if (e.attributes().contains(
"user"))
164 if (e.attributes().contains(
"rollbacktoken"))
167 this->RollbackToken = e.attribute(
"rollbacktoken");
170 if (e.attributes().contains(
"revid"))
172 this->
RevID = e.attribute(
"revid").toInt();
175 if (e.attributes().contains(
"comment"))
177 this->
Summary = e.attribute(
"comment");
181 if (diff.count() > 0)
183 QDomElement e = diff.at(0).toElement();
184 if (e.nodeName() ==
"diff")
186 this->DiffText = e.text();
193 this->ProcessingDiff =
false;
197 if (this->ProcessingRevs || this->ProcessingDiff)
202 if (this->DiffText ==
"")
209 this->ProcessingQuery = NULL;
211 this->DifferenceQuery = NULL;
212 this->ProcessingByWorkerThread =
true;
213 ProcessorThread::EditLock.lock();
214 ProcessorThread::PendingEdits.append(
this);
215 ProcessorThread::EditLock.unlock();
223 QString text = this->DiffText.toLower();
224 if (this->
Page->Contents !=
"")
226 text = this->
Page->Contents.toLower();
228 while (xx<Configuration::LocalConfig_ScoreParts.count())
230 QString w = Configuration::LocalConfig_ScoreParts.at(xx).word;
231 if (text.contains(w))
233 this->Score += Configuration::LocalConfig_ScoreParts.at(xx).score;
234 ScoreWords.append(w);
239 while (xx<Configuration::LocalConfig_ScoreWords.count())
241 QString w = Configuration::LocalConfig_ScoreWords.at(xx).word;
242 if (text.contains(
" " + w +
" ") || text.contains(
" " + w +
".")
243 || text.contains(
" " + w +
",") || text.contains(
" " + w +
"!")
244 || text.contains(
" " + w +
"\n") || text.contains(
"\n" + w +
"\n")
245 || text.contains(
"\n" + w +
" "))
247 this->Score += Configuration::LocalConfig_ScoreWords.at(xx).score;
248 ScoreWords.append(w);
256 if (this->PostProcessing)
260 this->PostProcessing =
true;
261 this->ProcessingQuery =
new ApiQuery();
262 this->ProcessingQuery->
SetAction(ActionQuery);
263 this->ProcessingQuery->
Parameters =
"prop=revisions&rvprop=" + QUrl::toPercentEncoding(
"timestamp|user|comment|content") +
"&titles=" +
268 this->ProcessingQuery->
Process();
269 this->DifferenceQuery =
new ApiQuery();
270 this->DifferenceQuery->
SetAction(ActionQuery);
271 if (this->
RevID != -1)
274 this->DifferenceQuery->
Parameters =
"prop=revisions&rvprop=" + QUrl::toPercentEncoding(
"ids|user|timestamp|comment" ) +
"&rvlimit=1&rvtoken=rollback&rvstartid=" +
275 QString::number(this->
RevID) +
"&rvdiffto=prev&titles=" +
279 this->DifferenceQuery->
Parameters =
"prop=revisions&rvprop=" + QUrl::toPercentEncoding(
"ids|user|timestamp|comment" ) +
"&rvlimit=1&rvtoken=rollback&rvdiffto=prev&titles=" +
286 this->DifferenceQuery->
Process();
287 this->ProcessingDiff =
true;
288 this->ProcessingRevs =
true;
294 "&diff=" + QString::number(this->
RevID);
299 if (this->Status == StatusPostProcessed)
306 QMutex ProcessorThread::EditLock(QMutex::Recursive);
307 QList<WikiEdit*> ProcessorThread::PendingEdits;
309 void ProcessorThread::run()
313 ProcessorThread::EditLock.lock();
315 while (e<ProcessorThread::PendingEdits.count())
317 this->Process(PendingEdits.at(e));
320 PendingEdits.clear();
321 ProcessorThread::EditLock.unlock();
322 QThread::usleep(200000);
326 void ProcessorThread::Process(
WikiEdit *edit)
331 edit->Score += Configuration::LocalConfig_IPScore;
335 edit->Score += Configuration::LocalConfig_BotScore;
337 if (edit->
Page->IsUserpage())
345 if (edit->
Size > 1200 || edit->
Size < -1200)
382 edit->PostProcessing =
false;
383 edit->ProcessedByWorkerThread =
true;
385 edit->Status = StatusPostProcessed;
395 QStringList sections;
396 int CurrentIndex = 0;
397 while (CurrentIndex < page.length())
399 if (!page.startsWith(
"==") && !page.contains(
"\n=="))
402 sections.append(page);
408 if (!page.startsWith(
"==") && page.contains(
"\n=="))
410 page = page.mid(page.indexOf(
"\n==") + 1);
415 if (!page.mid(CurrentIndex).contains(
"\n=="))
417 sections.append(page);
420 bottom = page.indexOf(
"\n==", CurrentIndex);
422 QString section = page.mid(0, bottom);
423 page = page.mid(bottom);
424 sections.append(section);
433 while (CurrentIndex < sections.count())
436 if (!sections.at(CurrentIndex).contains(
"(UTC)"))
439 page = page.replace(sections.at(CurrentIndex),
"");
443 QString section = sections.at(CurrentIndex);
444 section = section.mid(0, section.indexOf(
"(UTC)"));
445 if (section.endsWith(
" "))
448 section = section.mid(0, section.length() - 1);
451 if (!section.contains(
","))
454 page = page.replace(sections.at(CurrentIndex),
"");
459 QString time = section.mid(section.lastIndexOf(
","));
460 if (time.length() < 2)
463 page = page.replace(sections.at(CurrentIndex),
"");
470 QDate date = QDate::fromString(time,
"d MMMM yyyy");
473 page = page.replace(sections.at(CurrentIndex),
"");
479 if (QDate::currentDate().addDays(Configuration::LocalConfig_TemplateAge) > date)
482 page = page.replace(sections.at(CurrentIndex),
"");
495 while (xx<Configuration::LocalConfig_WarningDefs.count())
497 QString defs=Configuration::LocalConfig_WarningDefs.at(xx);
498 if (Core::GetKeyFromValue(defs).toInt() == level)
500 if (page.contains(Core::GetValueFromKey(defs)))
QString GetContentsOfTalkPage()
GetContentsOfTalkPage returns a precached content of this users talk page If there is a global instan...
static QString GetProjectScriptURL()
Return a script url like http://en.wikipedia.org/w/.
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.
bool IsTalk()
Return true in case this is a talk page.
virtual bool Processed()
Returns true in case that query is processed.
bool IsIP()
Returns true in case the current user is IP user.
void UnregisterConsumer(const int consumer)
This function will remove a string which prevent the object from being removed.
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...
QString Username
Username.
long getBadnessScore(bool _resync=true)
Retrieve a badness score for current user, see WikiUser::BadnessScore for more.
static bool TrimOldWarnings
This is experimental feature that removes the old templates from talk pages when they are being read...
static QList< WikiEdit * > EditList
This list contains reference to all existing edits in memory.
int Priority
Priority in queue.
int WarningLevel
Current warning level of user.
QString Summary
Summary of edit.
WarningLevel CurrentUserWarningLevel
Current warning level.
void PostProcess()
This function is called by internals of huggle.
bool EditMadeByHuggle
If this is true the edit was made by huggle.
bool IsPostProcessed()
Return true in case this edit was post processed already.
void SetAction(const Action action)
Change the action type.
WikiEdit()
Creates a new empty wiki edit.
bool Minor
Edit is a minor edit.
static int GetLevel(QString page)
Get a level of warning from talk page.
static int LocalConfig_ScoreChange
Score that is added for every edit that has really big size.
WikiUser * User
User who changed the page.
static bool Running
Change this to false when you want to terminate all threads properly (you will need to wait few ms) ...
static void DebugLog(QString Message, unsigned int Verbosity=1)
This log is only shown if verbosity is same or larger than requested verbosity.
QString GetFullUrl()
Return a full url to edit.
QString Parameters
Parameters for action, for example page title.
bool FinalizePostProcessing()
This function is called by core.
int Size
Size of change of edit.
QString GetTalk()
Return a link to talk page of this user (like User talk:Jimbo)
QString PageName
Name of page.
This class can be used to execute any kind of api query on any wiki.
bool Bot
Edit is a bot edit.
bool OwnEdit
Edit was made by you.
WikiPage * Page
Page that was changed by edit.
void SetContentsOfTalkPage(QString text)
SetContentsOfTalkPage Change a cache for talk page in local and global cache.
QString Data
Data retrieved by query.
QueryResult * Result
Result of query, see documentation of QueryResult for more.