]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/api/ApiPurge.php
MediaWiki 1.16.0
[autoinstallsdev/mediawiki.git] / includes / api / ApiPurge.php
index 27d5cac66f6d3b8bee6f9ada3c5c3dbc4bbbb00c..76d45404c628f851b80eba8634c78245b5aa441f 100644 (file)
@@ -23,8 +23,8 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
-if (!defined('MEDIAWIKI')) {
-       require_once ('ApiBase.php');
+if ( !defined( 'MEDIAWIKI' ) ) {
+       require_once ( 'ApiBase.php' );
 }
 
 /**
@@ -33,8 +33,8 @@ if (!defined('MEDIAWIKI')) {
  */
 class ApiPurge extends ApiBase {
 
-       public function __construct($main, $action) {
-               parent :: __construct($main, $action);
+       public function __construct( $main, $action ) {
+               parent :: __construct( $main, $action );
        }
 
        /**
@@ -43,35 +43,35 @@ class ApiPurge extends ApiBase {
        public function execute() {
                global $wgUser;
                $params = $this->extractRequestParams();
-               if(!$wgUser->isAllowed('purge'))
-                       $this->dieUsageMsg(array('cantpurge'));
-               if(!isset($params['titles']))
-                       $this->dieUsageMsg(array('missingparam', 'titles'));
+               if ( !$wgUser->isAllowed( 'purge' ) )
+                       $this->dieUsageMsg( array( 'cantpurge' ) );
+               if ( !isset( $params['titles'] ) )
+                       $this->dieUsageMsg( array( 'missingparam', 'titles' ) );
                $result = array();
-               foreach($params['titles'] as $t) {
+               foreach ( $params['titles'] as $t ) {
                        $r = array();
-                       $title = Title::newFromText($t);
-                       if(!$title instanceof Title)
+                       $title = Title::newFromText( $t );
+                       if ( !$title instanceof Title )
                        {
                                $r['title'] = $t;
                                $r['invalid'] = '';
                                $result[] = $r;
                                continue;
                        }
-                       ApiQueryBase::addTitleInfo($r, $title);
-                       if(!$title->exists())
+                       ApiQueryBase::addTitleInfo( $r, $title );
+                       if ( !$title->exists() )
                        {
                                $r['missing'] = '';
                                $result[] = $r;
                                continue;
                        }
-                       $article = new Article($title);
+                       $article = Mediawiki::articleFromTitle( $title );
                        $article->doPurge(); // Directly purge and skip the UI part of purge().
                        $r['purged'] = '';
                        $result[] = $r;
                }
-               $this->getResult()->setIndexedTagName($result, 'page');
-               $this->getResult()->addValue(null, $this->getModuleName(), $result);
+               $this->getResult()->setIndexedTagName( $result, 'page' );
+               $this->getResult()->addValue( null, $this->getModuleName(), $result );
        }
 
        public function mustBePosted() {
@@ -102,6 +102,13 @@ class ApiPurge extends ApiBase {
                        'Purge the cache for the given titles.'
                );
        }
+       
+    public function getPossibleErrors() {
+               return array_merge( parent::getPossibleErrors(), array(
+                       array( 'cantpurge' ),
+                       array( 'missingparam', 'titles' ),
+        ) );
+       }
 
        protected function getExamples() {
                return array(
@@ -110,6 +117,6 @@ class ApiPurge extends ApiBase {
        }
 
        public function getVersion() {
-               return __CLASS__ . ': $Id: ApiPurge.php 48091 2009-03-06 13:49:44Z catrope $';
+               return __CLASS__ . ': $Id: ApiPurge.php 69578 2010-07-20 02:46:20Z tstarling $';
        }
 }