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 ApiQueryCategoryInfo extends ApiQueryBase {
00037
00038 public function __construct( $query, $moduleName ) {
00039 parent :: __construct( $query, $moduleName, 'ci' );
00040 }
00041
00042 public function execute() {
00043 $params = $this->extractRequestParams();
00044 $alltitles = $this->getPageSet()->getAllTitlesByNamespace();
00045 if ( empty( $alltitles[NS_CATEGORY] ) ) {
00046 return;
00047 }
00048 $categories = $alltitles[NS_CATEGORY];
00049
00050 $titles = $this->getPageSet()->getGoodTitles() +
00051 $this->getPageSet()->getMissingTitles();
00052 $cattitles = array();
00053 foreach ( $categories as $c )
00054 {
00055 $t = $titles[$c];
00056 $cattitles[$c] = $t->getDBkey();
00057 }
00058
00059 $this->addTables( array( 'category', 'page', 'page_props' ) );
00060 $this->addJoinConds( array(
00061 'page' => array( 'LEFT JOIN', array(
00062 'page_namespace' => NS_CATEGORY,
00063 'page_title=cat_title' ) ),
00064 'page_props' => array( 'LEFT JOIN', array(
00065 'pp_page=page_id',
00066 'pp_propname' => 'hiddencat' ) ),
00067 ) );
00068
00069 $this->addFields( array( 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files', 'pp_propname AS cat_hidden' ) );
00070 $this->addWhere( array( 'cat_title' => $cattitles ) );
00071
00072 if ( !is_null( $params['continue'] ) )
00073 {
00074 $title = $this->getDB()->addQuotes( $params['continue'] );
00075 $this->addWhere( "cat_title >= $title" );
00076 }
00077 $this->addOption( 'ORDER BY', 'cat_title' );
00078
00079 $db = $this->getDB();
00080 $res = $this->select( __METHOD__ );
00081
00082 $catids = array_flip( $cattitles );
00083 while ( $row = $db->fetchObject( $res ) )
00084 {
00085 $vals = array();
00086 $vals['size'] = intval( $row->cat_pages );
00087 $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
00088 $vals['files'] = intval( $row->cat_files );
00089 $vals['subcats'] = intval( $row->cat_subcats );
00090 if ( $row->cat_hidden )
00091 $vals['hidden'] = '';
00092 $fit = $this->addPageSubItems( $catids[$row->cat_title], $vals );
00093 if ( !$fit )
00094 {
00095 $this->setContinueEnumParameter( 'continue', $row->cat_title );
00096 break;
00097 }
00098 }
00099 $db->freeResult( $res );
00100 }
00101
00102 public function getCacheMode( $params ) {
00103 return 'public';
00104 }
00105
00106 public function getAllowedParams() {
00107 return array (
00108 'continue' => null,
00109 );
00110 }
00111
00112 public function getParamDescription() {
00113 return array (
00114 'continue' => 'When more results are available, use this to continue',
00115 );
00116 }
00117
00118 public function getDescription() {
00119 return 'Returns information about the given categories';
00120 }
00121
00122 protected function getExamples() {
00123 return "api.php?action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar";
00124 }
00125
00126 public function getVersion() {
00127 return __CLASS__ . ': $Id: ApiQueryCategoryInfo.php 69932 2010-07-26 08:03:21Z tstarling $';
00128 }
00129 }