Merge "Add a test for named vs. positional parameter whitespace stripping"
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogout.php
index a7257de..4be36c6 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 /**
+ * Implements Special:Userlogout
  *
  * 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
  *
  * 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.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
- */
-
-/**
+ *
  * @file
  * @ingroup SpecialPage
  */
 
 /**
- * constructor
+ * Implements Special:Userlogout
+ *
+ * @ingroup SpecialPage
  */
-function wfSpecialUserlogout() {
-       global $wgUser, $wgOut;
-
-       /**
-        * Some satellite ISPs use broken precaching schemes that log people out straight after
-        * they're logged in (bug 17790). Luckily, there's a way to detect such requests.
-        */
-       if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], '&amp;' ) !== false ) {
-               wfDebug( "Special:Userlogout request {$_SERVER['REQUEST_URI']} looks suspicious, denying.\n" );
-               wfHttpError( 400, wfMsg( 'loginerror' ), wfMsg( 'suspicious-userlogout' ) );
-               return;
+class SpecialUserlogout extends UnlistedSpecialPage {
+
+       function __construct() {
+               parent::__construct( 'Userlogout' );
        }
-       
-       $oldName = $wgUser->getName();
-       $wgUser->logout();
-       $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
-       // Hook.
-       $injected_html = '';
-       wfRunHooks( 'UserLogoutComplete', array(&$wgUser, &$injected_html, $oldName) );
+       function execute( $par ) {
+               /**
+                * Some satellite ISPs use broken precaching schemes that log people out straight after
+                * they're logged in (bug 17790). Luckily, there's a way to detect such requests.
+                */
+               if ( isset( $_SERVER['REQUEST_URI'] ) && strpos( $_SERVER['REQUEST_URI'], '&amp;' ) !== false ) {
+                       wfDebug( "Special:Userlogout request {$_SERVER['REQUEST_URI']} looks suspicious, denying.\n" );
+                       throw new HttpError( 400, $this->msg( 'suspicious-userlogout' ), $this->msg( 'loginerror' ) );
+               }
 
-       $wgOut->addHTML( wfMsgExt( 'logouttext', array( 'parse' ) ) . $injected_html );
-       $wgOut->returnToMain();
+               $this->setHeaders();
+               $this->outputHeader();
+
+               $user = $this->getUser();
+               $oldName = $user->getName();
+               $user->logout();
+
+               $loginURL = SpecialPage::getTitleFor( 'Userlogin' )->getFullURL(
+                       $this->getRequest()->getValues( 'returnto', 'returntoquery' ) );
+
+               $out = $this->getOutput();
+               $out->addWikiMsg( 'logouttext', $loginURL );
+
+               // Hook.
+               $injected_html = '';
+               wfRunHooks( 'UserLogoutComplete', array( &$user, &$injected_html, $oldName ) );
+               $out->addHTML( $injected_html );
+
+               $out->returnToMain();
+       }
 }