(bug 23936) - Add "displaytitle" to query/info API
authorSam Reed <reedy@users.mediawiki.org>
Thu, 22 Jul 2010 08:48:34 +0000 (08:48 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Thu, 22 Jul 2010 08:48:34 +0000 (08:48 +0000)
Complete usage of accidental code from r69716

Move a $db = $this->getDB to after check in getTSIDs

RELEASE-NOTES
includes/api/ApiQueryInfo.php

index 516d3f5..eb82134 100644 (file)
@@ -282,6 +282,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 24296) Added converttitles parameter to convert titles to their 
   canonical language variant.
 * Fixed "link" parameter in image links with "thumb" parameter.
+* (bug 23936) - Add "displaytitle" to query/info API
 
 === Languages updated in 1.17 ===
 
index f75b54e..37557a4 100644 (file)
@@ -262,6 +262,10 @@ class ApiQueryInfo extends ApiQueryBase {
                if ( $this->fld_talkid || $this->fld_subjectid ) {
                        $this->getTSIDs();
                }
+               
+               if ( $this->fld_displaytitle ) {
+                       $this->getDisplayTitle();
+               }
 
                foreach ( $this->everything as $pageid => $title ) {
                        $pageInfo = $this->extractPageInfo( $pageid, $title );
@@ -357,9 +361,13 @@ class ApiQueryInfo extends ApiQueryBase {
                }
                
                if ( $this->fld_displaytitle ) {
-               
+                       if ( isset( $this->displaytitles[$title->getArticleId()] ) ) {
+                               $pageInfo['displaytitle'] = $this->displaytitles[$title->getArticleId()];
+                       } else {
+                               $pageInfo['displaytitle'] = $title;
+                       }
                }
-               
+
                return $pageInfo;
        }
 
@@ -512,7 +520,7 @@ class ApiQueryInfo extends ApiQueryBase {
         */
        private function getTSIDs() {
                $getTitles = $this->talkids = $this->subjectids = array();
-               $db = $this->getDB();
+
                foreach ( $this->everything as $t ) {
                        if ( MWNamespace::isTalk( $t->getNamespace() ) ) {
                                if ( $this->fld_subjectid ) {
@@ -525,6 +533,8 @@ class ApiQueryInfo extends ApiQueryBase {
                if ( !count( $getTitles ) ) {
                        return;
                }
+               
+               $db = $this->getDB();
 
                // Construct a custom WHERE clause that matches
                // all titles in $getTitles
@@ -544,6 +554,31 @@ class ApiQueryInfo extends ApiQueryBase {
                        }
                }
        }
+       
+       private function getDisplayTitle() {
+               $pageIds = $this->displaytitles = array();
+               
+               foreach ( $this->everything as $t ) {
+                       $pageIds = $t->getArticleID();
+               }
+       
+               if ( !count( $pageIds ) ) {
+                       return;
+               }
+               
+               $db = $this->getDB();
+
+               $this->resetQueryParams();
+               $this->addTables( 'page_props' );
+               $this->addFields( array( 'pp_page', 'pp_value' ) );
+               $this->addWhereFld( 'pp_page', $pageIds );
+               $this->addWhereFld( 'pp_propname', 'displaytitle' );
+               $res = $this->select( __METHOD__ );
+               
+               foreach ( $res as $row ) {
+                       $this->displaytitles[$row->pp_page] = $row->pp_value;
+               }
+       }
 
        /**
         * Get information about watched status and put it in $this->watched
@@ -589,7 +624,8 @@ class ApiQueryInfo extends ApiQueryBase {
                                        'subjectid',
                                        'url',
                                        'readable',
-                                       'preload'
+                                       'preload',
+                                       'displaytitle',
                                ) ),
                        'token' => array(
                                ApiBase::PARAM_DFLT => null,