Index: branches/apiedit/phase3/includes/Article.php |
— | — | @@ -37,6 +37,19 @@ |
38 | 38 | /**@}}*/ |
39 | 39 | |
40 | 40 | /** |
| 41 | + * Constants used by internal components to get rollback results |
| 42 | + */ |
| 43 | + const SUCCESS = 0; |
| 44 | + const PERM_DENIED = 1; // Permission denied |
| 45 | + const BLOCKED = 2; // User has been blocked |
| 46 | + const READONLY = 3; // Wiki is in read-only mode |
| 47 | + const BAD_TOKEN = 4; // Invalid token specified |
| 48 | + const BAD_TITLE = 5; // $this is not a valid Article |
| 49 | + const ALREADYROLLED = 6;// Someone else already rolled this back. $info['usertext'] and $info['comment'] will be set |
| 50 | + const ONLY_AUTHOR = 7; // User is the only author of the page |
| 51 | + const EDIT_FAILED = 8; // Article::doEdit() failed. This is a very weird error |
| 52 | + |
| 53 | + /** |
41 | 54 | * Constructor and clear the article |
42 | 55 | * @param $title Reference to a Title object. |
43 | 56 | * @param $oldId Integer revision ID, null to fetch from request, zero for current |
— | — | @@ -2161,34 +2174,40 @@ |
2162 | 2175 | * @param bool $bot - If true, mark all reverted edits as bot. |
2163 | 2176 | * @param string $summary - Custom summary. Set to default summary if empty. |
2164 | 2177 | * @param array $info - Reference to associative array that will be set to contain the revision ID, edit summary, etc. |
2165 | | - * @return ROLLBACK_SUCCES on succes, ROLLBACK_* on failure |
| 2178 | + * @return self::SUCCESS on succes, self::* on failure |
2166 | 2179 | */ |
2167 | | - public function doRollback($user, $token, $bot = false, $summary = "", &$info = NULL) |
2168 | | - { |
| 2180 | + public function doRollback($user, $token, $bot = false, $summary = "", &$info = NULL) { |
2169 | 2181 | global $wgUser, $wgUseRCPatrol; |
2170 | | - if(!$wgUser->isAllowed('rollback')) |
2171 | | - return ROLLBACK_PERM; |
2172 | | - if($wgUser->isBlocked()) |
2173 | | - return ROLLBACK_BLOCKED; |
2174 | | - if(wfReadOnly()) |
2175 | | - return ROLLBACK_READONLY; |
| 2182 | + |
| 2183 | + if(!$wgUser->isAllowed('rollback')) { |
| 2184 | + return self::PERM_DENIED; |
| 2185 | + } |
| 2186 | + if( $wgUser->isBlocked() ) { |
| 2187 | + return self::BLOCKED; |
| 2188 | + } |
| 2189 | + if ( wfReadOnly() ) { |
| 2190 | + return self::READONLY; |
| 2191 | + } |
2176 | 2192 | |
2177 | 2193 | // Check token first |
2178 | | - if(!$wgUser->matchEditToken($token, array($this->mTitle->getPrefixedText(), $user))) |
2179 | | - return ROLLBACK_BADTOKEN; |
| 2194 | + if( !$wgUser->matchEditToken( $token, |
| 2195 | + array( $this->mTitle->getPrefixedText(), |
| 2196 | + $user ) ) ) { |
| 2197 | + return self::BAD_TOKEN; |
| 2198 | + } |
| 2199 | + $dbw = wfGetDB( DB_MASTER ); |
2180 | 2200 | |
2181 | | - $dbw = wfGetDB(DB_MASTER); |
2182 | 2201 | $current = Revision::newFromTitle($this->mTitle); |
2183 | 2202 | if(is_null($current)) |
2184 | | - return ROLLBACK_BADARTICLE; |
| 2203 | + return self::BAD_TITLE; |
2185 | 2204 | |
2186 | 2205 | // Check if someone else was there first |
2187 | | - if($user != $current->getUserText()) |
2188 | | - { |
| 2206 | + if( $user != $current->getUserText() ) { |
2189 | 2207 | $info['usertext'] = $current->getUserText(); |
2190 | 2208 | $info['comment'] = $current->getComment(); |
2191 | | - return ROLLBACK_ALREADYROLLED; |
| 2209 | + return self::ALREADYROLLED; |
2192 | 2210 | } |
| 2211 | + |
2193 | 2212 | // Get the last edit not by $user |
2194 | 2213 | $userid = intval($current->getUser()); |
2195 | 2214 | $s = $dbw->selectRow('revision', |
— | — | @@ -2199,26 +2218,35 @@ |
2200 | 2219 | ), __METHOD__, |
2201 | 2220 | array( |
2202 | 2221 | 'USE INDEX' => 'page_timestamp', |
2203 | | - 'ORDER BY' => 'rev_timestamp DESC' |
2204 | | - )); |
2205 | | - if($s === false) |
2206 | | - return ROLLBACK_ONLYAUTHOR; |
| 2222 | + 'ORDER BY' => 'rev_timestamp DESC' ) |
| 2223 | + ); |
| 2224 | + if( $s === false ) { |
| 2225 | + # Something wrong |
| 2226 | + return self::ONLY_AUTHOR; |
| 2227 | + } |
| 2228 | + |
2207 | 2229 | $target = Revision::newFromID($s->rev_id); |
2208 | 2230 | |
2209 | 2231 | // If the reverted edits should be marked bot or patrolled, do so |
2210 | 2232 | $set = array(); |
2211 | | - if($bot) |
| 2233 | + if ( $bot ) { |
| 2234 | + # Mark all reverted edits as bot |
2212 | 2235 | $set['rc_bot'] = 1; |
2213 | | - if($wgUseRCPatrol) |
| 2236 | + } |
| 2237 | + if ( $wgUseRCPatrol ) { |
| 2238 | + # Mark all reverted edits as patrolled |
2214 | 2239 | $set['rc_patrolled'] = 1; |
2215 | | - if($set) |
2216 | | - $dbw->update('recentchanges', $set, |
2217 | | - array( |
| 2240 | + } |
| 2241 | + |
| 2242 | + if ( $set ) { |
| 2243 | + $dbw->update( 'recentchanges', $set, |
| 2244 | + array( /* WHERE */ |
2218 | 2245 | 'rc_cur_id' => $current->getPage(), |
2219 | 2246 | 'rc_user_text' => $user, |
2220 | 2247 | "rc_timestamp > '{$s->rev_timestamp}'" |
2221 | 2248 | ), __METHOD__ |
2222 | 2249 | ); |
| 2250 | + } |
2223 | 2251 | |
2224 | 2252 | // Generate an edit summary |
2225 | 2253 | if(empty($summary)) |
— | — | @@ -2229,11 +2257,11 @@ |
2230 | 2258 | if($bot) |
2231 | 2259 | $flags |= EDIT_FORCE_BOT; |
2232 | 2260 | if(!$this->doEdit($target->getText(), $summary, $flags)) |
2233 | | - return ROLLBACK_EDITFAILED; |
| 2261 | + return self::EDIT_FAILED; |
2234 | 2262 | |
2235 | 2263 | if(is_null($info)) |
2236 | 2264 | // Save time |
2237 | | - return ROLLBACK_SUCCESS; |
| 2265 | + return self::SUCCESS; |
2238 | 2266 | |
2239 | 2267 | $info['title'] = $this->mTitle->getPrefixedText(); |
2240 | 2268 | $info['pageid'] = $current->getPage(); |
— | — | @@ -2247,7 +2275,7 @@ |
2248 | 2276 | $info['to'] = $target->getUserText(); // The user whose last version was reverted to |
2249 | 2277 | if($bot) |
2250 | 2278 | $info['bot'] = ""; |
2251 | | - return ROLLBACK_SUCCESS; |
| 2279 | + return self::SUCCESS; |
2252 | 2280 | } |
2253 | 2281 | |
2254 | 2282 | /** UI entry point for rollbacks. Relies on doRollback() to do the hard work */ |
— | — | @@ -2260,31 +2288,31 @@ |
2261 | 2289 | $wgRequest->getText('summary'), &$info); |
2262 | 2290 | switch($retval) |
2263 | 2291 | { |
2264 | | - case ROLLBACK_SUCCESS: |
2265 | | - case ROLLBACK_EDITFAILED: // Is ignored |
| 2292 | + case self::SUCCESS: |
| 2293 | + case self::EDIT_FAILED: // Is ignored |
2266 | 2294 | $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) ); |
2267 | 2295 | $wgOut->setRobotpolicy( 'noindex,nofollow' ); |
2268 | 2296 | $wgOut->addHTML( '<h2>' . htmlspecialchars( $info['summary'] ) . "</h2>\n<hr />\n" ); |
2269 | 2297 | $this->doRedirect(true); |
2270 | 2298 | $wgOut->returnToMain(false); |
2271 | 2299 | return; |
2272 | | - case ROLLBACK_PERM: |
| 2300 | + case self::PERM_DENIED: |
2273 | 2301 | $wgOut->permissionRequired('rollback'); |
2274 | 2302 | return; |
2275 | | - case ROLLBACK_BLOCKED: |
| 2303 | + case self::BLOCKED: |
2276 | 2304 | $wgOut->blockedPage(); |
2277 | 2305 | return; |
2278 | | - case ROLLBACK_READONLY: |
| 2306 | + case self::READONLY: |
2279 | 2307 | $wgOut->readOnlyPage($this->getContent()); |
2280 | 2308 | return; |
2281 | | - case ROLLBACK_BADTOKEN: |
| 2309 | + case self::BAD_TOKEN: |
2282 | 2310 | $wgOut->setPageTitle(wfMsg('rollbackfailed')); |
2283 | 2311 | $wgOut->addWikiText(wfMsg('sessionfailure')); |
2284 | 2312 | return; |
2285 | | - case ROLLBACK_BADARTICLE: |
| 2313 | + case self::BAD_TITLE: |
2286 | 2314 | $wgOut->addHTML(wfMsg('notanarticle')); |
2287 | 2315 | return; |
2288 | | - case ROLLBACK_ALREADYROLLED: |
| 2316 | + case self::ALREADYROLLED: |
2289 | 2317 | $wgOut->setPageTitle(wfMsg('rollbackfailed')); |
2290 | 2318 | $wgOut->addWikiText(wfMsg('alreadyrolled', |
2291 | 2319 | htmlspecialchars($this->mTitle->getPrefixedText()), |
— | — | @@ -2294,7 +2322,7 @@ |
2295 | 2323 | $wgOut->addHTML(wfMsg('editcomment', |
2296 | 2324 | $wgUser->getSkin()->formatComment($info['comment']))); |
2297 | 2325 | return; |
2298 | | - case ROLLBACK_ONLYAUTHOR: |
| 2326 | + case self::ONLY_AUTHOR: |
2299 | 2327 | $wgOut->setPageTitle(wfMsg('rollbackfailed')); |
2300 | 2328 | $wgOut->addHTML(wfMsg('cantrollback')); |
2301 | 2329 | return; |
Index: branches/apiedit/phase3/includes/api/ApiRollback.php |
— | — | @@ -67,29 +67,29 @@ |
68 | 68 | |
69 | 69 | switch($retval) |
70 | 70 | { |
71 | | - case ROLLBACK_SUCCESS: |
| 71 | + case Article::SUCCESS: |
72 | 72 | break; // We'll deal with that later |
73 | | - case ROLLBACK_PERM: |
74 | | - $this->dieUsage('You don\'t have permission to rollback', 'permissiondenied'); |
75 | | - case ROLLBACK_BLOCKED: // If we get BLOCKED or PERM that's very weird, but it's possible |
| 73 | + case Article::PERM_DENIED: |
| 74 | + $this->dieUsage("You don't have permission to rollback", 'permissiondenied'); |
| 75 | + case Article::BLOCKED: // If we get BLOCKED or PERM_DENIED that's very weird, but it's possible |
76 | 76 | $this->dieUsage('You have been blocked from editing', 'blocked'); |
77 | | - case ROLLBACK_READONLY: |
| 77 | + case Article::READONLY: |
78 | 78 | $this->dieUsage('The wiki is in read-only mode', 'readonly'); |
79 | | - case ROLLBACK_BADTOKEN: |
| 79 | + case Article::BAD_TOKEN: |
80 | 80 | $this->dieUsage('Invalid token', 'badtoken'); |
81 | | - case ROLLBACK_BADARTICLE: |
| 81 | + case Article::BAD_TITLE: |
82 | 82 | $this->dieUsage("The article ``{$params['title']}'' doesn't exist", 'missingtitle'); |
83 | | - case ROLLBACK_ALREADYROLLED: |
| 83 | + case Article::ALREADYROLLED: |
84 | 84 | $this->dieUsage('The edit(s) you tried to rollback is/are already rolled back', 'alreadyrolled'); |
85 | | - case ROLLBACK_ONLYAUTHOR: |
| 85 | + case Article::ONLY_AUTHOR: |
86 | 86 | $this->dieUsage("{$params['user']} is the only author of the page", 'onlyauthor'); |
87 | | - case ROLLBACK_EDITFAILED: |
| 87 | + case Article::EDIT_FAILED: |
88 | 88 | $this->dieDebug(__METHOD__, 'Article::doEdit() failed'); |
89 | 89 | default: |
90 | 90 | // rollback() has apparently invented a new error, which is extremely weird |
91 | 91 | $this->dieDebug(__METHOD__, "rollback() returned an unknown error ($retval)"); |
92 | 92 | } |
93 | | - // $retval has to be ROLLBACK_SUCCESS if we get here |
| 93 | + // $retval has to be Article::SUCCESS if we get here |
94 | 94 | $this->getResult()->addValue(null, 'rollback', $info); |
95 | 95 | } |
96 | 96 | |
Index: branches/apiedit/phase3/includes/api/ApiDelete.php |
— | — | @@ -125,7 +125,7 @@ |
126 | 126 | $this->dieUsage('The wiki is in read-only mode', 'readonly'); |
127 | 127 | case DELETE_BADTOKEN: |
128 | 128 | $this->dieUsage('Invalid token', 'badtoken'); |
129 | | - case ROLLBACK_BADARTICLE: |
| 129 | + case Article::RB_BADARTICLE: |
130 | 130 | $this->dieUsage("The article ``{$params['title']}'' doesn't exist or has already been deleted", 'missingtitle'); |
131 | 131 | default: |
132 | 132 | // delete() has apparently invented a new error, which is extremely weird |
Index: branches/apiedit/phase3/includes/Defines.php |
— | — | @@ -195,19 +195,6 @@ |
196 | 196 | define( 'EDIT_AUTOSUMMARY', 64 ); |
197 | 197 | /**#@-*/ |
198 | 198 | |
199 | | -/**#@+ |
200 | | - * Article::doRollback() return values |
201 | | - */ |
202 | | -define('ROLLBACK_SUCCES', 0); |
203 | | -define('ROLLBACK_PERM', 1); // Permission denied |
204 | | -define('ROLLBACK_BLOCKED', 2); // User has been blocked |
205 | | -define('ROLLBACK_READONLY', 3); // Wiki is in read-only mode |
206 | | -define('ROLLBACK_BADTOKEN', 4); // Invalid token specified |
207 | | -define('ROLLBACK_BADARTICLE', 5); // $this is not a valid Article |
208 | | -define('ROLLBACK_ALREADYROLLED', 6); // Someone else already rolled this back. $info['usertext'] and $info['comment'] will be set |
209 | | -define('ROLLBACK_ONLYAUTHOR', 7); // User is the only author of the page |
210 | | -define('ROLLBACK_EDITFAILED', 8); // Article::doEdit() failed. This is a very weird error |
211 | | - |
212 | 199 | /** |
213 | 200 | * Flags for Database::makeList() |
214 | 201 | * These are also available as Database class constants |