Special page for making sysops.
[lhc/web/wiklou.git] / includes / SpecialMakesysop.php
1 <?
2 include_once( "LinksUpdate.php" );
3
4 function wfSpecialMakesysop()
5 {
6 global $wgUser, $wgOut, $action, $target;
7
8 if ( 0 == $wgUser->getID() or $wgUser->isBlocked() ) {
9 $wgOut->errorpage( "movenologin", "movenologintext" );
10 return;
11 }
12 if (! $wgUser->isBureaucrat()){
13 $wgOut->errorpage( "bureaucrattitle", "bureaucrattext" );
14 return;
15 }
16
17 if ( wfReadOnly() ) {
18 $wgOut->readOnlyPage();
19 return;
20 }
21
22 $f = new MakesysopForm();
23
24 if ( $_POST['wpMakesysopSubmit'] ) {
25 $f->doSubmit();
26 } else {
27 $f->showForm( "" );
28 }
29 }
30
31 class MakesysopForm {
32 function showForm( $err = "")
33 {
34 global $wgOut, $wgUser, $wgLang;
35 global $wpNewTitle, $wpOldTitle, $wpMovetalk, $target;
36
37 $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
38
39 $wgOut->addWikiText( wfMsg( "makesysoptext" ) );
40
41 $action = wfLocalUrlE( $wgLang->specialPage( "Makesysop" ),
42 "action=submit" );
43
44 if ( "" != $err ) {
45 $wgOut->setSubtitle( wfMsg( "formerror" ) );
46 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
47 }
48 $namedesc = wfMsg( "makesysopname" );
49 $wgOut->addHTML( "<p>
50 <form id=\"makesysop\" method=\"post\" action=\"{$action}\">
51 <table border=0>
52 <tr>
53 <td align=right>$namedesc</td>
54 <td align=left>
55 <input type=text size=40 name=\"wpMakesysopUser\">
56 </td>
57 </tr>"
58 );
59 $mss = wfMsg( "makesysopsubmit" );
60 $wgOut->addHTML(
61 "<tr>
62 <td>&nbsp;</td><td align=left>
63 <input type=submit name=\"wpMakesysopSubmit\" value=\"{$mss}\">
64 </td></tr></table>
65 </form>\n"
66 );
67
68 }
69
70 function doSubmit()
71 {
72 global $wgOut, $wgUser, $wgLang, $wpMakesysopUser, $wgDBname, $wgMemc;
73 $sqname = addslashes($wpMakesysopUser);
74 $res = wfQuery("SELECT user_id, user_rights FROM user WHERE user_name = '{$sqname}'", DB_WRITE);
75 if( ! $sqname || wfNumRows( $res ) == 0 ){
76 $this->showFail();
77 return;
78 }
79
80 $row = wfFetchObject( $res );
81 $id = intval( $row->user_id );
82
83 if( $row->user_rights ){
84 $rights = explode(",", $row->user_rights );
85 if(! in_array("sysop", $rights ) ){
86 $rights[] = "sysop";
87 }
88 $newrights = addslashes( implode( ",", $rights ) );
89 } else {
90 $newrights = "sysop";
91 }
92
93 $sql = "UPDATE user SET user_rights = '{$newrights}' WHERE user_id = $id LIMIT 1";
94 wfQuery($sql, DB_WRITE);
95 $wgMemc->delete( "$wgDBname:user:id:$id" );
96
97 $this->showSuccess();
98 }
99
100 function showSuccess()
101 {
102 global $wgOut, $wpMakesysopUser;
103
104 $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
105 $text = wfMsg( "makesysopok", $wpMakesysopUser );
106 $wgOut->addWikiText( $text );
107 $this->showForm();
108
109 }
110
111 function showFail()
112 {
113 global $wgOut, $wpMakesysopUser;
114
115 $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
116 $this->showForm( wfMsg( "makesysopfail", $wpMakesysopUser ) );
117 }
118 }
119 ?>