Merge "Displaying search results for multiple wikis"
[lhc/web/wiklou.git] / includes / api / ApiPurge.php
index 7667b23..34f9b6c 100644 (file)
@@ -38,7 +38,8 @@ class ApiPurge extends ApiBase {
        public function execute() {
                $params = $this->extractRequestParams();
 
-               $this->getResult()->beginContinuation( $params['continue'], array(), array() );
+               $continuationManager = new ApiContinuationManager( $this, array(), array() );
+               $this->setContinuationManager( $continuationManager );
 
                $forceLinkUpdate = $params['forcelinkupdate'];
                $forceRecursiveLinkUpdate = $params['forcerecursivelinkupdate'];
@@ -46,16 +47,22 @@ class ApiPurge extends ApiBase {
                $pageSet->execute();
 
                $result = $pageSet->getInvalidTitlesAndRevisions();
+               $user = $this->getUser();
 
                foreach ( $pageSet->getGoodTitles() as $title ) {
                        $r = array();
                        ApiQueryBase::addTitleInfo( $r, $title );
                        $page = WikiPage::factory( $title );
-                       $page->doPurge(); // Directly purge and skip the UI part of purge().
-                       $r['purged'] = '';
+                       if ( !$user->pingLimiter( 'purge' ) ) {
+                               $page->doPurge(); // Directly purge and skip the UI part of purge().
+                               $r['purged'] = true;
+                       } else {
+                               $error = $this->parseMsg( array( 'actionthrottledtext' ) );
+                               $this->setWarning( $error['info'] );
+                       }
 
                        if ( $forceLinkUpdate || $forceRecursiveLinkUpdate ) {
-                               if ( !$this->getUser()->pingLimiter( 'linkpurge' ) ) {
+                               if ( !$user->pingLimiter( 'linkpurge' ) ) {
                                        $popts = $page->makeParserOptions( 'canonical' );
 
                                        # Parse content; note that HTML generation is only needed if we want to cache the result.
@@ -73,7 +80,7 @@ class ApiPurge extends ApiBase {
                                                $title, null, $forceRecursiveLinkUpdate, $p_result );
                                        DataUpdate::runUpdates( $updates );
 
-                                       $r['linkupdate'] = '';
+                                       $r['linkupdate'] = true;
 
                                        if ( $enableParserCache ) {
                                                $pcache = ParserCache::singleton();
@@ -89,7 +96,7 @@ class ApiPurge extends ApiBase {
                        $result[] = $r;
                }
                $apiResult = $this->getResult();
-               $apiResult->setIndexedTagName( $result, 'page' );
+               ApiResult::setIndexedTagName( $result, 'page' );
                $apiResult->addValue( null, $this->getModuleName(), $result );
 
                $values = $pageSet->getNormalizedTitlesAsResult( $apiResult );
@@ -105,7 +112,8 @@ class ApiPurge extends ApiBase {
                        $apiResult->addValue( null, 'redirects', $values );
                }
 
-               $apiResult->endContinuation();
+               $this->setContinuationManager( null );
+               $continuationManager->setContinuationIntoResult( $apiResult );
        }
 
        /**
@@ -133,7 +141,9 @@ class ApiPurge extends ApiBase {
                $result = array(
                        'forcelinkupdate' => false,
                        'forcerecursivelinkupdate' => false,
-                       'continue' => '',
+                       'continue' => array(
+                               ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
+                       ),
                );
                if ( $flags ) {
                        $result += $this->getPageSet()->getFinalParams( $flags );
@@ -142,25 +152,12 @@ class ApiPurge extends ApiBase {
                return $result;
        }
 
-       public function getParamDescription() {
-               return $this->getPageSet()->getFinalParamDescription()
-                       + array(
-                               'forcelinkupdate' => 'Update the links tables',
-                               'forcerecursivelinkupdate' => 'Update the links table, and update ' .
-                                       'the links tables for any page that uses this page as a template',
-                               'continue' => 'When more results are available, use this to continue',
-                       );
-       }
-
-       public function getDescription() {
-               return array( 'Purge the cache for the given titles.',
-                       'Requires a POST request if the user is not logged in.'
-               );
-       }
-
-       public function getExamples() {
+       protected function getExamplesMessages() {
                return array(
-                       'api.php?action=purge&titles=Main_Page|API' => 'Purge the "Main Page" and the "API" page',
+                       'action=purge&titles=Main_Page|API'
+                               => 'apihelp-purge-example-simple',
+                       'action=purge&generator=allpages&gapnamespace=0&gaplimit=10'
+                               => 'apihelp-purge-example-generator',
                );
        }