API: Have action=parse indicate hidden categories
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 2 Oct 2013 18:58:54 +0000 (14:58 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Mon, 4 Nov 2013 17:20:56 +0000 (12:20 -0500)
Also whether the category page exists, since we can get that basically
for free along with the 'hidden' flag.

Bug: 54884
Change-Id: I5c435f04b1b3b65c4153dea1767d48b49ed427c2

RELEASE-NOTES-1.23
includes/api/ApiParse.php

index c9b56b9..804ea43 100644 (file)
@@ -26,6 +26,8 @@ production.
   acting as if the latest revision was being viewed.
 
 === API changes in 1.23 ===
+* (bug 54884) action=parse&prop=categories now indicates hidden and missing
+  categories.
 
 === Languages updated in 1.23===
 
index a369994..301affb 100644 (file)
@@ -461,12 +461,41 @@ class ApiParse extends ApiBase {
 
        private function formatCategoryLinks( $links ) {
                $result = array();
+
+               if ( !$links ) {
+                       return $result;
+               }
+
+               // Fetch hiddencat property
+               $lb = new LinkBatch;
+               $lb->setArray( array( NS_CATEGORY => $links ) );
+               $db = $this->getDB();
+               $res = $db->select( array( 'page', 'page_props' ),
+                       array( 'page_title', 'pp_propname' ),
+                       $lb->constructSet( 'page', $db ),
+                       __METHOD__,
+                       array(),
+                       array( 'page_props' => array(
+                               'LEFT JOIN', array( 'pp_propname' => 'hiddencat', 'pp_page = page_id' )
+                       ) )
+               );
+               $hiddencats = array();
+               foreach ( $res as $row ) {
+                       $hiddencats[$row->page_title] = isset( $row->pp_propname );
+               }
+
                foreach ( $links as $link => $sortkey ) {
                        $entry = array();
                        $entry['sortkey'] = $sortkey;
                        ApiResult::setContent( $entry, $link );
+                       if ( !isset( $hiddencats[$link] ) ) {
+                               $entry['missing'] = '';
+                       } elseif ( $hiddencats[$link] ) {
+                               $entry['hidden'] = '';
+                       }
                        $result[] = $entry;
                }
+
                return $result;
        }