Merge "Use Xml::element instead of Html::element for empty elements"
[lhc/web/wiklou.git] / includes / specials / SpecialUnlockdb.php
index 5fbf38a..a8b97d7 100644 (file)
  *
  * @ingroup SpecialPage
  */
-class SpecialUnlockdb extends SpecialPage {
+class SpecialUnlockdb extends FormSpecialPage {
 
        public function __construct() {
                parent::__construct( 'Unlockdb', 'siteadmin' );
        }
 
-       public function execute( $par ) {
-               global $wgUser, $wgOut, $wgRequest;
-
-               $this->setHeaders();
-
-               if( !$wgUser->isAllowed( 'siteadmin' ) ) {
-                       $wgOut->permissionRequired( 'siteadmin' );
-                       return;
-               }
-
-               $this->outputHeader();
-
-               $action = $wgRequest->getVal( 'action' );
-
-               if ( $action == 'success' ) {
-                       $this->showSuccess();
-               } elseif ( $action == 'submit' && $wgRequest->wasPosted() &&
-                       $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
-                       $this->doSubmit();
-               } else {
-                       $this->showForm();
-               }
+       public function requiresWrite() {
+               return false;
        }
 
-       private function showForm( $err = '' ) {
-               global $wgOut, $wgUser;
-
-               global $wgReadOnlyFile;
-               if( !file_exists( $wgReadOnlyFile ) ) {
-                       $wgOut->addWikiMsg( 'databasenotlocked' );
-                       return;
-               }
-
-               $wgOut->addWikiMsg( 'unlockdbtext' );
-
-               if ( $err != '' ) {
-                       $wgOut->setSubtitle( wfMsg( 'formerror' ) );
-                       $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
+       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->addHTML(
-                       Html::openElement( 'form', array( 'id' => 'unlockdb', 'method' => 'POST',
-                               'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ) . "
-<table>
-       <tr>
-               " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
-                       " . Html::input( 'wpLockConfirm', null, 'checkbox' ) . "
-               </td>
-               " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
-                       wfMsgHtml( 'unlockconfirm' ) . "</td>
-       </tr>
-       <tr>
-               <td>&#160;</td>
-               " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
-                       " . Html::input( 'wpLock', wfMsg( 'unlockbtn' ), 'submit' ) . "
-               </td>
-       </tr>
-</table>\n" .
-                       Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
-                       Html::closeElement( 'form' )
+       protected function getFormFields() {
+               return array(
+                       'Confirm' => array(
+                               'type' => 'toggle',
+                               'label-message' => 'unlockconfirm',
+                       ),
                );
-
        }
 
-       private function doSubmit() {
-               global $wgOut, $wgRequest, $wgReadOnlyFile;
+       protected function alterForm( HTMLForm $form ) {
+               $form->setWrapperLegend( false );
+               $form->setHeaderText( $this->msg( 'unlockdbtext' )->parseAsBlock() );
+               $form->setSubmitTextMsg( 'unlockbtn' );
+       }
 
-               $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
-               if ( !$wpLockConfirm ) {
-                       $this->showForm( wfMsg( 'locknoconfirm' ) );
-                       return;
+       public function onSubmit( array $data ) {
+               if ( !$data['Confirm'] ) {
+                       return Status::newFatal( 'locknoconfirm' );
                }
 
+               $readOnlyFile = $this->getConfig()->get( 'ReadOnlyFile' );
                wfSuppressWarnings();
-               $res = unlink( $wgReadOnlyFile );
+               $res = unlink( $readOnlyFile );
                wfRestoreWarnings();
 
-               if ( !$res ) {
-                       $wgOut->showFileDeleteError( $wgReadOnlyFile );
-                       return;
+               if ( $res ) {
+                       return Status::newGood();
+               } else {
+                       return Status::newFatal( 'filedeleteerror', $readOnlyFile );
                }
-
-               $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
        }
 
-       private function showSuccess() {
-               global $wgOut;
+       public function onSuccess() {
+               $out = $this->getOutput();
+               $out->addSubtitle( $this->msg( 'unlockdbsuccesssub' ) );
+               $out->addWikiMsg( 'unlockdbsuccesstext' );
+       }
 
-               $wgOut->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) );
-               $wgOut->addWikiMsg( 'unlockdbsuccesstext' );
+       protected function getGroupName() {
+               return 'wiki';
        }
 }