Index: branches/apiedit/phase3/includes/api/ApiQueryDeletedrevs.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /* |
5 | | - * Created on June 30, 2007 |
| 5 | + * Created on Jul 2, 2007 |
6 | 6 | * |
7 | 7 | * API for MediaWiki 1.8+ |
8 | 8 | * |
Index: branches/apiedit/phase3/includes/api/ApiDelete.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /* |
5 | | - * Created on Jun 21, 2007 |
| 5 | + * Created on Jun 30, 2007 |
6 | 6 | * API for MediaWiki 1.8+ |
7 | 7 | * |
8 | 8 | * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl |
Index: branches/apiedit/phase3/includes/api/ApiUndelete.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /* |
5 | | - * Created on Jun 20, 2007 |
| 5 | + * Created on Jul 3, 2007 |
6 | 6 | * API for MediaWiki 1.8+ |
7 | 7 | * |
8 | 8 | * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl |
— | — | @@ -59,11 +59,22 @@ |
60 | 60 | if(!$titleObj) |
61 | 61 | $this->dieUsage("bad title {$params['title']}", 'invalidtitle'); |
62 | 62 | $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 | + } |
65 | 74 | |
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]; |
68 | 79 | $this->getResult()->addValue(null, $this->getModuleName(), $info); |
69 | 80 | } |
70 | 81 | |
Index: branches/apiedit/phase3/includes/SpecialUndelete.php |
— | — | @@ -249,6 +249,9 @@ |
250 | 250 | return ($n > 0); |
251 | 251 | } |
252 | 252 | |
| 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 |
253 | 256 | /** |
254 | 257 | * Restore the given (or all) text and file revisions for the page. |
255 | 258 | * Once restored, the items will be removed from the archive tables. |
— | — | @@ -258,7 +261,7 @@ |
259 | 262 | * @param string $comment |
260 | 263 | * @param array $fileVersions |
261 | 264 | * |
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 |
263 | 266 | */ |
264 | 267 | function undelete( $timestamps, $comment = '', $fileVersions = array() ) { |
265 | 268 | // If both the set of text revisions and file revisions are empty, |
— | — | @@ -273,12 +276,18 @@ |
274 | 277 | if( $restoreFiles && $this->title->getNamespace() == NS_IMAGE ) { |
275 | 278 | $img = wfLocalFile( $this->title ); |
276 | 279 | $filesRestored = $img->restore( $fileVersions ); |
| 280 | + // TODO: includes/filerepo/LocalFile.php |
277 | 281 | } else { |
278 | 282 | $filesRestored = 0; |
279 | 283 | } |
280 | 284 | |
281 | 285 | if( $restoreText ) { |
282 | 286 | $textRestored = $this->undeleteRevisions( $timestamps ); |
| 287 | + if($textRestored < 0) // It must be one of UNDELETE_* |
| 288 | + { |
| 289 | + $dbw->rollback(); |
| 290 | + return $textRestored; |
| 291 | + } |
283 | 292 | } else { |
284 | 293 | $textRestored = 0; |
285 | 294 | } |
— | — | @@ -299,7 +308,7 @@ |
300 | 309 | $wgContLang->formatNum( $filesRestored ) ); |
301 | 310 | } else { |
302 | 311 | wfDebug( "Undelete: nothing undeleted...\n" ); |
303 | | - return false; |
| 312 | + return UNDELETE_NOTHINGRESTORED; |
304 | 313 | } |
305 | 314 | |
306 | 315 | if( trim( $comment ) != '' ) |
— | — | @@ -307,9 +316,9 @@ |
308 | 317 | $log->addEntry( 'restore', $this->title, $reason ); |
309 | 318 | |
310 | 319 | $dbw->commit(); |
311 | | - return true; |
| 320 | + return array($textRestored, $filesRestored, $reason); |
312 | 321 | } |
313 | | - |
| 322 | + |
314 | 323 | /** |
315 | 324 | * This is the meaty bit -- restores archived revisions of the given page |
316 | 325 | * to the cur/old tables. If the page currently exists, all revisions will |
— | — | @@ -319,7 +328,7 @@ |
320 | 329 | * @param string $comment |
321 | 330 | * @param array $fileVersions |
322 | 331 | * |
323 | | - * @return int number of revisions restored |
| 332 | + * @return int number of revisions restored on success or UNDELETE_* on failure |
324 | 333 | */ |
325 | 334 | private function undeleteRevisions( $timestamps ) { |
326 | 335 | $restoreAll = empty( $timestamps ); |
— | — | @@ -385,7 +394,7 @@ |
386 | 395 | ); |
387 | 396 | if( $dbw->numRows( $result ) < count( $timestamps ) ) { |
388 | 397 | wfDebug( __METHOD__.": couldn't find all requested rows\n" ); |
389 | | - return false; |
| 398 | + return self::UNDELETE_NOTAVAIL; |
390 | 399 | } |
391 | 400 | |
392 | 401 | $revision = null; |
— | — | @@ -437,7 +446,8 @@ |
438 | 447 | Article::onArticleEdit( $this->title ); |
439 | 448 | } |
440 | 449 | } else { |
441 | | - # Something went terribly wrong! |
| 450 | + // Revision couldn't be created. This is very weird |
| 451 | + return self::UNDELETE_UNKNOWNERR; |
442 | 452 | } |
443 | 453 | |
444 | 454 | # Now that it's safely stored, take it out of the archive |
— | — | @@ -840,7 +850,7 @@ |
841 | 851 | $this->mComment, |
842 | 852 | $this->mFileVersions ); |
843 | 853 | |
844 | | - if( $ok ) { |
| 854 | + if( is_array($ok) ) { |
845 | 855 | $skin = $wgUser->getSkin(); |
846 | 856 | $link = $skin->makeKnownLinkObj( $this->mTargetObj ); |
847 | 857 | $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) ); |