[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/api/ -> ApiQueryCategoryInfo.php (source)

   1  <?php
   2  /**
   3   *
   4   *
   5   * Created on May 13, 2007
   6   *
   7   * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
   8   *
   9   * This program is free software; you can redistribute it and/or modify
  10   * it under the terms of the GNU General Public License as published by
  11   * the Free Software Foundation; either version 2 of the License, or
  12   * (at your option) any later version.
  13   *
  14   * This program is distributed in the hope that it will be useful,
  15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17   * GNU General Public License for more details.
  18   *
  19   * You should have received a copy of the GNU General Public License along
  20   * with this program; if not, write to the Free Software Foundation, Inc.,
  21   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22   * http://www.gnu.org/copyleft/gpl.html
  23   *
  24   * @file
  25   */
  26  
  27  /**
  28   * This query adds the "<categories>" subelement to all pages with the list of
  29   * categories the page is in.
  30   *
  31   * @ingroup API
  32   */
  33  class ApiQueryCategoryInfo extends ApiQueryBase {
  34  
  35  	public function __construct( ApiQuery $query, $moduleName ) {
  36          parent::__construct( $query, $moduleName, 'ci' );
  37      }
  38  
  39  	public function execute() {
  40          $params = $this->extractRequestParams();
  41          $alltitles = $this->getPageSet()->getAllTitlesByNamespace();
  42          if ( empty( $alltitles[NS_CATEGORY] ) ) {
  43              return;
  44          }
  45          $categories = $alltitles[NS_CATEGORY];
  46  
  47          $titles = $this->getPageSet()->getGoodTitles() +
  48              $this->getPageSet()->getMissingTitles();
  49          $cattitles = array();
  50          foreach ( $categories as $c ) {
  51              /** @var $t Title */
  52              $t = $titles[$c];
  53              $cattitles[$c] = $t->getDBkey();
  54          }
  55  
  56          $this->addTables( array( 'category', 'page', 'page_props' ) );
  57          $this->addJoinConds( array(
  58              'page' => array( 'LEFT JOIN', array(
  59                  'page_namespace' => NS_CATEGORY,
  60                  'page_title=cat_title' ) ),
  61              'page_props' => array( 'LEFT JOIN', array(
  62                  'pp_page=page_id',
  63                  'pp_propname' => 'hiddencat' ) ),
  64          ) );
  65  
  66          $this->addFields( array(
  67              'cat_title',
  68              'cat_pages',
  69              'cat_subcats',
  70              'cat_files',
  71              'cat_hidden' => 'pp_propname'
  72          ) );
  73          $this->addWhere( array( 'cat_title' => $cattitles ) );
  74  
  75          if ( !is_null( $params['continue'] ) ) {
  76              $title = $this->getDB()->addQuotes( $params['continue'] );
  77              $this->addWhere( "cat_title >= $title" );
  78          }
  79          $this->addOption( 'ORDER BY', 'cat_title' );
  80  
  81          $res = $this->select( __METHOD__ );
  82  
  83          $catids = array_flip( $cattitles );
  84          foreach ( $res as $row ) {
  85              $vals = array();
  86              $vals['size'] = intval( $row->cat_pages );
  87              $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
  88              $vals['files'] = intval( $row->cat_files );
  89              $vals['subcats'] = intval( $row->cat_subcats );
  90              if ( $row->cat_hidden ) {
  91                  $vals['hidden'] = '';
  92              }
  93              $fit = $this->addPageSubItems( $catids[$row->cat_title], $vals );
  94              if ( !$fit ) {
  95                  $this->setContinueEnumParameter( 'continue', $row->cat_title );
  96                  break;
  97              }
  98          }
  99      }
 100  
 101  	public function getCacheMode( $params ) {
 102          return 'public';
 103      }
 104  
 105  	public function getAllowedParams() {
 106          return array(
 107              'continue' => null,
 108          );
 109      }
 110  
 111  	public function getParamDescription() {
 112          return array(
 113              'continue' => 'When more results are available, use this to continue',
 114          );
 115      }
 116  
 117  	public function getDescription() {
 118          return 'Returns information about the given categories.';
 119      }
 120  
 121  	public function getExamples() {
 122          return 'api.php?action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar';
 123      }
 124  
 125  	public function getHelpUrls() {
 126          return 'https://www.mediawiki.org/wiki/API:Properties#categoryinfo_.2F_ci';
 127      }
 128  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1