File indexing completed on 2025-01-05 03:53:35

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2011-03-22
0007  * Description : a Iface C++ interface
0008  *
0009  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2011      by Alexandre Mendes <alex dot mendes1988 at gmail dot com>
0011  * SPDX-FileCopyrightText: 2011      by Hormiere Guillaume <hormiere dot guillaume at gmail dot com>
0012  * SPDX-FileCopyrightText: 2011      by Manuel Campomanes <campomanes dot manuel at gmail dot com>
0013  *
0014  * SPDX-License-Identifier: GPL-2.0-or-later
0015  *
0016  * ============================================================ */
0017 
0018 #ifndef DIGIKAM_MEDIAWIKI_EDIT_H
0019 #define DIGIKAM_MEDIAWIKI_EDIT_H
0020 
0021 // Qt includes
0022 
0023 #include <QDateTime>
0024 #include <QString>
0025 #include <QUrl>
0026 #include <QVariant>
0027 #include <QNetworkCookieJar>
0028 
0029 // Local includes
0030 
0031 #include "mediawiki_job.h"
0032 #include "mediawiki_queryinfo.h"
0033 
0034 namespace MediaWiki
0035 {
0036 
0037 class Iface;
0038 class EditPrivate;
0039 
0040 /**
0041  * @brief Edit job.
0042  *
0043  * Uses for create or edit a wiki.
0044  */
0045 class Edit : public Job
0046 {
0047     Q_OBJECT
0048     Q_DECLARE_PRIVATE(Edit)
0049 
0050 public:
0051 
0052     /**
0053      * @brief Indicates all possible error conditions found during the processing of the edit.
0054      */
0055     enum
0056     {
0057         /**
0058          * @brief Text is missing.
0059          */
0060         TextMissing = Job::UserDefinedError+1,
0061 
0062         /**
0063          * @brief The section is invalid.
0064          */
0065         InvalidSection,
0066 
0067         /**
0068          * @brief The page name is protected.
0069          */
0070         TitleProtected,
0071 
0072         /**
0073          * @brief The permission for create page is missing.
0074          */
0075         CreatePagePermissionMissing,
0076 
0077         /**
0078          * @brief The permission for create page is missing for anonymous.
0079          */
0080         AnonymousCreatePagePermissionMissing,
0081 
0082         /**
0083          * @brief The article already exist.
0084          */
0085         ArticleDuplication,
0086 
0087         /**
0088          * @brief The permission for create image is missing for anonymous.
0089          */
0090         AnonymousCreateImagePermissionMissing,
0091 
0092         /**
0093          * @brief The permission for create image is missing.
0094          */
0095         CreateImagePermissionMissing,
0096 
0097         /**
0098          * @brief The MediaWiki considers you are spamming.
0099          */
0100         SpamDetected,
0101 
0102         /**
0103          * @brief The MediaWiki refuses your edit.
0104          */
0105         Filtered,
0106 
0107         /**
0108          * @brief The size of the article exceed.
0109          */
0110         ArticleSizeExceed,
0111 
0112         /**
0113          * @brief The permission for edit page is missing for anonymous.
0114          */
0115         AnonymousEditPagePermissionMissing,
0116 
0117         /**
0118          * @brief The permission for edit page is missing.
0119          */
0120         EditPagePermissionMissing,
0121 
0122         /**
0123          * @brief The page is deleted.
0124          */
0125         PageDeleted,
0126 
0127         /**
0128          * @brief The page is empty.
0129          */
0130         EmptyPage,
0131 
0132         /**
0133          * @brief The section is empty.
0134          */
0135         EmptySection,
0136 
0137         /**
0138          * @brief Mediwiki detect an edit conflict.
0139          */
0140         EditConflict,
0141 
0142         /**
0143          * @brief The revision isn't a valid revision.
0144          */
0145         RevWrongPage,
0146 
0147         /**
0148          * @brief The undo failed.
0149          */
0150         UndoFailed
0151     };
0152 
0153     /**
0154      * @brief Specify how the watchlist is affected by this edit.
0155      */
0156     enum Watchlist
0157     {
0158         /**
0159          * @brief Add the page to the watchlist
0160          */
0161         watch,
0162 
0163         /**
0164          * @brief Remove the page from the watchlist
0165          */
0166         unwatch,
0167 
0168         /**
0169          * @brief Use the preference settings
0170          */
0171         preferences,
0172 
0173         /**
0174          * @brief Don't change the watchlist
0175          */
0176         nochange
0177     };
0178 
0179 public:
0180 
0181     /**
0182      * @brief Constructs an Edit job.
0183      * @param parent the QObject parent
0184      */
0185     explicit Edit(Iface& media, QObject* const parent = nullptr);
0186 
0187     /**
0188      * @brief Destroys the Edit job.
0189      */
0190     ~Edit() override;
0191 
0192     /**
0193      * @brief Starts the job asynchronously.
0194      */
0195     void start() override;
0196 
0197     /**
0198      * @brief Specify how the watchlist is affected by this edit.
0199      * @param watchlist Specify how the watchlist is affected by this edit
0200      */
0201     void setWatchList(Edit::Watchlist watchlist);
0202 
0203     /**
0204      * @brief If set, suppress errors about the page having been deleted in the meantime and recreate it.
0205      * @param recreate if set, suppress errors about the page having been deleted in the meantime and recreate it
0206      */
0207     void setRecreate(bool recreate);
0208 
0209     /**
0210      * @brief If set, throw an error if the page already exists.
0211      * @param if set, throw an error if the page already exists
0212      */
0213     void setCreateonly(bool createonly);
0214 
0215     /**
0216      * @brief If set, throw a missingtitle error if the page doesn't exist.
0217      * @param norecreate if set, throw a missingtitle error if the page doesn't exist
0218      */
0219     void setNocreate(bool norecreate);
0220 
0221     /**
0222      * @brief If set to true, mark the edit as minor
0223      * @param minor if set to true, mark the edit as minor
0224      */
0225     void setMinor(bool minor);
0226 
0227     /**
0228      * @brief Set the section.
0229      * @param section new section or integer
0230      */
0231     void setSection(const QString& section);
0232 
0233     /**
0234      * @brief Set the summary.
0235      * @param summary the summary
0236      */
0237     void setSummary(const QString& summary);
0238 
0239     /**
0240      * @brief Undo all revisions from undo to this one. If not set, just undo one revision.
0241      * @param undoafter if true set the undo after property
0242      */
0243     void setUndoAfter(int undoafter);
0244 
0245     /**
0246      * @brief Undo this revision. Overrides text, prependtext and appendtext.
0247      * @param undo if true set the undo
0248      */
0249     void setUndo(int undo);
0250 
0251     /**
0252      * @brief Set the text added to the beginning of the page. Overrides text.
0253      * @param prependText the text added to the beginning of the page
0254      */
0255     void setPrependText(const QString& prependText);
0256 
0257     /**
0258      * @brief Set the text added to the end of the page. Overrides text.
0259      * @param appendText the text added to the end of the page
0260      */
0261     void setAppendText(const QString& appendText);
0262 
0263     /**
0264      * @brief Set the page title.
0265      * @param pageName the page title
0266      */
0267     void setPageName(const QString& pageName);
0268 
0269     /**
0270      * @brief Set the edit token. Retrieve from QueryInfo.
0271      * @param token the edit token
0272      */
0273     void setToken(const QString& token);
0274 
0275     /**
0276      * @brief Set the timestamp of the base revision. Leave unset to ignore conflict.
0277      * @param baseTimestamp the timestamp of the base revision
0278      */
0279     void setBaseTimestamp(const QDateTime& baseTimestamp);
0280 
0281     /**
0282      * @brief Set the timestamp when you obtained the edit token.
0283      * @param startTimestamp the timestamp when you obtained the edit token
0284      */
0285     void setStartTimestamp(const QDateTime& startTimestamp);
0286 
0287     /**
0288      * @brief Set the page content.
0289      * @param text the page content.
0290      */
0291     void setText(const QString& text);
0292 
0293 Q_SIGNALS:
0294 
0295     /**
0296      * @brief Emit the captcha question.
0297      * @param captcha the captcha question
0298      */
0299     void resultCaptcha(const QVariant& captcha);
0300 
0301 private Q_SLOTS:
0302 
0303     void doWorkSendRequest(const Page& page);
0304     void finishedEdit();
0305 
0306 public Q_SLOTS:
0307 
0308     /**
0309      * @brief Put the captcha answer.
0310      * @param captcha the captcha answer
0311      */
0312     void finishedCaptcha(const QString& captcha);
0313 };
0314 
0315 } // namespace MediaWiki
0316 
0317 #endif // DIGIKAM_MEDIAWIKI_EDIT_H