Fix prop=userid in list=protectedtitles
[lhc/web/wiklou.git] / includes / api / ApiQueryTags.php
index 51a4948..f97c1b2 100644 (file)
@@ -1,9 +1,8 @@
 <?php
-
 /**
- * Created on Jul 9, 2009
  *
- * API for MediaWiki 1.8+
+ *
+ * Created on Jul 9, 2009
  *
  * Copyright © 2009
  *
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * Query module to enumerate change tags.
  *
@@ -35,7 +31,12 @@ if ( !defined( 'MEDIAWIKI' ) ) {
  */
 class ApiQueryTags extends ApiQueryBase {
 
-       private $limit, $result;
+       /**
+        * @var ApiResult
+        */
+       private $result;
+
+       private $limit;
        private $fld_displayname = false, $fld_description = false,
                        $fld_hitcount = false;
 
@@ -55,16 +56,10 @@ class ApiQueryTags extends ApiQueryBase {
                $this->limit = $params['limit'];
                $this->result = $this->getResult();
 
-               $pageSet = $this->getPageSet();
-               $titles = $pageSet->getTitles();
-               $data = array();
-
                $this->addTables( 'change_tag' );
                $this->addFields( 'ct_tag' );
 
-               if ( $this->fld_hitcount ) {
-                       $this->addFields( 'count(*) AS hitcount' );
-               }
+               $this->addFieldsIf( array( 'hitcount' => 'COUNT(*)' ), $this->fld_hitcount );
 
                $this->addOption( 'LIMIT', $this->limit + 1 );
                $this->addOption( 'GROUP BY', 'ct_tag' );
@@ -74,11 +69,11 @@ class ApiQueryTags extends ApiQueryBase {
 
                $ok = true;
 
-               while ( $row = $res->fetchObject() ) {
+               foreach ( $res as $row ) {
                        if ( !$ok ) {
                                break;
                        }
-                       $ok = $this->doTag( $row->ct_tag, $row->hitcount );
+                       $ok = $this->doTag( $row->ct_tag, $this->fld_hitcount ? $row->hitcount : 0 );
                }
 
                // include tags with no hits yet
@@ -113,9 +108,8 @@ class ApiQueryTags extends ApiQueryBase {
                }
 
                if ( $this->fld_description ) {
-                       $msg = wfMsg( "tag-$tagName-description" );
-                       $msg = wfEmptyMsg( "tag-$tagName-description", $msg ) ? '' : $msg;
-                       $tag['description'] = $msg;
+                       $msg = wfMessage( "tag-$tagName-description" );
+                       $tag['description'] = $msg->exists() ? $msg->text() : '';
                }
 
                if ( $this->fld_hitcount ) {
@@ -133,6 +127,10 @@ class ApiQueryTags extends ApiQueryBase {
                return true;
        }
 
+       public function getCacheMode( $params ) {
+               return 'public';
+       }
+
        public function getAllowedParams() {
                return array(
                        'continue' => array(
@@ -161,7 +159,30 @@ class ApiQueryTags extends ApiQueryBase {
                return array(
                        'continue' => 'When more results are available, use this to continue',
                        'limit' => 'The maximum number of tags to list',
-                       'prop' => 'Which properties to get',
+                       'prop' => array(
+                               'Which properties to get',
+                               ' name         - Adds name of tag',
+                               ' displayname  - Adds system messsage for the tag',
+                               ' description  - Adds description of the tag',
+                               ' hitcount     - Adds the amount of revisions that have this tag',
+                       ),
+               );
+       }
+
+       public function getResultProperties() {
+               return array(
+                       '' => array(
+                               'name' => 'string'
+                       ),
+                       'displayname' => array(
+                               'displayname' => 'string'
+                       ),
+                       'description' => array(
+                               'description' => 'string'
+                       ),
+                       'hitcount' => array(
+                               'hitcount' => 'integer'
+                       )
                );
        }
 
@@ -169,7 +190,7 @@ class ApiQueryTags extends ApiQueryBase {
                return 'List change tags';
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'api.php?action=query&list=tags&tgprop=displayname|description|hitcount'
                );