Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

SpecialMakesysop.php

Go to the documentation of this file.
00001 <?php 00002 require_once( "LinksUpdate.php" ); 00003 00004 function wfSpecialMakesysop() 00005 { 00006 global $wgUser, $wgOut, $wgRequest; 00007 00008 if ( 0 == $wgUser->getID() or $wgUser->isBlocked() ) { 00009 $wgOut->errorpage( "movenologin", "movenologintext" ); 00010 return; 00011 } 00012 if (! $wgUser->isBureaucrat() && ! $wgUser->isDeveloper() ){ 00013 $wgOut->errorpage( "bureaucrattitle", "bureaucrattext" ); 00014 return; 00015 } 00016 00017 if ( wfReadOnly() ) { 00018 $wgOut->readOnlyPage(); 00019 return; 00020 } 00021 00022 $f = new MakesysopForm( $wgRequest ); 00023 00024 if ( $f->mSubmit ) { 00025 $f->doSubmit(); 00026 } else { 00027 $f->showForm( "" ); 00028 } 00029 } 00030 00031 class MakesysopForm { 00032 var $mTarget, $mAction, $mRights, $mUser, $mSubmit; 00033 00034 function MakesysopForm( &$request ) 00035 { 00036 $this->mAction = $request->getText( 'action' ); 00037 $this->mRights = $request->getVal( 'wpRights' ); 00038 $this->mUser = $request->getText( 'wpMakesysopUser' ); 00039 $this->mSubmit = $request->getBool( 'wpMakesysopSubmit' ) && $request->wasPosted(); 00040 $this->mBuro = $request->getBool( 'wpSetBureaucrat' ); 00041 } 00042 00043 function showForm( $err = "") 00044 { 00045 global $wgOut, $wgUser, $wgLang; 00046 00047 if ( $wgUser->isDeveloper() ) { 00048 $wgOut->setPageTitle( wfMsg( "set_user_rights" ) ); 00049 } else { 00050 $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) ); 00051 } 00052 00053 $wgOut->addWikiText( wfMsg( "makesysoptext" ) ); 00054 00055 $titleObj = Title::makeTitle( NS_SPECIAL, "Makesysop" ); 00056 $action = $titleObj->escapeLocalURL( "action=submit" ); 00057 00058 if ( "" != $err ) { 00059 $wgOut->setSubtitle( wfMsg( "formerror" ) ); 00060 $wgOut->addHTML( "<p class='error'>{$err}</p>\n" ); 00061 } 00062 $namedesc = wfMsg( "makesysopname" ); 00063 if ( !is_null( $this->mUser ) ) { 00064 $encUser = htmlspecialchars( $this->mUser ); 00065 } else { 00066 $encUser = ""; 00067 } 00068 00069 $wgOut->addHTML( " 00070 <form id=\"makesysop\" method=\"post\" action=\"{$action}\"> 00071 <table border='0'> 00072 <tr> 00073 <td align='right'>$namedesc</td> 00074 <td align='left'> 00075 <input type='text' size='40' name=\"wpMakesysopUser\" value=\"$encUser\" /> 00076 </td> 00077 </tr>" 00078 ); 00079 /* 00080 $makeburo = wfMsg( "setbureaucratflag" ); 00081 $wgOut->addHTML( 00082 "<tr> 00083 <td>&nbsp;</td><td align=left> 00084 <input type=checkbox name=\"wpSetBureaucrat\" value=1>$makeburo 00085 </td> 00086 </tr>" 00087 );*/ 00088 00089 if ( $wgUser->isDeveloper() ) { 00090 $rights = wfMsg( "rights" ); 00091 if ( !is_null( $this->mRights ) ) { 00092 $encRights = htmlspecialchars( $this->mRights ); 00093 } else { 00094 $encRights = "sysop"; 00095 } 00096 00097 $wgOut->addHTML( " 00098 <tr> 00099 <td align='right'>$rights</td> 00100 <td align='left'> 00101 <input type='text' size='40' name=\"wpRights\" value=\"$encRights\" /> 00102 </td> 00103 </tr>" 00104 ); 00105 } 00106 00107 if ( $wgUser->isDeveloper() ) { 00108 $mss = wfMsg( "set_user_rights" ); 00109 } else { 00110 $mss = wfMsg( "makesysopsubmit" ); 00111 } 00112 $wgOut->addHTML( 00113 "<tr> 00114 <td>&nbsp;</td><td align='left'> 00115 <input type='submit' name=\"wpMakesysopSubmit\" value=\"{$mss}\" /> 00116 </td></tr></table> 00117 </form>\n" 00118 ); 00119 00120 } 00121 00122 function doSubmit() 00123 { 00124 global $wgOut, $wgUser, $wgLang; 00125 global $wgDBname, $wgMemc, $wgLocalDatabases; 00126 00127 $parts = explode( "@", $this->mUser ); 00128 if( count( $parts ) == 2 && $wgUser->isDeveloper() ){ 00129 $username = wfStrencode( $parts[0] ); 00130 if ( array_key_exists( $parts[1], $wgLocalDatabases ) ) { 00131 $dbName = $wgLocalDatabases[$parts[1]]; 00132 $usertable = $dbName . ".user"; 00133 } else { 00134 $this->showFail(); 00135 return; 00136 } 00137 } else { 00138 $username = wfStrencode( $this->mUser ); 00139 $usertable = "user"; 00140 $dbName = $wgDBname; 00141 } 00142 if ( $username{0} == "#" ) { 00143 $id = intval( substr( $username, 1 ) ); 00144 $sql = "SELECT user_id,user_rights FROM $usertable WHERE user_id=$id"; 00145 } else { 00146 $encName = wfStrencode( $username ); 00147 $sql = "SELECT user_id, user_rights FROM $usertable WHERE user_name = '{$username}'"; 00148 } 00149 00150 $prev = wfIgnoreSQLErrors( TRUE ); 00151 $res = wfQuery( $sql, DB_WRITE ); 00152 wfIgnoreSQLErrors( $prev ); 00153 00154 if( wfLastErrno() || ! $username || wfNumRows( $res ) == 0 ){ 00155 $this->showFail(); 00156 return; 00157 } 00158 00159 $row = wfFetchObject( $res ); 00160 $id = intval( $row->user_id ); 00161 $rightsNotation = array(); 00162 00163 if ( $wgUser->isDeveloper() ) { 00164 $newrights = (string)$this->mRights; 00165 $rightsNotation[] = "=$this->mRights"; 00166 } else { 00167 if( $row->user_rights ){ 00168 $rights = explode(",", $row->user_rights ); 00169 if(! in_array("sysop", $rights ) ){ 00170 $rights[] = "sysop"; 00171 $rightsNotation[] = "+sysop "; 00172 } 00173 if ( $this->mBuro && !in_array( "bureaucrat", $rights ) ) { 00174 $rights[] = "bureaucrat"; 00175 $rightsNotation[] = "+bureaucrat "; 00176 } 00177 $newrights = addslashes( implode( ",", $rights ) ); 00178 } else { 00179 $newrights = "sysop"; 00180 $rightsNotation[] = "+sysop"; 00181 if ( $this->mBuro ) { 00182 $rightsNotation[] = "+bureaucrat"; 00183 $newrights .= ",bureaucrat"; 00184 } 00185 } 00186 } 00187 00188 if ( count( $rightsNotation ) == 0 ) { 00189 $this->showFail(); 00190 } else { 00191 $sql = "UPDATE $usertable SET user_rights = '{$newrights}' WHERE user_id = $id LIMIT 1"; 00192 wfQuery($sql, DB_WRITE); 00193 $wgMemc->delete( "$dbName:user:id:$id" ); 00194 00195 $bureaucratLog = wfMsg( "bureaucratlog" ); 00196 $action = wfMsg( "bureaucratlogentry", $this->mUser, implode( " ", $rightsNotation ) ); 00197 00198 $log = new LogPage( $bureaucratLog ); 00199 $log->addEntry( $action, "" ); 00200 00201 $this->showSuccess(); 00202 } 00203 } 00204 00205 function showSuccess() 00206 { 00207 global $wgOut, $wgUser; 00208 00209 $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) ); 00210 00211 if ( $wgUser->isDeveloper() ) { 00212 $text = wfMsg( "user_rights_set", $this->mUser ); 00213 } else { 00214 $text = wfMsg( "makesysopok", $this->mUser ); 00215 } 00216 $text .= "\n\n"; 00217 $wgOut->addWikiText( $text ); 00218 $this->showForm(); 00219 00220 } 00221 00222 function showFail() 00223 { 00224 global $wgOut, $wgUser; 00225 00226 $wgOut->setPagetitle( wfMsg( "makesysoptitle" ) ); 00227 if ( $wgUser->isDeveloper() ) { 00228 $this->showForm( wfMsg( "set_rights_fail", $this->mUser ) ); 00229 } else { 00230 $this->showForm( wfMsg( "makesysopfail", $this->mUser ) ); 00231 } 00232 } 00233 } 00234 ?>

Generated on Tue Jun 29 23:40:07 2004 for Mediawiki by doxygen 1.3.7