Fix for compatibility with short_open_tag = Off
[lhc/web/wiklou.git] / includes / SpecialMakesysop.php
1 <?php
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 $makeburo = wfMsg( "setbureaucratflag" );
60 $wgOut->addHTML(
61 "<tr>
62 <td>&nbsp;</td><td align=left>
63 <input type=checkbox name=\"wpSetBureaucrat\" value=1>$makeburo
64 </td>
65 </tr>"
66 );
67
68 $mss = wfMsg( "makesysopsubmit" );
69 $wgOut->addHTML(
70 "<tr>
71 <td>&nbsp;</td><td align=left>
72 <input type=submit name=\"wpMakesysopSubmit\" value=\"{$mss}\">
73 </td></tr></table>
74 </form>\n"
75 );
76
77 }
78
79 function doSubmit()
80 {
81 global $wgOut, $wgUser, $wgLang, $wpMakesysopUser, $wpSetBureaucrat;
82 global $wgDBname, $wgMemc;
83 /*
84 $parts = explode( "@", $wpMakesysopUser );
85 if( count( $parts ) == 2){
86 $username = addslashes( $parts[0] );
87 $usertable = $parts[1] . "wiki.user";
88 $dbName = $parts[1] . "wiki";
89 } else {*/
90 $username = addslashes( $wpMakesysopUser );
91 $usertable = "user";
92 $dbName = $wgDBname;
93 #}
94 $prev = wfIgnoreSQLErrors( TRUE );
95 $res = wfQuery("SELECT user_id, user_rights FROM user WHERE user_name = '{$username}'", DB_WRITE);
96 wfIgnoreSQLErrors( $prev );
97
98 if( wfLastErrno() || ! $username || wfNumRows( $res ) == 0 ){
99 $this->showFail();
100 return;
101 }
102
103 $row = wfFetchObject( $res );
104 $id = intval( $row->user_id );
105 $rightsNotation = array();
106
107 if( $row->user_rights ){
108 $rights = explode(",", $row->user_rights );
109 if(! in_array("sysop", $rights ) ){
110 $rights[] = "sysop";
111 $rightsNotation[] = "+sysop ";
112 }
113 if ( $wpSetBureaucrat && !in_array( "bureaucrat", $rights ) ) {
114 $rights[] = "bureaucrat";
115 $rightsNotation[] = "+bureaucrat ";
116 }
117 $newrights = addslashes( implode( ",", $rights ) );
118 } else {
119 $newrights = "sysop";
120 $rightsNotation[] = "+sysop";
121 if ( $wpSetBureaucrat ) {
122 $rightsNotation[] = "+bureaucrat";
123 $newrights .= ",bureaucrat";
124 }
125 }
126
127 if ( count( $rightsNotation ) == 0 ) {
128 $this->showFail();
129 } else {
130 $sql = "UPDATE user SET user_rights = '{$newrights}' WHERE user_id = $id LIMIT 1";
131 wfQuery($sql, DB_WRITE);
132 $wgMemc->delete( "$wgDBname:user:id:$id" );
133
134 $bureaucratLog = wfMsg( "bureaucratlog" );
135 $action = wfMsg( "bureaucratlogentry", $wpMakesysopUser, implode( " ", $rightsNotation ) );
136
137 $log = new LogPage( $bureaucratLog );
138 $log->addEntry( $action, "" );
139
140 $this->showSuccess();
141 }
142 }
143
144 function showSuccess()
145 {
146 global $wgOut, $wpMakesysopUser;
147
148 $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
149 $text = wfMsg( "makesysopok", $wpMakesysopUser );
150 $wgOut->addWikiText( $text );
151 $this->showForm();
152
153 }
154
155 function showFail()
156 {
157 global $wgOut, $wpMakesysopUser;
158
159 $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
160 $this->showForm( wfMsg( "makesysopfail", $wpMakesysopUser ) );
161 }
162 }
163 ?>