From 34a22d81f5982dee6f3bb3d908b3aafb1657287d Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 26 Aug 2008 21:34:47 +0000 Subject: [PATCH] API: Improvements to action=emailuser: * Add two messages from ApiEmailUser to ApiBase::$messageMap * Add email tokens to prop=info --- includes/api/ApiBase.php | 3 +++ includes/api/ApiQueryInfo.php | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 86aae574b0..ea652fbc0b 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -632,6 +632,9 @@ abstract class ApiBase { 'ipb_already_blocked' => array('code' => 'alreadyblocked', 'info' => "The user you tried to block was already blocked"), 'ipb_blocked_as_range' => array('code' => 'blockedasrange', 'info' => "IP address ``\$1'' was blocked as part of range ``\$2''. You can't unblock the IP invidually, but you can unblock the range as a whole."), 'ipb_cant_unblock' => array('code' => 'cantunblock', 'info' => "The block you specified was not found. It may have been unblocked already"), + 'mailnologin' => array('code' => 'cantsend', 'info' => "You're not logged in or you don't have a confirmed e-mail address, so you can't send e-mail"), + 'blockedemailuser' => array('code' => 'blockedfrommail', 'info' => "You have been blocked from sending e-mail"), + // API-specific messages 'missingparam' => array('code' => 'no$1', 'info' => "The \$1 parameter must be set"), diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index 5353fcf746..884473eac1 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -68,7 +68,8 @@ class ApiQueryInfo extends ApiQueryBase { 'protect' => array( 'ApiQueryInfo', 'getProtectToken' ), 'move' => array( 'ApiQueryInfo', 'getMoveToken' ), 'block' => array( 'ApiQueryInfo', 'getBlockToken' ), - 'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ) + 'unblock' => array( 'ApiQueryInfo', 'getUnblockToken' ), + 'email' => array( 'ApiQueryInfo', 'getEmailToken' ), ); wfRunHooks('APIQueryInfoTokens', array(&$this->tokenFunctions)); return $this->tokenFunctions; @@ -153,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; -- 2.20.1