ApiPurge.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /*
  3. * Created on Sep 2, 2008
  4. *
  5. * API for MediaWiki 1.14+
  6. *
  7. * Copyright (C) 2008 Chad Horohoe
  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. * API interface for page purging
  29. * @ingroup API
  30. */
  31. class ApiPurge extends ApiBase {
  32. public function __construct($main, $action) {
  33. parent :: __construct($main, $action);
  34. }
  35. /**
  36. * Purges the cache of a page
  37. */
  38. public function execute() {
  39. global $wgUser;
  40. $params = $this->extractRequestParams();
  41. if(!$wgUser->isAllowed('purge'))
  42. $this->dieUsageMsg(array('cantpurge'));
  43. if(!isset($params['titles']))
  44. $this->dieUsageMsg(array('missingparam', 'titles'));
  45. $result = array();
  46. foreach($params['titles'] as $t) {
  47. $r = array();
  48. $title = Title::newFromText($t);
  49. if(!$title instanceof Title)
  50. {
  51. $r['title'] = $t;
  52. $r['invalid'] = '';
  53. $result[] = $r;
  54. continue;
  55. }
  56. ApiQueryBase::addTitleInfo($r, $title);
  57. if(!$title->exists())
  58. {
  59. $r['missing'] = '';
  60. $result[] = $r;
  61. continue;
  62. }
  63. $article = new Article($title);
  64. $article->doPurge(); // Directly purge and skip the UI part of purge().
  65. $r['purged'] = '';
  66. $result[] = $r;
  67. }
  68. $this->getResult()->setIndexedTagName($result, 'page');
  69. $this->getResult()->addValue(null, $this->getModuleName(), $result);
  70. }
  71. public function mustBePosted() {
  72. global $wgUser;
  73. return $wgUser->isAnon();
  74. }
  75. public function isWriteMode() {
  76. return true;
  77. }
  78. public function getAllowedParams() {
  79. return array (
  80. 'titles' => array(
  81. ApiBase :: PARAM_ISMULTI => true
  82. )
  83. );
  84. }
  85. public function getParamDescription() {
  86. return array (
  87. 'titles' => 'A list of titles',
  88. );
  89. }
  90. public function getDescription() {
  91. return array (
  92. 'Purge the cache for the given titles.'
  93. );
  94. }
  95. protected function getExamples() {
  96. return array(
  97. 'api.php?action=purge&titles=Main_Page|API'
  98. );
  99. }
  100. public function getVersion() {
  101. return __CLASS__ . ': $Id: ApiPurge.php 48091 2009-03-06 13:49:44Z catrope $';
  102. }
  103. }