]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/api/ApiQueryTags.php
MediaWiki 1.17.4
[autoinstallsdev/mediawiki.git] / includes / api / ApiQueryTags.php
index a5d152bc6a4313dd4c5a26f8ca1b101f0badd1c2..eec15fbc13a8543b71e43edf561995627b9a776c 100644 (file)
@@ -1,11 +1,10 @@
 <?php
-
-/*
- * Created on Jul 9, 2009
- *
+/**
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2009
+ * Created on Jul 9, 2009
+ *
+ * Copyright © 2009
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 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' );
+       require_once( 'ApiQueryBase.php' );
 }
 
 /**
@@ -34,148 +35,154 @@ if ( !defined( 'MEDIAWIKI' ) ) {
  * @ingroup API
  */
 class ApiQueryTags extends ApiQueryBase {
-       
+
        private $limit, $result;
        private $fld_displayname = false, $fld_description = false,
                        $fld_hitcount = false;
-       
+
        public function __construct( $query, $moduleName ) {
-               parent :: __construct( $query, $moduleName, 'tg' );
+               parent::__construct( $query, $moduleName, 'tg' );
        }
 
        public function execute() {
                $params = $this->extractRequestParams();
-               
+
                $prop = array_flip( $params['prop'] );
-               
+
                $this->fld_displayname = isset( $prop['displayname'] );
                $this->fld_description = isset( $prop['description'] );
                $this->fld_hitcount = isset( $prop['hitcount'] );
-               
+
                $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 )
+
+               if ( $this->fld_hitcount ) {
                        $this->addFields( 'count(*) AS hitcount' );
-               
+               }
+
                $this->addOption( 'LIMIT', $this->limit + 1 );
                $this->addOption( 'GROUP BY', 'ct_tag' );
                $this->addWhereRange( 'ct_tag', 'newer', $params['continue'], null );
-               
+
                $res = $this->select( __METHOD__ );
-               
+
                $ok = true;
-               
-               while ( $row = $res->fetchObject() ) {
-                       if ( !$ok ) break;
+
+               foreach ( $res as $row ) {
+                       if ( !$ok ) {
+                               break;
+                       }
                        $ok = $this->doTag( $row->ct_tag, $row->hitcount );
                }
-               
+
                // include tags with no hits yet
                foreach ( ChangeTags::listDefinedTags() as $tag ) {
-                       if ( !$ok ) break;
+                       if ( !$ok ) {
+                               break;
+                       }
                        $ok = $this->doTag( $tag, 0 );
                }
-                       
+
                $this->result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'tag' );
        }
-       
+
        private function doTag( $tagName, $hitcount ) {
                static $count = 0;
                static $doneTags = array();
-               
+
                if ( in_array( $tagName, $doneTags ) ) {
                        return true;
                }
-               
-               if ( ++$count > $this->limit )
-               {
+
+               if ( ++$count > $this->limit ) {
                        $this->setContinueEnumParameter( 'continue', $tagName );
                        return false;
                }
-               
+
                $tag = array();
                $tag['name'] = $tagName;
-               
-               if ( $this->fld_displayname )
+
+               if ( $this->fld_displayname ) {
                        $tag['displayname'] = ChangeTags::tagDescription( $tagName );
-               
-               if ( $this->fld_description )
-               {
+               }
+
+               if ( $this->fld_description ) {
                        $msg = wfMsg( "tag-$tagName-description" );
                        $msg = wfEmptyMsg( "tag-$tagName-description", $msg ) ? '' : $msg;
                        $tag['description'] = $msg;
                }
-                       
-               if ( $this->fld_hitcount )
+
+               if ( $this->fld_hitcount ) {
                        $tag['hitcount'] = $hitcount;
-               
+               }
+
                $doneTags[] = $tagName;
-               
+
                $fit = $this->result->addValue( array( 'query', $this->getModuleName() ), null, $tag );
-               if ( !$fit )
-               {
+               if ( !$fit ) {
                        $this->setContinueEnumParameter( 'continue', $tagName );
                        return false;
                }
-                       
+
                return true;
        }
-       
+
        public function getCacheMode( $params ) {
                return 'public';
        }
 
        public function getAllowedParams() {
-               return array (
+               return array(
                        'continue' => array(
                        ),
                        'limit' => array(
-                               ApiBase :: PARAM_DFLT => 10,
-                               ApiBase :: PARAM_TYPE => 'limit',
-                               ApiBase :: PARAM_MIN => 1,
-                               ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
-                               ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+                               ApiBase::PARAM_DFLT => 10,
+                               ApiBase::PARAM_TYPE => 'limit',
+                               ApiBase::PARAM_MIN => 1,
+                               ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
+                               ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
                        ),
                        'prop' => array(
-                               ApiBase :: PARAM_DFLT => 'name',
-                               ApiBase :: PARAM_TYPE => array(
-                                               'name',
-                                               'displayname',
-                                               'description',
-                                               'hitcount'
-                                       ),
-                               ApiBase :: PARAM_ISMULTI => true
+                               ApiBase::PARAM_DFLT => 'name',
+                               ApiBase::PARAM_TYPE => array(
+                                       'name',
+                                       'displayname',
+                                       'description',
+                                       'hitcount'
+                               ),
+                               ApiBase::PARAM_ISMULTI => true
                        )
                );
        }
 
        public function getParamDescription() {
-               return array (
+               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 getDescription() {
-               return 'List change tags.';
+               return 'List change tags';
        }
 
        protected function getExamples() {
-               return array (
+               return array(
                        'api.php?action=query&list=tags&tgprop=displayname|description|hitcount'
                );
        }
 
        public function getVersion() {
-               return __CLASS__ . ': $Id: ApiQueryTags.php 69932 2010-07-26 08:03:21Z tstarling $';
+               return __CLASS__ . ': $Id$';
        }
 }