File indexing completed on 2024-04-14 14:55:12

0001 /** ===========================================================
0002  * @file
0003  *
0004  * This file is a part of KDE project
0005  * <a href="https://commits.kde.org/libmediawiki">libmediawiki</a>
0006  *
0007  * @date   2011-03-22
0008  * @brief  a MediaWiki C++ interface for KDE
0009  *
0010  * @author Copyright (C) 2011-2013 by Gilles Caulier
0011  *         <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a>
0012  * @author Copyright (C) 2011 by Manuel Campomanes
0013  *         <a href="mailto:campomanes dot manuel at gmail dot com">campomanes dot manuel at gmail dot com</a>
0014  * @author Copyright (C) 2010 by Hormiere Guillaume
0015  *         <a href="mailto:hormiere dot guillaume at gmail dot com">hormiere dot guillaume at gmail dot com</a>
0016  *
0017  * This program is free software; you can redistribute it
0018  * and/or modify it under the terms of the GNU General
0019  * Public License as published by the Free Software Foundation;
0020  * either version 2, or (at your option)
0021  * any later version.
0022  *
0023  * This program is distributed in the hope that it will be useful,
0024  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0025  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0026  * GNU General Public License for more details.
0027  *
0028  * ============================================================ */
0029 
0030 #ifndef QUERYREVISION_H
0031 #define QUERYREVISION_H
0032 
0033 // Qt includes
0034 
0035 #include <QDateTime>
0036 #include <QList>
0037 #include <QString>
0038 
0039 // Local includes
0040 
0041 #include "job.h"
0042 #include "revision.h"
0043 #include "mediawiki_export.h"
0044 
0045 namespace mediawiki
0046 {
0047 
0048 class MediaWiki;
0049 class QueryRevisionPrivate;
0050 
0051 /**
0052  * @brief QueryRevision job.
0053  *
0054  * Uses for fetch a revision information about one pages of the wiki.
0055  */
0056 class MEDIAWIKI_EXPORT QueryRevision : public Job
0057 {
0058     Q_OBJECT
0059     Q_DECLARE_PRIVATE(QueryRevision)
0060 
0061 public:
0062 
0063     /**
0064      * @brief Direction to list revisions.
0065      */
0066     enum Direction
0067     {
0068         /**
0069          * @brief List newest revisions first.
0070          */
0071         Older,
0072 
0073         /**
0074          * @brief List oldest revisions first.
0075          */
0076         Newer
0077     };
0078 
0079     /**
0080      * @brief Tokens can get for each revision.
0081      */
0082     enum Token
0083     {
0084         /**
0085          * @brief Rollback token.
0086          */
0087         Rollback
0088     };
0089 
0090     /**
0091      * @brief Indicates all possible error conditions found during the processing of the job.
0092      */
0093     enum
0094     {
0095         /**
0096          * @brief The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).
0097          */
0098         WrongRevisionId = Job::UserDefinedError + 1,
0099 
0100         /**
0101          * @brief titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.
0102          */
0103         MultiPagesNotAllowed,
0104 
0105         /**
0106          * @brief The current user is not allowed to read title.
0107          */
0108         TitleAccessDenied,
0109 
0110         /**
0111          * @brief start and startid or end and endid or user and excludeuser cannot be used together
0112          */
0113         TooManyParams,
0114 
0115         /**
0116          * @brief There is no section section in rrevid
0117          */
0118         SectionNotFound
0119     };
0120 
0121     /**
0122      * @brief Property.
0123      */
0124     enum Property
0125     {
0126         Ids         = 0x01,
0127         Flags       = 0x02,
0128         Timestamp   = 0x04,
0129         User        = 0x08,
0130         Comment     = 0x10,
0131         Size        = 0x20,
0132         Content     = 0x40
0133     };
0134     Q_DECLARE_FLAGS(Properties, Property)
0135 
0136 public:
0137 
0138     /**
0139      * @brief Constructs a Revision job.
0140      * @param mediawiki the mediawiki concerned by the job
0141      * @param parent the QObject parent
0142      */
0143     explicit QueryRevision(MediaWiki& mediawiki, QObject* const parent = nullptr);
0144 
0145     /**
0146      * @brief Destroys the QueryRevision job.
0147      */
0148     ~QueryRevision() override;
0149 
0150     /**
0151      * @brief Starts the job asynchronously.
0152      */
0153     void start() override;
0154 
0155     /**
0156      * @brief Set the page id.
0157      * @param pageId the page id
0158      */
0159     void setPageId(unsigned int pageId);
0160 
0161     /**
0162      * @param Set the revision id.
0163      * @param revisionId the revision id
0164      */
0165     void setRevisionId(unsigned int revisionId);
0166 
0167     /**
0168      * @brief Set the page name.
0169      * @param pageName the page name
0170      */
0171     void setPageName(const QString& pageName);
0172 
0173     /**
0174      * @brief Which properties to get for each revision.
0175      * @param properties properties to get for each revision
0176      */
0177     void setProperties(Properties properties);
0178 
0179     /**
0180      * @brief Set the maximum number of revisions to return.
0181      * @param limit the maximum number of revisions to return
0182      */
0183     void setLimit(int limit);
0184 
0185     /**
0186      * @brief Set the revision ID to start listing from.
0187      * @param startId the revision ID to start listing from
0188      */
0189     void setStartId(int startId);
0190 
0191     /**
0192      * @brief Set the revision ID to stop listing at.
0193      * @param endId the revision ID to stop listing at
0194      */
0195     void setEndId(int endId);
0196 
0197     /**
0198      * @brief Set the timestamp to start listing from.
0199      * @param start the timestamp to start listing from
0200      */
0201     void setStartTimestamp(const QDateTime& start);
0202 
0203     /**
0204      * @brief Set the timestamp to end listing at.
0205      * @param end the timestamp to end listing at
0206      */
0207     void setEndTimestamp(const QDateTime& end);
0208 
0209     /**
0210      * @brief Set the user.
0211      *
0212      * Do list revisions made by this user.
0213      *
0214      * @param user the user
0215      */
0216     void setUser(const QString& user);
0217 
0218     /**
0219      * @brief Set the user to exclude.
0220      *
0221      * Do not list revisions made by this user
0222      *
0223      * @param excludeUser the user to exclude
0224      */
0225     void setExcludeUser(const QString& excludeUser);
0226 
0227     /**
0228      * @brief Set the direction to list revisions.
0229      * @param direction the direction to list revisions
0230      */
0231     void setDirection(QueryRevision::Direction direction);
0232 
0233     /**
0234      * @brief Set XML generation to parse tree for revision content.
0235      * @param generateXML if true set XML generation to parse tree for revision content
0236      */
0237     void setGenerateXML(bool generateXML);
0238 
0239     /**
0240      * @brief Set the section.
0241      *
0242      * If the property content is set, only retrieve the contents of this section.
0243      *
0244      * @param section the section
0245      */
0246     void setSection(int section);
0247 
0248     /**
0249      * @brief Set the token to get for each revision.
0250      * @param token the token to get for each revision
0251      */
0252     void setToken(QueryRevision::Token token);
0253 
0254     /**
0255      * @brief Set expand templates.
0256      *
0257      * Only if the property content is set.
0258      *
0259      * @param expandTemplates if true set expand templates
0260      */
0261     void setExpandTemplates(bool expandTemplates);
0262 
0263 Q_SIGNALS:
0264 
0265     /**
0266      * @brief Provides a list of all user groups.
0267      * @param revision list of all user groups
0268      */
0269     void revision(const QList<Revision>& revision);
0270 
0271 private Q_SLOTS:
0272 
0273     void doWorkSendRequest();
0274     void doWorkProcessReply();
0275 };
0276 
0277 Q_DECLARE_OPERATORS_FOR_FLAGS(QueryRevision::Properties)
0278 
0279 } // namespace mediawiki
0280 
0281 #endif //QUERYREVISION_H