]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialUnlockdb.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialUnlockdb.php
index a3e8a0c4fffe20f32a4019ba6d9886ecda87d8d4..8cd86ce645394407f3f2d75769737d7b7ee71f3b 100644 (file)
 <?php
 /**
+ * Implements Special:Unlockdb
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup SpecialPage
  */
 
 /**
+ * Implements Special:Unlockdb
  *
+ * @ingroup SpecialPage
  */
-function wfSpecialUnlockdb() {
-       global $wgUser, $wgOut, $wgRequest;
+class SpecialUnlockdb extends FormSpecialPage {
 
-       if( !$wgUser->isAllowed( 'siteadmin' ) ) {
-               $wgOut->permissionRequired( 'siteadmin' );
-               return;
+       public function __construct() {
+               parent::__construct( 'Unlockdb', 'siteadmin' );
        }
 
-       $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( "" );
+       public function doesWrites() {
+               return false;
        }
-}
 
-/**
- * @ingroup SpecialPage
- */
-class DBUnlockForm {
-       function showForm( $err )
-       {
-               global $wgOut, $wgUser;
+       public function requiresWrite() {
+               return false;
+       }
 
-               global $wgReadOnlyFile;
-               if( !file_exists( $wgReadOnlyFile ) ) {
-                       $wgOut->addWikiMsg( 'databasenotlocked' );
-                       return;
+       public function checkExecutePermissions( User $user ) {
+               parent::checkExecutePermissions( $user );
+               # If the lock file isn't writable, we can do sweet bugger all
+               if ( !file_exists( $this->getConfig()->get( 'ReadOnlyFile' ) ) ) {
+                       throw new ErrorPageError( 'lockdb', 'databasenotlocked' );
                }
+       }
 
-               $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
-               $wgOut->addWikiMsg( "unlockdbtext" );
+       protected function getFormFields() {
+               return [
+                       'Confirm' => [
+                               'type' => 'toggle',
+                               'label-message' => 'unlockconfirm',
+                       ],
+               ];
+       }
 
-               if ( "" != $err ) {
-                       $wgOut->setSubtitle( wfMsg( "formerror" ) );
-                       $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
-               }
-               $lc = htmlspecialchars( wfMsg( "unlockconfirm" ) );
-               $lb = htmlspecialchars( wfMsg( "unlockbtn" ) );
-               $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
-               $action = $titleObj->escapeLocalURL( "action=submit" );
-               $token = htmlspecialchars( $wgUser->editToken() );
+       protected function alterForm( HTMLForm $form ) {
+               $form->setWrapperLegend( false )
+                       ->setHeaderText( $this->msg( 'unlockdbtext' )->parseAsBlock() )
+                       ->setSubmitTextMsg( 'unlockbtn' );
+       }
 
-               $wgOut->addHTML( <<<END
+       public function onSubmit( array $data ) {
+               if ( !$data['Confirm'] ) {
+                       return Status::newFatal( 'locknoconfirm' );
+               }
 
-<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
-);
+               $readOnlyFile = $this->getConfig()->get( 'ReadOnlyFile' );
+               MediaWiki\suppressWarnings();
+               $res = unlink( $readOnlyFile );
+               MediaWiki\restoreWarnings();
 
+               if ( $res ) {
+                       return Status::newGood();
+               } else {
+                       return Status::newFatal( 'filedeleteerror', $readOnlyFile );
+               }
        }
 
-       function doSubmit() {
-               global $wgOut, $wgRequest, $wgReadOnlyFile;
-
-               $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
-               if ( ! $wpLockConfirm ) {
-                       $this->showForm( wfMsg( "locknoconfirm" ) );
-                       return;
-               }
-               if ( @! unlink( $wgReadOnlyFile ) ) {
-                       $wgOut->showFileDeleteError( $wgReadOnlyFile );
-                       return;
-               }
-               $titleObj = SpecialPage::getTitleFor( "Unlockdb" );
-               $success = $titleObj->getFullURL( "action=success" );
-               $wgOut->redirect( $success );
+       public function onSuccess() {
+               $out = $this->getOutput();
+               $out->addSubtitle( $this->msg( 'unlockdbsuccesssub' ) );
+               $out->addWikiMsg( 'unlockdbsuccesstext' );
        }
 
-       function showSuccess() {
-               global $wgOut;
+       protected function getDisplayFormat() {
+               return 'ooui';
+       }
 
-               $wgOut->setPagetitle( wfMsg( "unlockdb" ) );
-               $wgOut->setSubtitle( wfMsg( "unlockdbsuccesssub" ) );
-               $wgOut->addWikiMsg( "unlockdbsuccesstext" );
+       protected function getGroupName() {
+               return 'wiki';
        }
 }