[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/api/ -> ApiPurge.php (source)

   1  <?php
   2  
   3  /**
   4   * API for MediaWiki 1.14+
   5   *
   6   * Created on Sep 2, 2008
   7   *
   8   * Copyright © 2008 Chad Horohoe
   9   *
  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.
  14   *
  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.
  19   *
  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
  24   *
  25   * @file
  26   */
  27  
  28  /**
  29   * API interface for page purging
  30   * @ingroup API
  31   */
  32  class ApiPurge extends ApiBase {
  33      private $mPageSet;
  34  
  35      /**
  36       * Purges the cache of a page
  37       */
  38  	public function execute() {
  39          $params = $this->extractRequestParams();
  40  
  41          $this->getResult()->beginContinuation( $params['continue'], array(), array() );
  42  
  43          $forceLinkUpdate = $params['forcelinkupdate'];
  44          $forceRecursiveLinkUpdate = $params['forcerecursivelinkupdate'];
  45          $pageSet = $this->getPageSet();
  46          $pageSet->execute();
  47  
  48          $result = $pageSet->getInvalidTitlesAndRevisions();
  49  
  50          foreach ( $pageSet->getGoodTitles() as $title ) {
  51              $r = array();
  52              ApiQueryBase::addTitleInfo( $r, $title );
  53              $page = WikiPage::factory( $title );
  54              $page->doPurge(); // Directly purge and skip the UI part of purge().
  55              $r['purged'] = '';
  56  
  57              if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) {
  58                  if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) {
  59                      $popts = $page->makeParserOptions( 'canonical' );
  60  
  61                      # Parse content; note that HTML generation is only needed if we want to cache the result.
  62                      $content = $page->getContent( Revision::RAW );
  63                      $enableParserCache = $this->getConfig()->get( 'EnableParserCache' );
  64                      $p_result = $content->getParserOutput(
  65                          $title,
  66                          $page->getLatest(),
  67                          $popts,
  68                          $enableParserCache
  69                      );
  70  
  71                      # Update the links tables
  72                      $updates = $content->getSecondaryDataUpdates(
  73                          $title, null, $forceRecursiveLinkUpdate, $p_result );
  74                      DataUpdate::runUpdates( $updates );
  75  
  76                      $r['linkupdate'] = '';
  77  
  78                      if ( $enableParserCache ) {
  79                          $pcache = ParserCache::singleton();
  80                          $pcache->save( $p_result, $page, $popts );
  81                      }
  82                  } else {
  83                      $error = $this->parseMsg( array( 'actionthrottledtext' ) );
  84                      $this->setWarning( $error['info'] );
  85                      $forceLinkUpdate = false;
  86                  }
  87              }
  88  
  89              $result[] = $r;
  90          }
  91          $apiResult = $this->getResult();
  92          $apiResult->setIndexedTagName( $result, 'page' );
  93          $apiResult->addValue( null, $this->getModuleName(), $result );
  94  
  95          $values = $pageSet->getNormalizedTitlesAsResult( $apiResult );
  96          if ( $values ) {
  97              $apiResult->addValue( null, 'normalized', $values );
  98          }
  99          $values = $pageSet->getConvertedTitlesAsResult( $apiResult );
 100          if ( $values ) {
 101              $apiResult->addValue( null, 'converted', $values );
 102          }
 103          $values = $pageSet->getRedirectTitlesAsResult( $apiResult );
 104          if ( $values ) {
 105              $apiResult->addValue( null, 'redirects', $values );
 106          }
 107  
 108          $apiResult->endContinuation();
 109      }
 110  
 111      /**
 112       * Get a cached instance of an ApiPageSet object
 113       * @return ApiPageSet
 114       */
 115  	private function getPageSet() {
 116          if ( !isset( $this->mPageSet ) ) {
 117              $this->mPageSet = new ApiPageSet( $this );
 118          }
 119  
 120          return $this->mPageSet;
 121      }
 122  
 123  	public function isWriteMode() {
 124          return true;
 125      }
 126  
 127  	public function mustBePosted() {
 128          // Anonymous users are not allowed a non-POST request
 129          return !$this->getUser()->isAllowed( 'purge' );
 130      }
 131  
 132  	public function getAllowedParams( $flags = 0 ) {
 133          $result = array(
 134              'forcelinkupdate' => false,
 135              'forcerecursivelinkupdate' => false,
 136              'continue' => '',
 137          );
 138          if ( $flags ) {
 139              $result += $this->getPageSet()->getFinalParams( $flags );
 140          }
 141  
 142          return $result;
 143      }
 144  
 145  	public function getParamDescription() {
 146          return $this->getPageSet()->getFinalParamDescription()
 147              + array(
 148                  'forcelinkupdate' => 'Update the links tables',
 149                  'forcerecursivelinkupdate' => 'Update the links table, and update ' .
 150                      'the links tables for any page that uses this page as a template',
 151                  'continue' => 'When more results are available, use this to continue',
 152              );
 153      }
 154  
 155  	public function getDescription() {
 156          return array( 'Purge the cache for the given titles.',
 157              'Requires a POST request if the user is not logged in.'
 158          );
 159      }
 160  
 161  	public function getExamples() {
 162          return array(
 163              'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page',
 164          );
 165      }
 166  
 167  	public function getHelpUrls() {
 168          return 'https://www.mediawiki.org/wiki/API:Purge';
 169      }
 170  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1