Huggle  build:^490^dce1e5c
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
wikiuser.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 WIKIUSER_H
12 #define WIKIUSER_H
13 
14 #include <QList>
15 #include <QMutex>
16 #include <QString>
17 #include <QRegExp>
18 
19 #include "configuration.hpp"
20 #include "wikiedit.hpp"
21 
22 namespace Huggle
23 {
24  class WikiEdit;
25 
26  //! User
27  class WikiUser
28  {
29  public:
30  /*!
31  * \brief List of users that are scored in this instance of huggle
32  *
33  * Either vandals or even good users, this list is preserved on shutdown and startup
34  */
35  static QList<WikiUser*> ProblematicUsers;
36  //! Update a list of problematic users
37  static void UpdateUser(WikiUser *us);
38  /*!
39  * \brief Function that return static version of this user
40  *
41  * In case the user in question is already in list of problematic users, this function
42  * will return its instance. It compares the username against the usernames that
43  * are in this list.
44  * \param user
45  * \return static user from list of problematic users
46  */
47  static WikiUser *RetrieveUser(WikiUser *user);
48  static QMutex ProblematicUserListLock;
49  //! Delete all users that have badness score 0 these users aren't necessary to be stored in a list
50  static void TrimProblematicUsersList();
51  //! Username
52  QString Username;
53  //! Current warning level of user
55  /*!
56  * \brief GetContentsOfTalkPage returns a precached content of this users talk page
57  * If there is a global instance of this user, the talk page is retrieved from it
58  * so that in case there are multiple instances of this user, they all share same
59  * cached talk page.
60  *
61  * Because this function needs to obtain the user from global cache it may be slow,
62  * in case you need to use its value multiple times, cache it as QString instead
63  * of calling this function repeatedly
64  * \return a precached content of this users talk page
65  */
66  QString GetContentsOfTalkPage();
67  /*!
68  * \brief SetContentsOfTalkPage Change a cache for talk page in local and global cache
69  * \param text New content of talk page
70  */
71  void SetContentsOfTalkPage(QString text);
72  //! Local cache that holds information if user is reported or not. This information
73  //! may be wrong, don't relly on it
74  bool IsReported;
75  //! Call UpdateUser on current user
76  void Update(bool MatchingOnly = false);
77  //! Cache of contributions made by this user
78  QList<WikiEdit*> Contributions;
79  /*!
80  * \brief Change the IP property to true forcefully even if user isn't IP
81  */
82  void ForceIP();
83  //! Returns true in case the current user is IP user
84  bool IsIP();
85  WikiUser();
86  WikiUser(WikiUser *u);
87  WikiUser(const WikiUser& u);
88  WikiUser(QString user);
89  ~WikiUser();
90  //! Update the information of this user based on global user list
91 
92  //! This is useful when you created user in past and since then a global user has changed
93  //! so that you just call this to refresh all the scores and information or stuff
94  void Resync();
95  //! Return a link to talk page of this user (like User talk:Jimbo)
96  QString GetTalk();
97  //! Returns true if this user is wl
98  bool IsWhitelisted();
99  //! Retrieve a badness score for current user, see WikiUser::BadnessScore for more
100  long getBadnessScore(bool _resync = true);
101  void setBadnessScore(long value);
102  //! Flags
103 
104  //! w - is warned
105  //! r - is reported
106  //! T- has talkpage
107  //! R - is registered
108  //! E - exception
109  QString Flags();
110  bool GetBot() const;
111  void SetBot(bool value);
112 
113  private:
114  /*!
115  * \brief Badness score of current user
116  *
117  * This score change the badness score of edit, score can be positive (bad) as well as negative
118  * in case you want to change the score, don't forget to call WikiUser::UpdateUser(WikiUser *user)
119  */
121  //! Matches only IPv4
122  static QRegExp IPv4Regex;
123  //! Matches all IP
124  static QRegExp IPv6Regex;
125  int WhitelistInfo;
126  //! In case that we retrieved the talk page during parse of warning level, this string contains it
128  QMutex *UserLock;
129  bool Bot;
130  bool IP;
131  };
132 }
133 
134 #endif // WIKIUSER_H
QString GetContentsOfTalkPage()
GetContentsOfTalkPage returns a precached content of this users talk page If there is a global instan...
Definition: wikiuser.cpp:191
long BadnessScore
Badness score of current user.
Definition: wikiuser.hpp:120
void Update(bool MatchingOnly=false)
Call UpdateUser on current user.
Definition: wikiuser.cpp:220
bool IsIP()
Returns true in case the current user is IP user.
Definition: wikiuser.cpp:240
QString Username
Username.
Definition: wikiuser.hpp:52
long getBadnessScore(bool _resync=true)
Retrieve a badness score for current user, see WikiUser::BadnessScore for more.
Definition: wikiuser.cpp:271
static QRegExp IPv4Regex
Matches only IPv4.
Definition: wikiuser.hpp:122
static WikiUser * RetrieveUser(WikiUser *user)
Function that return static version of this user.
Definition: wikiuser.cpp:22
int WarningLevel
Current warning level of user.
Definition: wikiuser.hpp:54
void Resync()
Update the information of this user based on global user list.
Definition: wikiuser.cpp:174
QString Flags()
Flags.
Definition: wikiuser.cpp:286
bool IsWhitelisted()
Returns true if this user is wl.
Definition: wikiuser.cpp:250
static QList< WikiUser * > ProblematicUsers
List of users that are scored in this instance of huggle.
Definition: wikiuser.hpp:35
QString ContentsOfTalkPage
In case that we retrieved the talk page during parse of warning level, this string contains it...
Definition: wikiuser.hpp:127
static QRegExp IPv6Regex
Matches all IP.
Definition: wikiuser.hpp:124
QList< WikiEdit * > Contributions
Cache of contributions made by this user.
Definition: wikiuser.hpp:78
void ForceIP()
Change the IP property to true forcefully even if user isn&#39;t IP.
Definition: wikiuser.cpp:235
QString GetTalk()
Return a link to talk page of this user (like User talk:Jimbo)
Definition: wikiuser.cpp:245
static void TrimProblematicUsersList()
Delete all users that have badness score 0 these users aren&#39;t necessary to be stored in a list...
Definition: wikiuser.cpp:40
void SetContentsOfTalkPage(QString text)
SetContentsOfTalkPage Change a cache for talk page in local and global cache.
Definition: wikiuser.cpp:212
static void UpdateUser(WikiUser *us)
Update a list of problematic users.
Definition: wikiuser.cpp:59