From 88c6568f2bad43164379a7c5b1d8be3612bc83a8 Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Thu, 6 Dec 2007 16:06:22 +0000 Subject: [PATCH] Fix svn:eol-style and svn:keywords for files from merged APIEdit branch --- includes/api/ApiBlock.php | 328 +++++++++--------- includes/api/ApiChangeRights.php | 340 +++++++++---------- includes/api/ApiDelete.php | 344 +++++++++---------- includes/api/ApiMove.php | 362 ++++++++++---------- includes/api/ApiProtect.php | 284 ++++++++-------- includes/api/ApiQueryBlocks.php | 482 +++++++++++++-------------- includes/api/ApiQueryDeletedrevs.php | 460 ++++++++++++------------- includes/api/ApiRollback.php | 312 ++++++++--------- includes/api/ApiUnblock.php | 260 +++++++-------- includes/api/ApiUndelete.php | 258 +++++++------- 10 files changed, 1715 insertions(+), 1715 deletions(-) diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index 103a7757a9..ef9ad6cc22 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -1,164 +1,164 @@ -.@home.nl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ("ApiBase.php"); -} - -/** - * @addtogroup API - */ -class ApiBlock extends ApiBase { - - public function __construct($main, $action) { - parent :: __construct($main, $action); - } - - public function execute() { - global $wgUser; - $this->getMain()->requestWriteMode(); - $params = $this->extractRequestParams(); - - if($params['gettoken']) - { - $res['blocktoken'] = $wgUser->editToken(); - $this->getResult()->addValue(null, $this->getModuleName(), $res); - return; - } - - if(is_null($params['user'])) - $this->dieUsage('The user parameter must be set', 'nouser'); - if(is_null($params['token'])) - $this->dieUsage('The token parameter must be set', 'notoken'); - if(!$wgUser->matchEditToken($params['token'])) - $this->dieUsage('Invalid token', 'badtoken'); - if(!$wgUser->isAllowed('block')) - $this->dieUsage('You don\'t have permission to block users', 'permissiondenied'); - if($params['hidename'] && !$wgUser->isAllowed('hideuser')) - $this->dieUsage('You don\'t have permission to hide user names from the block log', 'nohide'); - if(wfReadOnly()) - $this->dieUsage('The wiki is in read-only mode', 'readonly'); - - $form = new IPBlockForm(''); - $form->BlockAddress = $params['user']; - $form->BlockReason = $params['reason']; - $form->BlockReasonList = 'other'; - $form->BlockExpiry = ($params['expiry'] == 'never' ? 'infinite' : $params['expiry']); - $form->BlockOther = ''; - $form->BlockAnonOnly = $params['anononly']; - $form->BlockCreateAccount = $params['nocreate']; - $form->BlockEnableAutoBlock = $params['autoblock']; - $form->BlockEmail = $params['noemail']; - $form->BlockHideName = $params['hidename']; - - $dbw = wfGetDb(DB_MASTER); - $dbw->begin(); - $retval = $form->doBlock($userID, $expiry); - switch($retval) - { - case IPBlockForm::BLOCK_SUCCESS: - break; // We'll deal with that later - case IPBlockForm::BLOCK_RANGE_INVALID: - $this->dieUsage("Invalid IP range ``{$params['user']}''", 'invalidrange'); - case IPBlockForm::BLOCK_RANGE_DISABLED: - $this->dieUsage('Blocking IP ranges has been disabled', 'rangedisabled'); - case IPBlockForm::BLOCK_NONEXISTENT_USER: - $this->dieUsage("User ``{$params['user']}'' doesn't exist", 'nosuchuser'); - case IPBlockForm::BLOCK_IP_INVALID: - $this->dieUsage("Invaild IP address ``{$params['user']}''", 'invalidip'); - case IPBlockForm::BLOCK_EXPIRY_INVALID: - $this->dieUsage("Invalid expiry time ``{$params['expiry']}''", 'invalidexpiry'); - case IPBlockForm::BLOCK_ALREADY_BLOCKED: - $this->dieUsage("User ``{$params['user']}'' is already blocked", 'alreadyblocked'); - default: - $this->dieDebug(__METHOD__, "IPBlockForm::doBlock() returned an unknown error ($retval)"); - } - $dbw->commit(); - - $res['user'] = $params['user']; - $res['userID'] = $userID; - $res['expiry'] = ($expiry == Block::infinity() ? 'infinite' : $expiry); - $res['reason'] = $params['reason']; - if($params['anononly']) - $res['anononly'] = ''; - if($params['nocreate']) - $res['nocreate'] = ''; - if($params['autoblock']) - $res['autoblock'] = ''; - if($params['noemail']) - $res['noemail'] = ''; - if($params['hidename']) - $res['hidename'] = ''; - - $this->getResult()->addValue(null, $this->getModuleName(), $res); - } - - protected function getAllowedParams() { - return array ( - 'user' => null, - 'token' => null, - 'gettoken' => false, - 'expiry' => 'never', - 'reason' => null, - 'anononly' => false, - 'nocreate' => false, - 'autoblock' => false, - 'noemail' => false, - 'hidename' => false, - ); - } - - protected function getParamDescription() { - return array ( - 'user' => 'Username, IP address or IP range you want to block', - 'token' => 'A block token previously obtained through the gettoken parameter', - 'gettoken' => 'If set, a block token will be returned, and no other action will be taken', - 'expiry' => 'Relative expiry time, e.g. \'5 months\' or \'2 weeks\'. If set to \'infinite\', \'indefinite\' or \'never\', the block will never expire.', - 'reason' => 'Reason for block (optional)', - 'anononly' => 'Block anonymous users only (i.e. disable anonymous edits for this IP)', - 'nocreate' => 'Prevent account creation', - 'autoblock' => 'Automatically block the last used IP address, and any subsequent IP addresses they try to login from', - 'noemail' => 'Prevent user from sending e-mail through the wiki', - 'hidename' => 'Hide the username from the block log.' - ); - } - - protected function getDescription() { - return array( - 'Block a user.' - ); - } - - protected function getExamples() { - return array ( - 'api.php?action=block&user=123.5.5.12&expiry=3%20days&reason=First%20strike', - 'api.php?action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate&autoblock&noemail' - ); - } - - public function getVersion() { - return __CLASS__ . ': $Id$'; - } -} +.@home.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +if (!defined('MEDIAWIKI')) { + // Eclipse helper - will be ignored in production + require_once ("ApiBase.php"); +} + +/** + * @addtogroup API + */ +class ApiBlock extends ApiBase { + + public function __construct($main, $action) { + parent :: __construct($main, $action); + } + + public function execute() { + global $wgUser; + $this->getMain()->requestWriteMode(); + $params = $this->extractRequestParams(); + + if($params['gettoken']) + { + $res['blocktoken'] = $wgUser->editToken(); + $this->getResult()->addValue(null, $this->getModuleName(), $res); + return; + } + + if(is_null($params['user'])) + $this->dieUsage('The user parameter must be set', 'nouser'); + if(is_null($params['token'])) + $this->dieUsage('The token parameter must be set', 'notoken'); + if(!$wgUser->matchEditToken($params['token'])) + $this->dieUsage('Invalid token', 'badtoken'); + if(!$wgUser->isAllowed('block')) + $this->dieUsage('You don\'t have permission to block users', 'permissiondenied'); + if($params['hidename'] && !$wgUser->isAllowed('hideuser')) + $this->dieUsage('You don\'t have permission to hide user names from the block log', 'nohide'); + if(wfReadOnly()) + $this->dieUsage('The wiki is in read-only mode', 'readonly'); + + $form = new IPBlockForm(''); + $form->BlockAddress = $params['user']; + $form->BlockReason = $params['reason']; + $form->BlockReasonList = 'other'; + $form->BlockExpiry = ($params['expiry'] == 'never' ? 'infinite' : $params['expiry']); + $form->BlockOther = ''; + $form->BlockAnonOnly = $params['anononly']; + $form->BlockCreateAccount = $params['nocreate']; + $form->BlockEnableAutoBlock = $params['autoblock']; + $form->BlockEmail = $params['noemail']; + $form->BlockHideName = $params['hidename']; + + $dbw = wfGetDb(DB_MASTER); + $dbw->begin(); + $retval = $form->doBlock($userID, $expiry); + switch($retval) + { + case IPBlockForm::BLOCK_SUCCESS: + break; // We'll deal with that later + case IPBlockForm::BLOCK_RANGE_INVALID: + $this->dieUsage("Invalid IP range ``{$params['user']}''", 'invalidrange'); + case IPBlockForm::BLOCK_RANGE_DISABLED: + $this->dieUsage('Blocking IP ranges has been disabled', 'rangedisabled'); + case IPBlockForm::BLOCK_NONEXISTENT_USER: + $this->dieUsage("User ``{$params['user']}'' doesn't exist", 'nosuchuser'); + case IPBlockForm::BLOCK_IP_INVALID: + $this->dieUsage("Invaild IP address ``{$params['user']}''", 'invalidip'); + case IPBlockForm::BLOCK_EXPIRY_INVALID: + $this->dieUsage("Invalid expiry time ``{$params['expiry']}''", 'invalidexpiry'); + case IPBlockForm::BLOCK_ALREADY_BLOCKED: + $this->dieUsage("User ``{$params['user']}'' is already blocked", 'alreadyblocked'); + default: + $this->dieDebug(__METHOD__, "IPBlockForm::doBlock() returned an unknown error ($retval)"); + } + $dbw->commit(); + + $res['user'] = $params['user']; + $res['userID'] = $userID; + $res['expiry'] = ($expiry == Block::infinity() ? 'infinite' : $expiry); + $res['reason'] = $params['reason']; + if($params['anononly']) + $res['anononly'] = ''; + if($params['nocreate']) + $res['nocreate'] = ''; + if($params['autoblock']) + $res['autoblock'] = ''; + if($params['noemail']) + $res['noemail'] = ''; + if($params['hidename']) + $res['hidename'] = ''; + + $this->getResult()->addValue(null, $this->getModuleName(), $res); + } + + protected function getAllowedParams() { + return array ( + 'user' => null, + 'token' => null, + 'gettoken' => false, + 'expiry' => 'never', + 'reason' => null, + 'anononly' => false, + 'nocreate' => false, + 'autoblock' => false, + 'noemail' => false, + 'hidename' => false, + ); + } + + protected function getParamDescription() { + return array ( + 'user' => 'Username, IP address or IP range you want to block', + 'token' => 'A block token previously obtained through the gettoken parameter', + 'gettoken' => 'If set, a block token will be returned, and no other action will be taken', + 'expiry' => 'Relative expiry time, e.g. \'5 months\' or \'2 weeks\'. If set to \'infinite\', \'indefinite\' or \'never\', the block will never expire.', + 'reason' => 'Reason for block (optional)', + 'anononly' => 'Block anonymous users only (i.e. disable anonymous edits for this IP)', + 'nocreate' => 'Prevent account creation', + 'autoblock' => 'Automatically block the last used IP address, and any subsequent IP addresses they try to login from', + 'noemail' => 'Prevent user from sending e-mail through the wiki', + 'hidename' => 'Hide the username from the block log.' + ); + } + + protected function getDescription() { + return array( + 'Block a user.' + ); + } + + protected function getExamples() { + return array ( + 'api.php?action=block&user=123.5.5.12&expiry=3%20days&reason=First%20strike', + 'api.php?action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate&autoblock&noemail' + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } +} diff --git a/includes/api/ApiChangeRights.php b/includes/api/ApiChangeRights.php index 71646fbe0f..4991437a58 100644 --- a/includes/api/ApiChangeRights.php +++ b/includes/api/ApiChangeRights.php @@ -1,170 +1,170 @@ -.@home.nl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ("ApiBase.php"); -} - -/** - * @addtogroup API - */ -class ApiChangeRights extends ApiBase { - - public function __construct($main, $action) { - parent :: __construct($main, $action); - } - - public function execute() { - global $wgUser, $wgRequest; - $this->getMain()->requestWriteMode(); - - if(wfReadOnly()) - $this->dieUsage('The wiki is in read-only mode', 'readonly'); - $params = $this->extractRequestParams(); - - $ur = new UserrightsForm($wgRequest); - $allowed = $ur->changeableGroups(); - $res = array(); - - if(is_null($params['user'])) - $this->dieUsage('The user parameter must be set', 'nouser'); - - $uName = User::getCanonicalName($params['user']); - $u = User::newFromName($uName); - if(!$u) - $this->dieUsage("Invalid username ``{$params['user']}''", 'invaliduser'); - if($u->getId() == 0) // Anon or non-existent - $this->dieUsage("User ``{$params['user']}'' doesn't exist", 'nosuchuser'); - - $curgroups = $u->getGroups(); - - if($params['listgroups']) - { - $res['user'] = $uName; - $res['allowedgroups'] = $allowed; - $res['ingroups'] = $curgroups; - $this->getResult()->setIndexedTagName($res['ingroups'], 'group'); - $this->getResult()->setIndexedTagName($res['allowedgroups']['add'], 'group'); - $this->getResult()->setIndexedTagName($res['allowedgroups']['remove'], 'group'); - } -; - if($params['gettoken']) - { - $res['changerightstoken'] = $wgUser->editToken($uName); - $this->getResult()->addValue(null, $this->getModuleName(), $res); - return; - } - - if(empty($params['addto']) && empty($params['rmfrom'])) - $this->dieUsage('At least one of the addto and rmfrom parameters must be set', 'noaddrm'); - if(is_null($params['token'])) - $this->dieUsage('The token parameter must be set', 'notoken'); - if(!$wgUser->matchEditToken($params['token'], $uName)) - $this->dieUsage('Invalid token', 'badtoken'); - - if(!$wgUser->isAllowed('userrights')) - $this->dieUsage('You don\'t have permission to change users\' rights', 'permissiondenied'); - - // First let's remove redundant groups and check permissions while we're at it - if(is_null($params['addto'])) - $params['addto'] = array(); - $addto = array(); - foreach($params['addto'] as $g) - { - if(!in_array($g, $allowed['add'])) - $this->dieUsage("You don't have permission to add to group ``$g''", 'cantadd'); - if(!in_array($g, $curgroups)) - $addto[] = $g; - } - - if(is_null($params['rmfrom'])) - $params['rmfrom'] = array(); - $rmfrom = array(); - foreach($params['rmfrom'] as $g) - { - if(!in_array($g, $allowed['remove'])) - $this->dieUsage("You don't have permission to remove from group ``$g''", 'cantremove'); - if(in_array($g, $curgroups)) - $rmfrom[] = $g; - } - $dbw = wfGetDb(DB_MASTER); - $dbw->begin(); - $ur->doSaveUserGroups($u, $rmfrom, $addto, $params['reason']); - $dbw->commit(); - $res['user'] = $uName; - $res['addedto'] = $addto; - $res['removedfrom'] = $rmfrom; - $res['reason'] = $params['reason']; - - $this->getResult()->setIndexedTagName($res['addedto'], 'group'); - $this->getResult()->setIndexedTagName($res['removedfrom'], 'group'); - $this->getResult()->addValue(null, $this->getModuleName(), $res); - } - - protected function getAllowedParams() { - return array ( - 'user' => null, - 'token' => null, - 'gettoken' => false, - 'listgroups' => false, - 'addto' => array( - ApiBase :: PARAM_ISMULTI => true, - ), - 'rmfrom' => array( - ApiBase :: PARAM_ISMULTI => true, - ), - 'reason' => '' - ); - } - - protected function getParamDescription() { - return array ( - 'user' => 'The user you want to add to or remove from groups.', - 'token' => 'A changerights token previously obtained through the gettoken parameter.', - 'gettoken' => 'Output a token. Note that the user parameter still has to be set.', - 'listgroups' => 'List the groups the user is in, and the ones you can add them to and remove them from.', - 'addto' => 'Pipe-separated list of groups to add this user to', - 'rmfrom' => 'Pipe-separated list of groups to remove this user from', - 'reason' => 'Reason for change (optional)' - ); - } - - protected function getDescription() { - return array( - 'Add or remove a user from certain groups.' - ); - } - - protected function getExamples() { - return array ( - 'api.php?action=changerights&user=Bob&gettoken&listgroups', - 'api.php?action=changerights&user=Bob&token=123ABC&addto=sysop&reason=Promoting%20per%20RFA' - ); - } - - public function getVersion() { - return __CLASS__ . ': $Id$'; - } -} +.@home.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +if (!defined('MEDIAWIKI')) { + // Eclipse helper - will be ignored in production + require_once ("ApiBase.php"); +} + +/** + * @addtogroup API + */ +class ApiChangeRights extends ApiBase { + + public function __construct($main, $action) { + parent :: __construct($main, $action); + } + + public function execute() { + global $wgUser, $wgRequest; + $this->getMain()->requestWriteMode(); + + if(wfReadOnly()) + $this->dieUsage('The wiki is in read-only mode', 'readonly'); + $params = $this->extractRequestParams(); + + $ur = new UserrightsForm($wgRequest); + $allowed = $ur->changeableGroups(); + $res = array(); + + if(is_null($params['user'])) + $this->dieUsage('The user parameter must be set', 'nouser'); + + $uName = User::getCanonicalName($params['user']); + $u = User::newFromName($uName); + if(!$u) + $this->dieUsage("Invalid username ``{$params['user']}''", 'invaliduser'); + if($u->getId() == 0) // Anon or non-existent + $this->dieUsage("User ``{$params['user']}'' doesn't exist", 'nosuchuser'); + + $curgroups = $u->getGroups(); + + if($params['listgroups']) + { + $res['user'] = $uName; + $res['allowedgroups'] = $allowed; + $res['ingroups'] = $curgroups; + $this->getResult()->setIndexedTagName($res['ingroups'], 'group'); + $this->getResult()->setIndexedTagName($res['allowedgroups']['add'], 'group'); + $this->getResult()->setIndexedTagName($res['allowedgroups']['remove'], 'group'); + } +; + if($params['gettoken']) + { + $res['changerightstoken'] = $wgUser->editToken($uName); + $this->getResult()->addValue(null, $this->getModuleName(), $res); + return; + } + + if(empty($params['addto']) && empty($params['rmfrom'])) + $this->dieUsage('At least one of the addto and rmfrom parameters must be set', 'noaddrm'); + if(is_null($params['token'])) + $this->dieUsage('The token parameter must be set', 'notoken'); + if(!$wgUser->matchEditToken($params['token'], $uName)) + $this->dieUsage('Invalid token', 'badtoken'); + + if(!$wgUser->isAllowed('userrights')) + $this->dieUsage('You don\'t have permission to change users\' rights', 'permissiondenied'); + + // First let's remove redundant groups and check permissions while we're at it + if(is_null($params['addto'])) + $params['addto'] = array(); + $addto = array(); + foreach($params['addto'] as $g) + { + if(!in_array($g, $allowed['add'])) + $this->dieUsage("You don't have permission to add to group ``$g''", 'cantadd'); + if(!in_array($g, $curgroups)) + $addto[] = $g; + } + + if(is_null($params['rmfrom'])) + $params['rmfrom'] = array(); + $rmfrom = array(); + foreach($params['rmfrom'] as $g) + { + if(!in_array($g, $allowed['remove'])) + $this->dieUsage("You don't have permission to remove from group ``$g''", 'cantremove'); + if(in_array($g, $curgroups)) + $rmfrom[] = $g; + } + $dbw = wfGetDb(DB_MASTER); + $dbw->begin(); + $ur->doSaveUserGroups($u, $rmfrom, $addto, $params['reason']); + $dbw->commit(); + $res['user'] = $uName; + $res['addedto'] = $addto; + $res['removedfrom'] = $rmfrom; + $res['reason'] = $params['reason']; + + $this->getResult()->setIndexedTagName($res['addedto'], 'group'); + $this->getResult()->setIndexedTagName($res['removedfrom'], 'group'); + $this->getResult()->addValue(null, $this->getModuleName(), $res); + } + + protected function getAllowedParams() { + return array ( + 'user' => null, + 'token' => null, + 'gettoken' => false, + 'listgroups' => false, + 'addto' => array( + ApiBase :: PARAM_ISMULTI => true, + ), + 'rmfrom' => array( + ApiBase :: PARAM_ISMULTI => true, + ), + 'reason' => '' + ); + } + + protected function getParamDescription() { + return array ( + 'user' => 'The user you want to add to or remove from groups.', + 'token' => 'A changerights token previously obtained through the gettoken parameter.', + 'gettoken' => 'Output a token. Note that the user parameter still has to be set.', + 'listgroups' => 'List the groups the user is in, and the ones you can add them to and remove them from.', + 'addto' => 'Pipe-separated list of groups to add this user to', + 'rmfrom' => 'Pipe-separated list of groups to remove this user from', + 'reason' => 'Reason for change (optional)' + ); + } + + protected function getDescription() { + return array( + 'Add or remove a user from certain groups.' + ); + } + + protected function getExamples() { + return array ( + 'api.php?action=changerights&user=Bob&gettoken&listgroups', + 'api.php?action=changerights&user=Bob&token=123ABC&addto=sysop&reason=Promoting%20per%20RFA' + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } +} diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 74695f1183..6ca9f953ea 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -1,172 +1,172 @@ -.@home.nl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ("ApiBase.php"); -} - - -/** - * @addtogroup API - */ -class ApiDelete extends ApiBase { - - public function __construct($main, $action) { - parent :: __construct($main, $action); - } - - /** - * We have our own delete() function, since Article.php's implementation is split in two phases - * @param Article $article - Article object to work on - * @param string $token - Delete token (same as edit token) - * @param string $reason - Reason for the deletion. Autogenerated if NULL - * @return DELETE_SUCCESS on success, DELETE_* on failure - */ - - const DELETE_SUCCESS = 0; - const DELETE_PERM = 1; - const DELETE_BLOCKED = 2; - const DELETE_READONLY = 3; - const DELETE_BADTOKEN = 4; - const DELETE_BADARTICLE = 5; - - public static function delete(&$article, $token, &$reason = NULL) - { - global $wgUser; - - // Check permissions first - if(!$article->mTitle->userCan('delete')) - return self::DELETE_PERM; - if($wgUser->isBlocked()) - return self::DELETE_BLOCKED; - if(wfReadOnly()) - return self::DELETE_READONLY; - - // Check token - if(!$wgUser->matchEditToken($token)) - return self::DELETE_BADTOKEN; - - // Auto-generate a summary, if necessary - if(is_null($reason)) - { - $reason = $article->generateReason($hasHistory); - if($reason === false) - return self::DELETE_BADARTICLE; - } - - // Luckily, Article.php provides a reusable delete function that does the hard work for us - if($article->doDeleteArticle($reason)) - return self::DELETE_SUCCESS; - return self::DELETE_BADARTICLE; - } - - public function execute() { - global $wgUser; - $this->getMain()->requestWriteMode(); - $params = $this->extractRequestParams(); - - $titleObj = NULL; - if(!isset($params['title'])) - $this->dieUsage('The title parameter must be set', 'notitle'); - if(!isset($params['token'])) - $this->dieUsage('The token parameter must be set', 'notoken'); - - // delete() also checks for these, but we wanna save some work - if(!$wgUser->isAllowed('delete')) - $this->dieUsage('You don\'t have permission to delete pages', 'permissiondenied'); - if($wgUser->isBlocked()) - $this->dieUsage('You have been blocked from editing', 'blocked'); - if(wfReadOnly()) - $this->dieUsage('The wiki is in read-only mode', 'readonly'); - - $titleObj = Title::newFromText($params['title']); - if(!$titleObj) - $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle'); - if(!$titleObj->exists()) - $this->dieUsage("``{$params['title']}'' doesn't exist", 'missingtitle'); - - $articleObj = new Article($titleObj); - $reason = (isset($params['reason']) ? $params['reason'] : NULL); - $dbw = wfGetDb(DB_MASTER); - $dbw->begin(); - $retval = self::delete(&$articleObj, $params['token'], &$reason); - - switch($retval) - { - case self::DELETE_SUCCESS: - break; // We'll deal with that later - case self::DELETE_PERM: // If we get PERM, BLOCKED or READONLY that's weird, but it's possible - $this->dieUsage('You don\'t have permission to delete', 'permissiondenied'); - case self::DELETE_BLOCKED: - $this->dieUsage('You have been blocked from editing', 'blocked'); - case self::DELETE_READONLY: - $this->dieUsage('The wiki is in read-only mode', 'readonly'); - case self::DELETE_BADTOKEN: - $this->dieUsage('Invalid token', 'badtoken'); - case self::DELETE_BADARTICLE: - $this->dieUsage("The article ``{$params['title']}'' doesn't exist or has already been deleted", 'missingtitle'); - default: - // delete() has apparently invented a new error, which is extremely weird - $this->dieDebug(__METHOD__, "delete() returned an unknown error ($retval)"); - } - // $retval has to be self::DELETE_SUCCESS if we get here - $dbw->commit(); - $r = array('title' => $titleObj->getPrefixedText(), 'reason' => $reason); - $this->getResult()->addValue(null, $this->getModuleName(), $r); - } - - protected function getAllowedParams() { - return array ( - 'title' => null, - 'token' => null, - 'reason' => null, - ); - } - - protected function getParamDescription() { - return array ( - 'title' => 'Title of the page you want to delete.', - 'token' => 'A delete token previously retrieved through prop=info', - 'reason' => 'Reason for the deletion. If not set, an automatically generated reason will be used.' - ); - } - - protected function getDescription() { - return array( - 'Deletes a page. You need to be logged in as a sysop to use this function, see also action=login.' - ); - } - - protected function getExamples() { - return array ( - 'api.php?action=delete&title=Main%20Page&token=123ABC', - 'api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move' - ); - } - - public function getVersion() { - return __CLASS__ . ': $Id: ApiDelete.php 22289 2007-05-20 23:31:44Z yurik $'; - } -} +.@home.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +if (!defined('MEDIAWIKI')) { + // Eclipse helper - will be ignored in production + require_once ("ApiBase.php"); +} + + +/** + * @addtogroup API + */ +class ApiDelete extends ApiBase { + + public function __construct($main, $action) { + parent :: __construct($main, $action); + } + + /** + * We have our own delete() function, since Article.php's implementation is split in two phases + * @param Article $article - Article object to work on + * @param string $token - Delete token (same as edit token) + * @param string $reason - Reason for the deletion. Autogenerated if NULL + * @return DELETE_SUCCESS on success, DELETE_* on failure + */ + + const DELETE_SUCCESS = 0; + const DELETE_PERM = 1; + const DELETE_BLOCKED = 2; + const DELETE_READONLY = 3; + const DELETE_BADTOKEN = 4; + const DELETE_BADARTICLE = 5; + + public static function delete(&$article, $token, &$reason = NULL) + { + global $wgUser; + + // Check permissions first + if(!$article->mTitle->userCan('delete')) + return self::DELETE_PERM; + if($wgUser->isBlocked()) + return self::DELETE_BLOCKED; + if(wfReadOnly()) + return self::DELETE_READONLY; + + // Check token + if(!$wgUser->matchEditToken($token)) + return self::DELETE_BADTOKEN; + + // Auto-generate a summary, if necessary + if(is_null($reason)) + { + $reason = $article->generateReason($hasHistory); + if($reason === false) + return self::DELETE_BADARTICLE; + } + + // Luckily, Article.php provides a reusable delete function that does the hard work for us + if($article->doDeleteArticle($reason)) + return self::DELETE_SUCCESS; + return self::DELETE_BADARTICLE; + } + + public function execute() { + global $wgUser; + $this->getMain()->requestWriteMode(); + $params = $this->extractRequestParams(); + + $titleObj = NULL; + if(!isset($params['title'])) + $this->dieUsage('The title parameter must be set', 'notitle'); + if(!isset($params['token'])) + $this->dieUsage('The token parameter must be set', 'notoken'); + + // delete() also checks for these, but we wanna save some work + if(!$wgUser->isAllowed('delete')) + $this->dieUsage('You don\'t have permission to delete pages', 'permissiondenied'); + if($wgUser->isBlocked()) + $this->dieUsage('You have been blocked from editing', 'blocked'); + if(wfReadOnly()) + $this->dieUsage('The wiki is in read-only mode', 'readonly'); + + $titleObj = Title::newFromText($params['title']); + if(!$titleObj) + $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle'); + if(!$titleObj->exists()) + $this->dieUsage("``{$params['title']}'' doesn't exist", 'missingtitle'); + + $articleObj = new Article($titleObj); + $reason = (isset($params['reason']) ? $params['reason'] : NULL); + $dbw = wfGetDb(DB_MASTER); + $dbw->begin(); + $retval = self::delete(&$articleObj, $params['token'], &$reason); + + switch($retval) + { + case self::DELETE_SUCCESS: + break; // We'll deal with that later + case self::DELETE_PERM: // If we get PERM, BLOCKED or READONLY that's weird, but it's possible + $this->dieUsage('You don\'t have permission to delete', 'permissiondenied'); + case self::DELETE_BLOCKED: + $this->dieUsage('You have been blocked from editing', 'blocked'); + case self::DELETE_READONLY: + $this->dieUsage('The wiki is in read-only mode', 'readonly'); + case self::DELETE_BADTOKEN: + $this->dieUsage('Invalid token', 'badtoken'); + case self::DELETE_BADARTICLE: + $this->dieUsage("The article ``{$params['title']}'' doesn't exist or has already been deleted", 'missingtitle'); + default: + // delete() has apparently invented a new error, which is extremely weird + $this->dieDebug(__METHOD__, "delete() returned an unknown error ($retval)"); + } + // $retval has to be self::DELETE_SUCCESS if we get here + $dbw->commit(); + $r = array('title' => $titleObj->getPrefixedText(), 'reason' => $reason); + $this->getResult()->addValue(null, $this->getModuleName(), $r); + } + + protected function getAllowedParams() { + return array ( + 'title' => null, + 'token' => null, + 'reason' => null, + ); + } + + protected function getParamDescription() { + return array ( + 'title' => 'Title of the page you want to delete.', + 'token' => 'A delete token previously retrieved through prop=info', + 'reason' => 'Reason for the deletion. If not set, an automatically generated reason will be used.' + ); + } + + protected function getDescription() { + return array( + 'Deletes a page. You need to be logged in as a sysop to use this function, see also action=login.' + ); + } + + protected function getExamples() { + return array ( + 'api.php?action=delete&title=Main%20Page&token=123ABC', + 'api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move' + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } +} diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 03752a4230..2fc8fb106d 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -1,181 +1,181 @@ -.@home.nl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ("ApiBase.php"); -} - - -/** - * @addtogroup API - */ -class ApiMove extends ApiBase { - - public function __construct($main, $action) { - parent :: __construct($main, $action); - } - - public function execute() { - global $wgUser; - $this->getMain()->requestWriteMode(); - $params = $this->extractRequestParams(); - if(is_null($params['reason'])) - $params['reason'] = ''; - - $titleObj = NULL; - if(!isset($params['from'])) - $this->dieUsage('The from parameter must be set', 'nofrom'); - if(!isset($params['to'])) - $this->dieUsage('The to parameter must be set', 'noto'); - if(!isset($params['token'])) - $this->dieUsage('The token parameter must be set', 'notoken'); - if(!$wgUser->matchEditToken($params['token'])) - $this->dieUsage('Invalid token', 'badtoken'); - - if($wgUser->isBlocked()) - $this->dieUsage('You have been blocked from editing', 'blocked'); - if(wfReadOnly()) - $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'); - - $fromTitle = Title::newFromText($params['from']); - if(!$fromTitle) - $this->dieUsage("Bad title ``{$params['from']}''", 'invalidtitle'); - if(!$fromTitle->exists()) - $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'); - $toTalk = $toTitle->getTalkPage(); - - $dbw = wfGetDB(DB_MASTER); - $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}''" ); - } - $r = array('from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason']); - if(!$params['noredirect']) - $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) - { - $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()) - { - $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); - } - - protected function getAllowedParams() { - return array ( - 'from' => null, - 'to' => null, - 'token' => null, - 'reason' => null, - 'movetalk' => false, - 'noredirect' => false - ); - } - - protected function getParamDescription() { - return array ( - 'from' => 'Title of the page you want to move.', - 'to' => 'Title you want to rename the page to.', - 'token' => 'A move token previously retrieved through prop=info', - 'reason' => 'Reason for the move (optional).', - 'movetalk' => 'Move the talk page, if it exists.', - 'noredirect' => 'Don\'t create a redirect' - ); - } - - protected function getDescription() { - return array( - 'Moves a page.' - ); - } - - protected function getExamples() { - return array ( - 'api.php?action=move&from=Exampel&to=Example&token=123ABC&reason=Misspelled%20title&movetalk&noredirect' - ); - } - - public function getVersion() { - return __CLASS__ . ': $Id$'; - } -} +.@home.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +if (!defined('MEDIAWIKI')) { + // Eclipse helper - will be ignored in production + require_once ("ApiBase.php"); +} + + +/** + * @addtogroup API + */ +class ApiMove extends ApiBase { + + public function __construct($main, $action) { + parent :: __construct($main, $action); + } + + public function execute() { + global $wgUser; + $this->getMain()->requestWriteMode(); + $params = $this->extractRequestParams(); + if(is_null($params['reason'])) + $params['reason'] = ''; + + $titleObj = NULL; + if(!isset($params['from'])) + $this->dieUsage('The from parameter must be set', 'nofrom'); + if(!isset($params['to'])) + $this->dieUsage('The to parameter must be set', 'noto'); + if(!isset($params['token'])) + $this->dieUsage('The token parameter must be set', 'notoken'); + if(!$wgUser->matchEditToken($params['token'])) + $this->dieUsage('Invalid token', 'badtoken'); + + if($wgUser->isBlocked()) + $this->dieUsage('You have been blocked from editing', 'blocked'); + if(wfReadOnly()) + $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'); + + $fromTitle = Title::newFromText($params['from']); + if(!$fromTitle) + $this->dieUsage("Bad title ``{$params['from']}''", 'invalidtitle'); + if(!$fromTitle->exists()) + $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'); + $toTalk = $toTitle->getTalkPage(); + + $dbw = wfGetDB(DB_MASTER); + $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}''" ); + } + $r = array('from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason']); + if(!$params['noredirect']) + $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) + { + $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()) + { + $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); + } + + protected function getAllowedParams() { + return array ( + 'from' => null, + 'to' => null, + 'token' => null, + 'reason' => null, + 'movetalk' => false, + 'noredirect' => false + ); + } + + protected function getParamDescription() { + return array ( + 'from' => 'Title of the page you want to move.', + 'to' => 'Title you want to rename the page to.', + 'token' => 'A move token previously retrieved through prop=info', + 'reason' => 'Reason for the move (optional).', + 'movetalk' => 'Move the talk page, if it exists.', + 'noredirect' => 'Don\'t create a redirect' + ); + } + + protected function getDescription() { + return array( + 'Moves a page.' + ); + } + + protected function getExamples() { + return array ( + 'api.php?action=move&from=Exampel&to=Example&token=123ABC&reason=Misspelled%20title&movetalk&noredirect' + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } +} diff --git a/includes/api/ApiProtect.php b/includes/api/ApiProtect.php index e48bfe602c..91fa57d55e 100644 --- a/includes/api/ApiProtect.php +++ b/includes/api/ApiProtect.php @@ -1,142 +1,142 @@ -.@home.nl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ("ApiBase.php"); -} - -/** - * @addtogroup API - */ -class ApiProtect extends ApiBase { - - public function __construct($main, $action) { - parent :: __construct($main, $action); - } - - public function execute() { - global $wgUser; - $this->getMain()->requestWriteMode(); - $params = $this->extractRequestParams(); - - $titleObj = NULL; - if(!isset($params['title'])) - $this->dieUsage('The title parameter must be set', 'notitle'); - if(!isset($params['token'])) - $this->dieUsage('The token parameter must be set', 'notoken'); - if(!isset($params['protections']) || empty($params['protections'])) - $this->dieUsage('The protections parameter must be set', 'noprotections'); - - if($wgUser->isBlocked()) - $this->dieUsage('You have been blocked from editing', 'blocked'); - if(wfReadOnly()) - $this->dieUsage('The wiki is in read-only mode', 'readonly'); - if(!$wgUser->matchEditToken($params['token'])) - $this->dieUsage('Invalid token', 'badtoken'); - - $titleObj = Title::newFromText($params['title']); - if(!$titleObj) - $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle'); - if(!$titleObj->exists()) - $this->dieUsage("``{$params['title']}'' doesn't exist", 'missingtitle'); - if(!$titleObj->userCan('protect')) - $this->dieUsage('You don\'t have permission to change protection levels', 'permissiondenied'); - $articleObj = new Article($titleObj); - - if(in_array($params['expiry'], array('infinite', 'indefinite', 'never'))) - $expiry = Block::infinity(); - else - { - $expiry = strtotime($params['expiry']); - if($expiry < 0 || $expiry == false) - $this->dieUsage('Invalid expiry time', 'invalidexpiry'); - - $expiry = wfTimestamp(TS_MW, $expiry); - if($expiry < wfTimestampNow()) - $this->dieUsage('Expiry time is in the past', 'pastexpiry'); - } - - $protections = array(); - foreach($params['protections'] as $prot) - { - $p = explode('=', $prot); - $protections[$p[0]] = ($p[1] == 'all' ? '' : $p[1]); - } - - $dbw = wfGetDb(DB_MASTER); - $dbw->begin(); - $ok = $articleObj->updateRestrictions($protections, $params['reason'], $params['cascade'], $expiry); - if(!$ok) - // This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime? - $this->dieUsage('Unknown error', 'unknownerror'); - $dbw->commit(); - $res = array('title' => $titleObj->getPrefixedText(), 'reason' => $params['reason'], 'expiry' => $expiry); - if($params['cascade']) - $res['cascade'] = ''; - $res['protections'] = $protections; - $this->getResult()->addValue(null, $this->getModuleName(), $res); - } - - protected function getAllowedParams() { - return array ( - 'title' => null, - 'token' => null, - 'protections' => array( - ApiBase :: PARAM_ISMULTI => true - ), - 'expiry' => 'infinite', - 'reason' => '', - 'cascade' => false - ); - } - - protected function getParamDescription() { - return array ( - 'title' => 'Title of the page you want to restore.', - 'token' => 'A protect token previously retrieved through prop=info', - 'protections' => 'Pipe-separated list of protection levels, formatted action=group (e.g. edit=sysop)', - 'expiry' => 'Expiry timestamp. If set to \'infinite\', \'indefinite\' or \'never\', the protection will never expire.', - 'reason' => 'Reason for (un)protecting (optional)', - 'cascade' => 'Enable cascading protection (i.e. protect pages included in this page)' - ); - } - - protected function getDescription() { - return array( - 'Change the protection level of a page.' - ); - } - - protected function getExamples() { - return array ( - 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=sysop|move=sysop&cascade&expiry=20070901163000', - 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=all|move=all&reason=Lifting%20restrictions' - ); - } - - public function getVersion() { - return __CLASS__ . ': $Id$'; - } -} +.@home.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +if (!defined('MEDIAWIKI')) { + // Eclipse helper - will be ignored in production + require_once ("ApiBase.php"); +} + +/** + * @addtogroup API + */ +class ApiProtect extends ApiBase { + + public function __construct($main, $action) { + parent :: __construct($main, $action); + } + + public function execute() { + global $wgUser; + $this->getMain()->requestWriteMode(); + $params = $this->extractRequestParams(); + + $titleObj = NULL; + if(!isset($params['title'])) + $this->dieUsage('The title parameter must be set', 'notitle'); + if(!isset($params['token'])) + $this->dieUsage('The token parameter must be set', 'notoken'); + if(!isset($params['protections']) || empty($params['protections'])) + $this->dieUsage('The protections parameter must be set', 'noprotections'); + + if($wgUser->isBlocked()) + $this->dieUsage('You have been blocked from editing', 'blocked'); + if(wfReadOnly()) + $this->dieUsage('The wiki is in read-only mode', 'readonly'); + if(!$wgUser->matchEditToken($params['token'])) + $this->dieUsage('Invalid token', 'badtoken'); + + $titleObj = Title::newFromText($params['title']); + if(!$titleObj) + $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle'); + if(!$titleObj->exists()) + $this->dieUsage("``{$params['title']}'' doesn't exist", 'missingtitle'); + if(!$titleObj->userCan('protect')) + $this->dieUsage('You don\'t have permission to change protection levels', 'permissiondenied'); + $articleObj = new Article($titleObj); + + if(in_array($params['expiry'], array('infinite', 'indefinite', 'never'))) + $expiry = Block::infinity(); + else + { + $expiry = strtotime($params['expiry']); + if($expiry < 0 || $expiry == false) + $this->dieUsage('Invalid expiry time', 'invalidexpiry'); + + $expiry = wfTimestamp(TS_MW, $expiry); + if($expiry < wfTimestampNow()) + $this->dieUsage('Expiry time is in the past', 'pastexpiry'); + } + + $protections = array(); + foreach($params['protections'] as $prot) + { + $p = explode('=', $prot); + $protections[$p[0]] = ($p[1] == 'all' ? '' : $p[1]); + } + + $dbw = wfGetDb(DB_MASTER); + $dbw->begin(); + $ok = $articleObj->updateRestrictions($protections, $params['reason'], $params['cascade'], $expiry); + if(!$ok) + // This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime? + $this->dieUsage('Unknown error', 'unknownerror'); + $dbw->commit(); + $res = array('title' => $titleObj->getPrefixedText(), 'reason' => $params['reason'], 'expiry' => $expiry); + if($params['cascade']) + $res['cascade'] = ''; + $res['protections'] = $protections; + $this->getResult()->addValue(null, $this->getModuleName(), $res); + } + + protected function getAllowedParams() { + return array ( + 'title' => null, + 'token' => null, + 'protections' => array( + ApiBase :: PARAM_ISMULTI => true + ), + 'expiry' => 'infinite', + 'reason' => '', + 'cascade' => false + ); + } + + protected function getParamDescription() { + return array ( + 'title' => 'Title of the page you want to restore.', + 'token' => 'A protect token previously retrieved through prop=info', + 'protections' => 'Pipe-separated list of protection levels, formatted action=group (e.g. edit=sysop)', + 'expiry' => 'Expiry timestamp. If set to \'infinite\', \'indefinite\' or \'never\', the protection will never expire.', + 'reason' => 'Reason for (un)protecting (optional)', + 'cascade' => 'Enable cascading protection (i.e. protect pages included in this page)' + ); + } + + protected function getDescription() { + return array( + 'Change the protection level of a page.' + ); + } + + protected function getExamples() { + return array ( + 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=sysop|move=sysop&cascade&expiry=20070901163000', + 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=all|move=all&reason=Lifting%20restrictions' + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } +} diff --git a/includes/api/ApiQueryBlocks.php b/includes/api/ApiQueryBlocks.php index 1ef9b4febf..8f5536888a 100644 --- a/includes/api/ApiQueryBlocks.php +++ b/includes/api/ApiQueryBlocks.php @@ -1,241 +1,241 @@ -.@home.nl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ('ApiQueryBase.php'); -} - -/** - * Query module to enumerate all available pages. - * - * @addtogroup API - */ -class ApiQueryBlocks extends ApiQueryBase { - - public function __construct($query, $moduleName) { - parent :: __construct($query, $moduleName, 'bk'); - } - - public function execute() { - $this->run(); - } - - private function run() { - global $wgUser; - - $params = $this->extractRequestParams(); - $prop = array_flip($params['prop']); - $fld_id = isset($prop['id']); - $fld_user = isset($prop['user']); - $fld_by = isset($prop['by']); - $fld_timestamp = isset($prop['timestamp']); - $fld_expiry = isset($prop['expiry']); - $fld_reason = isset($prop['reason']); - $fld_range = isset($prop['range']); - $fld_flags = isset($prop['flags']); - - $result = $this->getResult(); - $pageSet = $this->getPageSet(); - $titles = $pageSet->getTitles(); - $data = array(); - - $this->addTables('ipblocks'); - if($fld_id) - $this->addFields('ipb_id'); - if($fld_user) - $this->addFields(array('ipb_address', 'ipb_user')); - if($fld_by) - { - $this->addTables('user'); - $this->addFields(array('ipb_by', 'user_name')); - $this->addWhere('user_id = ipb_by'); - } - if($fld_timestamp) - $this->addFields('ipb_timestamp'); - if($fld_expiry) - $this->addFields('ipb_expiry'); - if($fld_reason) - $this->addFields('ipb_reason'); - if($fld_range) - $this->addFields(array('ipb_range_start', 'ipb_range_end')); - if($fld_flags) - $this->addFields(array('ipb_auto', 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted')); - - $this->addOption('LIMIT', $params['limit'] + 1); - $this->addWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']); - if(isset($params['ids'])) - $this->addWhere(array('ipb_id' => $params['ids'])); - if(isset($params['users'])) - $this->addWhere(array('ipb_address' => $params['users'])); - if(!$wgUser->isAllowed('oversight')) - $this->addWhere(array('ipb_deleted' => 0)); - - // Purge expired entries on one in every 10 queries - if(!mt_rand(0, 10)) - Block::purgeExpired(); - - $res = $this->select(__METHOD__); - $db = wfGetDB(); - - $count = 0; - while($row = $db->fetchObject($res)) - { - if($count++ == $params['limit']) - { - // We've had enough - $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp)); - break; - } - $block = array(); - if($fld_id) - $block['id'] = $row->ipb_id; - if($fld_user) - { - $block['user'] = $row->ipb_address; - $block['userid'] = $row->ipb_user; - } - if($fld_by) - { - $block['by'] = $row->user_name; - $block['byuserid'] = $row->ipb_by; - } - if($fld_timestamp) - $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp); - if($fld_expiry) - $block['expiry'] = Block::decodeExpiry($row->ipb_expiry, TS_ISO_8601); - if($fld_reason) - $block['reason'] = $row->ipb_reason; - if($fld_range) - { - $block['rangestart'] = $this->convertHexIP($row->ipb_range_start); - $block['rangeend'] = $this->convertHexIP($row->ipb_range_end); - } - if($fld_flags) - { - // For clarity, these flags use the same names as their action=block counterparts - if($row->ipb_auto) - $block['automatic'] = ''; - if($row->ipb_anon_only) - $block['anononly'] = ''; - if($row->ipb_create_account) - $block['nocreate'] = ''; - if($row->ipb_enable_autoblock) - $block['autoblock'] = ''; - if($row->ipb_block_email) - $block['noemail'] = ''; - if($row->ipb_deleted) - $block['hidden'] = ''; - } - $data[] = $block; - } - $result->setIndexedTagName($data, 'block'); - $result->addValue('query', $this->getModuleName(), $data); - } - - protected function convertHexIP($ip) - { - // Converts a hexadecimal IP to nnn.nnn.nnn.nnn format - $dec = wfBaseConvert($ip, 16, 10); - $parts[0] = (int)($dec / (256*256*256)); - $dec %= 256*256*256; - $parts[1] = (int)($dec / (256*256)); - $dec %= 256*256; - $parts[2] = (int)($dec / 256); - $parts[3] = $dec % 256; - return implode('.', $parts); - } - - protected function getAllowedParams() { - 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' - ), - 'ids' => array( - ApiBase :: PARAM_TYPE => 'integer', - ApiBase :: PARAM_ISMULTI => true - ), - 'users' => array( - ApiBase :: PARAM_ISMULTI => true - ), - '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 => 'id|user|by|timestamp|expiry|reason|flags', - ApiBase :: PARAM_TYPE => array( - 'id', - 'user', - 'by', - 'timestamp', - 'expiry', - 'reason', - 'range', - 'flags' - ), - 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', - 'ids' => 'Pipe-separated list of block IDs to list (optional)', - 'users' => 'Pipe-separated list of users to search for (optional)', - 'limit' => 'The maximum amount of blocks to list', - 'prop' => 'Which properties to get', - ); - } - - protected function getDescription() { - return 'List all blocked users and IP addresses.'; - } - - protected function getExamples() { - return array ( - ); - } - - public function getVersion() { - return __CLASS__ . ': $Id$'; - } -} +.@home.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +if (!defined('MEDIAWIKI')) { + // Eclipse helper - will be ignored in production + require_once ('ApiQueryBase.php'); +} + +/** + * Query module to enumerate all available pages. + * + * @addtogroup API + */ +class ApiQueryBlocks extends ApiQueryBase { + + public function __construct($query, $moduleName) { + parent :: __construct($query, $moduleName, 'bk'); + } + + public function execute() { + $this->run(); + } + + private function run() { + global $wgUser; + + $params = $this->extractRequestParams(); + $prop = array_flip($params['prop']); + $fld_id = isset($prop['id']); + $fld_user = isset($prop['user']); + $fld_by = isset($prop['by']); + $fld_timestamp = isset($prop['timestamp']); + $fld_expiry = isset($prop['expiry']); + $fld_reason = isset($prop['reason']); + $fld_range = isset($prop['range']); + $fld_flags = isset($prop['flags']); + + $result = $this->getResult(); + $pageSet = $this->getPageSet(); + $titles = $pageSet->getTitles(); + $data = array(); + + $this->addTables('ipblocks'); + if($fld_id) + $this->addFields('ipb_id'); + if($fld_user) + $this->addFields(array('ipb_address', 'ipb_user')); + if($fld_by) + { + $this->addTables('user'); + $this->addFields(array('ipb_by', 'user_name')); + $this->addWhere('user_id = ipb_by'); + } + if($fld_timestamp) + $this->addFields('ipb_timestamp'); + if($fld_expiry) + $this->addFields('ipb_expiry'); + if($fld_reason) + $this->addFields('ipb_reason'); + if($fld_range) + $this->addFields(array('ipb_range_start', 'ipb_range_end')); + if($fld_flags) + $this->addFields(array('ipb_auto', 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted')); + + $this->addOption('LIMIT', $params['limit'] + 1); + $this->addWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']); + if(isset($params['ids'])) + $this->addWhere(array('ipb_id' => $params['ids'])); + if(isset($params['users'])) + $this->addWhere(array('ipb_address' => $params['users'])); + if(!$wgUser->isAllowed('oversight')) + $this->addWhere(array('ipb_deleted' => 0)); + + // Purge expired entries on one in every 10 queries + if(!mt_rand(0, 10)) + Block::purgeExpired(); + + $res = $this->select(__METHOD__); + $db = wfGetDB(); + + $count = 0; + while($row = $db->fetchObject($res)) + { + if($count++ == $params['limit']) + { + // We've had enough + $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp)); + break; + } + $block = array(); + if($fld_id) + $block['id'] = $row->ipb_id; + if($fld_user) + { + $block['user'] = $row->ipb_address; + $block['userid'] = $row->ipb_user; + } + if($fld_by) + { + $block['by'] = $row->user_name; + $block['byuserid'] = $row->ipb_by; + } + if($fld_timestamp) + $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp); + if($fld_expiry) + $block['expiry'] = Block::decodeExpiry($row->ipb_expiry, TS_ISO_8601); + if($fld_reason) + $block['reason'] = $row->ipb_reason; + if($fld_range) + { + $block['rangestart'] = $this->convertHexIP($row->ipb_range_start); + $block['rangeend'] = $this->convertHexIP($row->ipb_range_end); + } + if($fld_flags) + { + // For clarity, these flags use the same names as their action=block counterparts + if($row->ipb_auto) + $block['automatic'] = ''; + if($row->ipb_anon_only) + $block['anononly'] = ''; + if($row->ipb_create_account) + $block['nocreate'] = ''; + if($row->ipb_enable_autoblock) + $block['autoblock'] = ''; + if($row->ipb_block_email) + $block['noemail'] = ''; + if($row->ipb_deleted) + $block['hidden'] = ''; + } + $data[] = $block; + } + $result->setIndexedTagName($data, 'block'); + $result->addValue('query', $this->getModuleName(), $data); + } + + protected function convertHexIP($ip) + { + // Converts a hexadecimal IP to nnn.nnn.nnn.nnn format + $dec = wfBaseConvert($ip, 16, 10); + $parts[0] = (int)($dec / (256*256*256)); + $dec %= 256*256*256; + $parts[1] = (int)($dec / (256*256)); + $dec %= 256*256; + $parts[2] = (int)($dec / 256); + $parts[3] = $dec % 256; + return implode('.', $parts); + } + + protected function getAllowedParams() { + 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' + ), + 'ids' => array( + ApiBase :: PARAM_TYPE => 'integer', + ApiBase :: PARAM_ISMULTI => true + ), + 'users' => array( + ApiBase :: PARAM_ISMULTI => true + ), + '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 => 'id|user|by|timestamp|expiry|reason|flags', + ApiBase :: PARAM_TYPE => array( + 'id', + 'user', + 'by', + 'timestamp', + 'expiry', + 'reason', + 'range', + 'flags' + ), + 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', + 'ids' => 'Pipe-separated list of block IDs to list (optional)', + 'users' => 'Pipe-separated list of users to search for (optional)', + 'limit' => 'The maximum amount of blocks to list', + 'prop' => 'Which properties to get', + ); + } + + protected function getDescription() { + return 'List all blocked users and IP addresses.'; + } + + protected function getExamples() { + return array ( + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } +} diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index c37f46c7d9..57e7fc0ad8 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -1,230 +1,230 @@ -.@home.nl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ('ApiQueryBase.php'); -} - -/** - * Query module to enumerate all available pages. - * - * @addtogroup API - */ -class ApiQueryDeletedrevs extends ApiQueryBase { - - public function __construct($query, $moduleName) { - parent :: __construct($query, $moduleName, 'dr'); - } - - public function execute() { - - 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 revision 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')); - 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 and stricter restrictions - if(!$wgUser->isAllowed('undelete')) - $this->dieUsage('You don\'t have permission to view deleted revision content', 'permissiondenied'); - $userMax = ApiBase :: LIMIT_SML1; - $botMax = ApiBase :: LIMIT_SML2; - $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) - $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; - } - $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); - } - - protected function getAllowedParams() { - 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' - ), - 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' - ); - } - - protected function getDescription() { - 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' - ); - } - - public function getVersion() { - return __CLASS__ . ': $Id: ApiQueryDeletedrevs.php 23531 2007-06-30 01:19:14Z simetrical $'; - } -} +.@home.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +if (!defined('MEDIAWIKI')) { + // Eclipse helper - will be ignored in production + require_once ('ApiQueryBase.php'); +} + +/** + * Query module to enumerate all available pages. + * + * @addtogroup API + */ +class ApiQueryDeletedrevs extends ApiQueryBase { + + public function __construct($query, $moduleName) { + parent :: __construct($query, $moduleName, 'dr'); + } + + public function execute() { + + 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 revision 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')); + 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 and stricter restrictions + if(!$wgUser->isAllowed('undelete')) + $this->dieUsage('You don\'t have permission to view deleted revision content', 'permissiondenied'); + $userMax = ApiBase :: LIMIT_SML1; + $botMax = ApiBase :: LIMIT_SML2; + $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) + $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; + } + $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); + } + + protected function getAllowedParams() { + 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' + ), + 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' + ); + } + + protected function getDescription() { + 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' + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } +} diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index 1d0e16ee97..1c7606eced 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -1,156 +1,156 @@ -.@home.nl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ("ApiBase.php"); -} - -/** - * @addtogroup API - */ -class ApiRollback extends ApiBase { - - public function __construct($main, $action) { - parent :: __construct($main, $action); - } - - public function execute() { - global $wgUser; - $this->getMain()->requestWriteMode(); - $params = $this->extractRequestParams(); - - $titleObj = NULL; - if(!isset($params['title'])) - $this->dieUsage('The title parameter must be set', 'notitle'); - if(!isset($params['user'])) - $this->dieUsage('The user parameter must be set', 'nouser'); - if(!isset($params['token'])) - $this->dieUsage('The token parameter must be set', 'notoken'); - - // doRollback() also checks for these, but we wanna save some work - if($wgUser->isBlocked()) - $this->dieUsage('You have been blocked from editing', 'blocked'); - if(wfReadOnly()) - $this->dieUsage('The wiki is in read-only mode', 'readonly'); - - $titleObj = Title::newFromText($params['title']); - if(!$titleObj) - $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle'); - if(!$titleObj->userCan('rollback')) - $this->dieUsage('You don\'t have permission to rollback', 'permissiondenied'); - - $username = User::getCanonicalName($params['user']); - if(!$username) - $this->dieUsage("Invalid username ``{$params['user']}''", 'invaliduser'); - - $articleObj = new Article($titleObj); - $summary = (isset($params['summary']) ? $params['summary'] : ""); - $details = NULL; - $dbw = wfGetDb(DB_MASTER); - $dbw->begin(); - $retval = $articleObj->doRollback($username, $summary, $params['token'], $params['markbot'], &$details); - - switch($retval) - { - case Article::SUCCESS: - break; // We'll deal with that later - case Article::PERM_DENIED: - $this->dieUsage("You don't have permission to rollback", 'permissiondenied'); - case Article::BLOCKED: // If we get BLOCKED or PERM_DENIED that's very weird, but it's possible - $this->dieUsage('You have been blocked from editing', 'blocked'); - case Article::READONLY: - $this->dieUsage('The wiki is in read-only mode', 'readonly'); - case Article::BAD_TOKEN: - $this->dieUsage('Invalid token', 'badtoken'); - case Article::BAD_TITLE: - $this->dieUsage("``{$params['title']}'' doesn't exist", 'missingtitle'); - case Article::ALREADYROLLED: - $current = $details['current']; - $currentID = $current->getId(); - $this->dieUsage("The edit(s) you tried to rollback is/are already rolled back." . - "The current revision ID is ``$currentID''", 'alreadyrolled'); - case Article::ONLY_AUTHOR: - $this->dieUsage("User ``$username'' is the only author of the page", 'onlyauthor'); - case Article::RATE_LIMITED: - $this->dieUsage("You can't rollback too many articles in too short a time. Please wait a little while and try again", 'ratelimited'); - default: - // rollback() has apparently invented a new error, which is extremely weird - $this->dieDebug(__METHOD__, "rollback() returned an unknown error ($retval)"); - } - // $retval has to be Article::SUCCESS if we get here - $dbw->commit(); - $current = $target = $summary = NULL; - extract($details); - - $info = array( - 'title' => $titleObj->getPrefixedText(), - 'pageid' => $current->getPage(), - 'summary' => $summary, - 'revid' => $titleObj->getLatestRevID(), - 'old_revid' => $current->getID(), - 'last_revid' => $target->getID() - ); - - $this->getResult()->addValue(null, $this->getModuleName(), $info); - } - - protected function getAllowedParams() { - return array ( - 'title' => null, - 'user' => null, - 'token' => null, - 'summary' => null, - 'markbot' => false - ); - } - - protected function getParamDescription() { - return array ( - 'title' => 'Title of the page you want to rollback.', - 'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.', - 'token' => 'A rollback token previously retrieved through prop=info', - 'summary' => 'Custom edit summary. If not set, default summary will be used.', - 'markbot' => 'Mark the reverted edits and the revert as bot edits' - ); - } - - protected function getDescription() { - return array( - 'Undoes the last edit to the page. If the last user who edited the page made multiple edits in a row,', - 'they will all be rolled back. You need to be logged in as a sysop to use this function, see also action=login.' - ); - } - - protected function getExamples() { - return array ( - 'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC', - 'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1' - ); - } - - public function getVersion() { - return __CLASS__ . ': $Id: ApiRollback.php 22289 2007-05-20 23:31:44Z yurik $'; - } -} +.@home.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +if (!defined('MEDIAWIKI')) { + // Eclipse helper - will be ignored in production + require_once ("ApiBase.php"); +} + +/** + * @addtogroup API + */ +class ApiRollback extends ApiBase { + + public function __construct($main, $action) { + parent :: __construct($main, $action); + } + + public function execute() { + global $wgUser; + $this->getMain()->requestWriteMode(); + $params = $this->extractRequestParams(); + + $titleObj = NULL; + if(!isset($params['title'])) + $this->dieUsage('The title parameter must be set', 'notitle'); + if(!isset($params['user'])) + $this->dieUsage('The user parameter must be set', 'nouser'); + if(!isset($params['token'])) + $this->dieUsage('The token parameter must be set', 'notoken'); + + // doRollback() also checks for these, but we wanna save some work + if($wgUser->isBlocked()) + $this->dieUsage('You have been blocked from editing', 'blocked'); + if(wfReadOnly()) + $this->dieUsage('The wiki is in read-only mode', 'readonly'); + + $titleObj = Title::newFromText($params['title']); + if(!$titleObj) + $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle'); + if(!$titleObj->userCan('rollback')) + $this->dieUsage('You don\'t have permission to rollback', 'permissiondenied'); + + $username = User::getCanonicalName($params['user']); + if(!$username) + $this->dieUsage("Invalid username ``{$params['user']}''", 'invaliduser'); + + $articleObj = new Article($titleObj); + $summary = (isset($params['summary']) ? $params['summary'] : ""); + $details = NULL; + $dbw = wfGetDb(DB_MASTER); + $dbw->begin(); + $retval = $articleObj->doRollback($username, $summary, $params['token'], $params['markbot'], &$details); + + switch($retval) + { + case Article::SUCCESS: + break; // We'll deal with that later + case Article::PERM_DENIED: + $this->dieUsage("You don't have permission to rollback", 'permissiondenied'); + case Article::BLOCKED: // If we get BLOCKED or PERM_DENIED that's very weird, but it's possible + $this->dieUsage('You have been blocked from editing', 'blocked'); + case Article::READONLY: + $this->dieUsage('The wiki is in read-only mode', 'readonly'); + case Article::BAD_TOKEN: + $this->dieUsage('Invalid token', 'badtoken'); + case Article::BAD_TITLE: + $this->dieUsage("``{$params['title']}'' doesn't exist", 'missingtitle'); + case Article::ALREADYROLLED: + $current = $details['current']; + $currentID = $current->getId(); + $this->dieUsage("The edit(s) you tried to rollback is/are already rolled back." . + "The current revision ID is ``$currentID''", 'alreadyrolled'); + case Article::ONLY_AUTHOR: + $this->dieUsage("User ``$username'' is the only author of the page", 'onlyauthor'); + case Article::RATE_LIMITED: + $this->dieUsage("You can't rollback too many articles in too short a time. Please wait a little while and try again", 'ratelimited'); + default: + // rollback() has apparently invented a new error, which is extremely weird + $this->dieDebug(__METHOD__, "rollback() returned an unknown error ($retval)"); + } + // $retval has to be Article::SUCCESS if we get here + $dbw->commit(); + $current = $target = $summary = NULL; + extract($details); + + $info = array( + 'title' => $titleObj->getPrefixedText(), + 'pageid' => $current->getPage(), + 'summary' => $summary, + 'revid' => $titleObj->getLatestRevID(), + 'old_revid' => $current->getID(), + 'last_revid' => $target->getID() + ); + + $this->getResult()->addValue(null, $this->getModuleName(), $info); + } + + protected function getAllowedParams() { + return array ( + 'title' => null, + 'user' => null, + 'token' => null, + 'summary' => null, + 'markbot' => false + ); + } + + protected function getParamDescription() { + return array ( + 'title' => 'Title of the page you want to rollback.', + 'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.', + 'token' => 'A rollback token previously retrieved through prop=info', + 'summary' => 'Custom edit summary. If not set, default summary will be used.', + 'markbot' => 'Mark the reverted edits and the revert as bot edits' + ); + } + + protected function getDescription() { + return array( + 'Undoes the last edit to the page. If the last user who edited the page made multiple edits in a row,', + 'they will all be rolled back. You need to be logged in as a sysop to use this function, see also action=login.' + ); + } + + protected function getExamples() { + return array ( + 'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC', + 'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1' + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } +} diff --git a/includes/api/ApiUnblock.php b/includes/api/ApiUnblock.php index 7b82998ca8..bf5f256097 100644 --- a/includes/api/ApiUnblock.php +++ b/includes/api/ApiUnblock.php @@ -1,130 +1,130 @@ -.@home.nl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ("ApiBase.php"); -} - -/** - * @addtogroup API - */ -class ApiUnblock extends ApiBase { - - public function __construct($main, $action) { - parent :: __construct($main, $action); - } - - public function execute() { - global $wgUser; - $this->getMain()->requestWriteMode(); - $params = $this->extractRequestParams(); - - if($params['gettoken']) - { - $res['unblocktoken'] = $wgUser->editToken(); - $this->getResult()->addValue(null, $this->getModuleName(), $res); - return; - } - - if(is_null($params['id']) && is_null($params['user'])) - $this->dieUsage('Either the id or the user parameter must be set', 'notarget'); - if(!is_null($params['id']) && !is_null($params['user'])) - $this->dieUsage('The id and user parameters can\'t be used together', 'idanduser'); - if(is_null($params['token'])) - $this->dieUsage('The token parameter must be set', 'notoken'); - if(!$wgUser->matchEditToken($params['token'])) - $this->dieUsage('Invalid token', 'badtoken'); - if(!$wgUser->isAllowed('block')) - $this->dieUsage('You don\'t have permission to unblock users', 'permissiondenied'); - if(wfReadOnly()) - $this->dieUsage('The wiki is in read-only mode', 'readonly'); - - $id = $params['id']; - $user = $params['user']; - $reason = $params['reason']; - $dbw = wfGetDb(DB_MASTER); - $dbw->begin(); - $retval = IPUnblockForm::doUnblock(&$id, &$user, &$reason, &$range); - - switch($retval) - { - case IPUnblockForm::UNBLOCK_SUCCESS: - break; // We'll deal with that later - case IPUnblockForm::UNBLOCK_NO_SUCH_ID: - $this->dieUsage("There is no block with ID ``$id''", 'nosuchid'); - case IPUnblockForm::UNBLOCK_USER_NOT_BLOCKED: - $this->dieUsage("User ``$user'' is not blocked", 'notblocked'); - case IPUnblockForm::UNBLOCK_BLOCKED_AS_RANGE: - $this->dieUsage("IP address ``$user'' was blocked as part of range ``$range''. You can't unblock the IP invidually, but you can unblock the range as a whole.", 'blockedasrange'); - case IPUnblockForm::UNBLOCK_UNKNOWNERR: - $this->dieUsage("Unknown error", 'unknownerr'); - default: - $this->dieDebug(__METHOD__, "IPBlockForm::doBlock() returned an unknown error ($retval)"); - } - $dbw->commit(); - - $res['id'] = $id; - $res['user'] = $user; - $res['reason'] = $reason; - $this->getResult()->addValue(null, $this->getModuleName(), $res); - } - - protected function getAllowedParams() { - return array ( - 'id' => null, - 'user' => null, - 'token' => null, - 'gettoken' => false, - 'reason' => null, - ); - } - - protected function getParamDescription() { - return array ( - 'id' => 'ID of the block you want to unblock (obtained through list=blocks). Cannot be user together with user', - 'user' => 'Username, IP address or IP range you want to unblock. Cannot be used together with id', - 'token' => 'An unblock token previously obtained through the gettoken parameter', - 'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken', - 'reason' => 'Reason for unblock (optional)', - ); - } - - protected function getDescription() { - return array( - 'Unblock a user.' - ); - } - - protected function getExamples() { - return array ( - 'api.php?action=unblock&id=105', - 'api.php?action=unblock&user=Bob&reason=Sorry%20Bob' - ); - } - - public function getVersion() { - return __CLASS__ . ': $Id$'; - } -} +.@home.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +if (!defined('MEDIAWIKI')) { + // Eclipse helper - will be ignored in production + require_once ("ApiBase.php"); +} + +/** + * @addtogroup API + */ +class ApiUnblock extends ApiBase { + + public function __construct($main, $action) { + parent :: __construct($main, $action); + } + + public function execute() { + global $wgUser; + $this->getMain()->requestWriteMode(); + $params = $this->extractRequestParams(); + + if($params['gettoken']) + { + $res['unblocktoken'] = $wgUser->editToken(); + $this->getResult()->addValue(null, $this->getModuleName(), $res); + return; + } + + if(is_null($params['id']) && is_null($params['user'])) + $this->dieUsage('Either the id or the user parameter must be set', 'notarget'); + if(!is_null($params['id']) && !is_null($params['user'])) + $this->dieUsage('The id and user parameters can\'t be used together', 'idanduser'); + if(is_null($params['token'])) + $this->dieUsage('The token parameter must be set', 'notoken'); + if(!$wgUser->matchEditToken($params['token'])) + $this->dieUsage('Invalid token', 'badtoken'); + if(!$wgUser->isAllowed('block')) + $this->dieUsage('You don\'t have permission to unblock users', 'permissiondenied'); + if(wfReadOnly()) + $this->dieUsage('The wiki is in read-only mode', 'readonly'); + + $id = $params['id']; + $user = $params['user']; + $reason = $params['reason']; + $dbw = wfGetDb(DB_MASTER); + $dbw->begin(); + $retval = IPUnblockForm::doUnblock(&$id, &$user, &$reason, &$range); + + switch($retval) + { + case IPUnblockForm::UNBLOCK_SUCCESS: + break; // We'll deal with that later + case IPUnblockForm::UNBLOCK_NO_SUCH_ID: + $this->dieUsage("There is no block with ID ``$id''", 'nosuchid'); + case IPUnblockForm::UNBLOCK_USER_NOT_BLOCKED: + $this->dieUsage("User ``$user'' is not blocked", 'notblocked'); + case IPUnblockForm::UNBLOCK_BLOCKED_AS_RANGE: + $this->dieUsage("IP address ``$user'' was blocked as part of range ``$range''. You can't unblock the IP invidually, but you can unblock the range as a whole.", 'blockedasrange'); + case IPUnblockForm::UNBLOCK_UNKNOWNERR: + $this->dieUsage("Unknown error", 'unknownerr'); + default: + $this->dieDebug(__METHOD__, "IPBlockForm::doBlock() returned an unknown error ($retval)"); + } + $dbw->commit(); + + $res['id'] = $id; + $res['user'] = $user; + $res['reason'] = $reason; + $this->getResult()->addValue(null, $this->getModuleName(), $res); + } + + protected function getAllowedParams() { + return array ( + 'id' => null, + 'user' => null, + 'token' => null, + 'gettoken' => false, + 'reason' => null, + ); + } + + protected function getParamDescription() { + return array ( + 'id' => 'ID of the block you want to unblock (obtained through list=blocks). Cannot be user together with user', + 'user' => 'Username, IP address or IP range you want to unblock. Cannot be used together with id', + 'token' => 'An unblock token previously obtained through the gettoken parameter', + 'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken', + 'reason' => 'Reason for unblock (optional)', + ); + } + + protected function getDescription() { + return array( + 'Unblock a user.' + ); + } + + protected function getExamples() { + return array ( + 'api.php?action=unblock&id=105', + 'api.php?action=unblock&user=Bob&reason=Sorry%20Bob' + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } +} diff --git a/includes/api/ApiUndelete.php b/includes/api/ApiUndelete.php index 62497ccbb2..56ce3c6668 100644 --- a/includes/api/ApiUndelete.php +++ b/includes/api/ApiUndelete.php @@ -1,129 +1,129 @@ -.@home.nl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * http://www.gnu.org/copyleft/gpl.html - */ - -if (!defined('MEDIAWIKI')) { - // Eclipse helper - will be ignored in production - require_once ("ApiBase.php"); -} - -/** - * @addtogroup API - */ -class ApiUndelete extends ApiBase { - - public function __construct($main, $action) { - parent :: __construct($main, $action); - } - - public function execute() { - global $wgUser; - $this->getMain()->requestWriteMode(); - $params = $this->extractRequestParams(); - - $titleObj = NULL; - if(!isset($params['title'])) - $this->dieUsage('The title parameter must be set', 'notitle'); - if(!isset($params['token'])) - $this->dieUsage('The token parameter must be set', 'notoken'); - - if(!$wgUser->isAllowed('undelete')) - $this->dieUsage('You don\'t have permission to restore deleted revisions', 'permissiondenied'); - if($wgUser->isBlocked()) - $this->dieUsage('You have been blocked from editing', 'blocked'); - if(wfReadOnly()) - $this->dieUsage('The wiki is in read-only mode', 'readonly'); - if(!$wgUser->matchEditToken($params['token'])) - $this->dieUsage('Invalid token', 'badtoken'); - - $titleObj = Title::newFromText($params['title']); - if(!$titleObj) - $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle'); - - // Convert timestamps - if(!is_array($params['timestamps'])) - $params['timestamps'] = array($params['timestamps']); - foreach($params['timestamps'] as $i => $ts) - $params['timestamps'][$i] = wfTimestamp(TS_MW, $ts); - - $pa = new PageArchive($titleObj); - $dbw = wfGetDb(DB_MASTER); - $dbw->begin(); - $retval = $pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason']); - if(!is_array($retval)) - switch($retval) - { - case PageArchive::UNDELETE_NOTHINGRESTORED: - $this->dieUsage('No revisions could be restored', 'norevs'); - case PageArchive::UNDELETE_NOTAVAIL: - $this->dieUsage('Not all requested revisions could be found', 'revsnotfound'); - case PageArchive::UNDELETE_UNKNOWNERR: - $this->dieUsage('Undeletion failed with unknown error', 'unknownerror'); - } - $dbw->commit(); - - $info['title'] = $titleObj->getPrefixedText(); - $info['revisions'] = $retval[0]; - $info['fileversions'] = $retval[1]; - $info['reason'] = $retval[2]; - $this->getResult()->addValue(null, $this->getModuleName(), $info); - } - - protected function getAllowedParams() { - return array ( - 'title' => null, - 'token' => null, - 'reason' => "", - 'timestamps' => array( - ApiBase :: PARAM_ISMULTI => true - ) - ); - } - - protected function getParamDescription() { - return array ( - 'title' => 'Title of the page you want to restore.', - 'token' => 'An undelete token previously retrieved through list=deletedrevs', - 'reason' => 'Reason for restoring (optional)', - 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.' - ); - } - - protected function getDescription() { - return array( - 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be', - 'retrieved through list=deletedrevs' - ); - } - - protected function getExamples() { - return array ( - 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page', - 'api.php?action=undelete&title=Main%20Page&token=123ABC×tamps=20070703220045|20070702194856' - ); - } - - public function getVersion() { - return __CLASS__ . ': $Id: ApiUndelete.php 22289 2007-05-20 23:31:44Z yurik $'; - } -} +.@home.nl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +if (!defined('MEDIAWIKI')) { + // Eclipse helper - will be ignored in production + require_once ("ApiBase.php"); +} + +/** + * @addtogroup API + */ +class ApiUndelete extends ApiBase { + + public function __construct($main, $action) { + parent :: __construct($main, $action); + } + + public function execute() { + global $wgUser; + $this->getMain()->requestWriteMode(); + $params = $this->extractRequestParams(); + + $titleObj = NULL; + if(!isset($params['title'])) + $this->dieUsage('The title parameter must be set', 'notitle'); + if(!isset($params['token'])) + $this->dieUsage('The token parameter must be set', 'notoken'); + + if(!$wgUser->isAllowed('undelete')) + $this->dieUsage('You don\'t have permission to restore deleted revisions', 'permissiondenied'); + if($wgUser->isBlocked()) + $this->dieUsage('You have been blocked from editing', 'blocked'); + if(wfReadOnly()) + $this->dieUsage('The wiki is in read-only mode', 'readonly'); + if(!$wgUser->matchEditToken($params['token'])) + $this->dieUsage('Invalid token', 'badtoken'); + + $titleObj = Title::newFromText($params['title']); + if(!$titleObj) + $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle'); + + // Convert timestamps + if(!is_array($params['timestamps'])) + $params['timestamps'] = array($params['timestamps']); + foreach($params['timestamps'] as $i => $ts) + $params['timestamps'][$i] = wfTimestamp(TS_MW, $ts); + + $pa = new PageArchive($titleObj); + $dbw = wfGetDb(DB_MASTER); + $dbw->begin(); + $retval = $pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason']); + if(!is_array($retval)) + switch($retval) + { + case PageArchive::UNDELETE_NOTHINGRESTORED: + $this->dieUsage('No revisions could be restored', 'norevs'); + case PageArchive::UNDELETE_NOTAVAIL: + $this->dieUsage('Not all requested revisions could be found', 'revsnotfound'); + case PageArchive::UNDELETE_UNKNOWNERR: + $this->dieUsage('Undeletion failed with unknown error', 'unknownerror'); + } + $dbw->commit(); + + $info['title'] = $titleObj->getPrefixedText(); + $info['revisions'] = $retval[0]; + $info['fileversions'] = $retval[1]; + $info['reason'] = $retval[2]; + $this->getResult()->addValue(null, $this->getModuleName(), $info); + } + + protected function getAllowedParams() { + return array ( + 'title' => null, + 'token' => null, + 'reason' => "", + 'timestamps' => array( + ApiBase :: PARAM_ISMULTI => true + ) + ); + } + + protected function getParamDescription() { + return array ( + 'title' => 'Title of the page you want to restore.', + 'token' => 'An undelete token previously retrieved through list=deletedrevs', + 'reason' => 'Reason for restoring (optional)', + 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.' + ); + } + + protected function getDescription() { + return array( + 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be', + 'retrieved through list=deletedrevs' + ); + } + + protected function getExamples() { + return array ( + 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page', + 'api.php?action=undelete&title=Main%20Page&token=123ABC×tamps=20070703220045|20070702194856' + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } +} -- 2.20.1