r23687 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23686‎ | r23687 | r23688 >
Date:20:44, 3 July 2007
Author:catrope
Status:old
Tags:
Comment:
apiedit: API:
* Add rudimentary action=undelete implementation, better implementation to follow tomorrow
* Minor sanity tweaks
Modified paths:
  • /branches/apiedit/phase3/includes/AutoLoader.php (modified) (history)
  • /branches/apiedit/phase3/includes/SpecialUndelete.php (modified) (history)
  • /branches/apiedit/phase3/includes/api/ApiDelete.php (modified) (history)
  • /branches/apiedit/phase3/includes/api/ApiMain.php (modified) (history)
  • /branches/apiedit/phase3/includes/api/ApiRollback.php (modified) (history)
  • /branches/apiedit/phase3/includes/api/ApiUndelete.php (added) (history)

Diff [purge]

Index: branches/apiedit/phase3/includes/api/ApiMain.php
@@ -56,6 +56,7 @@
5757 'query' => 'ApiQuery',
5858 'rollback' => 'ApiRollback',
5959 'delete' => 'ApiDelete',
 60+ 'undelete' => 'ApiUndelete',
6061 'opensearch' => 'ApiOpenSearch',
6162 'feedwatchlist' => 'ApiFeedWatchlist',
6263 'help' => 'ApiHelp',
Index: branches/apiedit/phase3/includes/api/ApiRollback.php
@@ -90,7 +90,7 @@
9191 $this->dieDebug(__METHOD__, "rollback() returned an unknown error ($retval)");
9292 }
9393 // $retval has to be Article::SUCCESS if we get here
94 - $this->getResult()->addValue(null, 'rollback', $info);
 94+ $this->getResult()->addValue(null, $this->getModuleName(), $info);
9595 }
9696
9797 protected function getAllowedParams() {
Index: branches/apiedit/phase3/includes/api/ApiDelete.php
@@ -128,7 +128,7 @@
129129 }
130130 // $retval has to be self::DELETE_SUCCESS if we get here
131131 $r = array('title' => $titleObj->getPrefixedText(), 'reason' => $reason);
132 - $this->getResult()->addValue(null, 'delete', $r);
 132+ $this->getResult()->addValue(null, $this->getModuleName(), $r);
133133 }
134134
135135 protected function getAllowedParams() {
@@ -149,8 +149,8 @@
150150
151151 protected function getDescription() {
152152 return array(
153 - 'Deletes a page. You need to be logged in as a sysop to use this function, see also action=login.'
154 - );
 153+ 'Deletes a page. You need to be logged in as a sysop to use this function, see also action=login.'
 154+ );
155155 }
156156
157157 protected function getExamples() {
Index: branches/apiedit/phase3/includes/api/ApiUndelete.php
@@ -0,0 +1,108 @@
 2+<?php
 3+
 4+/*
 5+ * Created on Jun 20, 2007
 6+ * API for MediaWiki 1.8+
 7+ *
 8+ * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
 9+ *
 10+ * This program is free software; you can redistribute it and/or modify
 11+ * it under the terms of the GNU General Public License as published by
 12+ * the Free Software Foundation; either version 2 of the License, or
 13+ * (at your option) any later version.
 14+ *
 15+ * This program is distributed in the hope that it will be useful,
 16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 18+ * GNU General Public License for more details.
 19+ *
 20+ * You should have received a copy of the GNU General Public License along
 21+ * with this program; if not, write to the Free Software Foundation, Inc.,
 22+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 23+ * http://www.gnu.org/copyleft/gpl.html
 24+ */
 25+
 26+if (!defined('MEDIAWIKI')) {
 27+ // Eclipse helper - will be ignored in production
 28+ require_once ("ApiBase.php");
 29+}
 30+
 31+/**
 32+ * @addtogroup API
 33+ */
 34+class ApiUndelete extends ApiBase {
 35+
 36+ public function __construct($main, $action) {
 37+ parent :: __construct($main, $action);
 38+ }
 39+
 40+ public function execute() {
 41+ global $wgUser;
 42+ $params = $this->extractRequestParams();
 43+
 44+ $titleObj = NULL;
 45+ if(!isset($params['title']))
 46+ $this->dieUsage('The title parameter must be set', 'notarget');
 47+ if(!isset($params['token']))
 48+ $this->dieUsage('The token parameter must be set', 'notoken');
 49+
 50+ if(!$wgUser->isAllowed('delete'))
 51+ $this->dieUsage('You don\'t have permission to restore deleted revisions', 'permissiondenied');
 52+ if($wgUser->isBlocked())
 53+ $this->dieUsage('You have been blocked from editing', 'blocked');
 54+ if(wfReadOnly())
 55+ $this->dieUsage('The wiki is in read-only mode', 'readonly');
 56+ if(!$wgUser->matchEditToken($params['token']))
 57+ $this->dieUsage('Invalid token', 'badtoken');
 58+
 59+ $titleObj = Title::newFromText($params['title']);
 60+ if(!$titleObj)
 61+ $this->dieUsage("bad title {$params['title']}", 'invalidtitle');
 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');
 65+
 66+ $info['title'] = $params['title'];
 67+ $info['reason'] = $params['reason']; // FIXME
 68+ $this->getResult()->addValue(null, $this->getModuleName(), $info);
 69+ }
 70+
 71+ protected function getAllowedParams() {
 72+ return array (
 73+ 'title' => null,
 74+ 'token' => null,
 75+ 'reason' => "",
 76+ 'timestamps' => array(
 77+ ApiBase :: PARAM_ISMULTI => true
 78+ )
 79+ );
 80+ }
 81+
 82+ protected function getParamDescription() {
 83+ return array (
 84+ 'title' => 'Title of the page you want to restore.',
 85+ 'token' => 'An undelete token previously retrieved through list=deletedrevs',
 86+ 'reason' => 'Reason for restoring (optional)',
 87+ 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.'
 88+ );
 89+ }
 90+
 91+ protected function getDescription() {
 92+ return array(
 93+ 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be',
 94+ 'retrieved through list=deletedrevs'
 95+ );
 96+ }
 97+
 98+ protected function getExamples() {
 99+ return array (
 100+ 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
 101+ 'api.php?action=undelete&title=Main%20Page&token=123ABC&timestamps=20070703220045|20070702194856'
 102+ );
 103+ }
 104+
 105+ public function getVersion() {
 106+ return __CLASS__ . ': $Id: ApiUndelete.php 22289 2007-05-20 23:31:44Z yurik $';
 107+ }
 108+}
 109+?>
Property changes on: branches/apiedit/phase3/includes/api/ApiUndelete.php
___________________________________________________________________
Added: svn:eol-style
1110 + native
Index: branches/apiedit/phase3/includes/SpecialUndelete.php
@@ -263,6 +263,8 @@
264264 function undelete( $timestamps, $comment = '', $fileVersions = array() ) {
265265 // If both the set of text revisions and file revisions are empty,
266266 // restore everything. Otherwise, just restore the requested items.
 267+ $dbw = wfGetDB(DB_MASTER);
 268+ $dbw->begin();
267269 $restoreAll = empty( $timestamps ) && empty( $fileVersions );
268270
269271 $restoreText = $restoreAll || !empty( $timestamps );
@@ -303,7 +305,8 @@
304306 if( trim( $comment ) != '' )
305307 $reason .= ": {$comment}";
306308 $log->addEntry( 'restore', $this->title, $reason );
307 -
 309+
 310+ $dbw->commit();
308311 return true;
309312 }
310313
Index: branches/apiedit/phase3/includes/AutoLoader.php
@@ -324,7 +324,8 @@
325325 'ApiQuerySiteinfo' => 'includes/api/ApiQuerySiteinfo.php',
326326 'ApiQueryWatchlist' => 'includes/api/ApiQueryWatchlist.php',
327327 'ApiResult' => 'includes/api/ApiResult.php',
328 - 'ApiRollback' => 'includes/api/ApiRollback.php'
 328+ 'ApiRollback' => 'includes/api/ApiRollback.php',
 329+ 'ApiUndelete' => 'includes/api/ApiUndelete.php'
329330 );
330331
331332 wfProfileIn( __METHOD__ );

Status & tagging log