2 include_once( "LinksUpdate.php" );
4 function wfSpecialMakesysop()
6 global $wgUser, $wgOut, $action, $target;
8 if ( 0 == $wgUser->getID() or $wgUser->isBlocked() ) {
9 $wgOut->errorpage( "movenologin", "movenologintext" );
12 if (! $wgUser->isBureaucrat() && ! $wgUser->isDeveloper() ){
13 $wgOut->errorpage( "bureaucrattitle", "bureaucrattext" );
18 $wgOut->readOnlyPage();
22 $f = new MakesysopForm();
24 if ( $_POST['wpMakesysopSubmit'] ) {
32 function showForm( $err = "")
34 global $wgOut, $wgUser, $wgLang;
35 global $wpNewTitle, $wpOldTitle, $wpMovetalk, $target, $wpRights, $wpMakesysopUser;
37 if ( $wgUser->isDeveloper() ) {
38 $wgOut->setPageTitle( wfMsg( "set_user_rights" ) );
40 $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
43 $wgOut->addWikiText( wfMsg( "makesysoptext" ) );
45 $action = wfLocalUrlE( $wgLang->specialPage( "Makesysop" ),
49 $wgOut->setSubtitle( wfMsg( "formerror" ) );
50 $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
52 $namedesc = wfMsg( "makesysopname" );
53 if ( isset( $wpMakesysopUser ) ) {
54 $encUser = htmlspecialchars( $wpMakesysopUser );
60 <form id=\"makesysop\" method=\"post\" action=\"{$action}\">
63 <td align=right>$namedesc</td>
65 <input type=text size=40 name=\"wpMakesysopUser\" value=\"$encUser\">
70 $makeburo = wfMsg( "setbureaucratflag" );
73 <td> </td><td align=left>
74 <input type=checkbox name=\"wpSetBureaucrat\" value=1>$makeburo
79 if ( $wgUser->isDeveloper() ) {
80 $rights = wfMsg( "rights" );
81 if ( isset( $wpRights ) ) {
82 $encRights = htmlspecialchars( $wpRights );
89 <td align=right>$rights</td>
91 <input type=text size=40 name=\"wpRights\" value=\"$encRights\">
97 if ( $wgUser->isDeveloper() ) {
98 $mss = wfMsg( "set_user_rights" );
100 $mss = wfMsg( "makesysopsubmit" );
104 <td> </td><td align=left>
105 <input type=submit name=\"wpMakesysopSubmit\" value=\"{$mss}\">
114 global $wgOut, $wgUser, $wgLang, $wpMakesysopUser, $wpSetBureaucrat;
115 global $wgDBname, $wgMemc, $wpRights;
117 $parts = explode( "@", $wpMakesysopUser );
118 if( count( $parts ) == 2 && $wgUser->isDeveloper() ){
119 $username = addslashes( $parts[0] );
120 $usertable = $parts[1] . "wiki.user";
121 $dbName = $parts[1] . "wiki";
123 $username = addslashes( $wpMakesysopUser );
127 $prev = wfIgnoreSQLErrors( TRUE );
128 $res = wfQuery("SELECT user_id, user_rights FROM user WHERE user_name = '{$username}'", DB_WRITE
);
129 wfIgnoreSQLErrors( $prev );
131 if( wfLastErrno() ||
! $username ||
wfNumRows( $res ) == 0 ){
136 $row = wfFetchObject( $res );
137 $id = intval( $row->user_id
);
138 $rightsNotation = array();
140 if ( $wgUser->isDeveloper() ) {
141 $newrights = (string)$wpRights;
142 $rightsNotation[] = "=$wpRights";
144 if( $row->user_rights
){
145 $rights = explode(",", $row->user_rights
);
146 if(! in_array("sysop", $rights ) ){
148 $rightsNotation[] = "+sysop ";
150 if ( $wpSetBureaucrat && !in_array( "bureaucrat", $rights ) ) {
151 $rights[] = "bureaucrat";
152 $rightsNotation[] = "+bureaucrat ";
154 $newrights = addslashes( implode( ",", $rights ) );
156 $newrights = "sysop";
157 $rightsNotation[] = "+sysop";
158 if ( $wpSetBureaucrat ) {
159 $rightsNotation[] = "+bureaucrat";
160 $newrights .= ",bureaucrat";
165 if ( count( $rightsNotation ) == 0 ) {
168 $sql = "UPDATE user SET user_rights = '{$newrights}' WHERE user_id = $id LIMIT 1";
169 wfQuery($sql, DB_WRITE
);
170 $wgMemc->delete( "$wgDBname:user:id:$id" );
172 $bureaucratLog = wfMsg( "bureaucratlog" );
173 $action = wfMsg( "bureaucratlogentry", $wpMakesysopUser, implode( " ", $rightsNotation ) );
175 $log = new LogPage( $bureaucratLog );
176 $log->addEntry( $action, "" );
178 $this->showSuccess();
182 function showSuccess()
184 global $wgOut, $wpMakesysopUser, $wgUser;
186 $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
188 if ( $wgUser->isDeveloper() ) {
189 $text = wfMsg( "user_rights_set", $wpMakesysopUser );
191 $text = wfMsg( "makesysopok", $wpMakesysopUser );
194 $wgOut->addWikiText( $text );
201 global $wgOut, $wpMakesysopUser, $wgUser;
203 $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) );
204 if ( $wgUser->isDeveloper() ) {
205 $this->showForm( wfMsg( "set_rights_fail", $wpMakesysopUser ) );
207 $this->showForm( wfMsg( "makesysopfail", $wpMakesysopUser ) );