Big blitz on unused variables (a lot of $db = $this->getDb() )
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
index d86aeb4..896e200 100644 (file)
@@ -19,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  */
 
@@ -38,7 +38,7 @@ class ApiQueryInfo extends ApiQueryBase {
        private $fld_protection = false, $fld_talkid = false,
                $fld_subjectid = false, $fld_url = false,
                $fld_readable = false, $fld_watched = false,
-               $fld_preload = false;
+               $fld_preload = false, $fld_displaytitle = false;
 
        public function __construct( $query, $moduleName ) {
                parent::__construct( $query, $moduleName, 'in' );
@@ -210,6 +210,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        $this->fld_url = isset( $prop['url'] );
                        $this->fld_readable = isset( $prop['readable'] );
                        $this->fld_preload = isset( $prop['preload'] );
+                       $this->fld_displaytitle = isset( $prop['displaytitle'] );
                }
 
                $pageSet = $this->getPageSet();
@@ -246,13 +247,13 @@ class ApiQueryInfo extends ApiQueryBase {
                $this->pageLatest = $pageSet->getCustomField( 'page_latest' );
                $this->pageLength = $pageSet->getCustomField( 'page_len' );
 
-               $db = $this->getDB();
                // Get protection info if requested
                if ( $this->fld_protection ) {
                        $this->getProtectionInfo();
                }
 
                if ( $this->fld_watched ) {
+                       $this->getMain()->setVaryCookie();
                        $this->getWatchedInfo();
                }
 
@@ -260,6 +261,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 );
@@ -289,6 +294,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        $pageInfo['lastrevid'] = intval( $this->pageLatest[$pageid] );
                        $pageInfo['counter'] = intval( $this->pageCounter[$pageid] );
                        $pageInfo['length'] = intval( $this->pageLength[$pageid] );
+
                        if ( $this->pageIsRedir[$pageid] ) {
                                $pageInfo['redirect'] = '';
                        }
@@ -298,6 +304,9 @@ class ApiQueryInfo extends ApiQueryBase {
                }
 
                if ( !is_null( $this->params['token'] ) ) {
+                       // Don't cache tokens
+                       $this->getMain()->setCachePrivate();
+                       
                        $tokenFunctions = $this->getTokenFunctions();
                        $pageInfo['starttimestamp'] = wfTimestamp( TS_ISO_8601, time() );
                        foreach ( $this->params['token'] as $t ) {
@@ -343,11 +352,21 @@ class ApiQueryInfo extends ApiQueryBase {
                        if ( $title->exists() ) {
                                $pageInfo['preload'] = '';
                        } else {
+                               $text = null;
                                wfRunHooks( 'EditFormPreloadText', array( &$text, &$title ) );
 
                                $pageInfo['preload'] = $text;
                        }
                }
+               
+               if ( $this->fld_displaytitle ) {
+                       if ( isset( $this->displaytitles[$title->getArticleId()] ) ) {
+                               $pageInfo['displaytitle'] = $this->displaytitles[$title->getArticleId()];
+                       } else {
+                               $pageInfo['displaytitle'] = $title->getPrefixedText();
+                       }
+               }
+
                return $pageInfo;
        }
 
@@ -500,7 +519,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 ) {
@@ -513,6 +532,8 @@ class ApiQueryInfo extends ApiQueryBase {
                if ( !count( $getTitles ) ) {
                        return;
                }
+               
+               $db = $this->getDB();
 
                // Construct a custom WHERE clause that matches
                // all titles in $getTitles
@@ -532,9 +553,30 @@ class ApiQueryInfo extends ApiQueryBase {
                        }
                }
        }
+       
+       private function getDisplayTitle() {
+               $this->displaytitles = array();
+               
+               $pageIds = array_keys( $this->titles );
+       
+               if ( !count( $pageIds ) ) {
+                       return;
+               }
+
+               $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 $watched
+        * Get information about watched status and put it in $this->watched
         */
        private function getWatchedInfo() {
                global $wgUser;
@@ -577,7 +619,8 @@ class ApiQueryInfo extends ApiQueryBase {
                                        'subjectid',
                                        'url',
                                        'readable',
-                                       'preload'
+                                       'preload',
+                                       'displaytitle',
                                ) ),
                        'token' => array(
                                ApiBase::PARAM_DFLT => null,
@@ -598,7 +641,8 @@ class ApiQueryInfo extends ApiQueryBase {
                                ' subjectid    - The page ID of the parent page for each talk page',
                                ' url          - Gives a full URL to the page, and also an edit URL',
                                ' readable     - Whether the user can read this page',
-                               ' preload      - Gives the text returned by EditFormPreloadText'
+                               ' preload      - Gives the text returned by EditFormPreloadText',
+                               ' displaytitle - Gives the way the page title is actually displayed',
                        ),
                        'token' => 'Request a token to perform a data-modifying action on a page',
                        'continue' => 'When more results are available, use this to continue',