(bug 15535) prop=info&inprop=protection doesn't list pre-1.10 protections if the...
[lhc/web/wiklou.git] / includes / api / ApiQueryInfo.php
index 8fea583..a8cc0c6 100644 (file)
@@ -58,13 +58,18 @@ class ApiQueryInfo extends ApiQueryBase {
                if(isset($this->tokenFunctions))
                        return $this->tokenFunctions;
 
+               // If we're in JSON callback mode, no tokens can be obtained
+               if(!is_null($this->getMain()->getRequest()->getVal('callback')))
+                       return array();
+
                $this->tokenFunctions = array(
-                       'edit' => 'ApiQueryInfo::getEditToken',
-                       'delete' => 'ApiQueryInfo::getDeleteToken',
-                       'protect' => 'ApiQueryInfo::getProtectToken',
-                       'move' => 'ApiQueryInfo::getMoveToken',
-                       'block' => 'ApiQueryInfo::getBlockToken',
-                       'unblock' => 'ApiQueryInfo::getUnblockToken'
+                       'edit' => array( 'ApiQueryInfo', 'getEditToken' ),
+                       'delete' => array( 'ApiQueryInfo', 'getDeleteToken' ),
+                       'protect' => array( 'ApiQueryInfo', 'getProtectToken' ),
+                       'move' => array( 'ApiQueryInfo', 'getMoveToken' ),
+                       'block' => array( 'ApiQueryInfo', 'getBlockToken' ),
+                       'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ),
+                       'email' => array( 'ApiQueryInfo', 'getEmailToken' ),
                );
                wfRunHooks('APIQueryInfoTokens', array(&$this->tokenFunctions));
                return $this->tokenFunctions;
@@ -149,6 +154,20 @@ class ApiQueryInfo extends ApiQueryBase {
                return self::getBlockToken($pageid, $title);
        }
 
+       public static function getEmailToken($pageid, $title)
+       {
+               global $wgUser;
+               if(!$wgUser->canSendEmail() || $wgUser->isBlockedFromEmailUser())
+                       return false;
+
+               static $cachedEmailToken = null;
+               if(!is_null($cachedEmailToken))
+                       return $cachedEmailToken;
+
+               $cachedEmailToken = $wgUser->editToken();
+               return $cachedEmailToken;
+       }
+
        public function execute() {
 
                global $wgUser;
@@ -393,40 +412,38 @@ class ApiQueryInfo extends ApiQueryBase {
                        }
 
                        if($fld_protection) {
+                               $pageInfo['protection'] = array();
                                if (isset($protections[$pageid])) {
                                        $pageInfo['protection'] = $protections[$pageid];
                                        $result->setIndexedTagName($pageInfo['protection'], 'pr');
-                               } else {
-                                       # Also check old restrictions
-                                       if( $pageRestrictions[$pageid] ) {
-                                               foreach( explode( ':', trim( $pageRestrictions[$pageid] ) ) as $restrict ) {
-                                                       $temp = explode( '=', trim( $restrict ) );
-                                                       if(count($temp) == 1) {
-                                                               // old old format should be treated as edit/move restriction
-                                                               $restriction = trim( $temp[0] );
-                                                               $pageInfo['protection'][] = array(
-                                                                       'type' => 'edit',
-                                                                       'level' => $restriction,
-                                                                       'expiry' => 'infinity',
-                                                               );
-                                                               $pageInfo['protection'][] = array(
-                                                                       'type' => 'move',
-                                                                       'level' => $restriction,
-                                                                       'expiry' => 'infinity',
-                                                               );
-                                                       } else {
-                                                               $restriction = trim( $temp[1] );
-                                                               $pageInfo['protection'][] = array(
-                                                                       'type' => $temp[0],
-                                                                       'level' => $restriction,
-                                                                       'expiry' => 'infinity',
-                                                               );
-                                                       }
+                               }
+                               # Also check old restrictions
+                               if( $pageRestrictions[$pageid] ) {
+                                       foreach( explode( ':', trim( $pageRestrictions[$pageid] ) ) as $restrict ) {
+                                               $temp = explode( '=', trim( $restrict ) );
+                                               if(count($temp) == 1) {
+                                                       // old old format should be treated as edit/move restriction
+                                                       $restriction = trim( $temp[0] );
+                                                       $pageInfo['protection'][] = array(
+                                                               'type' => 'edit',
+                                                               'level' => $restriction,
+                                                               'expiry' => 'infinity',
+                                                       );
+                                                       $pageInfo['protection'][] = array(
+                                                               'type' => 'move',
+                                                               'level' => $restriction,
+                                                               'expiry' => 'infinity',
+                                                       );
+                                               } else {
+                                                       $restriction = trim( $temp[1] );
+                                                       $pageInfo['protection'][] = array(
+                                                               'type' => $temp[0],
+                                                               'level' => $restriction,
+                                                               'expiry' => 'infinity',
+                                                       );
                                                }
-                                               $result->setIndexedTagName($pageInfo['protection'], 'pr');
-                                       } else {
-                                               $pageInfo['protection'] = array();
                                        }
+                                       $result->setIndexedTagName($pageInfo['protection'], 'pr');
                                }
                        }
                        if($fld_talkid && isset($talkids[$title->getNamespace()][$title->getDbKey()]))