Huggle  build:^490^dce1e5c
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
core.hpp
1 //This program is free software: you can redistribute it and/or modify
2 //it under the terms of the GNU General Public License as published by
3 //the Free Software Foundation, either version 3 of the License, or
4 //(at your option) any later version.
5 
6 //This program is distributed in the hope that it will be useful,
7 //but WITHOUT ANY WARRANTY; without even the implied warranty of
8 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 //GNU General Public License for more details.
10 
11 #ifndef CORE_H
12 #define CORE_H
13 
14 #include <iostream>
15 #include <QApplication>
16 #include <QNetworkAccessManager>
17 #include <QList>
18 #include <QString>
19 #include <QPluginLoader>
20 #include <QFile>
21 #include <QMap>
22 #include <QtXml>
23 #include <QMessageBox>
24 #include "query.hpp"
25 #include "login.hpp"
26 #include "configuration.hpp"
27 #include "wikiedit.hpp"
28 #include "mainwindow.hpp"
29 #include "exceptionwindow.hpp"
30 #include "message.hpp"
31 #include "iextension.hpp"
32 #include "hugglequeuefilter.hpp"
33 #include "editquery.hpp"
34 #include "history.hpp"
35 #include "apiquery.hpp"
36 #include "revertquery.hpp"
37 
38 #ifdef PYTHONENGINE
39 #include "pythonengine.h"
40 #endif
41 
42 namespace Huggle
43 {
44  // Predeclaring some types
45  class Login;
46  class Query;
47  class ApiQuery;
48  class MainWindow;
49  class HuggleFeed;
50  class EditQuery;
51  class ProcessorThread;
52  class Collectable;
53  class HuggleQueueFilter;
54  class WikiSite;
55  class WikiPage;
56  class OAuthLoginQuery;
57  class WikiUser;
58  class WikiEdit;
59  class RevertQuery;
60  class Message;
61  class iExtension;
62  class Configuration;
63 
64  /*!
65  * \brief This is a workaround that allow us to use sleep
66  */
67  class Sleeper : public QThread
68  {
69  public:
70  static void usleep(unsigned long usecs){QThread::usleep(usecs);}
71  static void msleep(unsigned long msecs){QThread::msleep(msecs);}
72  static void sleep(unsigned long secs){QThread::sleep(secs);}
73  };
74 
75  //! Overwrite of qapplication so that we can reimplement notify
76  class HgApplication : public QApplication
77  {
78  public:
79  HgApplication(int& argc, char** argv) :
80  QApplication(argc, argv) {}
81  bool notify(QObject* receiver, QEvent* event);
82  };
83 
84  /*!
85  * \brief The Language class
86  */
87  class Language
88  {
89  public:
90  //! Creates new instance of language
91  //! param name Name of language
92  Language(QString name);
93  //! This is a short language name which is used by system
94  QString LanguageName;
95  //! Long identifier of language that is seen by user
96  QString LanguageID;
97  QMap<QString, QString> Messages;
98  };
99 
100  /*!
101  * \brief Miscelanceous system functions, all of these functions are static
102  *
103  * Making any instance of this class is nonsense don't do it :D
104  */
105  class Core
106  {
107  public:
108  // Global variables
109  static QDateTime StartupTime;
110  //! Pointer to main
111  static MainWindow *Main;
112  //! Login form
113  static Login *f_Login;
114  //! This string contains a html header
115  static QString HtmlHeader;
116  //! This string contains a html footer
117  static QString HtmlFooter;
118  //! Pointer to primary feed provider
120  //! Pointer to secondary feed provider
122  //! This is a list of all edits that are being processed by some way
123  //! whole list needs to be checked and probed everytime once a while
124  static QList<WikiEdit*> ProcessingEdits;
125  //! Pending changes
126  static QList<EditQuery*> PendingMods;
127  //! List of extensions loaded in huggle
128  static QList<iExtension*> Extensions;
129  static QList<HuggleQueueFilter *> FilterDB;
130  //! Languages D:
131  static QList<Language*> LocalizationData;
132  //! Pointer to AIV page
133  static WikiPage *AIVP;
134  //! Pointer to UAA page
135  static WikiPage *UAAP;
136  //! Change this to false when you want to terminate all threads properly (you will need to wait few ms)
137  static bool Running;
138 
139 #ifdef PYTHONENGINE
140  static PythonEngine *Python;
141 #endif
142 
143  //! Function which is called as one of first when huggle is loaded
144  static void Init();
145  //! Write text to terminal as well as ring log
146  /*!
147  * \param Message Message to log
148  */
149  static void Log(QString Message);
150  //! Load extensions (libraries as well as python)
151  static void ExtensionLoad();
152  /*!
153  * \brief VersionRead - read the version from embedded git file
154  *
155  * This function may be called also from terminal parser
156  */
157  static void VersionRead();
158  //! This log is only shown if verbosity is same or larger than requested verbosity
159  static void DebugLog(QString Message, unsigned int Verbosity = 1);
160  //! Helper function that will return URL of project in question
161  /*!
162  * \param Project Site
163  * \return String with url
164  */
165  static QString GetProjectURL(WikiSite Project);
166  //! Return a full url like http://en.wikipedia.org/wiki/
167  static QString GetProjectWikiURL(WikiSite Project);
168  //! Return a script url like http://en.wikipedia.org/w/
169  static QString GetProjectScriptURL(WikiSite Project);
170  //! Return a base url of current project
171  static QString GetProjectURL();
172  //! Return a full url like http://en.wikipedia.org/wiki/
173  static QString GetProjectWikiURL();
174  //! Return a script url like http://en.wikipedia.org/w/
175  static QString GetProjectScriptURL();
176  static void ProcessEdit(WikiEdit *e);
177  //! Terminate the process, call this after you release all resources and finish all queries
178  static void Shutdown();
179  //! Return a ring log represented as 1 huge string
180  static QString RingLogToText();
181  /*!
182  * \brief Return a ring log as qstring list
183  * \return QStringList
184  */
185  static QStringList RingLogToQStringList();
186  static void InsertToRingLog(QString text);
187  //! Display a message box telling user that function is not allowed during developer mode
188  static void DeveloperError();
189  //! Check the edit summary and similar in order to
190  //! determine several edit attributes etc
191  static void PreProcessEdit(WikiEdit *_e);
192  //! Perform more expensive tasks to finalize
193  //! edit processing
194  static void PostProcessEdit(WikiEdit *_e);
195  //! Check if all running queries are finished and if so it removes them from list
196  static void CheckQueries();
197  //! Check if we can revert this edit
198  static bool PreflightCheck(WikiEdit *_e);
199  /*!
200  * \brief RevertEdit Reverts the edit
201  * \param _e Pointer to edit that needs to be reverted
202  * \param summary Summary to use if this is empty the default revert summary is used
203  * \param minor If revert should be considered as minor edit
204  * \param rollback If rollback feature should be used
205  * \param keep Whether the query produced by this function should not be automatically deleted
206  * \return Pointer to api query that executes this revert
207  */
208  static RevertQuery *RevertEdit(WikiEdit* _e, QString summary = "", bool minor = false, bool rollback = true, bool keep = false);
209  static void LoadDB();
210  //! Remove leading and finishing space of string
211  static QString Trim(QString text);
212  //! Remove edit in proper manner
213  static void DeleteEdit(WikiEdit *edit);
214  // the mess bellow exist because of a way how huggle config stores the lists
215  static QString GetSummaryOfWarningTypeFromWarningKey(QString key);
216  static QString GetNameOfWarningTypeFromWarningKey(QString key);
217  static QString GetKeyOfWarningTypeFromWarningName(QString id);
218  //! Parse a part patterns for score words
219  static void ParsePats(QString text);
220  //! Load a definitions of problematic users, see WikiUser::ProblematicUsers for details
221  static void LoadDefs();
222  //! Store a definitions of problematic users, see WikiUser::ProblematicUsers for details
223  static void SaveDefs();
224  static QString GetValueFromKey(QString item);
225  static QString GetKeyFromValue(QString item);
226  static void ParseWords(QString text);
227  /*!
228  * \brief MessageUser Message user
229  * \param user Pointer to user
230  * \param message Text of message
231  * \param title Title
232  * \param summary Summary
233  * \param section Whether this message should be created in a new section
234  * \param dependency Query that is used as a dependency, if it's not NULL
235  * the system will wait for it to finish before the message is sent
236  * \return
237  */
238  static Message *MessageUser(WikiUser *user, QString message, QString title, QString summary, bool section = true, Query *dependency = NULL);
239  static void FinalizeMessages();
240  static QString RetrieveTemplateToWarn(QString type);
241  static EditQuery *EditPage(WikiPage *page, QString text, QString summary = "Edited using huggle", bool minor = false);
242  /*!
243  * \brief Insert a query to internal list of running queries, so that they can be watched
244  * This will insert it to a process list in main form
245  * \param item Query that is about to be inserted to list of running queries
246  */
247  static void AppendQuery(Query* item);
248  static void ExceptionHandler(Exception *exception);
249  static QString Localize(QString key);
250  static void LoadLocalizations();
251  static bool ReportPreFlightCheck();
252  static int RunningQueriesGetCount();
253  private:
254  //! List of all running queries
255  static QList<Query*> RunningQueries;
256  //! Ring log is a buffer that contains system messages
257  static QStringList RingLog;
258  //! This is a post-processor for edits
260  //! List of all messages that are being sent
261  static QList<Message*> Messages;
262  Core() { }
263  /*!
264  * \brief Initializes a localization with given name
265  *
266  * This function will create a new localization object using built-in localization file
267  * using Core::MakeLanguage() and insert that to language list
268  * \param name Name of a localization that is a name of language without txt suffix in localization folder
269  */
270  static void LocalInit(QString name);
271  static Language *MakeLanguage(QString text, QString name);
272  };
273 }
274 
275 #endif // CORE_H
static QString GetProjectScriptURL()
Return a script url like http://en.wikipedia.org/w/.
Definition: core.cpp:674
static QString GetProjectWikiURL()
Return a full url like http://en.wikipedia.org/wiki/.
Definition: core.cpp:669
Primary huggle window.
Definition: mainwindow.hpp:110
static WikiPage * AIVP
Pointer to AIV page.
Definition: core.hpp:133
static void Log(QString Message)
Write text to terminal as well as ring log.
Definition: core.cpp:563
The Language class.
Definition: core.hpp:87
static WikiPage * UAAP
Pointer to UAA page.
Definition: core.hpp:135
static void SaveDefs()
Store a definitions of problematic users, see WikiUser::ProblematicUsers for details.
Definition: core.cpp:312
static QString HtmlHeader
This string contains a html header.
Definition: core.hpp:115
static QString GetProjectURL()
Return a base url of current project.
Definition: core.cpp:664
static void PostProcessEdit(WikiEdit *_e)
Definition: core.cpp:774
static QString RingLogToText()
Return a ring log represented as 1 huge string.
Definition: core.cpp:712
static QString HtmlFooter
This string contains a html footer.
Definition: core.hpp:117
Feed provider stub class every provider must be derived from this one.
Definition: hugglefeed.hpp:22
Language(QString name)
Definition: core.cpp:1043
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...
Definition: core.cpp:557
The RevertQuery class can be used to rollback any edit.
Definition: revertquery.hpp:32
static void VersionRead()
VersionRead - read the version from embedded git file.
Definition: core.cpp:627
static Message * MessageUser(WikiUser *user, QString message, QString title, QString summary, bool section=true, Query *dependency=NULL)
MessageUser Message user.
Definition: core.cpp:427
QString LanguageName
This is a short language name which is used by system.
Definition: core.hpp:94
static QList< EditQuery * > PendingMods
Pending changes.
Definition: core.hpp:126
static ProcessorThread * Processor
This is a post-processor for edits.
Definition: core.hpp:259
Overwrite of qapplication so that we can reimplement notify.
Definition: core.hpp:76
static void DeleteEdit(WikiEdit *edit)
Remove edit in proper manner.
Definition: core.cpp:178
static void CheckQueries()
Check if all running queries are finished and if so it removes them from list.
Definition: core.cpp:786
Window that is displayed as first when huggle is started.
Definition: login.hpp:56
This is similar to query, just it&#39;s more simple, you can use it to deliver messages to users...
Definition: message.hpp:26
static HuggleFeed * SecondaryFeedProvider
Pointer to secondary feed provider.
Definition: core.hpp:121
static void Shutdown()
Terminate the process, call this after you release all resources and finish all queries.
Definition: core.cpp:684
Mediawiki page.
Definition: wikipage.hpp:43
Edits are post processed in this thread.
Definition: wikiedit.hpp:50
static RevertQuery * RevertEdit(WikiEdit *_e, QString summary="", bool minor=false, bool rollback=true, bool keep=false)
RevertEdit Reverts the edit.
Definition: core.cpp:855
static void PreProcessEdit(WikiEdit *_e)
Definition: core.cpp:747
static HuggleFeed * PrimaryFeedProvider
Pointer to primary feed provider.
Definition: core.hpp:119
static void LocalInit(QString name)
Initializes a localization with given name.
Definition: core.cpp:937
Miscelanceous system functions, all of these functions are static.
Definition: core.hpp:105
Every exception raised by huggle is defined by this class.
Definition: exception.hpp:20
static void Init()
Function which is called as one of first when huggle is loaded.
Definition: core.cpp:41
static void DeveloperError()
Display a message box telling user that function is not allowed during developer mode.
Definition: core.cpp:738
Modifications of mediawiki pages can be done using this query.
Definition: editquery.hpp:25
static QList< WikiEdit * > ProcessingEdits
Definition: core.hpp:124
static QList< Query * > RunningQueries
List of all running queries.
Definition: core.hpp:255
static bool Running
Change this to false when you want to terminate all threads properly (you will need to wait few ms) ...
Definition: core.hpp:137
static void DebugLog(QString Message, unsigned int Verbosity=1)
This log is only shown if verbosity is same or larger than requested verbosity.
Definition: core.cpp:641
static void ParsePats(QString text)
Parse a part patterns for score words.
Definition: core.cpp:251
static QList< Message * > Messages
List of all messages that are being sent.
Definition: core.hpp:261
static QList< iExtension * > Extensions
List of extensions loaded in huggle.
Definition: core.hpp:128
This is a workaround that allow us to use sleep.
Definition: core.hpp:67
static QStringList RingLog
Ring log is a buffer that contains system messages.
Definition: core.hpp:257
static QList< Language * > LocalizationData
Languages D:
Definition: core.hpp:131
static void ExtensionLoad()
Load extensions (libraries as well as python)
Definition: core.cpp:576
static Login * f_Login
Login form.
Definition: core.hpp:113
Wiki edit.
Definition: wikiedit.hpp:67
static QStringList RingLogToQStringList()
Return a ring log as qstring list.
Definition: core.cpp:724
QString LanguageID
Long identifier of language that is seen by user.
Definition: core.hpp:96
static bool PreflightCheck(WikiEdit *_e)
Check if we can revert this edit.
Definition: core.cpp:835
static MainWindow * Main
Pointer to main.
Definition: core.hpp:111
static QString Trim(QString text)
Remove leading and finishing space of string.
Definition: core.cpp:164
static void LoadDefs()
Load a definitions of problematic users, see WikiUser::ProblematicUsers for details.
Definition: core.cpp:446
Query base class for all http queries executed by huggle.
Definition: query.hpp:64