typo
[lhc/web/wiklou.git] / includes / SpecialMakesysop.php
index f062ec2..653f062 100644 (file)
@@ -1,9 +1,9 @@
 <?php
-include_once( "LinksUpdate.php" );
+require_once( "LinksUpdate.php" );
 
 function wfSpecialMakesysop()
 {
-       global $wgUser, $wgOut, $action, $target;
+       global $wgUser, $wgOut, $wgRequest;
 
        if ( 0 == $wgUser->getID() or $wgUser->isBlocked() ) {
                $wgOut->errorpage( "movenologin", "movenologintext" );
@@ -13,26 +13,36 @@ function wfSpecialMakesysop()
                $wgOut->errorpage( "bureaucrattitle", "bureaucrattext" );
                return;
        }
-
+       
        if ( wfReadOnly() ) {
                $wgOut->readOnlyPage();
                return;
        }
 
-       $f = new MakesysopForm();
+       $f = new MakesysopForm( $wgRequest );
 
-       if ( $_POST['wpMakesysopSubmit'] ) { 
+       if ( $f->mSubmit ) { 
                $f->doSubmit(); 
        } else { 
                $f->showForm( "" ); 
        }
 }
 
-class MakesysopForm {  
+class MakesysopForm {
+       var $mTarget, $mAction, $mRights, $mUser, $mSubmit;
+
+       function MakesysopForm( &$request ) 
+       {
+               $this->mAction = $request->getText( 'action' );
+               $this->mRights = $request->getVal( 'wpRights' );
+               $this->mUser = $request->getText( 'wpMakesysopUser' );
+               $this->mSubmit = $request->getBool( 'wpMakesysopSubmit' ) && $request->wasPosted();
+               $this->mBuro = $request->getBool( 'wpSetBureaucrat' );
+       }
+
        function showForm( $err = "")
        {
                global $wgOut, $wgUser, $wgLang;
-               global $wpNewTitle, $wpOldTitle, $wpMovetalk, $target, $wpRights, $wpMakesysopUser;
 
                if ( $wgUser->isDeveloper() ) {
                        $wgOut->setPageTitle( wfMsg( "set_user_rights" ) );
@@ -47,22 +57,22 @@ class MakesysopForm {
 
                if ( "" != $err ) {
                        $wgOut->setSubtitle( wfMsg( "formerror" ) );
-                       $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
+                       $wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
                }
                $namedesc = wfMsg( "makesysopname" );
-               if ( isset( $wpMakesysopUser ) ) {
-                       $encUser = htmlspecialchars( $wpMakesysopUser );
+               if ( !is_null( $this->mUser ) ) {
+                       $encUser = htmlspecialchars( $this->mUser );
                } else {
                        $encUser = "";
                }
 
-               $wgOut->addHTML( "<p>
+               $wgOut->addHTML( "
                        <form id=\"makesysop\" method=\"post\" action=\"{$action}\">
-                       <table border=0>
+                       <table border='0'>
                        <tr>
-                               <td align=right>$namedesc</td>
-                               <td align=left>
-                                       <input type=text size=40 name=\"wpMakesysopUser\" value=\"$encUser\">
+                               <td align='right'>$namedesc</td>
+                               <td align='left'>
+                                       <input type='text' size='40' name=\"wpMakesysopUser\" value=\"$encUser\" />
                                </td>
                        </tr>" 
                );
@@ -78,17 +88,17 @@ class MakesysopForm {
 
                if ( $wgUser->isDeveloper() ) {
                        $rights = wfMsg( "rights" );
-                       if ( isset( $wpRights ) ) {
-                               $encRights = htmlspecialchars( $wpRights );
+                       if ( !is_null( $this->mRights ) ) {
+                               $encRights = htmlspecialchars( $this->mRights );
                        } else {
                                $encRights = "sysop";
                        }
 
                        $wgOut->addHTML( "
                                <tr>
-                                       <td align=right>$rights</td>
-                                       <td align=left>
-                                               <input type=text size=40 name=\"wpRights\" value=\"$encRights\">
+                                       <td align='right'>$rights</td>
+                                       <td align='left'>
+                                               <input type='text' size='40' name=\"wpRights\" value=\"$encRights\" />
                                        </td>
                                </tr>" 
                        );
@@ -101,8 +111,8 @@ class MakesysopForm {
                }
                $wgOut->addHTML(
                        "<tr>
-                               <td>&nbsp;</td><td align=left>
-                                       <input type=submit name=\"wpMakesysopSubmit\" value=\"{$mss}\">
+                               <td>&nbsp;</td><td align='left'>
+                                       <input type='submit' name=\"wpMakesysopSubmit\" value=\"{$mss}\" />
                                </td></tr></table>
                        </form>\n" 
                );
@@ -111,10 +121,10 @@ class MakesysopForm {
 
        function doSubmit()
        {
-               global $wgOut, $wgUser, $wgLang, $wpMakesysopUser, $wpSetBureaucrat;
-               global $wgDBname, $wgMemc, $wpRights, $wgLocalDatabases;
-               
-               $parts = explode( "@", $wpMakesysopUser );
+               global $wgOut, $wgUser, $wgLang;
+               global $wgDBname, $wgMemc, $wgLocalDatabases;
+
+               $parts = explode( "@", $this->mUser );
                if( count( $parts ) == 2 && $wgUser->isDeveloper() ){
                        $username = wfStrencode( $parts[0] );
                        if ( array_key_exists( $parts[1], $wgLocalDatabases ) ) {
@@ -125,12 +135,20 @@ class MakesysopForm {
                                return;
                        }
                } else {
-                       $username = wfStrencode( $wpMakesysopUser );
+                       $username = wfStrencode( $this->mUser );
                        $usertable = "user";
                        $dbName = $wgDBname;
                }
+               if ( $username{0} == "#" ) {
+                       $id = intval( substr( $username, 1 ) );
+                       $sql = "SELECT user_id,user_rights FROM $usertable WHERE user_id=$id";
+               } else {
+                       $encName = wfStrencode( $username );
+                       $sql = "SELECT user_id, user_rights FROM $usertable WHERE user_name = '{$username}'";
+               }
+               
                $prev = wfIgnoreSQLErrors( TRUE );
-               $res = wfQuery("SELECT user_id, user_rights FROM $usertable WHERE user_name = '{$username}'", DB_WRITE);
+               $res = wfQuery( $sql, DB_WRITE );
                wfIgnoreSQLErrors( $prev );
 
                if( wfLastErrno() || ! $username || wfNumRows( $res ) == 0 ){
@@ -143,8 +161,8 @@ class MakesysopForm {
                $rightsNotation = array();
 
                if ( $wgUser->isDeveloper() ) {
-                       $newrights = (string)$wpRights;
-                       $rightsNotation[] = "=$wpRights";
+                       $newrights = (string)$this->mRights;
+                       $rightsNotation[] = "=$this->mRights";
                } else {
                        if( $row->user_rights ){
                                $rights = explode(",", $row->user_rights );
@@ -152,7 +170,7 @@ class MakesysopForm {
                                        $rights[] = "sysop";
                                        $rightsNotation[] = "+sysop ";
                                }
-                               if ( $wpSetBureaucrat && !in_array( "bureaucrat", $rights ) ) {
+                               if ( $this->mBuro && !in_array( "bureaucrat", $rights ) ) {
                                        $rights[] = "bureaucrat";
                                        $rightsNotation[] = "+bureaucrat ";
                                }
@@ -160,7 +178,7 @@ class MakesysopForm {
                        } else {
                                $newrights = "sysop";
                                $rightsNotation[] = "+sysop";
-                               if ( $wpSetBureaucrat ) {
+                               if ( $this->mBuro ) {
                                        $rightsNotation[] = "+bureaucrat";
                                        $newrights .= ",bureaucrat";
                                }
@@ -175,7 +193,7 @@ class MakesysopForm {
                        $wgMemc->delete( "$dbName:user:id:$id" );
                        
                        $bureaucratLog = wfMsg( "bureaucratlog" );
-                       $action = wfMsg( "bureaucratlogentry", $wpMakesysopUser, implode( " ", $rightsNotation ) );
+                       $action = wfMsg( "bureaucratlogentry", $this->mUser, implode( " ", $rightsNotation ) );
                        
                        $log = new LogPage( $bureaucratLog );
                        $log->addEntry( $action, "" );
@@ -186,14 +204,14 @@ class MakesysopForm {
 
        function showSuccess()
        {
-               global $wgOut, $wpMakesysopUser, $wgUser;
+               global $wgOut, $wgUser;
 
                $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
 
                if ( $wgUser->isDeveloper() ) {
-                       $text = wfMsg( "user_rights_set", $wpMakesysopUser );
+                       $text = wfMsg( "user_rights_set", $this->mUser );
                } else {
-                       $text = wfMsg( "makesysopok", $wpMakesysopUser );
+                       $text = wfMsg( "makesysopok", $this->mUser );
                }
                $text .= "\n\n";
                $wgOut->addWikiText( $text );
@@ -203,13 +221,13 @@ class MakesysopForm {
 
        function showFail()
        {
-               global $wgOut, $wpMakesysopUser, $wgUser;
+               global $wgOut, $wgUser;
 
                $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
                if ( $wgUser->isDeveloper() ) {
-                       $this->showForm( wfMsg( "set_rights_fail", $wpMakesysopUser ) );
+                       $this->showForm( wfMsg( "set_rights_fail", $this->mUser ) );
                } else {
-                       $this->showForm( wfMsg( "makesysopfail", $wpMakesysopUser ) );
+                       $this->showForm( wfMsg( "makesysopfail", $this->mUser ) );
                }
        }
 }