Index: trunk/phase3/includes/Article.php |
— | — | @@ -2167,7 +2167,11 @@ |
2168 | 2168 | return true; |
2169 | 2169 | } |
2170 | 2170 | |
2171 | | - /** Backend rollback implementation. UI logic is in rollback() |
| 2171 | + /** |
| 2172 | + * Roll back the most recent consecutive set of edits to a page |
| 2173 | + * from the same user; fails if there are no eligible edits to |
| 2174 | + * roll back to, e.g. user is the sole contributor |
| 2175 | + * |
2172 | 2176 | * @param string $fromP - Name of the user whose edits to rollback. |
2173 | 2177 | * @param string $summary - Custom summary. Set to default summary if empty. |
2174 | 2178 | * @param string $token - Rollback token. |
— | — | @@ -2179,9 +2183,8 @@ |
2180 | 2184 | * |
2181 | 2185 | * @return self::SUCCESS on succes, self::* on failure |
2182 | 2186 | */ |
2183 | | - public function doRollback($fromP, $summary, $token, $bot, &$resultDetails) { |
| 2187 | + public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails ) { |
2184 | 2188 | global $wgUser, $wgUseRCPatrol; |
2185 | | - |
2186 | 2189 | $resultDetails = null; |
2187 | 2190 | |
2188 | 2191 | if( $wgUser->isAllowed( 'rollback' ) ) { |
— | — | @@ -2195,14 +2198,11 @@ |
2196 | 2199 | if ( wfReadOnly() ) { |
2197 | 2200 | return self::READONLY; |
2198 | 2201 | } |
2199 | | - if( !$wgUser->matchEditToken( $token, |
2200 | | - array( $this->mTitle->getPrefixedText(), $fromP ))) { |
| 2202 | + if( !$wgUser->matchEditToken( $token, array( $this->mTitle->getPrefixedText(), $fromP ) ) ) |
2201 | 2203 | return self::BAD_TOKEN; |
2202 | | - } |
| 2204 | + |
2203 | 2205 | $dbw = wfGetDB( DB_MASTER ); |
2204 | 2206 | |
2205 | | - # Replace all this user's current edits with the next one down |
2206 | | - |
2207 | 2207 | # Get the last editor |
2208 | 2208 | $current = Revision::newFromTitle( $this->mTitle ); |
2209 | 2209 | if( is_null( $current ) ) { |
— | — | @@ -2212,7 +2212,7 @@ |
2213 | 2213 | |
2214 | 2214 | $from = str_replace( '_', ' ', $fromP ); |
2215 | 2215 | if( $from != $current->getUserText() ) { |
2216 | | - $resultDetails = array('current' => $current); |
| 2216 | + $resultDetails = array( 'current' => $current ); |
2217 | 2217 | return self::ALREADY_ROLLED; |
2218 | 2218 | } |
2219 | 2219 | |
— | — | @@ -2256,7 +2256,7 @@ |
2257 | 2257 | |
2258 | 2258 | # Get the edit summary |
2259 | 2259 | $target = Revision::newFromId( $s->rev_id ); |
2260 | | - if (empty($summary)) |
| 2260 | + if( empty( $summary ) ) |
2261 | 2261 | $summary = wfMsgForContent( 'revertpage', $target->getUserText(), $from ); |
2262 | 2262 | |
2263 | 2263 | # Save |
— | — | @@ -2268,28 +2268,27 @@ |
2269 | 2269 | $resultDetails = array( |
2270 | 2270 | 'summary' => $summary, |
2271 | 2271 | 'current' => $current, |
2272 | | - 'target' => $target); |
| 2272 | + 'target' => $target, |
| 2273 | + ); |
2273 | 2274 | return self::SUCCESS; |
2274 | 2275 | } |
2275 | 2276 | |
2276 | | - /** UI entry point for rollbacks. Relies on doRollback() to do the hard work */ |
| 2277 | + /** |
| 2278 | + * User interface for rollback operations |
| 2279 | + */ |
2277 | 2280 | function rollback() { |
2278 | 2281 | global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol; |
2279 | 2282 | |
2280 | | - // Call doRollback() and interpret its return value |
2281 | | - $resultDetails = null; |
2282 | | - $retval = $this->doRollback( |
2283 | | - $wgRequest->getVal('from'), |
2284 | | - $wgRequest->getText('summary'), |
2285 | | - $wgRequest->getVal('token'), |
2286 | | - $wgRequest->getBool('bot'), |
2287 | | - $resultDetails); |
| 2283 | + $details = null; |
| 2284 | + $result = $this->doRollback( |
| 2285 | + $wgRequest->getVal( 'from' ), |
| 2286 | + $wgRequest->getText( 'summary' ), |
| 2287 | + $wgRequest->getVal( 'token' ), |
| 2288 | + $wgRequest->getBool( 'bot' ), |
| 2289 | + $details |
| 2290 | + ); |
2288 | 2291 | |
2289 | | - switch($retval) |
2290 | | - { |
2291 | | - default: |
2292 | | - throw new MWException( "Unknown retval $retval" ); |
2293 | | - break; |
| 2292 | + switch( $result ) { |
2294 | 2293 | case self::BLOCKED: |
2295 | 2294 | $wgOut->blockedPage(); |
2296 | 2295 | break; |
— | — | @@ -2304,30 +2303,30 @@ |
2305 | 2304 | $wgOut->addWikiText( wfMsg( 'sessionfailure' ) ); |
2306 | 2305 | break; |
2307 | 2306 | case self::BAD_TITLE: |
2308 | | - $wgOut->addHTML( wfMsg( 'notanarticle' ) ); |
| 2307 | + $wgOut->addHtml( wfMsg( 'notanarticle' ) ); |
2309 | 2308 | break; |
2310 | 2309 | case self::ALREADY_ROLLED: |
2311 | | - $current = $resultDetails['current']; |
2312 | | - $wgOut->setPageTitle( wfMsg('rollbackfailed') ); |
2313 | | - $wgOut->addWikiText( wfMsg( 'alreadyrolled', |
2314 | | - htmlspecialchars( $this->mTitle->getPrefixedText()), |
2315 | | - htmlspecialchars( $wgRequest->getVal('from') ), |
2316 | | - htmlspecialchars( $current->getUserText() ) ) ); |
2317 | | - if( $current->getComment() != '') { |
2318 | | - $wgOut->addHTML( |
2319 | | - wfMsg( 'editcomment', |
| 2310 | + $current = $details['current']; |
| 2311 | + $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) ); |
| 2312 | + $wgOut->addWikiText( |
| 2313 | + wfMsg( 'alreadyrolled', |
| 2314 | + htmlspecialchars( $this->mTitle->getPrefixedText() ), |
| 2315 | + htmlspecialchars( $wgRequest->getVal( 'from' ) ), |
| 2316 | + htmlspecialchars( $current->getUserText() ) |
| 2317 | + ) |
| 2318 | + ); |
| 2319 | + if( $current->getComment() != '' ) { |
| 2320 | + $wgOut->addHtml( wfMsg( 'editcomment', |
2320 | 2321 | $wgUser->getSkin()->formatComment( $current->getComment() ) ) ); |
2321 | 2322 | } |
2322 | 2323 | break; |
2323 | 2324 | case self::ONLY_AUTHOR: |
2324 | | - $wgOut->setPageTitle(wfMsg('rollbackfailed')); |
2325 | | - $wgOut->addHTML( wfMsg( 'cantrollback' ) ); |
| 2325 | + $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) ); |
| 2326 | + $wgOut->addHtml( wfMsg( 'cantrollback' ) ); |
2326 | 2327 | break; |
2327 | 2328 | case self::SUCCESS: |
2328 | | - # User feedback |
2329 | | - $current = $resultDetails['current']; |
2330 | | - $target = $resultDetails['target']; |
2331 | | - |
| 2329 | + $current = $details['current']; |
| 2330 | + $target = $details['target']; |
2332 | 2331 | $wgOut->setPageTitle( wfMsg( 'actioncomplete' ) ); |
2333 | 2332 | $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
2334 | 2333 | $old = $wgUser->getSkin()->userLink( $current->getUser(), $current->getUserText() ) |
— | — | @@ -2335,10 +2334,12 @@ |
2336 | 2335 | $new = $wgUser->getSkin()->userLink( $target->getUser(), $target->getUserText() ) |
2337 | 2336 | . $wgUser->getSkin()->userToolLinks( $target->getUser(), $target->getUserText() ); |
2338 | 2337 | $wgOut->addHtml( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) ); |
2339 | | - |
2340 | 2338 | $wgOut->returnToMain( false ); |
2341 | 2339 | break; |
| 2340 | + default: |
| 2341 | + throw new MWException( __METHOD__ . ": Unknown return value `{$retval}`" ); |
2342 | 2342 | } |
| 2343 | + |
2343 | 2344 | } |
2344 | 2345 | |
2345 | 2346 | |