fix merge of Iec98e472
[lhc/web/wiklou.git] / includes / api / ApiPurge.php
index f0ae64e..3cf32ad 100644 (file)
@@ -47,17 +47,32 @@ class ApiPurge extends ApiBase {
                }
 
                $forceLinkUpdate = $params['forcelinkupdate'];
+               $pageSet = new ApiPageSet( $this );
+               $pageSet->execute();
 
                $result = array();
-               foreach ( $params['titles'] as $t ) {
+               foreach( $pageSet->getInvalidTitles() as $title ) {
                        $r = array();
-                       $title = Title::newFromText( $t );
-                       if ( !$title instanceof Title ) {
-                               $r['title'] = $t;
-                               $r['invalid'] = '';
-                               $result[] = $r;
-                               continue;
-                       }
+                       $r['title'] = $title;
+                       $r['invalid'] = '';
+                       $result[] = $r;
+               }
+               foreach( $pageSet->getMissingPageIDs() as $p ) {
+                       $page = array();
+                       $page['pageid'] = $p;
+                       $page['missing'] = '';
+                       $result[] = $page;
+               }
+               foreach( $pageSet->getMissingRevisionIDs() as $r ) {
+                       $rev = array();
+                       $rev['revid'] = $r;
+                       $rev['missing'] = '';
+                       $result[] = $rev;
+               }
+
+               foreach ( $pageSet->getTitles() as $title ) {
+                       $r = array();
+
                        ApiQueryBase::addTitleInfo( $r, $title );
                        if ( !$title->exists() ) {
                                $r['missing'] = '';
@@ -71,14 +86,18 @@ class ApiPurge extends ApiBase {
 
                        if( $forceLinkUpdate ) {
                                if ( !$user->pingLimiter() ) {
-                                       global $wgParser, $wgEnableParserCache;
+                                       global $wgEnableParserCache;
+
+                                       $popts = $page->makeParserOptions( 'canonical' );
+                                       $popts->setTidy( true );
 
-                                       $popts = ParserOptions::newFromContext( $this->getContext() );
-                                       $p_result = $wgParser->parse( $page->getRawText(), $title, $popts );
+                                       # Parse content; note that HTML generation is only needed if we want to cache the result.
+                                       $content = $page->getContent( Revision::RAW );
+                                       $p_result = $content->getParserOutput( $title, $page->getLatest(), $popts, $wgEnableParserCache );
 
                                        # Update the links tables
-                                       $u = new LinksUpdate( $title, $p_result );
-                                       $u->doUpdate();
+                                       $updates = $content->getSecondaryDataUpdates( $title, null, true, $p_result );
+                                       DataUpdate::runUpdates( $updates );
 
                                        $r['linkupdate'] = '';
 
@@ -87,7 +106,8 @@ class ApiPurge extends ApiBase {
                                                $pcache->save( $p_result, $page, $popts );
                                        }
                                } else {
-                                       $this->setWarning( $this->parseMsg( array( 'actionthrottledtext' ) ) );
+                                       $error = $this->parseMsg( array( 'actionthrottledtext' ) );
+                                       $this->setWarning( $error['info'] );
                                        $forceLinkUpdate = false;
                                }
                        }
@@ -104,22 +124,47 @@ class ApiPurge extends ApiBase {
        }
 
        public function getAllowedParams() {
-               return array(
-                       'titles' => array(
-                               ApiBase::PARAM_ISMULTI => true,
-                               ApiBase::PARAM_REQUIRED => true
-                       ),
+               $psModule = new ApiPageSet( $this );
+               return $psModule->getAllowedParams() + array(
                        'forcelinkupdate' => false,
                );
        }
 
        public function getParamDescription() {
-               return array(
-                       'titles' => 'A list of titles',
+               $psModule = new ApiPageSet( $this );
+               return $psModule->getParamDescription() + array(
                        'forcelinkupdate' => 'Update the links tables',
                );
        }
 
+       public function getResultProperties() {
+               return array(
+                       ApiBase::PROP_LIST => true,
+                       '' => array(
+                               'ns' => array(
+                                       ApiBase::PROP_TYPE => 'namespace',
+                                       ApiBase::PROP_NULLABLE => true
+                               ),
+                               'title' => array(
+                                       ApiBase::PROP_TYPE => 'string',
+                                       ApiBase::PROP_NULLABLE => true
+                               ),
+                               'pageid' => array(
+                                       ApiBase::PROP_TYPE => 'integer',
+                                       ApiBase::PROP_NULLABLE => true
+                               ),
+                               'revid' => array(
+                                       ApiBase::PROP_TYPE => 'integer',
+                                       ApiBase::PROP_NULLABLE => true
+                               ),
+                               'invalid' => 'boolean',
+                               'missing' => 'boolean',
+                               'purged' => 'boolean',
+                               'linkupdate' => 'boolean'
+                       )
+               );
+       }
+
        public function getDescription() {
                return array( 'Purge the cache for the given titles.',
                        'Requires a POST request if the user is not logged in.'
@@ -127,14 +172,16 @@ class ApiPurge extends ApiBase {
        }
 
        public function getPossibleErrors() {
-               return array_merge( parent::getPossibleErrors(), array(
-                       array( 'cantpurge' ),
-               ) );
+               $psModule = new ApiPageSet( $this );
+               return array_merge(
+                       parent::getPossibleErrors(),
+                       $psModule->getPossibleErrors()
+               );
        }
 
        public function getExamples() {
                return array(
-                       'api.php?action=purge&titles=Main_Page|API'
+                       'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page',
                );
        }