From: Victor Vasiliev Date: Tue, 8 Jan 2008 18:10:58 +0000 (+0000) Subject: API: add action=logout X-Git-Tag: 1.31.0-rc.0~50101 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/modifier.php?a=commitdiff_plain;h=4cc099d5d1aa9e93dbcbe62932e0d349f4f6e1bb;p=lhc%2Fweb%2Fwiklou.git API: add action=logout --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2d67a64713..ec58ad7c39 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -409,6 +409,7 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API * Fix output of wfSajaxSearch * (bug 12413) meta=userinfo missing tag * Add list of sections to action=parse output +* Added action=logout === Languages updated in 1.12 === diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index af08937fa9..83afaebfbf 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -314,6 +314,7 @@ function __autoload($className) { 'ApiFormatYaml' => 'includes/api/ApiFormatYaml.php', 'ApiHelp' => 'includes/api/ApiHelp.php', 'ApiLogin' => 'includes/api/ApiLogin.php', + 'ApiLogout' => 'includes/api/ApiLogout.php', 'ApiMain' => 'includes/api/ApiMain.php', 'ApiOpenSearch' => 'includes/api/ApiOpenSearch.php', 'ApiPageSet' => 'includes/api/ApiPageSet.php', diff --git a/includes/SpecialUserlogout.php b/includes/SpecialUserlogout.php index 6e464ced4a..d9952ea594 100644 --- a/includes/SpecialUserlogout.php +++ b/includes/SpecialUserlogout.php @@ -10,17 +10,10 @@ function wfSpecialUserlogout() { global $wgUser, $wgOut; - if (wfRunHooks('UserLogout', array(&$wgUser))) { - - $wgUser->logout(); - - wfRunHooks('UserLogoutComplete', array(&$wgUser)); - - $wgOut->setRobotpolicy( 'noindex,nofollow' ); - $wgOut->addHTML( wfMsgExt( 'logouttext', array( 'parse' ) ) ); - $wgOut->returnToMain(); - - } + $wgUser->logout(); + $wgOut->setRobotpolicy( 'noindex,nofollow' ); + $wgOut->addHTML( wfMsgExt( 'logouttext', array( 'parse' ) ) ); + $wgOut->returnToMain(); } diff --git a/includes/User.php b/includes/User.php index 756355a3d6..00c8981e58 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1958,10 +1958,20 @@ class User { } /** - * Logout user - * Clears the cookies and session, resets the instance cache + * Logout user. */ function logout() { + if( wfRunHooks( 'UserLogout', array(&$this) ) ) { + $this->doLogout(); + wfRunHooks( 'UserLogoutComplete', array(&$wgUser) ); + } + } + + /** + * Really logout user + * Clears the cookies and session, resets the instance cache + */ + function doLogout() { global $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgCookiePrefix; $this->clearInstanceCache( 'defaults' ); diff --git a/includes/api/ApiLogout.php b/includes/api/ApiLogout.php new file mode 100644 index 0000000000..34dbb83e58 --- /dev/null +++ b/includes/api/ApiLogout.php @@ -0,0 +1,65 @@ +@gmail.com, + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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. + * http://www.gnu.org/copyleft/gpl.html + */ + +if (!defined('MEDIAWIKI')) { + // Eclipse helper - will be ignored in production + require_once ('ApiBase.php'); +} + +class ApiLogout extends ApiBase { + + public function __construct($main, $action) { + parent :: __construct($main, $action, 'lo'); + } + + public function execute() { + global $wgUser; + $wgUser->logout(); + } + + protected function getAllowedParams() { + return array (); + } + + protected function getParamDescription() { + return array (); + } + + protected function getDescription() { + return array ( + 'This module is used to logout and clear session data' + ); + } + + protected function getExamples() { + return array( + 'api.php?action=logout' + ); + } + + public function getVersion() { + return __CLASS__ . ': $Id$'; + } +} \ No newline at end of file diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 922a8f902c..43621255b2 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -53,6 +53,7 @@ class ApiMain extends ApiBase { */ private static $Modules = array ( 'login' => 'ApiLogin', + 'logout' => 'ApiLogout', 'query' => 'ApiQuery', 'expandtemplates' => 'ApiExpandTemplates', 'render' => 'ApiRender', @@ -115,8 +116,9 @@ class ApiMain extends ApiBase { global $wgUser; if (!$wgUser->isAllowed('read')) { self::$Modules = array( - 'login' => self::$Modules['login'], - 'help' => self::$Modules['help'] + 'login' => self::$Modules['login'], + 'logout' => self::$Modules['logout'], + 'help' => self::$Modules['help'], ); } } @@ -296,9 +298,9 @@ class ApiMain extends ApiBase { * Execute the actual module, without any error handling */ protected function executeAction() { - + $params = $this->extractRequestParams(); - + $this->mShowVersions = $params['version']; $this->mAction = $params['action']; diff --git a/includes/api/ApiQueryAllmessages.php b/includes/api/ApiQueryAllmessages.php index 9fe74e662b..da48f690eb 100644 --- a/includes/api/ApiQueryAllmessages.php +++ b/includes/api/ApiQueryAllmessages.php @@ -84,7 +84,7 @@ class ApiQueryAllmessages extends ApiQueryBase { $messages_out[] = $message; } $result->setIndexedTagName( $messages_out, 'message' ); - $result->addValue( null, $this->getModuleName(), $messages_out ); + $result->addValue( 'query', $this->getModuleName(), $messages_out ); } protected function getAllowedParams() {