Move optionstoken from meta=userinfo to action=tokens.
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
index fe98bb3..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
@@ -233,6 +228,21 @@ class ApiQueryInfo extends ApiQueryBase {
                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'] ) ) {
@@ -383,7 +393,7 @@ class ApiQueryInfo extends ApiQueryBase {
                        $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();
                        }
@@ -729,7 +739,7 @@ class ApiQueryInfo extends ApiQueryBase {
        }
 
        public function getHelpUrls() {
-               return 'http://www.mediawiki.org/wiki/API:Properties#info_.2F_in';
+               return 'https://www.mediawiki.org/wiki/API:Properties#info_.2F_in';
        }
 
        public function getVersion() {