Merge "Remove not used private member variable mParserWarnings from OutputPage"
[mediawiki.git] / includes / api / ApiPurge.php
blob34f9b6c84ec610fb1e08b2458c2022578cb8fc60
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 $continuationManager = new ApiContinuationManager( $this, array(), array() );
42 $this->setContinuationManager( $continuationManager );
44 $forceLinkUpdate = $params['forcelinkupdate'];
45 $forceRecursiveLinkUpdate = $params['forcerecursivelinkupdate'];
46 $pageSet = $this->getPageSet();
47 $pageSet->execute();
49 $result = $pageSet->getInvalidTitlesAndRevisions();
50 $user = $this->getUser();
52 foreach ( $pageSet->getGoodTitles() as $title ) {
53 $r = array();
54 ApiQueryBase::addTitleInfo( $r, $title );
55 $page = WikiPage::factory( $title );
56 if ( !$user->pingLimiter( 'purge' ) ) {
57 $page->doPurge(); // Directly purge and skip the UI part of purge().
58 $r['purged'] = true;
59 } else {
60 $error = $this->parseMsg( array( 'actionthrottledtext' ) );
61 $this->setWarning( $error['info'] );
64 if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) {
65 if ( !$user->pingLimiter( 'linkpurge' ) ) {
66 $popts = $page->makeParserOptions( 'canonical' );
68 # Parse content; note that HTML generation is only needed if we want to cache the result.
69 $content = $page->getContent( Revision::RAW );
70 $enableParserCache = $this->getConfig()->get( 'EnableParserCache' );
71 $p_result = $content->getParserOutput(
72 $title,
73 $page->getLatest(),
74 $popts,
75 $enableParserCache
78 # Update the links tables
79 $updates = $content->getSecondaryDataUpdates(
80 $title, null, $forceRecursiveLinkUpdate, $p_result );
81 DataUpdate::runUpdates( $updates );
83 $r['linkupdate'] = true;
85 if ( $enableParserCache ) {
86 $pcache = ParserCache::singleton();
87 $pcache->save( $p_result, $page, $popts );
89 } else {
90 $error = $this->parseMsg( array( 'actionthrottledtext' ) );
91 $this->setWarning( $error['info'] );
92 $forceLinkUpdate = false;
96 $result[] = $r;
98 $apiResult = $this->getResult();
99 ApiResult::setIndexedTagName( $result, 'page' );
100 $apiResult->addValue( null, $this->getModuleName(), $result );
102 $values = $pageSet->getNormalizedTitlesAsResult( $apiResult );
103 if ( $values ) {
104 $apiResult->addValue( null, 'normalized', $values );
106 $values = $pageSet->getConvertedTitlesAsResult( $apiResult );
107 if ( $values ) {
108 $apiResult->addValue( null, 'converted', $values );
110 $values = $pageSet->getRedirectTitlesAsResult( $apiResult );
111 if ( $values ) {
112 $apiResult->addValue( null, 'redirects', $values );
115 $this->setContinuationManager( null );
116 $continuationManager->setContinuationIntoResult( $apiResult );
120 * Get a cached instance of an ApiPageSet object
121 * @return ApiPageSet
123 private function getPageSet() {
124 if ( !isset( $this->mPageSet ) ) {
125 $this->mPageSet = new ApiPageSet( $this );
128 return $this->mPageSet;
131 public function isWriteMode() {
132 return true;
135 public function mustBePosted() {
136 // Anonymous users are not allowed a non-POST request
137 return !$this->getUser()->isAllowed( 'purge' );
140 public function getAllowedParams( $flags = 0 ) {
141 $result = array(
142 'forcelinkupdate' => false,
143 'forcerecursivelinkupdate' => false,
144 'continue' => array(
145 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
148 if ( $flags ) {
149 $result += $this->getPageSet()->getFinalParams( $flags );
152 return $result;
155 protected function getExamplesMessages() {
156 return array(
157 'action=purge&titles=Main_Page|API'
158 => 'apihelp-purge-example-simple',
159 'action=purge&generator=allpages&gapnamespace=0&gaplimit=10'
160 => 'apihelp-purge-example-generator',
164 public function getHelpUrls() {
165 return 'https://www.mediawiki.org/wiki/API:Purge';