-<?php\r
-\r
-/*\r
- * Created on Sep 4, 2007\r
- * API for MediaWiki 1.8+\r
- *\r
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * http://www.gnu.org/copyleft/gpl.html\r
- */\r
-\r
-if (!defined('MEDIAWIKI')) {\r
- // Eclipse helper - will be ignored in production\r
- require_once ("ApiBase.php");\r
-}\r
-\r
-/**\r
- * @addtogroup API\r
- */\r
-class ApiBlock extends ApiBase {\r
-\r
- public function __construct($main, $action) {\r
- parent :: __construct($main, $action);\r
- }\r
-\r
- public function execute() {\r
- global $wgUser;\r
- $this->getMain()->requestWriteMode();\r
- $params = $this->extractRequestParams();\r
-\r
- if($params['gettoken'])\r
- {\r
- $res['blocktoken'] = $wgUser->editToken();\r
- $this->getResult()->addValue(null, $this->getModuleName(), $res);\r
- return;\r
- }\r
-\r
- if(is_null($params['user']))\r
- $this->dieUsage('The user parameter must be set', 'nouser');\r
- if(is_null($params['token']))\r
- $this->dieUsage('The token parameter must be set', 'notoken');\r
- if(!$wgUser->matchEditToken($params['token']))\r
- $this->dieUsage('Invalid token', 'badtoken');\r
- if(!$wgUser->isAllowed('block'))\r
- $this->dieUsage('You don\'t have permission to block users', 'permissiondenied');\r
- if($params['hidename'] && !$wgUser->isAllowed('hideuser'))\r
- $this->dieUsage('You don\'t have permission to hide user names from the block log', 'nohide');\r
- if(wfReadOnly())\r
- $this->dieUsage('The wiki is in read-only mode', 'readonly');\r
-\r
- $form = new IPBlockForm('');\r
- $form->BlockAddress = $params['user'];\r
- $form->BlockReason = $params['reason'];\r
- $form->BlockReasonList = 'other';\r
- $form->BlockExpiry = ($params['expiry'] == 'never' ? 'infinite' : $params['expiry']);\r
- $form->BlockOther = '';\r
- $form->BlockAnonOnly = $params['anononly'];\r
- $form->BlockCreateAccount = $params['nocreate'];\r
- $form->BlockEnableAutoBlock = $params['autoblock'];\r
- $form->BlockEmail = $params['noemail'];\r
- $form->BlockHideName = $params['hidename'];\r
-\r
- $dbw = wfGetDb(DB_MASTER);\r
- $dbw->begin();\r
- $retval = $form->doBlock($userID, $expiry);\r
- switch($retval)\r
- {\r
- case IPBlockForm::BLOCK_SUCCESS:\r
- break; // We'll deal with that later\r
- case IPBlockForm::BLOCK_RANGE_INVALID:\r
- $this->dieUsage("Invalid IP range ``{$params['user']}''", 'invalidrange');\r
- case IPBlockForm::BLOCK_RANGE_DISABLED:\r
- $this->dieUsage('Blocking IP ranges has been disabled', 'rangedisabled');\r
- case IPBlockForm::BLOCK_NONEXISTENT_USER:\r
- $this->dieUsage("User ``{$params['user']}'' doesn't exist", 'nosuchuser');\r
- case IPBlockForm::BLOCK_IP_INVALID:\r
- $this->dieUsage("Invaild IP address ``{$params['user']}''", 'invalidip');\r
- case IPBlockForm::BLOCK_EXPIRY_INVALID:\r
- $this->dieUsage("Invalid expiry time ``{$params['expiry']}''", 'invalidexpiry');\r
- case IPBlockForm::BLOCK_ALREADY_BLOCKED:\r
- $this->dieUsage("User ``{$params['user']}'' is already blocked", 'alreadyblocked');\r
- default:\r
- $this->dieDebug(__METHOD__, "IPBlockForm::doBlock() returned an unknown error ($retval)");\r
- }\r
- $dbw->commit();\r
- \r
- $res['user'] = $params['user'];\r
- $res['userID'] = $userID;\r
- $res['expiry'] = ($expiry == Block::infinity() ? 'infinite' : $expiry);\r
- $res['reason'] = $params['reason'];\r
- if($params['anononly'])\r
- $res['anononly'] = '';\r
- if($params['nocreate'])\r
- $res['nocreate'] = '';\r
- if($params['autoblock'])\r
- $res['autoblock'] = '';\r
- if($params['noemail'])\r
- $res['noemail'] = '';\r
- if($params['hidename'])\r
- $res['hidename'] = '';\r
-\r
- $this->getResult()->addValue(null, $this->getModuleName(), $res);\r
- }\r
-\r
- protected function getAllowedParams() {\r
- return array (\r
- 'user' => null,\r
- 'token' => null,\r
- 'gettoken' => false,\r
- 'expiry' => 'never',\r
- 'reason' => null,\r
- 'anononly' => false,\r
- 'nocreate' => false,\r
- 'autoblock' => false,\r
- 'noemail' => false,\r
- 'hidename' => false,\r
- );\r
- }\r
-\r
- protected function getParamDescription() {\r
- return array (\r
- 'user' => 'Username, IP address or IP range you want to block',\r
- 'token' => 'A block token previously obtained through the gettoken parameter',\r
- 'gettoken' => 'If set, a block token will be returned, and no other action will be taken',\r
- 'expiry' => 'Relative expiry time, e.g. \'5 months\' or \'2 weeks\'. If set to \'infinite\', \'indefinite\' or \'never\', the block will never expire.',\r
- 'reason' => 'Reason for block (optional)',\r
- 'anononly' => 'Block anonymous users only (i.e. disable anonymous edits for this IP)',\r
- 'nocreate' => 'Prevent account creation',\r
- 'autoblock' => 'Automatically block the last used IP address, and any subsequent IP addresses they try to login from',\r
- 'noemail' => 'Prevent user from sending e-mail through the wiki',\r
- 'hidename' => 'Hide the username from the block log.'\r
- );\r
- }\r
-\r
- protected function getDescription() {\r
- return array(\r
- 'Block a user.'\r
- );\r
- }\r
-\r
- protected function getExamples() {\r
- return array (\r
- 'api.php?action=block&user=123.5.5.12&expiry=3%20days&reason=First%20strike',\r
- 'api.php?action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate&autoblock&noemail'\r
- );\r
- }\r
-\r
- public function getVersion() {\r
- return __CLASS__ . ': $Id$';\r
- }\r
-}\r
+<?php
+
+/*
+ * Created on Sep 4, 2007
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@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$';
+ }
+}
-<?php\r
-\r
-/*\r
- * Created on Sep 11, 2007\r
- * API for MediaWiki 1.8+\r
- *\r
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * http://www.gnu.org/copyleft/gpl.html\r
- */\r
-\r
-if (!defined('MEDIAWIKI')) {\r
- // Eclipse helper - will be ignored in production\r
- require_once ("ApiBase.php");\r
-}\r
-\r
-/**\r
- * @addtogroup API\r
- */\r
-class ApiChangeRights extends ApiBase {\r
-\r
- public function __construct($main, $action) {\r
- parent :: __construct($main, $action);\r
- }\r
-\r
- public function execute() {\r
- global $wgUser, $wgRequest;\r
- $this->getMain()->requestWriteMode();\r
- \r
- if(wfReadOnly())\r
- $this->dieUsage('The wiki is in read-only mode', 'readonly');\r
- $params = $this->extractRequestParams();\r
-\r
- $ur = new UserrightsForm($wgRequest);\r
- $allowed = $ur->changeableGroups();\r
- $res = array();\r
-\r
- if(is_null($params['user']))\r
- $this->dieUsage('The user parameter must be set', 'nouser');\r
-\r
- $uName = User::getCanonicalName($params['user']);\r
- $u = User::newFromName($uName);\r
- if(!$u)\r
- $this->dieUsage("Invalid username ``{$params['user']}''", 'invaliduser');\r
- if($u->getId() == 0) // Anon or non-existent\r
- $this->dieUsage("User ``{$params['user']}'' doesn't exist", 'nosuchuser');\r
-\r
- $curgroups = $u->getGroups();\r
-\r
- if($params['listgroups'])\r
- {\r
- $res['user'] = $uName;\r
- $res['allowedgroups'] = $allowed;\r
- $res['ingroups'] = $curgroups;\r
- $this->getResult()->setIndexedTagName($res['ingroups'], 'group');\r
- $this->getResult()->setIndexedTagName($res['allowedgroups']['add'], 'group');\r
- $this->getResult()->setIndexedTagName($res['allowedgroups']['remove'], 'group');\r
- }\r
-;\r
- if($params['gettoken'])\r
- {\r
- $res['changerightstoken'] = $wgUser->editToken($uName);\r
- $this->getResult()->addValue(null, $this->getModuleName(), $res);\r
- return;\r
- }\r
-\r
- if(empty($params['addto']) && empty($params['rmfrom']))\r
- $this->dieUsage('At least one of the addto and rmfrom parameters must be set', 'noaddrm');\r
- if(is_null($params['token']))\r
- $this->dieUsage('The token parameter must be set', 'notoken');\r
- if(!$wgUser->matchEditToken($params['token'], $uName))\r
- $this->dieUsage('Invalid token', 'badtoken');\r
-\r
- if(!$wgUser->isAllowed('userrights'))\r
- $this->dieUsage('You don\'t have permission to change users\' rights', 'permissiondenied');\r
-\r
- // First let's remove redundant groups and check permissions while we're at it\r
- if(is_null($params['addto']))\r
- $params['addto'] = array();\r
- $addto = array();\r
- foreach($params['addto'] as $g)\r
- {\r
- if(!in_array($g, $allowed['add']))\r
- $this->dieUsage("You don't have permission to add to group ``$g''", 'cantadd');\r
- if(!in_array($g, $curgroups))\r
- $addto[] = $g;\r
- }\r
-\r
- if(is_null($params['rmfrom']))\r
- $params['rmfrom'] = array();\r
- $rmfrom = array();\r
- foreach($params['rmfrom'] as $g)\r
- {\r
- if(!in_array($g, $allowed['remove']))\r
- $this->dieUsage("You don't have permission to remove from group ``$g''", 'cantremove');\r
- if(in_array($g, $curgroups))\r
- $rmfrom[] = $g;\r
- }\r
- $dbw = wfGetDb(DB_MASTER);\r
- $dbw->begin();\r
- $ur->doSaveUserGroups($u, $rmfrom, $addto, $params['reason']);\r
- $dbw->commit();\r
- $res['user'] = $uName;\r
- $res['addedto'] = $addto;\r
- $res['removedfrom'] = $rmfrom;\r
- $res['reason'] = $params['reason'];\r
-\r
- $this->getResult()->setIndexedTagName($res['addedto'], 'group');\r
- $this->getResult()->setIndexedTagName($res['removedfrom'], 'group');\r
- $this->getResult()->addValue(null, $this->getModuleName(), $res);\r
- }\r
-\r
- protected function getAllowedParams() {\r
- return array (\r
- 'user' => null,\r
- 'token' => null,\r
- 'gettoken' => false,\r
- 'listgroups' => false,\r
- 'addto' => array(\r
- ApiBase :: PARAM_ISMULTI => true,\r
- ),\r
- 'rmfrom' => array(\r
- ApiBase :: PARAM_ISMULTI => true,\r
- ),\r
- 'reason' => ''\r
- );\r
- }\r
-\r
- protected function getParamDescription() {\r
- return array (\r
- 'user' => 'The user you want to add to or remove from groups.',\r
- 'token' => 'A changerights token previously obtained through the gettoken parameter.',\r
- 'gettoken' => 'Output a token. Note that the user parameter still has to be set.',\r
- 'listgroups' => 'List the groups the user is in, and the ones you can add them to and remove them from.',\r
- 'addto' => 'Pipe-separated list of groups to add this user to',\r
- 'rmfrom' => 'Pipe-separated list of groups to remove this user from',\r
- 'reason' => 'Reason for change (optional)'\r
- );\r
- }\r
-\r
- protected function getDescription() {\r
- return array(\r
- 'Add or remove a user from certain groups.'\r
- );\r
- }\r
-\r
- protected function getExamples() {\r
- return array (\r
- 'api.php?action=changerights&user=Bob&gettoken&listgroups',\r
- 'api.php?action=changerights&user=Bob&token=123ABC&addto=sysop&reason=Promoting%20per%20RFA'\r
- );\r
- }\r
-\r
- public function getVersion() {\r
- return __CLASS__ . ': $Id$';\r
- }\r
-}\r
+<?php
+
+/*
+ * Created on Sep 11, 2007
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@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$';
+ }
+}
-<?php\r
-\r
-/*\r
- * Created on Jun 30, 2007\r
- * API for MediaWiki 1.8+\r
- *\r
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * http://www.gnu.org/copyleft/gpl.html\r
- */\r
-\r
-if (!defined('MEDIAWIKI')) {\r
- // Eclipse helper - will be ignored in production\r
- require_once ("ApiBase.php");\r
-}\r
-\r
-\r
-/**\r
- * @addtogroup API\r
- */\r
-class ApiDelete extends ApiBase {\r
-\r
- public function __construct($main, $action) {\r
- parent :: __construct($main, $action);\r
- }\r
-\r
- /**\r
- * We have our own delete() function, since Article.php's implementation is split in two phases\r
- * @param Article $article - Article object to work on\r
- * @param string $token - Delete token (same as edit token)\r
- * @param string $reason - Reason for the deletion. Autogenerated if NULL\r
- * @return DELETE_SUCCESS on success, DELETE_* on failure\r
- */\r
-\r
- const DELETE_SUCCESS = 0;\r
- const DELETE_PERM = 1;\r
- const DELETE_BLOCKED = 2;\r
- const DELETE_READONLY = 3;\r
- const DELETE_BADTOKEN = 4;\r
- const DELETE_BADARTICLE = 5;\r
-\r
- public static function delete(&$article, $token, &$reason = NULL)\r
- {\r
- global $wgUser;\r
-\r
- // Check permissions first\r
- if(!$article->mTitle->userCan('delete'))\r
- return self::DELETE_PERM;\r
- if($wgUser->isBlocked())\r
- return self::DELETE_BLOCKED;\r
- if(wfReadOnly())\r
- return self::DELETE_READONLY;\r
-\r
- // Check token\r
- if(!$wgUser->matchEditToken($token))\r
- return self::DELETE_BADTOKEN;\r
-\r
- // Auto-generate a summary, if necessary\r
- if(is_null($reason))\r
- {\r
- $reason = $article->generateReason($hasHistory);\r
- if($reason === false)\r
- return self::DELETE_BADARTICLE;\r
- }\r
-\r
- // Luckily, Article.php provides a reusable delete function that does the hard work for us\r
- if($article->doDeleteArticle($reason))\r
- return self::DELETE_SUCCESS;\r
- return self::DELETE_BADARTICLE;\r
- }\r
-\r
- public function execute() {\r
- global $wgUser;\r
- $this->getMain()->requestWriteMode();\r
- $params = $this->extractRequestParams();\r
- \r
- $titleObj = NULL;\r
- if(!isset($params['title']))\r
- $this->dieUsage('The title parameter must be set', 'notitle');\r
- if(!isset($params['token']))\r
- $this->dieUsage('The token parameter must be set', 'notoken');\r
-\r
- // delete() also checks for these, but we wanna save some work\r
- if(!$wgUser->isAllowed('delete'))\r
- $this->dieUsage('You don\'t have permission to delete pages', 'permissiondenied');\r
- if($wgUser->isBlocked())\r
- $this->dieUsage('You have been blocked from editing', 'blocked');\r
- if(wfReadOnly())\r
- $this->dieUsage('The wiki is in read-only mode', 'readonly');\r
-\r
- $titleObj = Title::newFromText($params['title']);\r
- if(!$titleObj)\r
- $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle');\r
- if(!$titleObj->exists())\r
- $this->dieUsage("``{$params['title']}'' doesn't exist", 'missingtitle');\r
-\r
- $articleObj = new Article($titleObj);\r
- $reason = (isset($params['reason']) ? $params['reason'] : NULL);\r
- $dbw = wfGetDb(DB_MASTER);\r
- $dbw->begin();\r
- $retval = self::delete(&$articleObj, $params['token'], &$reason);\r
-\r
- switch($retval)\r
- {\r
- case self::DELETE_SUCCESS:\r
- break; // We'll deal with that later\r
- case self::DELETE_PERM: // If we get PERM, BLOCKED or READONLY that's weird, but it's possible\r
- $this->dieUsage('You don\'t have permission to delete', 'permissiondenied');\r
- case self::DELETE_BLOCKED:\r
- $this->dieUsage('You have been blocked from editing', 'blocked');\r
- case self::DELETE_READONLY:\r
- $this->dieUsage('The wiki is in read-only mode', 'readonly');\r
- case self::DELETE_BADTOKEN:\r
- $this->dieUsage('Invalid token', 'badtoken');\r
- case self::DELETE_BADARTICLE:\r
- $this->dieUsage("The article ``{$params['title']}'' doesn't exist or has already been deleted", 'missingtitle');\r
- default:\r
- // delete() has apparently invented a new error, which is extremely weird\r
- $this->dieDebug(__METHOD__, "delete() returned an unknown error ($retval)");\r
- }\r
- // $retval has to be self::DELETE_SUCCESS if we get here\r
- $dbw->commit();\r
- $r = array('title' => $titleObj->getPrefixedText(), 'reason' => $reason);\r
- $this->getResult()->addValue(null, $this->getModuleName(), $r);\r
- }\r
- \r
- protected function getAllowedParams() {\r
- return array (\r
- 'title' => null,\r
- 'token' => null,\r
- 'reason' => null,\r
- );\r
- }\r
-\r
- protected function getParamDescription() {\r
- return array (\r
- 'title' => 'Title of the page you want to delete.',\r
- 'token' => 'A delete token previously retrieved through prop=info',\r
- 'reason' => 'Reason for the deletion. If not set, an automatically generated reason will be used.'\r
- );\r
- }\r
-\r
- protected function getDescription() {\r
- return array(\r
- 'Deletes a page. You need to be logged in as a sysop to use this function, see also action=login.'\r
- );\r
- }\r
-\r
- protected function getExamples() {\r
- return array (\r
- 'api.php?action=delete&title=Main%20Page&token=123ABC',\r
- 'api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move'\r
- );\r
- }\r
-\r
- public function getVersion() {\r
- return __CLASS__ . ': $Id: ApiDelete.php 22289 2007-05-20 23:31:44Z yurik $';\r
- }\r
-}\r
+<?php
+
+/*
+ * Created on Jun 30, 2007
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@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$';
+ }
+}
-<?php\r
-\r
-/*\r
- * Created on Oct 31, 2007\r
- * API for MediaWiki 1.8+\r
- *\r
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * http://www.gnu.org/copyleft/gpl.html\r
- */\r
-\r
-if (!defined('MEDIAWIKI')) {\r
- // Eclipse helper - will be ignored in production\r
- require_once ("ApiBase.php");\r
-}\r
-\r
-\r
-/**\r
- * @addtogroup API\r
- */\r
-class ApiMove extends ApiBase {\r
-\r
- public function __construct($main, $action) {\r
- parent :: __construct($main, $action);\r
- }\r
- \r
- public function execute() {\r
- global $wgUser;\r
- $this->getMain()->requestWriteMode();\r
- $params = $this->extractRequestParams();\r
- if(is_null($params['reason']))\r
- $params['reason'] = '';\r
- \r
- $titleObj = NULL;\r
- if(!isset($params['from']))\r
- $this->dieUsage('The from parameter must be set', 'nofrom');\r
- if(!isset($params['to']))\r
- $this->dieUsage('The to parameter must be set', 'noto');\r
- if(!isset($params['token']))\r
- $this->dieUsage('The token parameter must be set', 'notoken');\r
- if(!$wgUser->matchEditToken($params['token']))\r
- $this->dieUsage('Invalid token', 'badtoken');\r
-\r
- if($wgUser->isBlocked())\r
- $this->dieUsage('You have been blocked from editing', 'blocked');\r
- if(wfReadOnly())\r
- $this->dieUsage('The wiki is in read-only mode', 'readonly');\r
- if($params['noredirect'] && !$wgUser->isAllowed('suppressredirect'))\r
- $this->dieUsage("You don't have permission to suppress redirect creation", 'nosuppress');\r
-\r
- $fromTitle = Title::newFromText($params['from']);\r
- if(!$fromTitle)\r
- $this->dieUsage("Bad title ``{$params['from']}''", 'invalidtitle');\r
- if(!$fromTitle->exists())\r
- $this->dieUsage("``{$params['from']}'' doesn't exist", 'missingtitle');\r
- $fromTalk = $fromTitle->getTalkPage();\r
-\r
- \r
- $toTitle = Title::newFromText($params['to']);\r
- if(!$toTitle)\r
- $this->dieUsage("Bad title ``{$params['to']}''", 'invalidtitle');\r
- $toTalk = $toTitle->getTalkPage();\r
-\r
- $dbw = wfGetDB(DB_MASTER);\r
- $dbw->begin(); \r
- $retval = $fromTitle->moveTo($toTitle, true, $params['reason'], !$params['noredirect']);\r
- if($retval !== true)\r
- switch($retval)\r
- {\r
- // case 'badtitletext': Can't happen\r
- // case 'badarticleerror': Can't happen\r
- case 'selfmove':\r
- $this->dieUsage("Can't move ``{$params['from']}'' to itself", 'selfmove');\r
- case 'immobile_namespace':\r
- if($fromTitle->isMovable())\r
- $this->dieUsage("Pages in the ``{$fromTitle->getNsText()}'' namespace can't be moved", 'immobilenamespace-from');\r
- $this->dieUsage("Pages in the ``{$toTitle->getNsText()}'' namespace can't be moved", 'immobilenamespace-to');\r
- case 'articleexists':\r
- $this->dieUsage("``{$toTitle->getPrefixedText()}'' already exists and is not a redirect to ``{$fromTitle->getPrefixedText()}''", 'targetexists');\r
- case 'protectedpage':\r
- $this->dieUsage("You don't have permission to move ``{$fromTitle->getPrefixedText()}'' to ``{$toTitle->getPrefixedText()}''", 'permissiondenied');\r
- default:\r
- throw new MWException( "Title::moveTo: Unknown return value ``{$retval}''" );\r
- }\r
- $r = array('from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason']);\r
- if(!$params['noredirect'])\r
- $r['redirectcreated'] = '';\r
- \r
- if($params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage())\r
- {\r
- // We need to move the talk page as well\r
- $toTalk = $toTitle->getTalkPage();\r
- $retval = $fromTalk->moveTo($toTalk, true, $params['reason'], !$params['noredirect']);\r
- if($retval === true)\r
- {\r
- $r['talkfrom'] = $fromTalk->getPrefixedText();\r
- $r['talkto'] = $toTalk->getPrefixedText();\r
- }\r
- // We're not gonna dieUsage() on failure, since we already changed something\r
- else\r
- switch($retval)\r
- {\r
- case 'immobile_namespace':\r
- if($fromTalk->isMovable())\r
- {\r
- $r['talkmove-error-code'] = 'immobilenamespace-from';\r
- $r['talkmove-error-info'] = "Pages in the ``{$fromTalk->getNsText()}'' namespace can't be moved";\r
- }\r
- else\r
- {\r
- $r['talkmove-error-code'] = 'immobilenamespace-to';\r
- $r['talkmove-error-info'] = "Pages in the ``{$toTalk->getNsText()}'' namespace can't be moved";\r
- }\r
- break;\r
- case 'articleexists':\r
- $r['talkmove-error-code'] = 'targetexists';\r
- $r['talkmove-error-info'] = "``{$toTalk->getPrefixedText()}'' already exists and is not a redirect to ``{$fromTalk->getPrefixedText()}''";\r
- break;\r
- case 'protectedpage':\r
- $r['talkmove-error-code'] = 'permissiondenied';\r
- $r['talkmove-error-info'] = "You don't have permission to move ``{$fromTalk->getPrefixedText()}'' to ``{$toTalk->getPrefixedText()}''";\r
- default:\r
- $r['talkmove-error-code'] = 'unknownerror';\r
- $r['talkmove-error-info'] = "Unknown error ``$retval''";\r
- } \r
- }\r
- $dbw->commit(); // Make sure all changes are really written to the DB\r
- $this->getResult()->addValue(null, $this->getModuleName(), $r);\r
- }\r
- \r
- protected function getAllowedParams() {\r
- return array (\r
- 'from' => null,\r
- 'to' => null,\r
- 'token' => null,\r
- 'reason' => null,\r
- 'movetalk' => false,\r
- 'noredirect' => false\r
- );\r
- }\r
-\r
- protected function getParamDescription() {\r
- return array (\r
- 'from' => 'Title of the page you want to move.',\r
- 'to' => 'Title you want to rename the page to.',\r
- 'token' => 'A move token previously retrieved through prop=info',\r
- 'reason' => 'Reason for the move (optional).',\r
- 'movetalk' => 'Move the talk page, if it exists.',\r
- 'noredirect' => 'Don\'t create a redirect'\r
- );\r
- }\r
-\r
- protected function getDescription() {\r
- return array(\r
- 'Moves a page.'\r
- );\r
- }\r
-\r
- protected function getExamples() {\r
- return array (\r
- 'api.php?action=move&from=Exampel&to=Example&token=123ABC&reason=Misspelled%20title&movetalk&noredirect'\r
- );\r
- }\r
-\r
- public function getVersion() {\r
- return __CLASS__ . ': $Id$';\r
- }\r
-}\r
+<?php
+
+/*
+ * Created on Oct 31, 2007
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@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$';
+ }
+}
-<?php\r
-\r
-/*\r
- * Created on Sep 1, 2007\r
- * API for MediaWiki 1.8+\r
- *\r
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * http://www.gnu.org/copyleft/gpl.html\r
- */\r
-\r
-if (!defined('MEDIAWIKI')) {\r
- // Eclipse helper - will be ignored in production\r
- require_once ("ApiBase.php");\r
-}\r
-\r
-/**\r
- * @addtogroup API\r
- */\r
-class ApiProtect extends ApiBase {\r
-\r
- public function __construct($main, $action) {\r
- parent :: __construct($main, $action);\r
- }\r
-\r
- public function execute() {\r
- global $wgUser;\r
- $this->getMain()->requestWriteMode();\r
- $params = $this->extractRequestParams();\r
- \r
- $titleObj = NULL;\r
- if(!isset($params['title']))\r
- $this->dieUsage('The title parameter must be set', 'notitle');\r
- if(!isset($params['token']))\r
- $this->dieUsage('The token parameter must be set', 'notoken');\r
- if(!isset($params['protections']) || empty($params['protections']))\r
- $this->dieUsage('The protections parameter must be set', 'noprotections');\r
-\r
- if($wgUser->isBlocked())\r
- $this->dieUsage('You have been blocked from editing', 'blocked');\r
- if(wfReadOnly())\r
- $this->dieUsage('The wiki is in read-only mode', 'readonly');\r
- if(!$wgUser->matchEditToken($params['token']))\r
- $this->dieUsage('Invalid token', 'badtoken');\r
-\r
- $titleObj = Title::newFromText($params['title']);\r
- if(!$titleObj)\r
- $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle');\r
- if(!$titleObj->exists())\r
- $this->dieUsage("``{$params['title']}'' doesn't exist", 'missingtitle');\r
- if(!$titleObj->userCan('protect'))\r
- $this->dieUsage('You don\'t have permission to change protection levels', 'permissiondenied');\r
- $articleObj = new Article($titleObj);\r
- \r
- if(in_array($params['expiry'], array('infinite', 'indefinite', 'never')))\r
- $expiry = Block::infinity();\r
- else\r
- {\r
- $expiry = strtotime($params['expiry']);\r
- if($expiry < 0 || $expiry == false)\r
- $this->dieUsage('Invalid expiry time', 'invalidexpiry');\r
- \r
- $expiry = wfTimestamp(TS_MW, $expiry);\r
- if($expiry < wfTimestampNow())\r
- $this->dieUsage('Expiry time is in the past', 'pastexpiry');\r
- }\r
-\r
- $protections = array();\r
- foreach($params['protections'] as $prot)\r
- {\r
- $p = explode('=', $prot);\r
- $protections[$p[0]] = ($p[1] == 'all' ? '' : $p[1]);\r
- }\r
-\r
- $dbw = wfGetDb(DB_MASTER);\r
- $dbw->begin();\r
- $ok = $articleObj->updateRestrictions($protections, $params['reason'], $params['cascade'], $expiry);\r
- if(!$ok)\r
- // This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime?\r
- $this->dieUsage('Unknown error', 'unknownerror');\r
- $dbw->commit();\r
- $res = array('title' => $titleObj->getPrefixedText(), 'reason' => $params['reason'], 'expiry' => $expiry);\r
- if($params['cascade'])\r
- $res['cascade'] = '';\r
- $res['protections'] = $protections;\r
- $this->getResult()->addValue(null, $this->getModuleName(), $res);\r
- }\r
-\r
- protected function getAllowedParams() {\r
- return array (\r
- 'title' => null,\r
- 'token' => null,\r
- 'protections' => array(\r
- ApiBase :: PARAM_ISMULTI => true\r
- ),\r
- 'expiry' => 'infinite',\r
- 'reason' => '',\r
- 'cascade' => false\r
- );\r
- }\r
-\r
- protected function getParamDescription() {\r
- return array (\r
- 'title' => 'Title of the page you want to restore.',\r
- 'token' => 'A protect token previously retrieved through prop=info',\r
- 'protections' => 'Pipe-separated list of protection levels, formatted action=group (e.g. edit=sysop)',\r
- 'expiry' => 'Expiry timestamp. If set to \'infinite\', \'indefinite\' or \'never\', the protection will never expire.',\r
- 'reason' => 'Reason for (un)protecting (optional)',\r
- 'cascade' => 'Enable cascading protection (i.e. protect pages included in this page)'\r
- );\r
- }\r
-\r
- protected function getDescription() {\r
- return array(\r
- 'Change the protection level of a page.'\r
- );\r
- }\r
-\r
- protected function getExamples() {\r
- return array (\r
- 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=sysop|move=sysop&cascade&expiry=20070901163000',\r
- 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=all|move=all&reason=Lifting%20restrictions'\r
- );\r
- }\r
-\r
- public function getVersion() {\r
- return __CLASS__ . ': $Id$';\r
- }\r
-}\r
+<?php
+
+/*
+ * Created on Sep 1, 2007
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@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$';
+ }
+}
-<?php\r
-\r
-/*\r
- * Created on Sep 10, 2007\r
- *\r
- * API for MediaWiki 1.8+\r
- *\r
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * http://www.gnu.org/copyleft/gpl.html\r
- */\r
-\r
-if (!defined('MEDIAWIKI')) {\r
- // Eclipse helper - will be ignored in production\r
- require_once ('ApiQueryBase.php');\r
-}\r
-\r
-/**\r
- * Query module to enumerate all available pages.\r
- * \r
- * @addtogroup API\r
- */\r
-class ApiQueryBlocks extends ApiQueryBase {\r
-\r
- public function __construct($query, $moduleName) {\r
- parent :: __construct($query, $moduleName, 'bk');\r
- }\r
-\r
- public function execute() {\r
- $this->run();\r
- }\r
-\r
- private function run() {\r
- global $wgUser;\r
-\r
- $params = $this->extractRequestParams();\r
- $prop = array_flip($params['prop']);\r
- $fld_id = isset($prop['id']);\r
- $fld_user = isset($prop['user']);\r
- $fld_by = isset($prop['by']);\r
- $fld_timestamp = isset($prop['timestamp']);\r
- $fld_expiry = isset($prop['expiry']);\r
- $fld_reason = isset($prop['reason']);\r
- $fld_range = isset($prop['range']);\r
- $fld_flags = isset($prop['flags']);\r
-\r
- $result = $this->getResult();\r
- $pageSet = $this->getPageSet();\r
- $titles = $pageSet->getTitles();\r
- $data = array();\r
-\r
- $this->addTables('ipblocks');\r
- if($fld_id)\r
- $this->addFields('ipb_id');\r
- if($fld_user)\r
- $this->addFields(array('ipb_address', 'ipb_user'));\r
- if($fld_by)\r
- {\r
- $this->addTables('user');\r
- $this->addFields(array('ipb_by', 'user_name'));\r
- $this->addWhere('user_id = ipb_by');\r
- }\r
- if($fld_timestamp)\r
- $this->addFields('ipb_timestamp');\r
- if($fld_expiry)\r
- $this->addFields('ipb_expiry');\r
- if($fld_reason)\r
- $this->addFields('ipb_reason');\r
- if($fld_range)\r
- $this->addFields(array('ipb_range_start', 'ipb_range_end'));\r
- if($fld_flags)\r
- $this->addFields(array('ipb_auto', 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted'));\r
-\r
- $this->addOption('LIMIT', $params['limit'] + 1);\r
- $this->addWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']);\r
- if(isset($params['ids']))\r
- $this->addWhere(array('ipb_id' => $params['ids']));\r
- if(isset($params['users']))\r
- $this->addWhere(array('ipb_address' => $params['users']));\r
- if(!$wgUser->isAllowed('oversight'))\r
- $this->addWhere(array('ipb_deleted' => 0));\r
-\r
- // Purge expired entries on one in every 10 queries\r
- if(!mt_rand(0, 10))\r
- Block::purgeExpired();\r
-\r
- $res = $this->select(__METHOD__);\r
- $db = wfGetDB();\r
-\r
- $count = 0;\r
- while($row = $db->fetchObject($res))\r
- {\r
- if($count++ == $params['limit'])\r
- {\r
- // We've had enough\r
- $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp));\r
- break;\r
- }\r
- $block = array();\r
- if($fld_id)\r
- $block['id'] = $row->ipb_id;\r
- if($fld_user)\r
- {\r
- $block['user'] = $row->ipb_address;\r
- $block['userid'] = $row->ipb_user;\r
- }\r
- if($fld_by)\r
- {\r
- $block['by'] = $row->user_name;\r
- $block['byuserid'] = $row->ipb_by;\r
- }\r
- if($fld_timestamp)\r
- $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp);\r
- if($fld_expiry)\r
- $block['expiry'] = Block::decodeExpiry($row->ipb_expiry, TS_ISO_8601);\r
- if($fld_reason)\r
- $block['reason'] = $row->ipb_reason;\r
- if($fld_range)\r
- {\r
- $block['rangestart'] = $this->convertHexIP($row->ipb_range_start);\r
- $block['rangeend'] = $this->convertHexIP($row->ipb_range_end);\r
- }\r
- if($fld_flags)\r
- {\r
- // For clarity, these flags use the same names as their action=block counterparts\r
- if($row->ipb_auto)\r
- $block['automatic'] = '';\r
- if($row->ipb_anon_only)\r
- $block['anononly'] = '';\r
- if($row->ipb_create_account)\r
- $block['nocreate'] = '';\r
- if($row->ipb_enable_autoblock)\r
- $block['autoblock'] = '';\r
- if($row->ipb_block_email)\r
- $block['noemail'] = '';\r
- if($row->ipb_deleted)\r
- $block['hidden'] = '';\r
- }\r
- $data[] = $block;\r
- }\r
- $result->setIndexedTagName($data, 'block');\r
- $result->addValue('query', $this->getModuleName(), $data);\r
- }\r
-\r
- protected function convertHexIP($ip)\r
- {\r
- // Converts a hexadecimal IP to nnn.nnn.nnn.nnn format\r
- $dec = wfBaseConvert($ip, 16, 10);\r
- $parts[0] = (int)($dec / (256*256*256));\r
- $dec %= 256*256*256;\r
- $parts[1] = (int)($dec / (256*256));\r
- $dec %= 256*256;\r
- $parts[2] = (int)($dec / 256);\r
- $parts[3] = $dec % 256;\r
- return implode('.', $parts);\r
- }\r
-\r
- protected function getAllowedParams() {\r
- return array (\r
- 'start' => array(\r
- ApiBase :: PARAM_TYPE => 'timestamp'\r
- ),\r
- 'end' => array(\r
- ApiBase :: PARAM_TYPE => 'timestamp',\r
- ),\r
- 'dir' => array(\r
- ApiBase :: PARAM_TYPE => array(\r
- 'newer',\r
- 'older'\r
- ),\r
- ApiBase :: PARAM_DFLT => 'older'\r
- ),\r
- 'ids' => array(\r
- ApiBase :: PARAM_TYPE => 'integer',\r
- ApiBase :: PARAM_ISMULTI => true\r
- ),\r
- 'users' => array(\r
- ApiBase :: PARAM_ISMULTI => true\r
- ),\r
- 'limit' => array(\r
- ApiBase :: PARAM_DFLT => 10,\r
- ApiBase :: PARAM_TYPE => 'limit',\r
- ApiBase :: PARAM_MIN => 1,\r
- ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,\r
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2\r
- ),\r
- 'prop' => array(\r
- ApiBase :: PARAM_DFLT => 'id|user|by|timestamp|expiry|reason|flags',\r
- ApiBase :: PARAM_TYPE => array(\r
- 'id',\r
- 'user',\r
- 'by',\r
- 'timestamp',\r
- 'expiry',\r
- 'reason',\r
- 'range',\r
- 'flags'\r
- ),\r
- ApiBase :: PARAM_ISMULTI => true\r
- )\r
- );\r
- }\r
-\r
- protected function getParamDescription() {\r
- return array (\r
- 'start' => 'The timestamp to start enumerating from',\r
- 'end' => 'The timestamp to stop enumerating at',\r
- 'dir' => 'The direction in which to enumerate',\r
- 'ids' => 'Pipe-separated list of block IDs to list (optional)',\r
- 'users' => 'Pipe-separated list of users to search for (optional)',\r
- 'limit' => 'The maximum amount of blocks to list',\r
- 'prop' => 'Which properties to get',\r
- );\r
- }\r
-\r
- protected function getDescription() {\r
- return 'List all blocked users and IP addresses.';\r
- }\r
-\r
- protected function getExamples() {\r
- return array (\r
- );\r
- }\r
-\r
- public function getVersion() {\r
- return __CLASS__ . ': $Id$';\r
- }\r
-}\r
+<?php
+
+/*
+ * Created on Sep 10, 2007
+ *
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@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$';
+ }
+}
-<?php\r
-\r
-/*\r
- * Created on Jul 2, 2007\r
- *\r
- * API for MediaWiki 1.8+\r
- *\r
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * http://www.gnu.org/copyleft/gpl.html\r
- */\r
-\r
-if (!defined('MEDIAWIKI')) {\r
- // Eclipse helper - will be ignored in production\r
- require_once ('ApiQueryBase.php');\r
-}\r
-\r
-/**\r
- * Query module to enumerate all available pages.\r
- * \r
- * @addtogroup API\r
- */\r
-class ApiQueryDeletedrevs extends ApiQueryBase {\r
-\r
- public function __construct($query, $moduleName) {\r
- parent :: __construct($query, $moduleName, 'dr');\r
- }\r
-\r
- public function execute() {\r
-\r
- global $wgUser;\r
- // Before doing anything at all, let's check permissions\r
- if(!$wgUser->isAllowed('deletedhistory'))\r
- $this->dieUsage('You don\'t have permission to view deleted revision information', 'permissiondenied');\r
-\r
- $db = $this->getDB();\r
- $params = $this->extractRequestParams();\r
- $prop = array_flip($params['prop']);\r
- $fld_revid = isset($prop['revid']);\r
- $fld_user = isset($prop['user']);\r
- $fld_comment = isset($prop['comment']);\r
- $fld_minor = isset($prop['minor']);\r
- $fld_len = isset($prop['len']);\r
- $fld_content = isset($prop['content']);\r
- $fld_token = isset($prop['token']);\r
-\r
- $result = $this->getResult();\r
- $pageSet = $this->getPageSet();\r
- $titles = $pageSet->getTitles();\r
- $data = array();\r
-\r
- $this->addTables('archive');\r
- $this->addFields(array('ar_title', 'ar_namespace', 'ar_timestamp'));\r
- if($fld_revid)\r
- $this->addFields('ar_rev_id');\r
- if($fld_user)\r
- $this->addFields('ar_user_text');\r
- if($fld_comment)\r
- $this->addFields('ar_comment');\r
- if($fld_minor)\r
- $this->addFields('ar_minor_edit');\r
- if($fld_len)\r
- $this->addFields('ar_len');\r
- if($fld_content)\r
- {\r
- $this->addTables('text');\r
- $this->addFields(array('ar_text', 'ar_text_id', 'old_text', 'old_flags'));\r
- $this->addWhere('ar_text_id = old_id');\r
-\r
- // This also means stricter limits and stricter restrictions\r
- if(!$wgUser->isAllowed('undelete'))\r
- $this->dieUsage('You don\'t have permission to view deleted revision content', 'permissiondenied');\r
- $userMax = ApiBase :: LIMIT_SML1;\r
- $botMax = ApiBase :: LIMIT_SML2;\r
- $this->validateLimit('limit', $params['limit'], 1, $userMax, $botMax);\r
- }\r
- if($fld_token)\r
- // Undelete tokens are identical for all pages, so we cache one here\r
- $token = $wgUser->editToken();\r
-\r
- // We need a custom WHERE clause that matches all titles.\r
- if(count($titles) > 0)\r
- {\r
- $lb = new LinkBatch($titles);\r
- $where = $lb->constructSet('ar', $db);\r
- $this->addWhere($where);\r
- }\r
-\r
- $this->addOption('LIMIT', $params['limit'] + 1);\r
- $this->addWhereRange('ar_timestamp', $params['dir'], $params['start'], $params['end']);\r
- if(isset($params['namespace']))\r
- $this->addWhereFld('ar_namespace', $params['namespace']);\r
- $res = $this->select(__METHOD__);\r
- $pages = array();\r
- $count = 0;\r
- // First populate the $pages array\r
- while($row = $db->fetchObject($res))\r
- {\r
- if($count++ == $params['limit'])\r
- {\r
- // We've had enough\r
- $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ar_timestamp));\r
- break;\r
- }\r
-\r
- $rev = array();\r
- $rev['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ar_timestamp);\r
- if($fld_revid)\r
- $rev['revid'] = $row->ar_rev_id;\r
- if($fld_user)\r
- $rev['user'] = $row->ar_user_text;\r
- if($fld_comment)\r
- $rev['comment'] = $row->ar_comment;\r
- if($fld_minor)\r
- if($row->ar_minor_edit == 1)\r
- $rev['minor'] = '';\r
- if($fld_len)\r
- $rev['len'] = $row->ar_len;\r
- if($fld_content)\r
- ApiResult::setContent($rev, Revision::getRevisionText($row));\r
-\r
- $t = Title::makeTitle($row->ar_namespace, $row->ar_title);\r
- if(!isset($pages[$t->getPrefixedText()]))\r
- {\r
- $pages[$t->getPrefixedText()] = array(\r
- 'title' => $t->getPrefixedText(),\r
- 'ns' => intval($row->ar_namespace),\r
- 'revisions' => array($rev)\r
- );\r
- if($fld_token)\r
- $pages[$t->getPrefixedText()]['token'] = $token;\r
- }\r
- else\r
- $pages[$t->getPrefixedText()]['revisions'][] = $rev;\r
- }\r
- $db->freeResult($res);\r
-\r
- // We don't want entire pagenames as keys, so let's make this array indexed\r
- foreach($pages as $page)\r
- {\r
- $result->setIndexedTagName($page['revisions'], 'rev');\r
- $data[] = $page;\r
- }\r
- $result->setIndexedTagName($data, 'page');\r
- $result->addValue('query', $this->getModuleName(), $data);\r
- }\r
-\r
- protected function getAllowedParams() {\r
- return array (\r
- 'start' => array(\r
- ApiBase :: PARAM_TYPE => 'timestamp'\r
- ),\r
- 'end' => array(\r
- ApiBase :: PARAM_TYPE => 'timestamp',\r
- ),\r
- 'dir' => array(\r
- ApiBase :: PARAM_TYPE => array(\r
- 'newer',\r
- 'older'\r
- ),\r
- ApiBase :: PARAM_DFLT => 'older'\r
- ),\r
- 'namespace' => array(\r
- ApiBase :: PARAM_ISMULTI => true,\r
- ApiBase :: PARAM_TYPE => 'namespace'\r
- ),\r
- 'limit' => array(\r
- ApiBase :: PARAM_DFLT => 10,\r
- ApiBase :: PARAM_TYPE => 'limit',\r
- ApiBase :: PARAM_MIN => 1,\r
- ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,\r
- ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2\r
- ),\r
- 'prop' => array(\r
- ApiBase :: PARAM_DFLT => 'user|comment',\r
- ApiBase :: PARAM_TYPE => array(\r
- 'revid',\r
- 'user',\r
- 'comment',\r
- 'minor',\r
- 'len',\r
- 'content',\r
- 'token'\r
- ),\r
- ApiBase :: PARAM_ISMULTI => true\r
- )\r
- );\r
- }\r
-\r
- protected function getParamDescription() {\r
- return array (\r
- 'start' => 'The timestamp to start enumerating from',\r
- 'end' => 'The timestamp to stop enumerating at',\r
- 'dir' => 'The direction in which to enumerate',\r
- 'namespace' => 'The namespaces to search in',\r
- 'limit' => 'The maximum amount of revisions to list',\r
- 'prop' => 'Which properties to get'\r
- );\r
- }\r
-\r
- protected function getDescription() {\r
- return 'List deleted revisions.';\r
- }\r
-\r
- protected function getExamples() {\r
- return array (\r
- 'List the first 50 deleted revisions in the Category and Category talk namespaces',\r
- ' api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=14|15',\r
- 'List the last deleted revisions of Main Page and Talk:Main Page, with content:',\r
- ' api.php?action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&drprop=user|comment|content'\r
- );\r
- }\r
-\r
- public function getVersion() {\r
- return __CLASS__ . ': $Id: ApiQueryDeletedrevs.php 23531 2007-06-30 01:19:14Z simetrical $';\r
- }\r
-}\r
+<?php
+
+/*
+ * Created on Jul 2, 2007
+ *
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@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$';
+ }
+}
-<?php\r
-\r
-/*\r
- * Created on Jun 20, 2007\r
- * API for MediaWiki 1.8+\r
- *\r
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * http://www.gnu.org/copyleft/gpl.html\r
- */\r
-\r
-if (!defined('MEDIAWIKI')) {\r
- // Eclipse helper - will be ignored in production\r
- require_once ("ApiBase.php");\r
-}\r
-\r
-/**\r
- * @addtogroup API\r
- */\r
-class ApiRollback extends ApiBase {\r
-\r
- public function __construct($main, $action) {\r
- parent :: __construct($main, $action);\r
- }\r
-\r
- public function execute() {\r
- global $wgUser;\r
- $this->getMain()->requestWriteMode();\r
- $params = $this->extractRequestParams();\r
- \r
- $titleObj = NULL;\r
- if(!isset($params['title']))\r
- $this->dieUsage('The title parameter must be set', 'notitle');\r
- if(!isset($params['user']))\r
- $this->dieUsage('The user parameter must be set', 'nouser');\r
- if(!isset($params['token']))\r
- $this->dieUsage('The token parameter must be set', 'notoken');\r
-\r
- // doRollback() also checks for these, but we wanna save some work\r
- if($wgUser->isBlocked())\r
- $this->dieUsage('You have been blocked from editing', 'blocked');\r
- if(wfReadOnly())\r
- $this->dieUsage('The wiki is in read-only mode', 'readonly');\r
-\r
- $titleObj = Title::newFromText($params['title']);\r
- if(!$titleObj)\r
- $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle');\r
- if(!$titleObj->userCan('rollback'))\r
- $this->dieUsage('You don\'t have permission to rollback', 'permissiondenied');\r
-\r
- $username = User::getCanonicalName($params['user']);\r
- if(!$username)\r
- $this->dieUsage("Invalid username ``{$params['user']}''", 'invaliduser');\r
-\r
- $articleObj = new Article($titleObj);\r
- $summary = (isset($params['summary']) ? $params['summary'] : "");\r
- $details = NULL;\r
- $dbw = wfGetDb(DB_MASTER);\r
- $dbw->begin();\r
- $retval = $articleObj->doRollback($username, $summary, $params['token'], $params['markbot'], &$details);\r
-\r
- switch($retval)\r
- {\r
- case Article::SUCCESS:\r
- break; // We'll deal with that later\r
- case Article::PERM_DENIED:\r
- $this->dieUsage("You don't have permission to rollback", 'permissiondenied');\r
- case Article::BLOCKED: // If we get BLOCKED or PERM_DENIED that's very weird, but it's possible\r
- $this->dieUsage('You have been blocked from editing', 'blocked');\r
- case Article::READONLY:\r
- $this->dieUsage('The wiki is in read-only mode', 'readonly');\r
- case Article::BAD_TOKEN:\r
- $this->dieUsage('Invalid token', 'badtoken');\r
- case Article::BAD_TITLE:\r
- $this->dieUsage("``{$params['title']}'' doesn't exist", 'missingtitle');\r
- case Article::ALREADYROLLED:\r
- $current = $details['current'];\r
- $currentID = $current->getId();\r
- $this->dieUsage("The edit(s) you tried to rollback is/are already rolled back." .\r
- "The current revision ID is ``$currentID''", 'alreadyrolled');\r
- case Article::ONLY_AUTHOR:\r
- $this->dieUsage("User ``$username'' is the only author of the page", 'onlyauthor');\r
- case Article::RATE_LIMITED:\r
- $this->dieUsage("You can't rollback too many articles in too short a time. Please wait a little while and try again", 'ratelimited');\r
- default:\r
- // rollback() has apparently invented a new error, which is extremely weird\r
- $this->dieDebug(__METHOD__, "rollback() returned an unknown error ($retval)");\r
- }\r
- // $retval has to be Article::SUCCESS if we get here\r
- $dbw->commit();\r
- $current = $target = $summary = NULL;\r
- extract($details);\r
-\r
- $info = array(\r
- 'title' => $titleObj->getPrefixedText(),\r
- 'pageid' => $current->getPage(),\r
- 'summary' => $summary,\r
- 'revid' => $titleObj->getLatestRevID(),\r
- 'old_revid' => $current->getID(),\r
- 'last_revid' => $target->getID()\r
- );\r
-\r
- $this->getResult()->addValue(null, $this->getModuleName(), $info);\r
- }\r
- \r
- protected function getAllowedParams() {\r
- return array (\r
- 'title' => null,\r
- 'user' => null,\r
- 'token' => null,\r
- 'summary' => null,\r
- 'markbot' => false\r
- );\r
- }\r
-\r
- protected function getParamDescription() {\r
- return array (\r
- 'title' => 'Title of the page you want to rollback.',\r
- 'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.',\r
- 'token' => 'A rollback token previously retrieved through prop=info',\r
- 'summary' => 'Custom edit summary. If not set, default summary will be used.',\r
- 'markbot' => 'Mark the reverted edits and the revert as bot edits'\r
- );\r
- }\r
-\r
- protected function getDescription() {\r
- return array(\r
- 'Undoes the last edit to the page. If the last user who edited the page made multiple edits in a row,',\r
- 'they will all be rolled back. You need to be logged in as a sysop to use this function, see also action=login.'\r
- );\r
- }\r
-\r
- protected function getExamples() {\r
- return array (\r
- 'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC',\r
- 'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1'\r
- );\r
- }\r
-\r
- public function getVersion() {\r
- return __CLASS__ . ': $Id: ApiRollback.php 22289 2007-05-20 23:31:44Z yurik $';\r
- }\r
-}\r
+<?php
+
+/*
+ * Created on Jun 20, 2007
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@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$';
+ }
+}
-<?php\r
-\r
-/*\r
- * Created on Sep 7, 2007\r
- * API for MediaWiki 1.8+\r
- *\r
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * http://www.gnu.org/copyleft/gpl.html\r
- */\r
-\r
-if (!defined('MEDIAWIKI')) {\r
- // Eclipse helper - will be ignored in production\r
- require_once ("ApiBase.php");\r
-}\r
-\r
-/**\r
- * @addtogroup API\r
- */\r
-class ApiUnblock extends ApiBase {\r
-\r
- public function __construct($main, $action) {\r
- parent :: __construct($main, $action);\r
- }\r
-\r
- public function execute() {\r
- global $wgUser;\r
- $this->getMain()->requestWriteMode();\r
- $params = $this->extractRequestParams();\r
-\r
- if($params['gettoken'])\r
- {\r
- $res['unblocktoken'] = $wgUser->editToken();\r
- $this->getResult()->addValue(null, $this->getModuleName(), $res);\r
- return;\r
- }\r
-\r
- if(is_null($params['id']) && is_null($params['user']))\r
- $this->dieUsage('Either the id or the user parameter must be set', 'notarget');\r
- if(!is_null($params['id']) && !is_null($params['user']))\r
- $this->dieUsage('The id and user parameters can\'t be used together', 'idanduser');\r
- if(is_null($params['token']))\r
- $this->dieUsage('The token parameter must be set', 'notoken');\r
- if(!$wgUser->matchEditToken($params['token']))\r
- $this->dieUsage('Invalid token', 'badtoken');\r
- if(!$wgUser->isAllowed('block'))\r
- $this->dieUsage('You don\'t have permission to unblock users', 'permissiondenied');\r
- if(wfReadOnly())\r
- $this->dieUsage('The wiki is in read-only mode', 'readonly');\r
-\r
- $id = $params['id'];\r
- $user = $params['user'];\r
- $reason = $params['reason'];\r
- $dbw = wfGetDb(DB_MASTER);\r
- $dbw->begin();\r
- $retval = IPUnblockForm::doUnblock(&$id, &$user, &$reason, &$range);\r
-\r
- switch($retval)\r
- {\r
- case IPUnblockForm::UNBLOCK_SUCCESS:\r
- break; // We'll deal with that later\r
- case IPUnblockForm::UNBLOCK_NO_SUCH_ID:\r
- $this->dieUsage("There is no block with ID ``$id''", 'nosuchid');\r
- case IPUnblockForm::UNBLOCK_USER_NOT_BLOCKED:\r
- $this->dieUsage("User ``$user'' is not blocked", 'notblocked');\r
- case IPUnblockForm::UNBLOCK_BLOCKED_AS_RANGE:\r
- $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');\r
- case IPUnblockForm::UNBLOCK_UNKNOWNERR:\r
- $this->dieUsage("Unknown error", 'unknownerr');\r
- default:\r
- $this->dieDebug(__METHOD__, "IPBlockForm::doBlock() returned an unknown error ($retval)");\r
- }\r
- $dbw->commit();\r
- \r
- $res['id'] = $id;\r
- $res['user'] = $user;\r
- $res['reason'] = $reason;\r
- $this->getResult()->addValue(null, $this->getModuleName(), $res);\r
- }\r
-\r
- protected function getAllowedParams() {\r
- return array (\r
- 'id' => null,\r
- 'user' => null,\r
- 'token' => null,\r
- 'gettoken' => false,\r
- 'reason' => null,\r
- );\r
- }\r
-\r
- protected function getParamDescription() {\r
- return array (\r
- 'id' => 'ID of the block you want to unblock (obtained through list=blocks). Cannot be user together with user',\r
- 'user' => 'Username, IP address or IP range you want to unblock. Cannot be used together with id',\r
- 'token' => 'An unblock token previously obtained through the gettoken parameter',\r
- 'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',\r
- 'reason' => 'Reason for unblock (optional)',\r
- );\r
- }\r
-\r
- protected function getDescription() {\r
- return array(\r
- 'Unblock a user.'\r
- );\r
- }\r
-\r
- protected function getExamples() {\r
- return array (\r
- 'api.php?action=unblock&id=105',\r
- 'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'\r
- );\r
- }\r
-\r
- public function getVersion() {\r
- return __CLASS__ . ': $Id$';\r
- }\r
-}\r
+<?php
+
+/*
+ * Created on Sep 7, 2007
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@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$';
+ }
+}
-<?php\r
-\r
-/*\r
- * Created on Jul 3, 2007\r
- * API for MediaWiki 1.8+\r
- *\r
- * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * http://www.gnu.org/copyleft/gpl.html\r
- */\r
-\r
-if (!defined('MEDIAWIKI')) {\r
- // Eclipse helper - will be ignored in production\r
- require_once ("ApiBase.php");\r
-}\r
-\r
-/**\r
- * @addtogroup API\r
- */\r
-class ApiUndelete extends ApiBase {\r
-\r
- public function __construct($main, $action) {\r
- parent :: __construct($main, $action);\r
- }\r
-\r
- public function execute() {\r
- global $wgUser;\r
- $this->getMain()->requestWriteMode();\r
- $params = $this->extractRequestParams();\r
- \r
- $titleObj = NULL;\r
- if(!isset($params['title']))\r
- $this->dieUsage('The title parameter must be set', 'notitle');\r
- if(!isset($params['token']))\r
- $this->dieUsage('The token parameter must be set', 'notoken');\r
-\r
- if(!$wgUser->isAllowed('undelete'))\r
- $this->dieUsage('You don\'t have permission to restore deleted revisions', 'permissiondenied');\r
- if($wgUser->isBlocked())\r
- $this->dieUsage('You have been blocked from editing', 'blocked');\r
- if(wfReadOnly())\r
- $this->dieUsage('The wiki is in read-only mode', 'readonly');\r
- if(!$wgUser->matchEditToken($params['token']))\r
- $this->dieUsage('Invalid token', 'badtoken');\r
-\r
- $titleObj = Title::newFromText($params['title']);\r
- if(!$titleObj)\r
- $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle');\r
-\r
- // Convert timestamps\r
- if(!is_array($params['timestamps']))\r
- $params['timestamps'] = array($params['timestamps']);\r
- foreach($params['timestamps'] as $i => $ts)\r
- $params['timestamps'][$i] = wfTimestamp(TS_MW, $ts);\r
-\r
- $pa = new PageArchive($titleObj);\r
- $dbw = wfGetDb(DB_MASTER);\r
- $dbw->begin();\r
- $retval = $pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason']);\r
- if(!is_array($retval))\r
- switch($retval)\r
- {\r
- case PageArchive::UNDELETE_NOTHINGRESTORED:\r
- $this->dieUsage('No revisions could be restored', 'norevs');\r
- case PageArchive::UNDELETE_NOTAVAIL:\r
- $this->dieUsage('Not all requested revisions could be found', 'revsnotfound');\r
- case PageArchive::UNDELETE_UNKNOWNERR:\r
- $this->dieUsage('Undeletion failed with unknown error', 'unknownerror');\r
- }\r
- $dbw->commit();\r
- \r
- $info['title'] = $titleObj->getPrefixedText();\r
- $info['revisions'] = $retval[0];\r
- $info['fileversions'] = $retval[1];\r
- $info['reason'] = $retval[2];\r
- $this->getResult()->addValue(null, $this->getModuleName(), $info);\r
- }\r
- \r
- protected function getAllowedParams() {\r
- return array (\r
- 'title' => null,\r
- 'token' => null,\r
- 'reason' => "",\r
- 'timestamps' => array(\r
- ApiBase :: PARAM_ISMULTI => true\r
- )\r
- );\r
- }\r
-\r
- protected function getParamDescription() {\r
- return array (\r
- 'title' => 'Title of the page you want to restore.',\r
- 'token' => 'An undelete token previously retrieved through list=deletedrevs',\r
- 'reason' => 'Reason for restoring (optional)',\r
- 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.'\r
- );\r
- }\r
-\r
- protected function getDescription() {\r
- return array(\r
- 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be',\r
- 'retrieved through list=deletedrevs'\r
- );\r
- }\r
-\r
- protected function getExamples() {\r
- return array (\r
- 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',\r
- 'api.php?action=undelete&title=Main%20Page&token=123ABC×tamps=20070703220045|20070702194856'\r
- );\r
- }\r
-\r
- public function getVersion() {\r
- return __CLASS__ . ': $Id: ApiUndelete.php 22289 2007-05-20 23:31:44Z yurik $';\r
- }\r
-}\r
+<?php
+
+/*
+ * Created on Jul 3, 2007
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@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$';
+ }
+}