r23887 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23886‎ | r23887 | r23888 >
Date:08:12, 9 July 2007
Author:robchurch
Status:old
Tags:
Comment:
* Code conventions
* Throw a more helpful exception from Article::rollback()
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -2167,7 +2167,11 @@
21682168 return true;
21692169 }
21702170
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+ *
21722176 * @param string $fromP - Name of the user whose edits to rollback.
21732177 * @param string $summary - Custom summary. Set to default summary if empty.
21742178 * @param string $token - Rollback token.
@@ -2179,9 +2183,8 @@
21802184 *
21812185 * @return self::SUCCESS on succes, self::* on failure
21822186 */
2183 - public function doRollback($fromP, $summary, $token, $bot, &$resultDetails) {
 2187+ public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails ) {
21842188 global $wgUser, $wgUseRCPatrol;
2185 -
21862189 $resultDetails = null;
21872190
21882191 if( $wgUser->isAllowed( 'rollback' ) ) {
@@ -2195,14 +2198,11 @@
21962199 if ( wfReadOnly() ) {
21972200 return self::READONLY;
21982201 }
2199 - if( !$wgUser->matchEditToken( $token,
2200 - array( $this->mTitle->getPrefixedText(), $fromP ))) {
 2202+ if( !$wgUser->matchEditToken( $token, array( $this->mTitle->getPrefixedText(), $fromP ) ) )
22012203 return self::BAD_TOKEN;
2202 - }
 2204+
22032205 $dbw = wfGetDB( DB_MASTER );
22042206
2205 - # Replace all this user's current edits with the next one down
2206 -
22072207 # Get the last editor
22082208 $current = Revision::newFromTitle( $this->mTitle );
22092209 if( is_null( $current ) ) {
@@ -2212,7 +2212,7 @@
22132213
22142214 $from = str_replace( '_', ' ', $fromP );
22152215 if( $from != $current->getUserText() ) {
2216 - $resultDetails = array('current' => $current);
 2216+ $resultDetails = array( 'current' => $current );
22172217 return self::ALREADY_ROLLED;
22182218 }
22192219
@@ -2256,7 +2256,7 @@
22572257
22582258 # Get the edit summary
22592259 $target = Revision::newFromId( $s->rev_id );
2260 - if (empty($summary))
 2260+ if( empty( $summary ) )
22612261 $summary = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
22622262
22632263 # Save
@@ -2268,28 +2268,27 @@
22692269 $resultDetails = array(
22702270 'summary' => $summary,
22712271 'current' => $current,
2272 - 'target' => $target);
 2272+ 'target' => $target,
 2273+ );
22732274 return self::SUCCESS;
22742275 }
22752276
2276 - /** UI entry point for rollbacks. Relies on doRollback() to do the hard work */
 2277+ /**
 2278+ * User interface for rollback operations
 2279+ */
22772280 function rollback() {
22782281 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
22792282
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+ );
22882291
2289 - switch($retval)
2290 - {
2291 - default:
2292 - throw new MWException( "Unknown retval $retval" );
2293 - break;
 2292+ switch( $result ) {
22942293 case self::BLOCKED:
22952294 $wgOut->blockedPage();
22962295 break;
@@ -2304,30 +2303,30 @@
23052304 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
23062305 break;
23072306 case self::BAD_TITLE:
2308 - $wgOut->addHTML( wfMsg( 'notanarticle' ) );
 2307+ $wgOut->addHtml( wfMsg( 'notanarticle' ) );
23092308 break;
23102309 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',
23202321 $wgUser->getSkin()->formatComment( $current->getComment() ) ) );
23212322 }
23222323 break;
23232324 case self::ONLY_AUTHOR:
2324 - $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2325 - $wgOut->addHTML( wfMsg( 'cantrollback' ) );
 2325+ $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
 2326+ $wgOut->addHtml( wfMsg( 'cantrollback' ) );
23262327 break;
23272328 case self::SUCCESS:
2328 - # User feedback
2329 - $current = $resultDetails['current'];
2330 - $target = $resultDetails['target'];
2331 -
 2329+ $current = $details['current'];
 2330+ $target = $details['target'];
23322331 $wgOut->setPageTitle( wfMsg( 'actioncomplete' ) );
23332332 $wgOut->setRobotPolicy( 'noindex,nofollow' );
23342333 $old = $wgUser->getSkin()->userLink( $current->getUser(), $current->getUserText() )
@@ -2335,10 +2334,12 @@
23362335 $new = $wgUser->getSkin()->userLink( $target->getUser(), $target->getUserText() )
23372336 . $wgUser->getSkin()->userToolLinks( $target->getUser(), $target->getUserText() );
23382337 $wgOut->addHtml( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
2339 -
23402338 $wgOut->returnToMain( false );
23412339 break;
 2340+ default:
 2341+ throw new MWException( __METHOD__ . ": Unknown return value `{$retval}`" );
23422342 }
 2343+
23432344 }
23442345
23452346

Follow-up revisions

RevisionCommit summaryAuthorDate
r23912Merged revisions 23662-23909 via svnmerge from...david18:11, 9 July 2007

Status & tagging log