r23697 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23696‎ | r23697 | r23698 >
Date:10:25, 4 July 2007
Author:catrope
Status:old
Tags:
Comment:
apiedit: API:
* Made action=undelete more verbose
** On success, number of restored revisions and log text are returned
** On failure, more descriptive error message is returned
** PageArchive::undelete() now returns useful stuff as opposed to a simple bool
* Correcting creation dates in some API files
Modified paths:
  • /branches/apiedit/phase3/includes/SpecialUndelete.php (modified) (history)
  • /branches/apiedit/phase3/includes/api/ApiDelete.php (modified) (history)
  • /branches/apiedit/phase3/includes/api/ApiQueryDeletedrevs.php (modified) (history)
  • /branches/apiedit/phase3/includes/api/ApiUndelete.php (modified) (history)

Diff [purge]

Index: branches/apiedit/phase3/includes/api/ApiQueryDeletedrevs.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /*
5 - * Created on June 30, 2007
 5+ * Created on Jul 2, 2007
66 *
77 * API for MediaWiki 1.8+
88 *
Index: branches/apiedit/phase3/includes/api/ApiDelete.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /*
5 - * Created on Jun 21, 2007
 5+ * Created on Jun 30, 2007
66 * API for MediaWiki 1.8+
77 *
88 * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
Index: branches/apiedit/phase3/includes/api/ApiUndelete.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /*
5 - * Created on Jun 20, 2007
 5+ * Created on Jul 3, 2007
66 * API for MediaWiki 1.8+
77 *
88 * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
@@ -59,11 +59,22 @@
6060 if(!$titleObj)
6161 $this->dieUsage("bad title {$params['title']}", 'invalidtitle');
6262 $pa = new PageArchive($titleObj);
63 - if(!$pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason']))
64 - $this->dieUsage('Undeletion failed for unknown reason', 'failed');
 63+ $retval = $pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason']);
 64+ if(!is_array($retval))
 65+ switch($retval)
 66+ {
 67+ case PageArchive::UNDELETE_NOTHINGRESTORED:
 68+ $this->dieUsage('No revisions could be restored', 'norevs');
 69+ case PageArchive::UNDELETE_NOTAVAIL:
 70+ $this->dieUsage('Not all requested revisions could be found', 'revsnotfound');
 71+ case PageArchive::UNDELETE_UNKNOWN:
 72+ $this->dieUsage('Undeletion failed with unknown error', 'unknownerror');
 73+ }
6574
66 - $info['title'] = $params['title'];
67 - $info['reason'] = $params['reason']; // FIXME
 75+ $info['title'] = $titleObj->getPrefixedText();
 76+ $info['revisions'] = $retval[0];
 77+ $info['fileversions'] = $retval[1];
 78+ $info['reason'] = $retval[2];
6879 $this->getResult()->addValue(null, $this->getModuleName(), $info);
6980 }
7081
Index: branches/apiedit/phase3/includes/SpecialUndelete.php
@@ -249,6 +249,9 @@
250250 return ($n > 0);
251251 }
252252
 253+ const UNDELETE_NOTHINGRESTORED = 0; // No revisions could be restored
 254+ const UNDELETE_NOTAVAIL = -1; // Not all requested revisions are available
 255+ const UNDELETE_UNKNOWNERR = -2; // Unknown error
253256 /**
254257 * Restore the given (or all) text and file revisions for the page.
255258 * Once restored, the items will be removed from the archive tables.
@@ -258,7 +261,7 @@
259262 * @param string $comment
260263 * @param array $fileVersions
261264 *
262 - * @return true on success.
 265+ * @return array(number of revisions restored, number of file versions restored, log reason) on success or UNDELETE_* on failure
263266 */
264267 function undelete( $timestamps, $comment = '', $fileVersions = array() ) {
265268 // If both the set of text revisions and file revisions are empty,
@@ -273,12 +276,18 @@
274277 if( $restoreFiles && $this->title->getNamespace() == NS_IMAGE ) {
275278 $img = wfLocalFile( $this->title );
276279 $filesRestored = $img->restore( $fileVersions );
 280+ // TODO: includes/filerepo/LocalFile.php
277281 } else {
278282 $filesRestored = 0;
279283 }
280284
281285 if( $restoreText ) {
282286 $textRestored = $this->undeleteRevisions( $timestamps );
 287+ if($textRestored < 0) // It must be one of UNDELETE_*
 288+ {
 289+ $dbw->rollback();
 290+ return $textRestored;
 291+ }
283292 } else {
284293 $textRestored = 0;
285294 }
@@ -299,7 +308,7 @@
300309 $wgContLang->formatNum( $filesRestored ) );
301310 } else {
302311 wfDebug( "Undelete: nothing undeleted...\n" );
303 - return false;
 312+ return UNDELETE_NOTHINGRESTORED;
304313 }
305314
306315 if( trim( $comment ) != '' )
@@ -307,9 +316,9 @@
308317 $log->addEntry( 'restore', $this->title, $reason );
309318
310319 $dbw->commit();
311 - return true;
 320+ return array($textRestored, $filesRestored, $reason);
312321 }
313 -
 322+
314323 /**
315324 * This is the meaty bit -- restores archived revisions of the given page
316325 * to the cur/old tables. If the page currently exists, all revisions will
@@ -319,7 +328,7 @@
320329 * @param string $comment
321330 * @param array $fileVersions
322331 *
323 - * @return int number of revisions restored
 332+ * @return int number of revisions restored on success or UNDELETE_* on failure
324333 */
325334 private function undeleteRevisions( $timestamps ) {
326335 $restoreAll = empty( $timestamps );
@@ -385,7 +394,7 @@
386395 );
387396 if( $dbw->numRows( $result ) < count( $timestamps ) ) {
388397 wfDebug( __METHOD__.": couldn't find all requested rows\n" );
389 - return false;
 398+ return self::UNDELETE_NOTAVAIL;
390399 }
391400
392401 $revision = null;
@@ -437,7 +446,8 @@
438447 Article::onArticleEdit( $this->title );
439448 }
440449 } else {
441 - # Something went terribly wrong!
 450+ // Revision couldn't be created. This is very weird
 451+ return self::UNDELETE_UNKNOWNERR;
442452 }
443453
444454 # Now that it's safely stored, take it out of the archive
@@ -840,7 +850,7 @@
841851 $this->mComment,
842852 $this->mFileVersions );
843853
844 - if( $ok ) {
 854+ if( is_array($ok) ) {
845855 $skin = $wgUser->getSkin();
846856 $link = $skin->makeKnownLinkObj( $this->mTargetObj );
847857 $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );

Status & tagging log