* (bug 13395) list=allcategories should use category table
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Thu, 20 Mar 2008 09:20:23 +0000 (09:20 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Thu, 20 Mar 2008 09:20:23 +0000 (09:20 +0000)
* cat_hidden doesn't work. why?

RELEASE-NOTES
includes/api/ApiQueryAllCategories.php

index 6e25693..21efa3c 100644 (file)
@@ -110,6 +110,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 13428) Fix regression in protection form layout HTML validity
 * (bug 9403) Sanitize newlines from search term input
 * (bug 13429) Separate date and time in message sp-newimages-showfrom
+* (bug 13137) Allow setting 'editprotected' right separately from 'protect',    
+  so groups may optionally edit protected pages without having 'protect' perms
 
 
 === API changes in 1.13 ===
@@ -133,8 +135,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 13390) One invalid title no longer kills an entire API query
 * (bug 13419) Fix gblredirect so it actually works
 * (bug 13418) Disable eiredirect because it's useless
-* (bug 13137) Allow setting 'editprotected' right separately from 'protect',    
-  so groups may optionally edit protected pages without having 'protect' perms
+* (bug 13395) list=allcategories should use category table
 
 === Languages updated in 1.13 ===
 
index 78ed363..51b7a85 100644 (file)
@@ -53,21 +53,27 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                $db = $this->getDB();
                $params = $this->extractRequestParams();
 
-               $this->addTables('categorylinks');
-               $this->addFields('cl_to');
+               $this->addTables('category');
+               $this->addFields('cat_title');
                
                if (!is_null($params['from']))
-                       $this->addWhere('cl_to>=' . $db->addQuotes(ApiQueryBase :: titleToKey($params['from'])));
+                       $this->addWhere('cat_title>=' . $db->addQuotes(ApiQueryBase :: titleToKey($params['from'])));
                if (isset ($params['prefix']))
-                       $this->addWhere("cl_to LIKE '" . $db->escapeLike(ApiQueryBase :: titleToKey($params['prefix'])) . "%'");
+                       $this->addWhere("cat_title LIKE '" . $db->escapeLike(ApiQueryBase :: titleToKey($params['prefix'])) . "%'");
 
                $this->addOption('LIMIT', $params['limit']+1);
-               $this->addOption('ORDER BY', 'cl_to' . ($params['dir'] == 'descending' ? ' DESC' : ''));
+               $this->addOption('ORDER BY', 'cat_title' . ($params['dir'] == 'descending' ? ' DESC' : ''));
                $this->addOption('DISTINCT');
+               
+               $prop = array_flip($params['prop']);
+               $this->addFieldsIf( array( 'cat_pages', 'cat_subcats', 'cat_files' ), isset($prop['size']) );
+               //$this->addFieldsIf( 'cat_hidden', isset($prop['hidden']) );
 
                $res = $this->select(__METHOD__);
 
                $pages = array();
+               $categories = array();
+               $result = $this->getResult();
                $count = 0;
                while ($row = $db->fetchObject($res)) {
                        if (++ $count > $params['limit']) {
@@ -78,19 +84,29 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                        }
                        
                        // Normalize titles
-                       $titleObj = Title::makeTitle(NS_CATEGORY, $row->cl_to);
+                       $titleObj = Title::makeTitle(NS_CATEGORY, $row->cat_title);
                        if(!is_null($resultPageSet))
                                $pages[] = $titleObj->getPrefixedText();
-                       else
-                               // Don't show "Category:" everywhere in non-generator mode
-                               $pages[] = $titleObj->getText();
+                       else {
+                               $item = array();
+                               $result->setContent( $item, $titleObj->getText() );
+                               if( isset( $prop['size'] ) ) {
+                                       $item['size'] = $row->cat_pages;
+                                       $item['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
+                                       $item['files'] = $row->cat_files;
+                                       $item['subcats'] = $row->cat_subcats;
+                               }
+                               //Isn't populated, so doesn't work
+                               //if( isset( $prop['hidden'] ) && $row->cat_hidden )
+                               //      $item['hidden'] = '';
+                               $categories[] = $item;
+                       }
                }
                $db->freeResult($res);
 
                if (is_null($resultPageSet)) {
-                       $result = $this->getResult();
-                       $result->setIndexedTagName($pages, 'c');
-                       $result->addValue('query', $this->getModuleName(), $pages);
+                       $result->setIndexedTagName($categories, 'c');
+                       $result->addValue('query', $this->getModuleName(), $categories);
                } else {
                        $resultPageSet->populateFromTitles($pages);
                }
@@ -113,7 +129,12 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                                ApiBase :: PARAM_MIN => 1,
                                ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
                                ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
-                       )
+                       ),
+                       'prop' => array (
+                               ApiBase :: PARAM_TYPE => array( 'size', /*'hidden'*/ ),
+                               ApiBase :: PARAM_DFLT => '',
+                               ApiBase :: PARAM_ISMULTI => true
+                       ),
                );
        }
 
@@ -122,7 +143,8 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
                        'from' => 'The category to start enumerating from.',
                        'prefix' => 'Search for all category titles that begin with this value.',
                        'dir' => 'Direction to sort in.',
-                       'limit' => 'How many categories to return.'
+                       'limit' => 'How many categories to return.',
+                       'prop' => 'Indicates if API should output category size',
                );
        }
 
@@ -132,6 +154,7 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase {
 
        protected function getExamples() {
                return array (
+                       'api.php?action=query&list=allcategories&acprop=size',
                        'api.php?action=query&generator=allcategories&gacprefix=List&prop=info',
                );
        }