From 94947b6615d564b30a36ac8660a2d026b98ec651 Mon Sep 17 00:00:00 2001 From: "Mr. E23" Date: Sun, 1 Feb 2004 20:54:24 +0000 Subject: [PATCH] Special page for making sysops. --- includes/SpecialMakesysop.php | 119 ++++++++++++++++++++++++++++++++++ includes/User.php | 8 +++ languages/Language.php | 14 +++- 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 includes/SpecialMakesysop.php diff --git a/includes/SpecialMakesysop.php b/includes/SpecialMakesysop.php new file mode 100644 index 0000000000..522ff0ed4f --- /dev/null +++ b/includes/SpecialMakesysop.php @@ -0,0 +1,119 @@ +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( "

{$err}\n" ); + } + $namedesc = wfMsg( "makesysopname" ); + $wgOut->addHTML( "

+

+ + + + + " + ); + $mss = wfMsg( "makesysopsubmit" ); + $wgOut->addHTML( + " +
$namedesc + +
  + +
+
\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 ) ); + } +} +?> diff --git a/includes/User.php b/includes/User.php index 5de7e88533..4851b99177 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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(); diff --git a/languages/Language.php b/languages/Language.php index bdf0b84d92..50962ff954 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -362,7 +362,8 @@ this (alternative: like this?).", /* 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" => "User '$1' is now a sysop", +"makesysopfail" => "User '$1' could not be made into a sysop. (Did you enter the name correctly?)", + # Move page # "movepage" => "Move page", -- 2.20.1