API: (bug 15579) clshow considers all categories !hidden. Modified patch by Brad...
[lhc/web/wiklou.git] / includes / api / ApiQueryCategories.php
index 5e1f983..cbff86b 100644 (file)
@@ -54,6 +54,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
 
                $params = $this->extractRequestParams();
                $prop = $params['prop'];
+               $show = array_flip((array)$params['show']);
 
                $this->addFields(array (
                        'cl_from',
@@ -86,11 +87,31 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
                                $this->dieUsage("Invalid continue param. You should pass the " .
                                        "original value returned by the previous query", "_badcontinue");
                        $clfrom = intval($cont[0]);
-                       $clto = $this->getDb()->strencode($cont[1]);
+                       $clto = $this->getDB()->strencode($this->titleToKey($cont[1]));
                        $this->addWhere("cl_from > $clfrom OR ".
                                        "(cl_from = $clfrom AND ".
                                        "cl_to >= '$clto')");
                }
+               if(isset($show['hidden']) && isset($show['!hidden']))
+                       $this->dieUsage("Incorrect parameter - mutually exclusive values may not be supplied", 'show');
+               if(isset($show['hidden']) || isset($show['!hidden']))
+               {
+                       $this->addOption('STRAIGHT_JOIN');
+                       $this->addTables(array('page', 'page_props'));
+                       $this->addJoinConds(array(
+                               'page' => array('LEFT JOIN', array(
+                                       'page_namespace' => NS_CATEGORY,
+                                       'page_title = cl_to')),
+                               'page_props' => array('LEFT JOIN', array(
+                                       'pp_page=page_id',
+                                       'pp_propname' => 'hiddencat'))
+                       ));
+                       if(isset($show['hidden']))
+                               $this->addWhere(array('pp_propname IS NOT NULL'));
+                       else
+                               $this->addWhere(array('pp_propname IS NULL'));
+               }
+
                # Don't order by cl_from if it's constant in the WHERE clause
                if(count($this->getPageSet()->getGoodTitles()) == 1)
                        $this->addOption('ORDER BY', 'cl_to');
@@ -109,7 +130,8 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
                                if (++$count > $params['limit']) {
                                        // We've reached the one extra which shows that
                                        // there are additional pages to be had. Stop here...
-                                       $this->setContinueEnumParameter('continue', "{$row->cl_from}|{$row->cl_to}");
+                                       $this->setContinueEnumParameter('continue', $row->cl_from .
+                                                       '|' . $this->keyToTitle($row->cl_to));
                                        break;
                                }
                                if ($lastId != $row->cl_from) {
@@ -127,7 +149,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
                                if ($fld_sortkey)
                                        $vals['sortkey'] = $row->cl_sortkey;
                                if ($fld_timestamp)
-                                       $vals['timestamp'] = $row->cl_timestamp;
+                                       $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->cl_timestamp);
 
                                $data[] = $vals;
                        }
@@ -143,7 +165,8 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
                                if (++$count > $params['limit']) {
                                        // We've reached the one extra which shows that
                                        // there are additional pages to be had. Stop here...
-                                       $this->setContinueEnumParameter('continue', "{$row->il_from}|{$row->il_to}");
+                                       $this->setContinueEnumParameter('continue', $row->cl_from .
+                                                       '|' . $this->keyToTitle($row->cl_to));
                                        break;
                                }
 
@@ -164,6 +187,13 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
                                        'timestamp',
                                )
                        ),
+                       'show' => array(
+                               ApiBase :: PARAM_ISMULTI => true,
+                               ApiBase :: PARAM_TYPE => array(
+                                       'hidden',
+                                       '!hidden',
+                               )
+                       ),
                        'limit' => array(
                                ApiBase :: PARAM_DFLT => 10,
                                ApiBase :: PARAM_TYPE => 'limit',
@@ -178,7 +208,8 @@ class ApiQueryCategories extends ApiQueryGeneratorBase {
        public function getParamDescription() {
                return array (
                        'prop' => 'Which additional properties to get for each category.',
-                       'limit' => 'How many langlinks to return',
+                       'limit' => 'How many categories to return',
+                       'show' => 'Which kind of categories to show',
                        'continue' => 'When more results are available, use this to continue',
                );
        }