Cleanup
[lhc/web/wiklou.git] / includes / SpecialUnlockdb.php
index 5e51e8a..74b794d 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 /**
  *
+ * @addtogroup SpecialPage
  */
 
 /**
 function wfSpecialUnlockdb() {
        global $wgUser, $wgOut, $wgRequest;
 
-       if ( ! $wgUser->isDeveloper() ) {
-               $wgOut->developerRequired();
+       if( !$wgUser->isAllowed( 'siteadmin' ) ) {
+               $wgOut->permissionRequired( 'siteadmin' );
                return;
        }
-       $action = $wgRequest->getText( 'action' );
+
+       $action = $wgRequest->getVal( 'action' );
        $f = new DBUnlockForm();
 
-       if ( "success" == $action ) { $f->showSuccess(); }
-       else if ( "submit" == $action ) { $f->doSubmit(); }
-       else { $f->showForm( "" ); }
+       if ( "success" == $action ) {
+               $f->showSuccess();
+       } else if ( "submit" == $action && $wgRequest->wasPosted() &&
+               $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
+               $f->doSubmit();
+       } else {
+               $f->showForm( "" );
+       }
 }
 
 /**
  *
+ * @addtogroup SpecialPage
  */
 class DBUnlockForm {
        function showForm( $err )
        {
-               global $wgOut, $wgUser, $wgLang;
+               global $wgOut, $wgUser;
+
+               global $wgReadOnlyFile;
+               if( !file_exists( $wgReadOnlyFile ) ) {
+                       $wgOut->addWikiMsg( 'databasenotlocked' );
+                       return;
+               }
 
                $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
-               $wgOut->addWikiText( wfMsg( "unlockdbtext" ) );
+               $wgOut->addWikiMsg( "unlockdbtext" );
 
                if ( "" != $err ) {
                        $wgOut->setSubtitle( wfMsg( "formerror" ) );
-                       $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
+                       $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
                }
-               $lc = wfMsg( "unlockconfirm" );
-               $lb = wfMsg( "unlockbtn" );
-               $titleObj = Title::makeTitle( NS_SPECIAL, "Unlockdb" );
+               $lc = htmlspecialchars( wfMsg( "unlockconfirm" ) );
+               $lb = htmlspecialchars( wfMsg( "unlockbtn" ) );
+               $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
                $action = $titleObj->escapeLocalURL( "action=submit" );
+               $token = htmlspecialchars( $wgUser->editToken() );
+
+               $wgOut->addHTML( <<<END
 
-               $wgOut->addHTML( "<p>
-<form id=\"unlockdb\" method=\"post\" action=\"{$action}\">
-<table border=0><tr>
-<td align=right>
-<input type=checkbox name=\"wpLockConfirm\">
-</td>
-<td align=\"left\">{$lc}<td>
-</tr><tr>
-<td>&nbsp;</td><td align=left>
-<input type=submit name=\"wpLock\" value=\"{$lb}\">
-</td></tr></table>
-</form>\n" );
+<form id="unlockdb" method="post" action="{$action}">
+<table border="0">
+       <tr>
+               <td align="right">
+                       <input type="checkbox" name="wpLockConfirm" />
+               </td>
+               <td align="left">{$lc}</td>
+       </tr>
+       <tr>
+               <td>&nbsp;</td>
+               <td align="left">
+                       <input type="submit" name="wpLock" value="{$lb}" />
+               </td>
+       </tr>
+</table>
+<input type="hidden" name="wpEditToken" value="{$token}" />
+</form>
+END
+);
 
        }
 
        function doSubmit() {
-               global $wgOut, $wgUser, $wgLang;
-               global $wgRequest, $wgReadOnlyFile;
+               global $wgOut, $wgRequest, $wgReadOnlyFile;
 
                $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
                if ( ! $wpLockConfirm ) {
                        $this->showForm( wfMsg( "locknoconfirm" ) );
                        return;
                }
-               if ( ! unlink( $wgReadOnlyFile ) ) {
-                       $wgOut->fileDeleteError( $wgReadOnlyFile );
+               if ( @! unlink( $wgReadOnlyFile ) ) {
+                       $wgOut->showFileDeleteError( $wgReadOnlyFile );
                        return;
                }
-               $titleObj = Title::makeTitle( NS_SPECIAL, "Unlockdb" );
+               $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
                $success = $titleObj->getFullURL( "action=success" );
                $wgOut->redirect( $success );
        }
 
        function showSuccess() {
-               global $wgOut, $wgUser;
+               global $wgOut;
                global $ip;
 
                $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
                $wgOut->setSubtitle( wfMsg( "unlockdbsuccesssub" ) );
-               $wgOut->addWikiText( wfMsg( "unlockdbsuccesstext", $ip ) );
+               $wgOut->addWikiMsg( "unlockdbsuccesstext", $ip );
        }
 }
 
-?>
+