Special page for making sysops.
authorMr. E23 <e23@users.mediawiki.org>
Sun, 1 Feb 2004 20:54:24 +0000 (20:54 +0000)
committerMr. E23 <e23@users.mediawiki.org>
Sun, 1 Feb 2004 20:54:24 +0000 (20:54 +0000)
includes/SpecialMakesysop.php [new file with mode: 0644]
includes/User.php
languages/Language.php

diff --git a/includes/SpecialMakesysop.php b/includes/SpecialMakesysop.php
new file mode 100644 (file)
index 0000000..522ff0e
--- /dev/null
@@ -0,0 +1,119 @@
+<?
+include_once( "LinksUpdate.php" );
+
+function wfSpecialMakesysop()
+{
+       global $wgUser, $wgOut, $action, $target;
+
+       if ( 0 == $wgUser->getID() or $wgUser->isBlocked() ) {
+               $wgOut->errorpage( "movenologin", "movenologintext" );
+               return;
+       }
+       if (! $wgUser->isBureaucrat()){
+               $wgOut->errorpage( "bureaucrattitle", "bureaucrattext" );
+               return;
+       }
+
+       if ( wfReadOnly() ) {
+               $wgOut->readOnlyPage();
+               return;
+       }
+
+       $f = new MakesysopForm();
+
+       if ( $_POST['wpMakesysopSubmit'] ) { 
+               $f->doSubmit(); 
+       } else { 
+               $f->showForm( "" ); 
+       }
+}
+
+class MakesysopForm {  
+       function showForm( $err = "")
+       {
+               global $wgOut, $wgUser, $wgLang;
+               global $wpNewTitle, $wpOldTitle, $wpMovetalk, $target;
+
+               $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
+
+               $wgOut->addWikiText( wfMsg( "makesysoptext" ) );
+
+               $action = wfLocalUrlE( $wgLang->specialPage( "Makesysop" ),
+                 "action=submit" );
+
+               if ( "" != $err ) {
+                       $wgOut->setSubtitle( wfMsg( "formerror" ) );
+                       $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
+               }
+               $namedesc = wfMsg( "makesysopname" );
+               $wgOut->addHTML( "<p>
+                       <form id=\"makesysop\" method=\"post\" action=\"{$action}\">
+                       <table border=0>
+                       <tr>
+                               <td align=right>$namedesc</td>
+                               <td align=left>
+                                       <input type=text size=40 name=\"wpMakesysopUser\">
+                               </td>
+                       </tr>" 
+               );
+               $mss = wfMsg( "makesysopsubmit" );
+               $wgOut->addHTML(
+                       "<tr>
+                               <td>&nbsp;</td><td align=left>
+                                       <input type=submit name=\"wpMakesysopSubmit\" value=\"{$mss}\">
+                               </td></tr></table>
+                       </form>\n" 
+               );
+
+       }
+
+       function doSubmit()
+       {
+               global $wgOut, $wgUser, $wgLang, $wpMakesysopUser, $wgDBname, $wgMemc;
+               $sqname = addslashes($wpMakesysopUser);
+               $res = wfQuery("SELECT user_id, user_rights FROM user WHERE user_name = '{$sqname}'", DB_WRITE);
+               if( ! $sqname || wfNumRows( $res ) == 0 ){
+                       $this->showFail();
+                       return;
+               }
+
+               $row = wfFetchObject( $res );
+               $id = intval( $row->user_id );
+
+               if( $row->user_rights ){
+                       $rights = explode(",", $row->user_rights );
+                       if(! in_array("sysop", $rights ) ){
+                               $rights[] = "sysop";
+                       }
+                       $newrights = addslashes( implode( ",", $rights ) );
+               } else {
+                       $newrights = "sysop";
+               }
+               
+               $sql = "UPDATE user SET user_rights = '{$newrights}' WHERE user_id = $id LIMIT 1";
+               wfQuery($sql, DB_WRITE);
+               $wgMemc->delete( "$wgDBname:user:id:$id" );
+
+               $this->showSuccess();
+       }
+
+       function showSuccess()
+       {
+               global $wgOut, $wpMakesysopUser;
+
+               $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
+               $text = wfMsg( "makesysopok", $wpMakesysopUser );
+               $wgOut->addWikiText( $text );
+               $this->showForm();
+
+       }
+
+       function showFail()
+       {
+               global $wgOut, $wpMakesysopUser;
+
+               $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
+               $this->showForm( wfMsg( "makesysopfail", $wpMakesysopUser ) );
+       }
+}
+?>
index 5de7e88..4851b99 100644 (file)
@@ -428,6 +428,14 @@ class User {
                return in_array( "developer", $this->mRights );
        }
 
+       function isBureaucrat()
+       {
+               $this->loadFromDatabase();
+               if ( 0 == $this->mId ) { return false; }
+
+               return in_array( "bureaucrat", $this->mRights );
+       }
+
        function isBot()
        {
                $this->loadFromDatabase();
index bdf0b84..50962ff 100644 (file)
@@ -362,7 +362,8 @@ this</a> (alternative: like this<a href=\"\" class=\"internal\">?</a>).",
 /* private */ $wgSysopSpecialPagesEn = array(
        "Blockip"               => "Block a user/IP address",
        "Asksql"                => "Query the database",
-       "Undelete"              => "Restore deleted pages"
+       "Undelete"              => "Restore deleted pages",
+       "Makesysop"             => "Turn a user into a sysop"
 );
 
 /* private */ $wgDeveloperSpecialPagesEn = array(
@@ -455,6 +456,9 @@ See $1.",
 "developertext"        => "The action you have requested can only be
 performed by users with \"developer\" status.
 See $1.",
+"bureaucrattitle"      => "Bureaucrat access required",
+"bureaucrattext"       => "The action you have requested can only be
+performed by sysops with  \"bureaucrat\" status.",
 "nbytes"               => "$1 bytes",
 "go"                   => "Go",
 "ok"                   => "OK",
@@ -1266,6 +1270,14 @@ this function sparingly.",
 "selectonly"   => "Only read-only queries are allowed.",
 "querysuccessful" => "Query successful",
 
+# Make sysop
+"makesysoptitle"       => "Make a user into a sysop",
+"makesysoptext"                => "This form is used by bureaucrats to turn ordinary users into administrators. 
+Type the name of the user in the box and press the button to make the user an administrator",
+"makesysopsubmit"      => "Make this user into a sysop",
+"makesysopok"          => "<b>User '$1' is now a sysop</b>",
+"makesysopfail"                => "<b>User '$1' could not be made into a sysop. (Did you enter the name correctly?)</b>",
+
 # Move page
 #
 "movepage"             => "Move page",