Merge "SI standards for time units"
[lhc/web/wiklou.git] / includes / specials / SpecialBlockme.php
index 5728509..3840b2f 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 /**
+ * Implements Special:Blockme
  *
  * 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
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup SpecialPage
  */
 
 /**
- * @file
+ * A special page called by proxy_check.php to block open proxies
+ *
  * @ingroup SpecialPage
  */
+class SpecialBlockme extends UnlistedSpecialPage {
 
-function wfSpecialBlockme() {
-       global $wgRequest, $wgBlockOpenProxies, $wgOut, $wgProxyKey;
+       function __construct() {
+               parent::__construct( 'Blockme' );
+       }
 
-       $ip = wfGetIP();
+       function execute( $par ) {
+               global $wgBlockOpenProxies, $wgProxyKey;
 
-       if( !$wgBlockOpenProxies || $wgRequest->getText( 'ip' ) != md5( $ip . $wgProxyKey ) ) {
-               $wgOut->addWikiMsg( 'proxyblocker-disabled' );
-               return;
-       }
+               $this->setHeaders();
+               $this->outputHeader();
 
-       $blockerName = wfMsg( "proxyblocker" );
-       $reason = wfMsg( "proxyblockreason" );
-
-       $u = User::newFromName( $blockerName );
-       $id = $u->idForName();
-       if ( !$id ) {
-               $u = User::newFromName( $blockerName );
-               $u->addToDatabase();
-               $u->setPassword( bin2hex( mt_rand(0, 0x7fffffff ) ) );
-               $u->saveSettings();
-               $id = $u->getID();
-       }
+               $ip = $this->getRequest()->getIP();
+               if( !$wgBlockOpenProxies || $this->getRequest()->getText( 'ip' ) != md5( $ip . $wgProxyKey ) ) {
+                       $this->getOutput()->addWikiMsg( 'proxyblocker-disabled' );
+                       return;
+               }
+
+               $user = User::newFromName( $this->msg( 'proxyblocker' )->inContentLanguage()->text() );
+               # FIXME: newFromName could return false on a badly configured wiki.
+               if ( !$user->isLoggedIn() ) {
+                       $user->addToDatabase();
+               }
 
-       $block = new Block( $ip, 0, $id, $reason, wfTimestampNow() );
-       $block->insert();
+               $block = new Block();
+               $block->setTarget( $ip );
+               $block->setBlocker( $user );
+               $block->mReason = $this->msg( 'proxyblockreason' )->inContentLanguage()->text();
 
-       $wgOut->addWikiMsg( "proxyblocksuccess" );
+               $block->insert();
+
+               $this->getOutput()->addWikiMsg( 'proxyblocksuccess' );
+       }
 }