ApiPatrol.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /*
  3. * Created on Sep 2, 2008
  4. *
  5. * API for MediaWiki 1.14+
  6. *
  7. * Copyright (C) 2008 Soxred93 soxred93@gmail.com,
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. * http://www.gnu.org/copyleft/gpl.html
  23. */
  24. if (!defined('MEDIAWIKI')) {
  25. require_once ('ApiBase.php');
  26. }
  27. /**
  28. * Allows user to patrol pages
  29. * @ingroup API
  30. */
  31. class ApiPatrol extends ApiBase {
  32. public function __construct($main, $action) {
  33. parent :: __construct($main, $action);
  34. }
  35. /**
  36. * Patrols the article or provides the reason the patrol failed.
  37. */
  38. public function execute() {
  39. global $wgUser, $wgUseRCPatrol, $wgUseNPPatrol;
  40. $params = $this->extractRequestParams();
  41. if(!isset($params['token']))
  42. $this->dieUsageMsg(array('missingparam', 'token'));
  43. if(!isset($params['rcid']))
  44. $this->dieUsageMsg(array('missingparam', 'rcid'));
  45. if(!$wgUser->matchEditToken($params['token']))
  46. $this->dieUsageMsg(array('sessionfailure'));
  47. $rc = RecentChange::newFromID($params['rcid']);
  48. if(!$rc instanceof RecentChange)
  49. $this->dieUsageMsg(array('nosuchrcid', $params['rcid']));
  50. $retval = RecentChange::markPatrolled($params['rcid']);
  51. if($retval)
  52. $this->dieUsageMsg(reset($retval));
  53. $result = array('rcid' => intval($rc->getAttribute('rc_id')));
  54. ApiQueryBase::addTitleInfo($result, $rc->getTitle());
  55. $this->getResult()->addValue(null, $this->getModuleName(), $result);
  56. }
  57. public function isWriteMode() {
  58. return true;
  59. }
  60. public function getAllowedParams() {
  61. return array (
  62. 'token' => null,
  63. 'rcid' => array(
  64. ApiBase :: PARAM_TYPE => 'integer'
  65. ),
  66. );
  67. }
  68. public function getParamDescription() {
  69. return array (
  70. 'token' => 'Patrol token obtained from list=recentchanges',
  71. 'rcid' => 'Recentchanges ID to patrol',
  72. );
  73. }
  74. public function getDescription() {
  75. return array (
  76. 'Patrol a page or revision. '
  77. );
  78. }
  79. protected function getExamples() {
  80. return array(
  81. 'api.php?action=patrol&token=123abc&rcid=230672766'
  82. );
  83. }
  84. public function getVersion() {
  85. return __CLASS__ . ': $Id: ApiPatrol.php 48122 2009-03-07 12:58:41Z catrope $';
  86. }
  87. }