ApiUnblock.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /*
  3. * Created on Sep 7, 2007
  4. * API for MediaWiki 1.8+
  5. *
  6. * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. * http://www.gnu.org/copyleft/gpl.html
  22. */
  23. if (!defined('MEDIAWIKI')) {
  24. // Eclipse helper - will be ignored in production
  25. require_once ("ApiBase.php");
  26. }
  27. /**
  28. * API module that facilitates the unblocking of users. Requires API write mode
  29. * to be enabled.
  30. *
  31. * @ingroup API
  32. */
  33. class ApiUnblock extends ApiBase {
  34. public function __construct($main, $action) {
  35. parent :: __construct($main, $action);
  36. }
  37. /**
  38. * Unblocks the specified user or provides the reason the unblock failed.
  39. */
  40. public function execute() {
  41. global $wgUser;
  42. $params = $this->extractRequestParams();
  43. if($params['gettoken'])
  44. {
  45. $res['unblocktoken'] = $wgUser->editToken();
  46. $this->getResult()->addValue(null, $this->getModuleName(), $res);
  47. return;
  48. }
  49. if(is_null($params['id']) && is_null($params['user']))
  50. $this->dieUsageMsg(array('unblock-notarget'));
  51. if(!is_null($params['id']) && !is_null($params['user']))
  52. $this->dieUsageMsg(array('unblock-idanduser'));
  53. if(is_null($params['token']))
  54. $this->dieUsageMsg(array('missingparam', 'token'));
  55. if(!$wgUser->matchEditToken($params['token']))
  56. $this->dieUsageMsg(array('sessionfailure'));
  57. if(!$wgUser->isAllowed('block'))
  58. $this->dieUsageMsg(array('cantunblock'));
  59. $id = $params['id'];
  60. $user = $params['user'];
  61. $reason = (is_null($params['reason']) ? '' : $params['reason']);
  62. $retval = IPUnblockForm::doUnblock($id, $user, $reason, $range);
  63. if($retval)
  64. $this->dieUsageMsg($retval);
  65. $res['id'] = intval($id);
  66. $res['user'] = $user;
  67. $res['reason'] = $reason;
  68. $this->getResult()->addValue(null, $this->getModuleName(), $res);
  69. }
  70. public function mustBePosted() { return true; }
  71. public function isWriteMode() {
  72. return true;
  73. }
  74. public function getAllowedParams() {
  75. return array (
  76. 'id' => null,
  77. 'user' => null,
  78. 'token' => null,
  79. 'gettoken' => false,
  80. 'reason' => null,
  81. );
  82. }
  83. public function getParamDescription() {
  84. return array (
  85. 'id' => 'ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with user',
  86. 'user' => 'Username, IP address or IP range you want to unblock. Cannot be used together with id',
  87. 'token' => 'An unblock token previously obtained through the gettoken parameter or prop=info',
  88. 'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',
  89. 'reason' => 'Reason for unblock (optional)',
  90. );
  91. }
  92. public function getDescription() {
  93. return array(
  94. 'Unblock a user.'
  95. );
  96. }
  97. protected function getExamples() {
  98. return array (
  99. 'api.php?action=unblock&id=105',
  100. 'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
  101. );
  102. }
  103. public function getVersion() {
  104. return __CLASS__ . ': $Id: ApiUnblock.php 48091 2009-03-06 13:49:44Z catrope $';
  105. }
  106. }