r23725 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23724‎ | r23725 | r23726 >
Date:06:44, 5 July 2007
Author:yurik
Status:old
Tags:
Comment:
APIedit: Bringing Article.php closer to the original to simplify merging & validation
Modified paths:
  • /branches/apiedit/phase3/includes/Article.php (modified) (history)

Diff [purge]

Index: branches/apiedit/phase3/includes/Article.php
@@ -2172,52 +2172,58 @@
21732173 }
21742174
21752175 /** 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.
21772177 * @param string $token - Rollback token.
21782178 * @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.
21802180 * @param array $info - Reference to associative array that will be set to contain the revision ID, edit summary, etc.
21812181 * @return self::SUCCESS on succes, self::* on failure
21822182 */
2183 - public function doRollback($user, $token, $bot = false, $summary = "", &$info = NULL) {
 2183+ public function doRollback($fromP, $token, $bot = false, $newComment = "", &$info = NULL) {
21842184 global $wgUser, $wgUseRCPatrol;
21852185
2186 - if(!$wgUser->isAllowed('rollback')) {
 2186+ if( $wgUser->isAllowed( 'rollback' ) ) {
 2187+ if( $wgUser->isBlocked() ) {
 2188+ return self::BLOCKED;
 2189+ }
 2190+ } else {
21872191 return self::PERM_DENIED;
21882192 }
2189 - if( $wgUser->isBlocked() ) {
2190 - return self::BLOCKED;
2191 - }
 2193+
21922194 if ( wfReadOnly() ) {
21932195 return self::READONLY;
21942196 }
2195 -
2196 - // Check token first
21972197 if( !$wgUser->matchEditToken( $token,
21982198 array( $this->mTitle->getPrefixedText(),
2199 - $user ) ) ) {
 2199+ $fromP ) ) ) {
22002200 return self::BAD_TOKEN;
22012201 }
22022202 $dbw = wfGetDB( DB_MASTER );
22032203
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?
22062210 return self::BAD_TITLE;
 2211+ }
22072212
2208 - // Check if someone else was there first
2209 - if( $user != $current->getUserText() ) {
 2213+ $from = str_replace( '_', ' ', $fromP );
 2214+ if( $from != $current->getUserText() ) {
22102215 $info['usertext'] = $current->getUserText();
22112216 $info['comment'] = $current->getComment();
22122217 return self::ALREADYROLLED;
22132218 }
22142219
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' ),
22192225 array(
22202226 '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}"
22222228 ), __METHOD__,
22232229 array(
22242230 'USE INDEX' => 'page_timestamp',
@@ -2228,8 +2234,6 @@
22292235 return self::ONLY_AUTHOR;
22302236 }
22312237
2232 - $target = Revision::newFromID($s->rev_id);
2233 -
22342238 // If the reverted edits should be marked bot or patrolled, do so
22352239 $set = array();
22362240 if ( $bot ) {
@@ -2245,21 +2249,22 @@
22462250 $dbw->update( 'recentchanges', $set,
22472251 array( /* WHERE */
22482252 '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}'",
22512255 ), __METHOD__
22522256 );
22532257 }
22542258
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 );
22582263
2259 - // Now we *finally* get to commit the edit
 2264+ # Save it!
22602265 $flags = EDIT_UPDATE | EDIT_MINOR;
22612266 if($bot)
22622267 $flags |= EDIT_FORCE_BOT;
2263 - if(!$this->doEdit($target->getText(), $summary, $flags))
 2268+ if(!$this->doEdit( $target->getText(), $newComment, $flags))
22642269 return self::EDIT_FAILED;
22652270
22662271 if(is_null($info))
@@ -2268,13 +2273,13 @@
22692274
22702275 $info['title'] = $this->mTitle->getPrefixedText();
22712276 $info['pageid'] = $current->getPage();
2272 - $info['summary'] = $summary;
 2277+ $info['summary'] = $newComment;
22732278 // NOTE: If the rollback turned out to be a null edit, revid and old_revid will be equal
22742279 $info['revid'] = $this->mTitle->getLatestRevID(); // The revid of your rollback
22752280 $info['old_revid'] = $current->getId(); // The revid of the last edit before your rollback
22762281 $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
22792284 $info['to'] = $target->getUserText(); // The user whose last version was reverted to
22802285 if($bot)
22812286 $info['bot'] = "";
@@ -2291,6 +2296,9 @@
22922297 $wgRequest->getText('summary'), &$info);
22932298 switch($retval)
22942299 {
 2300+ default:
 2301+ throw new MWException( "Unknown retval $retval" );
 2302+ break;
22952303 case self::SUCCESS:
22962304 case self::EDIT_FAILED: // Is ignored
22972305 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
@@ -2298,23 +2306,23 @@
22992307 $wgOut->addHTML( '<h2>' . htmlspecialchars( $info['summary'] ) . "</h2>\n<hr />\n" );
23002308 $this->doRedirect(true);
23012309 $wgOut->returnToMain(false);
2302 - return;
 2310+ break;
23032311 case self::PERM_DENIED:
23042312 $wgOut->permissionRequired('rollback');
2305 - return;
 2313+ break;
23062314 case self::BLOCKED:
23072315 $wgOut->blockedPage();
2308 - return;
 2316+ break;
23092317 case self::READONLY:
23102318 $wgOut->readOnlyPage($this->getContent());
2311 - return;
 2319+ break;
23122320 case self::BAD_TOKEN:
23132321 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
23142322 $wgOut->addWikiText(wfMsg('sessionfailure'));
2315 - return;
 2323+ break;
23162324 case self::BAD_TITLE:
23172325 $wgOut->addHTML(wfMsg('notanarticle'));
2318 - return;
 2326+ break;
23192327 case self::ALREADYROLLED:
23202328 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
23212329 $wgOut->addWikiText(wfMsg('alreadyrolled',
@@ -2324,14 +2332,15 @@
23252333 if($info['comment'] != '')
23262334 $wgOut->addHTML(wfMsg('editcomment',
23272335 $wgUser->getSkin()->formatComment($info['comment'])));
2328 - return;
 2336+ break;
23292337 case self::ONLY_AUTHOR:
23302338 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
23312339 $wgOut->addHTML(wfMsg('cantrollback'));
2332 - return;
 2340+ break;
23332341 }
23342342 }
23352343
 2344+
23362345 /**
23372346 * Do standard deferred updates after page view
23382347 * @private

Status & tagging log