Merge "(bug 36568) Fixed "Illegal string offset 'LIMIT'" warnings in updater"
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
index 707a24c..e5db4d8 100644 (file)
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * A query module to show basic page information.
  *
@@ -76,7 +71,7 @@ class ApiQueryInfo extends ApiQueryBase {
         * Get an array mapping token names to their handler functions.
         * The prototype for a token function is func($pageid, $title)
         * it should return a token or false (permission denied)
-        * @return array(tokenname => function)
+        * @return array array(tokenname => function)
         */
        protected function getTokenFunctions() {
                // Don't call the hooks twice
@@ -119,7 +114,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        return $cachedEditToken;
                }
 
-               $cachedEditToken = $wgUser->editToken();
+               $cachedEditToken = $wgUser->getEditToken();
                return $cachedEditToken;
        }
 
@@ -134,7 +129,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        return $cachedDeleteToken;
                }
 
-               $cachedDeleteToken = $wgUser->editToken();
+               $cachedDeleteToken = $wgUser->getEditToken();
                return $cachedDeleteToken;
        }
 
@@ -149,7 +144,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        return $cachedProtectToken;
                }
 
-               $cachedProtectToken = $wgUser->editToken();
+               $cachedProtectToken = $wgUser->getEditToken();
                return $cachedProtectToken;
        }
 
@@ -164,7 +159,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        return $cachedMoveToken;
                }
 
-               $cachedMoveToken = $wgUser->editToken();
+               $cachedMoveToken = $wgUser->getEditToken();
                return $cachedMoveToken;
        }
 
@@ -179,7 +174,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        return $cachedBlockToken;
                }
 
-               $cachedBlockToken = $wgUser->editToken();
+               $cachedBlockToken = $wgUser->getEditToken();
                return $cachedBlockToken;
        }
 
@@ -199,7 +194,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        return $cachedEmailToken;
                }
 
-               $cachedEmailToken = $wgUser->editToken();
+               $cachedEmailToken = $wgUser->getEditToken();
                return $cachedEmailToken;
        }
 
@@ -214,7 +209,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        return $cachedImportToken;
                }
 
-               $cachedImportToken = $wgUser->editToken();
+               $cachedImportToken = $wgUser->getEditToken();
                return $cachedImportToken;
        }
 
@@ -229,10 +224,25 @@ class ApiQueryInfo extends ApiQueryBase {
                        return $cachedWatchToken;
                }
 
-               $cachedWatchToken = $wgUser->editToken( 'watch' );
+               $cachedWatchToken = $wgUser->getEditToken( 'watch' );
                return $cachedWatchToken;
        }
 
+       public static function getOptionsToken( $pageid, $title ) {
+               global $wgUser;
+               if ( !$wgUser->isLoggedIn() ) {
+                       return false;
+               }
+
+               static $cachedOptionsToken = null;
+               if ( !is_null( $cachedOptionsToken ) ) {
+                       return $cachedOptionsToken;
+               }
+
+               $cachedOptionsToken = $wgUser->getEditToken();
+               return $cachedOptionsToken;
+       }
+
        public function execute() {
                $this->params = $this->extractRequestParams();
                if ( !is_null( $this->params['prop'] ) ) {
@@ -380,10 +390,10 @@ class ApiQueryInfo extends ApiQueryBase {
                }
 
                if ( $this->fld_url ) {
-                       $pageInfo['fullurl'] = $title->getFullURL();
-                       $pageInfo['editurl'] = $title->getFullURL( 'action=edit' );
+                       $pageInfo['fullurl'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
+                       $pageInfo['editurl'] = wfExpandUrl( $title->getFullURL( 'action=edit' ), PROTO_CURRENT );
                }
-               if ( $this->fld_readable && $title->userCanRead() ) {
+               if ( $this->fld_readable && $title->userCan( 'read' ) ) {
                        $pageInfo['readable'] = '';
                }
 
@@ -399,8 +409,8 @@ class ApiQueryInfo extends ApiQueryBase {
                }
 
                if ( $this->fld_displaytitle ) {
-                       if ( isset( $this->displaytitles[$title->getArticleId()] ) ) {
-                               $pageInfo['displaytitle'] = $this->displaytitles[$title->getArticleId()];
+                       if ( isset( $this->displaytitles[$title->getArticleID()] ) ) {
+                               $pageInfo['displaytitle'] = $this->displaytitles[$title->getArticleID()];
                        } else {
                                $pageInfo['displaytitle'] = $title->getPrefixedText();
                        }
@@ -619,9 +629,9 @@ class ApiQueryInfo extends ApiQueryBase {
         * Get information about watched status and put it in $this->watched
         */
        private function getWatchedInfo() {
-               global $wgUser;
+               $user = $this->getUser();
 
-               if ( $wgUser->isAnon() || count( $this->everything ) == 0 ) {
+               if ( $user->isAnon() || count( $this->everything ) == 0 ) {
                        return;
                }
 
@@ -635,7 +645,7 @@ class ApiQueryInfo extends ApiQueryBase {
                $this->addFields( array( 'wl_title', 'wl_namespace' ) );
                $this->addWhere( array(
                        $lb->constructSet( 'wl', $db ),
-                       'wl_user' => $wgUser->getID()
+                       'wl_user' => $user->getID()
                ) );
 
                $res = $this->select( __METHOD__ );
@@ -721,13 +731,17 @@ class ApiQueryInfo extends ApiQueryBase {
                ) );
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'api.php?action=query&prop=info&titles=Main%20Page',
                        'api.php?action=query&prop=info&inprop=protection&titles=Main%20Page'
                );
        }
 
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';
+       }
+
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }