Merge "chmod 644"
[mediawiki.git] / includes / api / ApiPurge.php
blob981dc18f030f72005a29ab9cf602de93a22e6e79
1 <?php
3 /**
4 * API for MediaWiki 1.14+
6 * Created on Sep 2, 2008
8 * Copyright © 2008 Chad Horohoe
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
25 * @file
28 /**
29 * API interface for page purging
30 * @ingroup API
32 class ApiPurge extends ApiBase {
33 private $mPageSet;
35 /**
36 * Purges the cache of a page
38 public function execute() {
39 $params = $this->extractRequestParams();
41 $forceLinkUpdate = $params['forcelinkupdate'];
42 $forceRecursiveLinkUpdate = $params['forcerecursivelinkupdate'];
43 $pageSet = $this->getPageSet();
44 $pageSet->execute();
46 $result = $pageSet->getInvalidTitlesAndRevisions();
48 foreach ( $pageSet->getGoodTitles() as $title ) {
49 $r = array();
50 ApiQueryBase::addTitleInfo( $r, $title );
51 $page = WikiPage::factory( $title );
52 $page->doPurge(); // Directly purge and skip the UI part of purge().
53 $r['purged'] = '';
55 if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) {
56 if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) {
57 $popts = $page->makeParserOptions( 'canonical' );
59 # Parse content; note that HTML generation is only needed if we want to cache the result.
60 $content = $page->getContent( Revision::RAW );
61 $enableParserCache = $this->getConfig()->get( 'EnableParserCache' );
62 $p_result = $content->getParserOutput(
63 $title,
64 $page->getLatest(),
65 $popts,
66 $enableParserCache
69 # Update the links tables
70 $updates = $content->getSecondaryDataUpdates(
71 $title, null, $forceRecursiveLinkUpdate, $p_result );
72 DataUpdate::runUpdates( $updates );
74 $r['linkupdate'] = '';
76 if ( $enableParserCache ) {
77 $pcache = ParserCache::singleton();
78 $pcache->save( $p_result, $page, $popts );
80 } else {
81 $error = $this->parseMsg( array( 'actionthrottledtext' ) );
82 $this->setWarning( $error['info'] );
83 $forceLinkUpdate = false;
87 $result[] = $r;
89 $apiResult = $this->getResult();
90 $apiResult->setIndexedTagName( $result, 'page' );
91 $apiResult->addValue( null, $this->getModuleName(), $result );
93 $values = $pageSet->getNormalizedTitlesAsResult( $apiResult );
94 if ( $values ) {
95 $apiResult->addValue( null, 'normalized', $values );
97 $values = $pageSet->getConvertedTitlesAsResult( $apiResult );
98 if ( $values ) {
99 $apiResult->addValue( null, 'converted', $values );
101 $values = $pageSet->getRedirectTitlesAsResult( $apiResult );
102 if ( $values ) {
103 $apiResult->addValue( null, 'redirects', $values );
108 * Get a cached instance of an ApiPageSet object
109 * @return ApiPageSet
111 private function getPageSet() {
112 if ( !isset( $this->mPageSet ) ) {
113 $this->mPageSet = new ApiPageSet( $this );
116 return $this->mPageSet;
119 public function isWriteMode() {
120 return true;
123 public function mustBePosted() {
124 // Anonymous users are not allowed a non-POST request
125 return !$this->getUser()->isAllowed( 'purge' );
128 public function getAllowedParams( $flags = 0 ) {
129 $result = array(
130 'forcelinkupdate' => false,
131 'forcerecursivelinkupdate' => false
133 if ( $flags ) {
134 $result += $this->getPageSet()->getFinalParams( $flags );
137 return $result;
140 public function getParamDescription() {
141 return $this->getPageSet()->getFinalParamDescription()
142 + array(
143 'forcelinkupdate' => 'Update the links tables',
144 'forcerecursivelinkupdate' => 'Update the links table, and update ' .
145 'the links tables for any page that uses this page as a template',
149 public function getResultProperties() {
150 return array(
151 ApiBase::PROP_LIST => true,
152 '' => array(
153 'ns' => array(
154 ApiBase::PROP_TYPE => 'namespace',
155 ApiBase::PROP_NULLABLE => true
157 'title' => array(
158 ApiBase::PROP_TYPE => 'string',
159 ApiBase::PROP_NULLABLE => true
161 'pageid' => array(
162 ApiBase::PROP_TYPE => 'integer',
163 ApiBase::PROP_NULLABLE => true
165 'revid' => array(
166 ApiBase::PROP_TYPE => 'integer',
167 ApiBase::PROP_NULLABLE => true
169 'invalid' => 'boolean',
170 'special' => 'boolean',
171 'missing' => 'boolean',
172 'purged' => 'boolean',
173 'linkupdate' => 'boolean',
174 'iw' => array(
175 ApiBase::PROP_TYPE => 'string',
176 ApiBase::PROP_NULLABLE => true
182 public function getDescription() {
183 return array( 'Purge the cache for the given titles.',
184 'Requires a POST request if the user is not logged in.'
188 public function getPossibleErrors() {
189 return array_merge(
190 parent::getPossibleErrors(),
191 $this->getPageSet()->getFinalPossibleErrors()
195 public function getExamples() {
196 return array(
197 'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page',
201 public function getHelpUrls() {
202 return 'https://www.mediawiki.org/wiki/API:Purge';