Code style tweaks per brion's suggestions on Wikitech-l
[lhc/web/wiklou.git] / includes / SpecialUnlockdb.php
index 7050e0d..1f24d13 100644 (file)
  */
 function wfSpecialUnlockdb() {
        global $wgUser, $wgOut, $wgRequest;
-       if( $wgUser->isAllowed( 'siteadmin' ) ) {
-               $form = new DBUnlockForm();
-               if( $action == 'success' ) {
-                       $form->showSuccess();
-               } else if( $action == 'submit' && wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
-                       $form->doSubmit();
-               } else {
-                       $form->showForm();
-       } else {
+
+       if( !$wgUser->isAllowed( 'siteadmin' ) ) {
                $wgOut->permissionRequired( 'siteadmin' );
                return;
        }
+
+       $action = $wgRequest->getVal( 'action' );
+       $f = new DBUnlockForm();
+
+       if ( "success" == $action ) {
+               $f->showSuccess();
+       } else if ( "submit" == $action && $wgRequest->wasPosted() &&
+               $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
+               $f->doSubmit();
+       } else {
+               $f->showForm( "" );
+       }
 }
 
 /**
@@ -30,20 +35,26 @@ function wfSpecialUnlockdb() {
  * @subpackage SpecialPage
  */
 class DBUnlockForm {
-
-       function showForm( $error = false ) {
+       function showForm( $err )
+       {
                global $wgOut, $wgUser;
-               $wgOut->setPagetitle( wfMsg( 'unlockdb' ) );
-               $wgOut->addWikiText( wfMsg( 'unlockdbtext' ) );
-               
-               if( $error ) {
-                       $wgOut->setSubtitle( wfMsg( 'formerror' ) );
-                       $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $error ) . "</p>\n" );
+
+               global $wgReadOnlyFile;
+               if( !file_exists( $wgReadOnlyFile ) ) {
+                       $wgOut->addWikiText( wfMsg( 'databasenotlocked' ) );
+                       return;
+               }
+
+               $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
+               $wgOut->addWikiText( wfMsg( "unlockdbtext" ) );
+
+               if ( "" != $err ) {
+                       $wgOut->setSubtitle( wfMsg( "formerror" ) );
+                       $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
                }
-       
                $lc = htmlspecialchars( wfMsg( "unlockconfirm" ) );
                $lb = htmlspecialchars( wfMsg( "unlockbtn" ) );
-               $titleObj = Title::makeTitle( NS_SPECIAL, "Unlockdb" );
+               $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
                $action = $titleObj->escapeLocalURL( "action=submit" );
                $token = htmlspecialchars( $wgUser->editToken() );
 
@@ -72,7 +83,7 @@ END
        }
 
        function doSubmit() {
-               global $wgOut, $wgUser, $wgRequest, $wgReadOnlyFile;
+               global $wgOut, $wgRequest, $wgReadOnlyFile;
 
                $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
                if ( ! $wpLockConfirm ) {
@@ -80,16 +91,16 @@ END
                        return;
                }
                if ( @! unlink( $wgReadOnlyFile ) ) {
-                       $wgOut->fileDeleteError( $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" ) );