summaryrefslogtreecommitdiff
path: root/includes/specials/SpecialUnlockdb.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/specials/SpecialUnlockdb.php')
-rw-r--r--includes/specials/SpecialUnlockdb.php104
1 files changed, 32 insertions, 72 deletions
diff --git a/includes/specials/SpecialUnlockdb.php b/includes/specials/SpecialUnlockdb.php
index 95ad0bf5..2e772540 100644
--- a/includes/specials/SpecialUnlockdb.php
+++ b/includes/specials/SpecialUnlockdb.php
@@ -26,102 +26,62 @@
*
* @ingroup SpecialPage
*/
-class SpecialUnlockdb extends SpecialPage {
+class SpecialUnlockdb extends FormSpecialPage {
public function __construct() {
parent::__construct( 'Unlockdb', 'siteadmin' );
}
- public function execute( $par ) {
- global $wgUser, $wgRequest;
-
- $this->setHeaders();
-
- # Permission check
- if( !$this->userCanExecute( $wgUser ) ) {
- $this->displayRestrictionError();
- 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;
-
+ public function checkExecutePermissions( User $user ) {
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" );
+ parent::checkExecutePermissions( $user );
+ # If the lock file isn't writable, we can do sweet bugger all
+ if ( !file_exists( $wgReadOnlyFile ) ) {
+ 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',
+ ),
);
+ }
+ protected function alterForm( HTMLForm $form ) {
+ $form->setWrapperLegend( false );
+ $form->setHeaderText( $this->msg( 'unlockdbtext' )->parseAsBlock() );
+ $form->setSubmitTextMsg( 'unlockbtn' );
}
- private function doSubmit() {
- global $wgOut, $wgRequest, $wgReadOnlyFile;
+ public function onSubmit( array $data ) {
+ global $wgReadOnlyFile;
- $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
- if ( !$wpLockConfirm ) {
- $this->showForm( wfMsg( 'locknoconfirm' ) );
- return;
+ if ( !$data['Confirm'] ) {
+ return Status::newFatal( 'locknoconfirm' );
}
wfSuppressWarnings();
$res = unlink( $wgReadOnlyFile );
wfRestoreWarnings();
- if ( !$res ) {
- $wgOut->showFileDeleteError( $wgReadOnlyFile );
- return;
+ if ( $res ) {
+ return Status::newGood();
+ } else {
+ return Status::newFatal( 'filedeleteerror', $wgReadOnlyFile );
}
-
- $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
}
- private function showSuccess() {
- global $wgOut;
-
- $wgOut->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) );
- $wgOut->addWikiMsg( 'unlockdbsuccesstext' );
+ public function onSuccess() {
+ $out = $this->getOutput();
+ $out->addSubtitle( $this->msg( 'unlockdbsuccesssub' ) );
+ $out->addWikiMsg( 'unlockdbsuccesstext' );
}
}