00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if ( !defined( 'MEDIAWIKI' ) ) {
00027
00028 require_once ( 'ApiQueryBase.php' );
00029 }
00030
00036 class ApiQueryTags extends ApiQueryBase {
00037
00038 private $limit, $result;
00039 private $fld_displayname = false, $fld_description = false,
00040 $fld_hitcount = false;
00041
00042 public function __construct( $query, $moduleName ) {
00043 parent :: __construct( $query, $moduleName, 'tg' );
00044 }
00045
00046 public function execute() {
00047 $params = $this->extractRequestParams();
00048
00049 $prop = array_flip( $params['prop'] );
00050
00051 $this->fld_displayname = isset( $prop['displayname'] );
00052 $this->fld_description = isset( $prop['description'] );
00053 $this->fld_hitcount = isset( $prop['hitcount'] );
00054
00055 $this->limit = $params['limit'];
00056 $this->result = $this->getResult();
00057
00058 $pageSet = $this->getPageSet();
00059 $titles = $pageSet->getTitles();
00060 $data = array();
00061
00062 $this->addTables( 'change_tag' );
00063 $this->addFields( 'ct_tag' );
00064
00065 if ( $this->fld_hitcount )
00066 $this->addFields( 'count(*) AS hitcount' );
00067
00068 $this->addOption( 'LIMIT', $this->limit + 1 );
00069 $this->addOption( 'GROUP BY', 'ct_tag' );
00070 $this->addWhereRange( 'ct_tag', 'newer', $params['continue'], null );
00071
00072 $res = $this->select( __METHOD__ );
00073
00074 $ok = true;
00075
00076 while ( $row = $res->fetchObject() ) {
00077 if ( !$ok ) break;
00078 $ok = $this->doTag( $row->ct_tag, $row->hitcount );
00079 }
00080
00081
00082 foreach ( ChangeTags::listDefinedTags() as $tag ) {
00083 if ( !$ok ) break;
00084 $ok = $this->doTag( $tag, 0 );
00085 }
00086
00087 $this->result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'tag' );
00088 }
00089
00090 private function doTag( $tagName, $hitcount ) {
00091 static $count = 0;
00092 static $doneTags = array();
00093
00094 if ( in_array( $tagName, $doneTags ) ) {
00095 return true;
00096 }
00097
00098 if ( ++$count > $this->limit )
00099 {
00100 $this->setContinueEnumParameter( 'continue', $tagName );
00101 return false;
00102 }
00103
00104 $tag = array();
00105 $tag['name'] = $tagName;
00106
00107 if ( $this->fld_displayname )
00108 $tag['displayname'] = ChangeTags::tagDescription( $tagName );
00109
00110 if ( $this->fld_description )
00111 {
00112 $msg = wfMsg( "tag-$tagName-description" );
00113 $msg = wfEmptyMsg( "tag-$tagName-description", $msg ) ? '' : $msg;
00114 $tag['description'] = $msg;
00115 }
00116
00117 if ( $this->fld_hitcount )
00118 $tag['hitcount'] = $hitcount;
00119
00120 $doneTags[] = $tagName;
00121
00122 $fit = $this->result->addValue( array( 'query', $this->getModuleName() ), null, $tag );
00123 if ( !$fit )
00124 {
00125 $this->setContinueEnumParameter( 'continue', $tagName );
00126 return false;
00127 }
00128
00129 return true;
00130 }
00131
00132 public function getCacheMode( $params ) {
00133 return 'public';
00134 }
00135
00136 public function getAllowedParams() {
00137 return array (
00138 'continue' => array(
00139 ),
00140 'limit' => array(
00141 ApiBase :: PARAM_DFLT => 10,
00142 ApiBase :: PARAM_TYPE => 'limit',
00143 ApiBase :: PARAM_MIN => 1,
00144 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
00145 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
00146 ),
00147 'prop' => array(
00148 ApiBase :: PARAM_DFLT => 'name',
00149 ApiBase :: PARAM_TYPE => array(
00150 'name',
00151 'displayname',
00152 'description',
00153 'hitcount'
00154 ),
00155 ApiBase :: PARAM_ISMULTI => true
00156 )
00157 );
00158 }
00159
00160 public function getParamDescription() {
00161 return array (
00162 'continue' => 'When more results are available, use this to continue',
00163 'limit' => 'The maximum number of tags to list',
00164 'prop' => 'Which properties to get',
00165 );
00166 }
00167
00168 public function getDescription() {
00169 return 'List change tags.';
00170 }
00171
00172 protected function getExamples() {
00173 return array (
00174 'api.php?action=query&list=tags&tgprop=displayname|description|hitcount'
00175 );
00176 }
00177
00178 public function getVersion() {
00179 return __CLASS__ . ': $Id: ApiQueryTags.php 69932 2010-07-26 08:03:21Z tstarling $';
00180 }
00181 }