r29931 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29930‎ | r29931 | r29932 >
Date:19:38, 18 January 2008
Author:catrope
Status:old
Tags:
Comment:
* Changing PageArchive::undelete() and undeleteRevisions() to return false rather than an error code
* Refactoring ApiUndelete to use ApiBase::dieUsageMsg()
* Adding new messages to ApiBase::$messageMap
Modified paths:
  • /trunk/phase3/includes/SpecialUndelete.php (modified) (history)
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUndelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiUndelete.php
@@ -43,22 +43,22 @@
4444
4545 $titleObj = NULL;
4646 if(!isset($params['title']))
47 - $this->dieUsage('The title parameter must be set', 'notitle');
 47+ $this->dieUsageMsg(array('missingparam', 'title'));
4848 if(!isset($params['token']))
49 - $this->dieUsage('The token parameter must be set', 'notoken');
 49+ $this->dieUsageMsg(array('missingparam', 'token'));
5050
5151 if(!$wgUser->isAllowed('undelete'))
52 - $this->dieUsage('You don\'t have permission to restore deleted revisions', 'permissiondenied');
 52+ $this->dieUsageMsg(array('permdenied-undelete'));
5353 if($wgUser->isBlocked())
54 - $this->dieUsage('You have been blocked from editing', 'blocked');
 54+ $this->dieUsageMsg(array('blockedtext'));
5555 if(wfReadOnly())
56 - $this->dieUsage('The wiki is in read-only mode', 'readonly');
 56+ $this->dieUsageMsg(array('readonlytext'));
5757 if(!$wgUser->matchEditToken($params['token']))
58 - $this->dieUsage('Invalid token', 'badtoken');
 58+ $this->dieUsageMsg(array('sessionfailure'));
5959
6060 $titleObj = Title::newFromText($params['title']);
6161 if(!$titleObj)
62 - $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle');
 62+ $this->dieUsageMsg(array('invalidtitle', $params['title']));
6363
6464 // Convert timestamps
6565 if(!is_array($params['timestamps']))
@@ -71,17 +71,9 @@
7272 $dbw->begin();
7373 $retval = $pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason']);
7474 if(!is_array($retval))
75 - switch($retval)
76 - {
77 - case PageArchive::UNDELETE_NOTHINGRESTORED:
78 - $this->dieUsage('No revisions could be restored', 'norevs');
79 - case PageArchive::UNDELETE_NOTAVAIL:
80 - $this->dieUsage('Not all requested revisions could be found', 'revsnotfound');
81 - case PageArchive::UNDELETE_UNKNOWNERR:
82 - $this->dieUsage('Undeletion failed with unknown error', 'unknownerror');
83 - }
 75+ $this->dieUsageMsg(array('cannotundelete'));
 76+
8477 $dbw->commit();
85 -
8678 $info['title'] = $titleObj->getPrefixedText();
8779 $info['revisions'] = $retval[0];
8880 $info['fileversions'] = $retval[1];
Index: trunk/phase3/includes/api/ApiBase.php
@@ -616,6 +616,8 @@
617617 'unblock-notarget' => array('code' => 'notarget', 'info' => "Either the id or the user parameter must be set"),
618618 'unblock-idanduser' => array('code' => 'idanduser', 'info' => "The id and user parameters can\'t be used together"),
619619 'cantunblock' => array('code' => 'permissiondenied', 'info' => "You don't have permission to unblock users"),
 620+ 'cannotundelete' => array('code' => 'cantundelete', 'info' => "Couldn't undelete: the requested revisions may not exist, or may have been undeleted already"),
 621+ 'permdenied-undelete' => array('code' => 'permissiondenied', 'info' => "You don't have permission to restore deleted revisions"),
620622 );
621623
622624 /**
Index: trunk/phase3/includes/SpecialUndelete.php
@@ -303,9 +303,6 @@
304304 return ($n > 0);
305305 }
306306
307 - const UNDELETE_NOTHINGRESTORED = 0; // No revisions could be restored
308 - const UNDELETE_NOTAVAIL = -1; // Not all requested revisions are available
309 - const UNDELETE_UNKNOWNERR = -2; // Unknown error
310307 /**
311308 * Restore the given (or all) text and file revisions for the page.
312309 * Once restored, the items will be removed from the archive tables.
@@ -315,7 +312,8 @@
316313 * @param string $comment
317314 * @param array $fileVersions
318315 *
319 - * @return array(number of revisions restored, number of file versions restored, log reason) on success or UNDELETE_* on failure
 316+ * @return array(number of file revisions restored, number of image revisions restored, log message)
 317+ * on success, false on failure
320318 */
321319 function undelete( $timestamps, $comment = '', $fileVersions = array() ) {
322320 // If both the set of text revisions and file revisions are empty,
@@ -335,8 +333,8 @@
336334
337335 if( $restoreText ) {
338336 $textRestored = $this->undeleteRevisions( $timestamps );
339 - if($textRestored < 0) // It must be one of UNDELETE_*
340 - return $textRestored;
 337+ if($textRestored === false) // It must be one of UNDELETE_*
 338+ return false;
341339 } else {
342340 $textRestored = 0;
343341 }
@@ -357,7 +355,7 @@
358356 $wgContLang->formatNum( $filesRestored ) );
359357 } else {
360358 wfDebug( "Undelete: nothing undeleted...\n" );
361 - return self::UNDELETE_NOTHINGRESTORED;
 359+ return false;
362360 }
363361
364362 if( trim( $comment ) != '' )
@@ -376,10 +374,11 @@
377375 * @param string $comment
378376 * @param array $fileVersions
379377 *
380 - * @return int number of revisions restored on success or UNDELETE_* on failure
 378+ * @return mixed number of revisions restored or false on failure
381379 */
382380 private function undeleteRevisions( $timestamps ) {
383 - if ( wfReadOnly() ) return 0;
 381+ if ( wfReadOnly() )
 382+ return false;
384383
385384 $restoreAll = empty( $timestamps );
386385
@@ -444,7 +443,7 @@
445444 );
446445 if( $dbw->numRows( $result ) < count( $timestamps ) ) {
447446 wfDebug( __METHOD__.": couldn't find all requested rows\n" );
448 - return self::UNDELETE_NOTAVAIL;
 447+ return false;
449448 }
450449
451450 $revision = null;

Follow-up revisions

RevisionCommit summaryAuthorDate
r70129Followup r29931...reedy07:43, 29 July 2010

Status & tagging log