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