MediaWiki
master
|
00001 <?php 00033 class ApiQueryCategoryInfo extends ApiQueryBase { 00034 00035 public function __construct( $query, $moduleName ) { 00036 parent::__construct( $query, $moduleName, 'ci' ); 00037 } 00038 00039 public function execute() { 00040 $params = $this->extractRequestParams(); 00041 $alltitles = $this->getPageSet()->getAllTitlesByNamespace(); 00042 if ( empty( $alltitles[NS_CATEGORY] ) ) { 00043 return; 00044 } 00045 $categories = $alltitles[NS_CATEGORY]; 00046 00047 $titles = $this->getPageSet()->getGoodTitles() + 00048 $this->getPageSet()->getMissingTitles(); 00049 $cattitles = array(); 00050 foreach ( $categories as $c ) { 00051 $t = $titles[$c]; 00052 $cattitles[$c] = $t->getDBkey(); 00053 } 00054 00055 $this->addTables( array( 'category', 'page', 'page_props' ) ); 00056 $this->addJoinConds( array( 00057 'page' => array( 'LEFT JOIN', array( 00058 'page_namespace' => NS_CATEGORY, 00059 'page_title=cat_title' ) ), 00060 'page_props' => array( 'LEFT JOIN', array( 00061 'pp_page=page_id', 00062 'pp_propname' => 'hiddencat' ) ), 00063 ) ); 00064 00065 $this->addFields( array( 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files', 'cat_hidden' => 'pp_propname' ) ); 00066 $this->addWhere( array( 'cat_title' => $cattitles ) ); 00067 00068 if ( !is_null( $params['continue'] ) ) { 00069 $title = $this->getDB()->addQuotes( $params['continue'] ); 00070 $this->addWhere( "cat_title >= $title" ); 00071 } 00072 $this->addOption( 'ORDER BY', 'cat_title' ); 00073 00074 $res = $this->select( __METHOD__ ); 00075 00076 $catids = array_flip( $cattitles ); 00077 foreach ( $res as $row ) { 00078 $vals = array(); 00079 $vals['size'] = intval( $row->cat_pages ); 00080 $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files; 00081 $vals['files'] = intval( $row->cat_files ); 00082 $vals['subcats'] = intval( $row->cat_subcats ); 00083 if ( $row->cat_hidden ) { 00084 $vals['hidden'] = ''; 00085 } 00086 $fit = $this->addPageSubItems( $catids[$row->cat_title], $vals ); 00087 if ( !$fit ) { 00088 $this->setContinueEnumParameter( 'continue', $row->cat_title ); 00089 break; 00090 } 00091 } 00092 } 00093 00094 public function getCacheMode( $params ) { 00095 return 'public'; 00096 } 00097 00098 public function getAllowedParams() { 00099 return array( 00100 'continue' => null, 00101 ); 00102 } 00103 00104 public function getParamDescription() { 00105 return array( 00106 'continue' => 'When more results are available, use this to continue', 00107 ); 00108 } 00109 00110 public function getResultProperties() { 00111 return array( 00112 ApiBase::PROP_LIST => false, 00113 '' => array( 00114 'size' => array( 00115 ApiBase::PROP_TYPE => 'integer', 00116 ApiBase::PROP_NULLABLE => false 00117 ), 00118 'pages' => array( 00119 ApiBase::PROP_TYPE => 'integer', 00120 ApiBase::PROP_NULLABLE => false 00121 ), 00122 'files' => array( 00123 ApiBase::PROP_TYPE => 'integer', 00124 ApiBase::PROP_NULLABLE => false 00125 ), 00126 'subcats' => array( 00127 ApiBase::PROP_TYPE => 'integer', 00128 ApiBase::PROP_NULLABLE => false 00129 ), 00130 'hidden' => array( 00131 ApiBase::PROP_TYPE => 'boolean', 00132 ApiBase::PROP_NULLABLE => false 00133 ) 00134 ) 00135 ); 00136 } 00137 00138 public function getDescription() { 00139 return 'Returns information about the given categories'; 00140 } 00141 00142 public function getExamples() { 00143 return 'api.php?action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar'; 00144 } 00145 00146 public function getHelpUrls() { 00147 return 'https://www.mediawiki.org/wiki/API:Properties#categoryinfo_.2F_ci'; 00148 } 00149 00150 public function getVersion() { 00151 return __CLASS__ . ': $Id$'; 00152 } 00153 }