API: add action=logout
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Tue, 8 Jan 2008 18:10:58 +0000 (18:10 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Tue, 8 Jan 2008 18:10:58 +0000 (18:10 +0000)
RELEASE-NOTES
includes/AutoLoader.php
includes/SpecialUserlogout.php
includes/User.php
includes/api/ApiLogout.php [new file with mode: 0644]
includes/api/ApiMain.php
includes/api/ApiQueryAllmessages.php

index 2d67a64..ec58ad7 100644 (file)
@@ -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 <query> tag
 * Add list of sections to action=parse output
+* Added action=logout
 
 === Languages updated in 1.12 ===
 
index af08937..83afaeb 100644 (file)
@@ -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',
index 6e464ce..d9952ea 100644 (file)
 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();
 }
 
 
index 756355a..00c8981 100644 (file)
@@ -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 (file)
index 0000000..34dbb83
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+
+/*
+ * Created on Jan 4, 2008
+ *
+ * API for MediaWiki 1.8+
+ *
+ * Copyright (C) 2008 Yuri Astrakhan <Firstname><Lastname>@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
index 922a8f9..4362125 100644 (file)
@@ -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'];
 
index 9fe74e6..da48f69 100644 (file)
@@ -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() {