From 2821f1ef71945ca3d902a343a75f566225836663 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 4 Dec 2007 16:33:08 +0000 Subject: [PATCH] Removing double tabs inserted due to my editor's retarded tabsize=4 setting. --- includes/api/ApiChangeRights.php | 2 +- includes/api/ApiMove.php | 135 ++++++------ includes/api/ApiQueryDeletedrevs.php | 313 +++++++++++++-------------- 3 files changed, 222 insertions(+), 228 deletions(-) diff --git a/includes/api/ApiChangeRights.php b/includes/api/ApiChangeRights.php index e8138b8710..71646fbe0f 100644 --- a/includes/api/ApiChangeRights.php +++ b/includes/api/ApiChangeRights.php @@ -41,7 +41,7 @@ class ApiChangeRights extends ApiBase { $this->getMain()->requestWriteMode(); if(wfReadOnly()) - $this->dieUsage('The wiki is in read-only mode', 'readonly'); + $this->dieUsage('The wiki is in read-only mode', 'readonly'); $params = $this->extractRequestParams(); $ur = new UserrightsForm($wgRequest); diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index f122a29329..03752a4230 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -34,7 +34,7 @@ if (!defined('MEDIAWIKI')) { class ApiMove extends ApiBase { public function __construct($main, $action) { - parent :: __construct($main, $action); + parent :: __construct($main, $action); } public function execute() { @@ -42,100 +42,100 @@ class ApiMove extends ApiBase { $this->getMain()->requestWriteMode(); $params = $this->extractRequestParams(); if(is_null($params['reason'])) - $params['reason'] = ''; - + $params['reason'] = ''; + $titleObj = NULL; if(!isset($params['from'])) - $this->dieUsage('The from parameter must be set', 'nofrom'); + $this->dieUsage('The from parameter must be set', 'nofrom'); if(!isset($params['to'])) - $this->dieUsage('The to parameter must be set', 'noto'); + $this->dieUsage('The to parameter must be set', 'noto'); if(!isset($params['token'])) - $this->dieUsage('The token parameter must be set', 'notoken'); + $this->dieUsage('The token parameter must be set', 'notoken'); if(!$wgUser->matchEditToken($params['token'])) - $this->dieUsage('Invalid token', 'badtoken'); + $this->dieUsage('Invalid token', 'badtoken'); if($wgUser->isBlocked()) - $this->dieUsage('You have been blocked from editing', 'blocked'); + $this->dieUsage('You have been blocked from editing', 'blocked'); if(wfReadOnly()) - $this->dieUsage('The wiki is in read-only mode', 'readonly'); + $this->dieUsage('The wiki is in read-only mode', 'readonly'); if($params['noredirect'] && !$wgUser->isAllowed('suppressredirect')) - $this->dieUsage("You don't have permission to suppress redirect creation", 'nosuppress'); + $this->dieUsage("You don't have permission to suppress redirect creation", 'nosuppress'); $fromTitle = Title::newFromText($params['from']); if(!$fromTitle) - $this->dieUsage("Bad title ``{$params['from']}''", 'invalidtitle'); + $this->dieUsage("Bad title ``{$params['from']}''", 'invalidtitle'); if(!$fromTitle->exists()) - $this->dieUsage("``{$params['from']}'' doesn't exist", 'missingtitle'); + $this->dieUsage("``{$params['from']}'' doesn't exist", 'missingtitle'); $fromTalk = $fromTitle->getTalkPage(); - + $toTitle = Title::newFromText($params['to']); if(!$toTitle) - $this->dieUsage("Bad title ``{$params['to']}''", 'invalidtitle'); + $this->dieUsage("Bad title ``{$params['to']}''", 'invalidtitle'); $toTalk = $toTitle->getTalkPage(); $dbw = wfGetDB(DB_MASTER); - $dbw->begin(); + $dbw->begin(); $retval = $fromTitle->moveTo($toTitle, true, $params['reason'], !$params['noredirect']); if($retval !== true) - switch($retval) - { - // case 'badtitletext': Can't happen - // case 'badarticleerror': Can't happen - case 'selfmove': - $this->dieUsage("Can't move ``{$params['from']}'' to itself", 'selfmove'); - case 'immobile_namespace': - if($fromTitle->isMovable()) - $this->dieUsage("Pages in the ``{$fromTitle->getNsText()}'' namespace can't be moved", 'immobilenamespace-from'); - $this->dieUsage("Pages in the ``{$toTitle->getNsText()}'' namespace can't be moved", 'immobilenamespace-to'); - case 'articleexists': - $this->dieUsage("``{$toTitle->getPrefixedText()}'' already exists and is not a redirect to ``{$fromTitle->getPrefixedText()}''", 'targetexists'); - case 'protectedpage': - $this->dieUsage("You don't have permission to move ``{$fromTitle->getPrefixedText()}'' to ``{$toTitle->getPrefixedText()}''", 'permissiondenied'); - default: - throw new MWException( "Title::moveTo: Unknown return value ``{$retval}''" ); - } + switch($retval) + { + // case 'badtitletext': Can't happen + // case 'badarticleerror': Can't happen + case 'selfmove': + $this->dieUsage("Can't move ``{$params['from']}'' to itself", 'selfmove'); + case 'immobile_namespace': + if($fromTitle->isMovable()) + $this->dieUsage("Pages in the ``{$fromTitle->getNsText()}'' namespace can't be moved", 'immobilenamespace-from'); + $this->dieUsage("Pages in the ``{$toTitle->getNsText()}'' namespace can't be moved", 'immobilenamespace-to'); + case 'articleexists': + $this->dieUsage("``{$toTitle->getPrefixedText()}'' already exists and is not a redirect to ``{$fromTitle->getPrefixedText()}''", 'targetexists'); + case 'protectedpage': + $this->dieUsage("You don't have permission to move ``{$fromTitle->getPrefixedText()}'' to ``{$toTitle->getPrefixedText()}''", 'permissiondenied'); + default: + throw new MWException( "Title::moveTo: Unknown return value ``{$retval}''" ); + } $r = array('from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason']); if(!$params['noredirect']) - $r['redirectcreated'] = ''; - + $r['redirectcreated'] = ''; + if($params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage()) { - // We need to move the talk page as well - $toTalk = $toTitle->getTalkPage(); - $retval = $fromTalk->moveTo($toTalk, true, $params['reason'], !$params['noredirect']); - if($retval === true) + // We need to move the talk page as well + $toTalk = $toTitle->getTalkPage(); + $retval = $fromTalk->moveTo($toTalk, true, $params['reason'], !$params['noredirect']); + if($retval === true) + { + $r['talkfrom'] = $fromTalk->getPrefixedText(); + $r['talkto'] = $toTalk->getPrefixedText(); + } + // We're not gonna dieUsage() on failure, since we already changed something + else + switch($retval) { - $r['talkfrom'] = $fromTalk->getPrefixedText(); - $r['talkto'] = $toTalk->getPrefixedText(); - } - // We're not gonna dieUsage() on failure, since we already changed something - else - switch($retval) + case 'immobile_namespace': + if($fromTalk->isMovable()) { - case 'immobile_namespace': - if($fromTalk->isMovable()) - { - $r['talkmove-error-code'] = 'immobilenamespace-from'; - $r['talkmove-error-info'] = "Pages in the ``{$fromTalk->getNsText()}'' namespace can't be moved"; - } - else - { - $r['talkmove-error-code'] = 'immobilenamespace-to'; - $r['talkmove-error-info'] = "Pages in the ``{$toTalk->getNsText()}'' namespace can't be moved"; - } - break; - case 'articleexists': - $r['talkmove-error-code'] = 'targetexists'; - $r['talkmove-error-info'] = "``{$toTalk->getPrefixedText()}'' already exists and is not a redirect to ``{$fromTalk->getPrefixedText()}''"; - break; - case 'protectedpage': - $r['talkmove-error-code'] = 'permissiondenied'; - $r['talkmove-error-info'] = "You don't have permission to move ``{$fromTalk->getPrefixedText()}'' to ``{$toTalk->getPrefixedText()}''"; - default: - $r['talkmove-error-code'] = 'unknownerror'; - $r['talkmove-error-info'] = "Unknown error ``$retval''"; - } + $r['talkmove-error-code'] = 'immobilenamespace-from'; + $r['talkmove-error-info'] = "Pages in the ``{$fromTalk->getNsText()}'' namespace can't be moved"; + } + else + { + $r['talkmove-error-code'] = 'immobilenamespace-to'; + $r['talkmove-error-info'] = "Pages in the ``{$toTalk->getNsText()}'' namespace can't be moved"; + } + break; + case 'articleexists': + $r['talkmove-error-code'] = 'targetexists'; + $r['talkmove-error-info'] = "``{$toTalk->getPrefixedText()}'' already exists and is not a redirect to ``{$fromTalk->getPrefixedText()}''"; + break; + case 'protectedpage': + $r['talkmove-error-code'] = 'permissiondenied'; + $r['talkmove-error-info'] = "You don't have permission to move ``{$fromTalk->getPrefixedText()}'' to ``{$toTalk->getPrefixedText()}''"; + default: + $r['talkmove-error-code'] = 'unknownerror'; + $r['talkmove-error-info'] = "Unknown error ``$retval''"; + } } $dbw->commit(); // Make sure all changes are really written to the DB $this->getResult()->addValue(null, $this->getModuleName(), $r); @@ -179,4 +179,3 @@ class ApiMove extends ApiBase { return __CLASS__ . ': $Id$'; } } - diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index 5c9c7f3591..f799e4d976 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -48,190 +48,185 @@ class ApiQueryDeletedrevs extends ApiQueryBase { global $wgUser; // Before doing anything at all, let's check permissions if(!$wgUser->isAllowed('deletedhistory')) - $this->dieUsage('You don\'t have permission to view deleted revisions information', 'permissiondenied'); - - $db = $this->getDB(); - $params = $this->extractRequestParams(); - $prop = array_flip($params['prop']); - $fld_revid = isset($prop['revid']); - $fld_user = isset($prop['user']); - $fld_comment = isset($prop['comment']); - $fld_minor = isset($prop['minor']); - $fld_len = isset($prop['len']); - $fld_content = isset($prop['content']); - $fld_token = isset($prop['token']); - - $result = $this->getResult(); - $pageSet = $this->getPageSet(); - $titles = $pageSet->getTitles(); - $data = array(); - - $this->addTables('archive'); - $this->addFields(array('ar_title', 'ar_namespace', 'ar_timestamp')); + $this->dieUsage('You don\'t have permission to view deleted revisions', 'permissiondenied'); + + $db = $this->getDB(); + $params = $this->extractRequestParams(); + $prop = array_flip($params['prop']); + $fld_revid = isset($prop['revid']); + $fld_user = isset($prop['user']); + $fld_comment = isset($prop['comment']); + $fld_minor = isset($prop['minor']); + $fld_len = isset($prop['len']); + $fld_content = isset($prop['content']); + $fld_token = isset($prop['token']); + + $result = $this->getResult(); + $pageSet = $this->getPageSet(); + $titles = $pageSet->getTitles(); + $data = array(); + + $this->addTables('archive'); + $this->addFields(array('ar_title', 'ar_namespace', 'ar_timestamp')); + if($fld_revid) + $this->addFields('ar_rev_id'); + if($fld_user) + $this->addFields('ar_user_text'); + if($fld_comment) + $this->addFields('ar_comment'); + if($fld_minor) + $this->addFields('ar_minor_edit'); + if($fld_len) + $this->addFields('ar_len'); + if($fld_content) + { + $this->addTables('text'); + $this->addFields(array('ar_text', 'ar_text_id', 'old_text', 'old_flags')); + $this->addWhere('ar_text_id = old_id'); + + // This also means stricter limits + $userMax = 50; + $botMax = 200; + $this->validateLimit('limit', $params['limit'], 1, $userMax, $botMax); + } + if($fld_token) + // Undelete tokens are identical for all pages, so we cache one here + $token = $wgUser->editToken(); + + // We need a custom WHERE clause that matches all titles. + if(count($titles) > 0) + { + $lb = new LinkBatch($titles); + $where = $lb->constructSet('ar', $db); + $this->addWhere($where); + } + + $this->addOption('LIMIT', $params['limit'] + 1); + $this->addWhereRange('ar_timestamp', $params['dir'], $params['start'], $params['end']); + if(isset($params['namespace'])) + $this->addWhereFld('ar_namespace', $params['namespace']); + $res = $this->select(__METHOD__); + $pages = array(); + $count = 0; + // First populate the $pages array + while($row = $db->fetchObject($res)) + { + if($count++ == $params['limit']) + { + // We've had enough + $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ar_timestamp)); + break; + } + + $rev = array(); + $rev['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ar_timestamp); if($fld_revid) - $this->addFields('ar_rev_id'); + $rev['revid'] = $row->ar_rev_id; if($fld_user) - $this->addFields('ar_user_text'); + $rev['user'] = $row->ar_user_text; if($fld_comment) - $this->addFields('ar_comment'); + $rev['comment'] = $row->ar_comment; if($fld_minor) - $this->addFields('ar_minor_edit'); + if($row->ar_minor_edit == 1) + $rev['minor'] = ''; if($fld_len) - $this->addFields('ar_len'); + $rev['len'] = $row->ar_len; if($fld_content) - { - $this->addTables('text'); - $this->addFields(array('ar_text', 'ar_text_id', 'old_text', 'old_flags')); - $this->addWhere('ar_text_id = old_id'); - - // This also means stricter limits - $userMax = 50; - $botMax = 200; - $this->validateLimit('limit', $params['limit'], 1, $userMax, $botMax); - - // And also stricter restrictions - if(!$wgUser->isAllowed('delete')) { - $this->dieUsage('You don\'t have permission to view deleted revisions content', 'permissiondeniedcontent'); - } - } - if($fld_token) - // Undelete tokens are identical for all pages, so we cache one here - $token = $wgUser->editToken(); - - // We need a custom WHERE clause that matches all titles. - if(count($titles) > 0) - { - $lb = new LinkBatch($titles); - $where = $lb->constructSet('ar', $db); - $this->addWhere($where); - } + ApiResult::setContent($rev, Revision::getRevisionText($row)); - $this->addOption('LIMIT', $params['limit'] + 1); - $this->addWhereRange('ar_timestamp', $params['dir'], $params['start'], $params['end']); - if(isset($params['namespace'])) - $this->addWhereFld('ar_namespace', $params['namespace']); - $res = $this->select(__METHOD__); - $pages = array(); - $count = 0; - // First populate the $pages array - while($row = $db->fetchObject($res)) + $t = Title::makeTitle($row->ar_namespace, $row->ar_title); + if(!isset($pages[$t->getPrefixedText()])) { - if($count++ == $params['limit']) - { - // We've had enough - $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ar_timestamp)); - break; - } - - $rev = array(); - $rev['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ar_timestamp); - if($fld_revid) - $rev['revid'] = $row->ar_rev_id; - if($fld_user) - $rev['user'] = $row->ar_user_text; - if($fld_comment) - $rev['comment'] = $row->ar_comment; - if($fld_minor) - if($row->ar_minor_edit == 1) - $rev['minor'] = ''; - if($fld_len) - $rev['len'] = $row->ar_len; - if($fld_content) - ApiResult::setContent($rev, Revision::getRevisionText($row)); - - $t = Title::makeTitle($row->ar_namespace, $row->ar_title); - if(!isset($pages[$t->getPrefixedText()])) - { - $pages[$t->getPrefixedText()] = array( - 'title' => $t->getPrefixedText(), - 'ns' => intval($row->ar_namespace), - 'revisions' => array($rev) - ); - if($fld_token) - $pages[$t->getPrefixedText()]['token'] = $token; - } - else - $pages[$t->getPrefixedText()]['revisions'][] = $rev; + $pages[$t->getPrefixedText()] = array( + 'title' => $t->getPrefixedText(), + 'ns' => intval($row->ar_namespace), + 'revisions' => array($rev) + ); + if($fld_token) + $pages[$t->getPrefixedText()]['token'] = $token; } - $db->freeResult($res); + else + $pages[$t->getPrefixedText()]['revisions'][] = $rev; + } + $db->freeResult($res); - // We don't want entire pagenames as keys, so let's make this array indexed - foreach($pages as $page) - { - $result->setIndexedTagName($page['revisions'], 'rev'); - $data[] = $page; - } - $result->setIndexedTagName($data, 'page'); - $result->addValue('query', $this->getModuleName(), $data); + // We don't want entire pagenames as keys, so let's make this array indexed + foreach($pages as $page) + { + $result->setIndexedTagName($page['revisions'], 'rev'); + $data[] = $page; + } + $result->setIndexedTagName($data, 'page'); + $result->addValue('query', $this->getModuleName(), $data); } protected function getAllowedParams() { - return array ( - 'start' => array( - ApiBase :: PARAM_TYPE => 'timestamp' - ), - 'end' => array( - ApiBase :: PARAM_TYPE => 'timestamp', + return array ( + 'start' => array( + ApiBase :: PARAM_TYPE => 'timestamp' + ), + 'end' => array( + ApiBase :: PARAM_TYPE => 'timestamp', + ), + 'dir' => array( + ApiBase :: PARAM_TYPE => array( + 'newer', + 'older' + ), + ApiBase :: PARAM_DFLT => 'older' + ), + 'namespace' => array( + ApiBase :: PARAM_ISMULTI => true, + ApiBase :: PARAM_TYPE => 'namespace' + ), + 'limit' => array( + ApiBase :: PARAM_DFLT => 10, + ApiBase :: PARAM_TYPE => 'limit', + ApiBase :: PARAM_MIN => 1, + ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1, + ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 + ), + 'prop' => array( + ApiBase :: PARAM_DFLT => 'user|comment', + ApiBase :: PARAM_TYPE => array( + 'revid', + 'user', + 'comment', + 'minor', + 'len', + 'content', + 'token' ), - 'dir' => array( - ApiBase :: PARAM_TYPE => array( - 'newer', - 'older' - ), - ApiBase :: PARAM_DFLT => 'older' - ), - 'namespace' => array( - ApiBase :: PARAM_ISMULTI => true, - ApiBase :: PARAM_TYPE => 'namespace' - ), - 'limit' => array( - ApiBase :: PARAM_DFLT => 10, - ApiBase :: PARAM_TYPE => 'limit', - ApiBase :: PARAM_MIN => 1, - ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1, - ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 - ), - 'prop' => array( - ApiBase :: PARAM_DFLT => 'user|comment', - ApiBase :: PARAM_TYPE => array( - 'revid', - 'user', - 'comment', - 'minor', - 'len', - 'content', - 'token' - ), - ApiBase :: PARAM_ISMULTI => true - ) - ); + ApiBase :: PARAM_ISMULTI => true + ) + ); } protected function getParamDescription() { - return array ( - 'start' => 'The timestamp to start enumerating from', - 'end' => 'The timestamp to stop enumerating at', - 'dir' => 'The direction in which to enumerate', - 'namespace' => 'The namespaces to search in', - 'limit' => 'The maximum amount of revisions to list', - 'prop' => 'Which properties to get' - ); + return array ( + 'start' => 'The timestamp to start enumerating from', + 'end' => 'The timestamp to stop enumerating at', + 'dir' => 'The direction in which to enumerate', + 'namespace' => 'The namespaces to search in', + 'limit' => 'The maximum amount of revisions to list', + 'prop' => 'Which properties to get' + ); } protected function getDescription() { - return 'List deleted revisions.'; + return 'List deleted revisions.'; } protected function getExamples() { - return array ( - 'List the first 50 deleted revisions in the Category and Category talk namespaces', - ' api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=14|15', - 'List the last deleted revisions of Main Page and Talk:Main Page, with content:', - ' api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&drprop=user|comment|content' - ); + return array ( + 'List the first 50 deleted revisions in the Category and Category talk namespaces', + ' api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=14|15', + 'List the last deleted revisions of Main Page and Talk:Main Page, with content:', + ' api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&drprop=user|comment|content' + ); } public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryDeletedrevs.php 23531 2007-06-30 01:19:14Z simetrical $'; + return __CLASS__ . ': $Id: ApiQueryDeletedrevs.php 23531 2007-06-30 01:19:14Z simetrical $'; } } -- 2.20.1