From d01bd3b7992e80b109364ec232c60c10b7077587 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Mon, 4 May 2009 15:10:42 +0000 Subject: [PATCH] API: (bug 18518) Add clprop=hidden to prop=categories. Also use array_flip($params['prop']) to simplify code --- RELEASE-NOTES | 1 + includes/api/ApiQueryCategories.php | 33 ++++++++++------------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 19ced84c12..a1ddd465cb 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -133,6 +133,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 18617) Add xml:space="preserve" attribute to relevant tags in XML output * Added PHP and database version to meta=siteinfo output * (bug 18533) Add readonly message to meta=siteinfo output +* (bug 18518) Add clprop=hidden to prop=categories === Languages updated in 1.16 === diff --git a/includes/api/ApiQueryCategories.php b/includes/api/ApiQueryCategories.php index d8bd1cdc63..90056d2dfa 100644 --- a/includes/api/ApiQueryCategories.php +++ b/includes/api/ApiQueryCategories.php @@ -53,7 +53,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { return; // nothing to do $params = $this->extractRequestParams(); - $prop = $params['prop']; + $prop = array_flip((array)$params['prop']); $show = array_flip((array)$params['show']); $this->addFields(array ( @@ -61,23 +61,8 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { 'cl_to' )); - $fld_sortkey = $fld_timestamp = false; - if (!is_null($prop)) { - foreach($prop as $p) { - switch ($p) { - case 'sortkey': - $this->addFields('cl_sortkey'); - $fld_sortkey = true; - break; - case 'timestamp': - $this->addFields('cl_timestamp'); - $fld_timestamp = true; - break; - default : - ApiBase :: dieDebug(__METHOD__, "Unknown prop=$p"); - } - } - } + $this->addFieldsIf('cl_sortkey', isset($prop['sortkey'])); + $this->addFieldsIf('cl_timestamp', isset($prop['timestamp'])); $this->addTables('categorylinks'); $this->addWhereFld('cl_from', array_keys($this->getPageSet()->getGoodTitles())); @@ -107,10 +92,11 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { } 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'])) + if(isset($show['hidden']) || isset($show['!hidden']) || isset($prop['hidden'])) { $this->addOption('STRAIGHT_JOIN'); $this->addTables(array('page', 'page_props')); + $this->addFieldsIf('pp_propname', isset($prop['hidden'])); $this->addJoinConds(array( 'page' => array('LEFT JOIN', array( 'page_namespace' => NS_CATEGORY, @@ -121,7 +107,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { )); if(isset($show['hidden'])) $this->addWhere(array('pp_propname IS NOT NULL')); - else + else if(isset($show['!hidden'])) $this->addWhere(array('pp_propname IS NULL')); } @@ -150,10 +136,12 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { $title = Title :: makeTitle(NS_CATEGORY, $row->cl_to); $vals = array(); ApiQueryBase :: addTitleInfo($vals, $title); - if ($fld_sortkey) + if (isset($prop['sortkey'])) $vals['sortkey'] = $row->cl_sortkey; - if ($fld_timestamp) + if (isset($prop['timestamp'])) $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->cl_timestamp); + if (isset($prop['hidden']) && !is_null($row->pp_propname)) + $vals['hidden'] = ''; $fit = $this->addPageSubItem($row->cl_from, $vals); if(!$fit) @@ -190,6 +178,7 @@ class ApiQueryCategories extends ApiQueryGeneratorBase { ApiBase :: PARAM_TYPE => array ( 'sortkey', 'timestamp', + 'hidden', ) ), 'show' => array( -- 2.20.1