Index: branches/apiedit/phase3/includes/Article.php |
— | — | @@ -2172,52 +2172,58 @@ |
2173 | 2173 | } |
2174 | 2174 | |
2175 | 2175 | /** Backend rollback implementation. UI logic is in rollback() |
2176 | | - * @param string $user - Name of the user whose edits to rollback. |
| 2176 | + * @param string $fromP - Name of the user whose edits to rollback. |
2177 | 2177 | * @param string $token - Rollback token. |
2178 | 2178 | * @param bool $bot - If true, mark all reverted edits as bot. |
2179 | | - * @param string $summary - Custom summary. Set to default summary if empty. |
| 2179 | + * @param string $newComment - Custom summary. Set to default summary if empty. |
2180 | 2180 | * @param array $info - Reference to associative array that will be set to contain the revision ID, edit summary, etc. |
2181 | 2181 | * @return self::SUCCESS on succes, self::* on failure |
2182 | 2182 | */ |
2183 | | - public function doRollback($user, $token, $bot = false, $summary = "", &$info = NULL) { |
| 2183 | + public function doRollback($fromP, $token, $bot = false, $newComment = "", &$info = NULL) { |
2184 | 2184 | global $wgUser, $wgUseRCPatrol; |
2185 | 2185 | |
2186 | | - if(!$wgUser->isAllowed('rollback')) { |
| 2186 | + if( $wgUser->isAllowed( 'rollback' ) ) { |
| 2187 | + if( $wgUser->isBlocked() ) { |
| 2188 | + return self::BLOCKED; |
| 2189 | + } |
| 2190 | + } else { |
2187 | 2191 | return self::PERM_DENIED; |
2188 | 2192 | } |
2189 | | - if( $wgUser->isBlocked() ) { |
2190 | | - return self::BLOCKED; |
2191 | | - } |
| 2193 | + |
2192 | 2194 | if ( wfReadOnly() ) { |
2193 | 2195 | return self::READONLY; |
2194 | 2196 | } |
2195 | | - |
2196 | | - // Check token first |
2197 | 2197 | if( !$wgUser->matchEditToken( $token, |
2198 | 2198 | array( $this->mTitle->getPrefixedText(), |
2199 | | - $user ) ) ) { |
| 2199 | + $fromP ) ) ) { |
2200 | 2200 | return self::BAD_TOKEN; |
2201 | 2201 | } |
2202 | 2202 | $dbw = wfGetDB( DB_MASTER ); |
2203 | 2203 | |
2204 | | - $current = Revision::newFromTitle($this->mTitle); |
2205 | | - if(is_null($current)) |
| 2204 | + # Replace all this user's current edits with the next one down |
| 2205 | + |
| 2206 | + # Get the last editor |
| 2207 | + $current = Revision::newFromTitle( $this->mTitle ); |
| 2208 | + if( is_null( $current ) ) { |
| 2209 | + # Something wrong... no page? |
2206 | 2210 | return self::BAD_TITLE; |
| 2211 | + } |
2207 | 2212 | |
2208 | | - // Check if someone else was there first |
2209 | | - if( $user != $current->getUserText() ) { |
| 2213 | + $from = str_replace( '_', ' ', $fromP ); |
| 2214 | + if( $from != $current->getUserText() ) { |
2210 | 2215 | $info['usertext'] = $current->getUserText(); |
2211 | 2216 | $info['comment'] = $current->getComment(); |
2212 | 2217 | return self::ALREADYROLLED; |
2213 | 2218 | } |
2214 | 2219 | |
2215 | | - // Get the last edit not by $user |
2216 | | - $userid = intval($current->getUser()); |
2217 | | - $s = $dbw->selectRow('revision', |
2218 | | - array('rev_id', 'rev_timestamp'), |
| 2220 | + # Get the last edit not by this guy |
| 2221 | + $user = intval( $current->getUser() ); |
| 2222 | + $user_text = $dbw->addQuotes( $current->getUserText() ); |
| 2223 | + $s = $dbw->selectRow( 'revision', |
| 2224 | + array( 'rev_id', 'rev_timestamp' ), |
2219 | 2225 | array( |
2220 | 2226 | 'rev_page' => $current->getPage(), |
2221 | | - "rev_user <> $userid OR rev_user_text <> {$dbw->addQuotes($user)}" |
| 2227 | + "rev_user <> {$user} OR rev_user_text <> {$user_text}" |
2222 | 2228 | ), __METHOD__, |
2223 | 2229 | array( |
2224 | 2230 | 'USE INDEX' => 'page_timestamp', |
— | — | @@ -2228,8 +2234,6 @@ |
2229 | 2235 | return self::ONLY_AUTHOR; |
2230 | 2236 | } |
2231 | 2237 | |
2232 | | - $target = Revision::newFromID($s->rev_id); |
2233 | | - |
2234 | 2238 | // If the reverted edits should be marked bot or patrolled, do so |
2235 | 2239 | $set = array(); |
2236 | 2240 | if ( $bot ) { |
— | — | @@ -2245,21 +2249,22 @@ |
2246 | 2250 | $dbw->update( 'recentchanges', $set, |
2247 | 2251 | array( /* WHERE */ |
2248 | 2252 | 'rc_cur_id' => $current->getPage(), |
2249 | | - 'rc_user_text' => $user, |
2250 | | - "rc_timestamp > '{$s->rev_timestamp}'" |
| 2253 | + 'rc_user_text' => $current->getUserText(), |
| 2254 | + "rc_timestamp > '{$s->rev_timestamp}'", |
2251 | 2255 | ), __METHOD__ |
2252 | 2256 | ); |
2253 | 2257 | } |
2254 | 2258 | |
2255 | | - // Generate an edit summary |
2256 | | - if(empty($summary)) |
2257 | | - $summary = wfMsgForContent('revertpage', $target->getUserText(), $user); |
| 2259 | + # Get the edit summary |
| 2260 | + $target = Revision::newFromId( $s->rev_id ); |
| 2261 | + if(empty($newComment)) |
| 2262 | + $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from ); |
2258 | 2263 | |
2259 | | - // Now we *finally* get to commit the edit |
| 2264 | + # Save it! |
2260 | 2265 | $flags = EDIT_UPDATE | EDIT_MINOR; |
2261 | 2266 | if($bot) |
2262 | 2267 | $flags |= EDIT_FORCE_BOT; |
2263 | | - if(!$this->doEdit($target->getText(), $summary, $flags)) |
| 2268 | + if(!$this->doEdit( $target->getText(), $newComment, $flags)) |
2264 | 2269 | return self::EDIT_FAILED; |
2265 | 2270 | |
2266 | 2271 | if(is_null($info)) |
— | — | @@ -2268,13 +2273,13 @@ |
2269 | 2274 | |
2270 | 2275 | $info['title'] = $this->mTitle->getPrefixedText(); |
2271 | 2276 | $info['pageid'] = $current->getPage(); |
2272 | | - $info['summary'] = $summary; |
| 2277 | + $info['summary'] = $newComment; |
2273 | 2278 | // NOTE: If the rollback turned out to be a null edit, revid and old_revid will be equal |
2274 | 2279 | $info['revid'] = $this->mTitle->getLatestRevID(); // The revid of your rollback |
2275 | 2280 | $info['old_revid'] = $current->getId(); // The revid of the last edit before your rollback |
2276 | 2281 | $info['last_revid'] = $s->rev_id; // The revid of the last edit that was not rolled back |
2277 | | - $info['user'] = $user; // The name of the victim |
2278 | | - $info['userid'] = $userid; // And their userid |
| 2282 | + $info['user'] = $fromP; // The name of the victim |
| 2283 | + $info['userid'] = $user; // And their userid |
2279 | 2284 | $info['to'] = $target->getUserText(); // The user whose last version was reverted to |
2280 | 2285 | if($bot) |
2281 | 2286 | $info['bot'] = ""; |
— | — | @@ -2291,6 +2296,9 @@ |
2292 | 2297 | $wgRequest->getText('summary'), &$info); |
2293 | 2298 | switch($retval) |
2294 | 2299 | { |
| 2300 | + default: |
| 2301 | + throw new MWException( "Unknown retval $retval" ); |
| 2302 | + break; |
2295 | 2303 | case self::SUCCESS: |
2296 | 2304 | case self::EDIT_FAILED: // Is ignored |
2297 | 2305 | $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) ); |
— | — | @@ -2298,23 +2306,23 @@ |
2299 | 2307 | $wgOut->addHTML( '<h2>' . htmlspecialchars( $info['summary'] ) . "</h2>\n<hr />\n" ); |
2300 | 2308 | $this->doRedirect(true); |
2301 | 2309 | $wgOut->returnToMain(false); |
2302 | | - return; |
| 2310 | + break; |
2303 | 2311 | case self::PERM_DENIED: |
2304 | 2312 | $wgOut->permissionRequired('rollback'); |
2305 | | - return; |
| 2313 | + break; |
2306 | 2314 | case self::BLOCKED: |
2307 | 2315 | $wgOut->blockedPage(); |
2308 | | - return; |
| 2316 | + break; |
2309 | 2317 | case self::READONLY: |
2310 | 2318 | $wgOut->readOnlyPage($this->getContent()); |
2311 | | - return; |
| 2319 | + break; |
2312 | 2320 | case self::BAD_TOKEN: |
2313 | 2321 | $wgOut->setPageTitle(wfMsg('rollbackfailed')); |
2314 | 2322 | $wgOut->addWikiText(wfMsg('sessionfailure')); |
2315 | | - return; |
| 2323 | + break; |
2316 | 2324 | case self::BAD_TITLE: |
2317 | 2325 | $wgOut->addHTML(wfMsg('notanarticle')); |
2318 | | - return; |
| 2326 | + break; |
2319 | 2327 | case self::ALREADYROLLED: |
2320 | 2328 | $wgOut->setPageTitle(wfMsg('rollbackfailed')); |
2321 | 2329 | $wgOut->addWikiText(wfMsg('alreadyrolled', |
— | — | @@ -2324,14 +2332,15 @@ |
2325 | 2333 | if($info['comment'] != '') |
2326 | 2334 | $wgOut->addHTML(wfMsg('editcomment', |
2327 | 2335 | $wgUser->getSkin()->formatComment($info['comment']))); |
2328 | | - return; |
| 2336 | + break; |
2329 | 2337 | case self::ONLY_AUTHOR: |
2330 | 2338 | $wgOut->setPageTitle(wfMsg('rollbackfailed')); |
2331 | 2339 | $wgOut->addHTML(wfMsg('cantrollback')); |
2332 | | - return; |
| 2340 | + break; |
2333 | 2341 | } |
2334 | 2342 | } |
2335 | 2343 | |
| 2344 | + |
2336 | 2345 | /** |
2337 | 2346 | * Do standard deferred updates after page view |
2338 | 2347 | * @private |