*
* @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();
+ public function requiresWrite() {
+ return false;
+ }
- if( !$wgUser->isAllowed( 'siteadmin' ) ) {
- $wgOut->permissionRequired( 'siteadmin' );
- 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' );
}
+ }
- $this->outputHeader();
-
- $action = $wgRequest->getVal( 'action' );
-
- if ( $action == 'success' ) {
- $this->showSuccess();
- } else if ( $action == 'submit' && $wgRequest->wasPosted() &&
- $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
- $this->doSubmit();
- } else {
- $this->showForm();
- }
+ protected function getFormFields() {
+ return array(
+ 'Confirm' => array(
+ 'type' => 'toggle',
+ 'label-message' => 'unlockconfirm',
+ ),
+ );
}
- private function showForm( $err = '' ) {
- global $wgOut, $wgUser;
+ protected function alterForm( HTMLForm $form ) {
+ $form->setWrapperLegend( false );
+ $form->setHeaderText( $this->msg( 'unlockdbtext' )->parseAsBlock() );
+ $form->setSubmitTextMsg( 'unlockbtn' );
+ }
- global $wgReadOnlyFile;
- if( !file_exists( $wgReadOnlyFile ) ) {
- $wgOut->addWikiMsg( 'databasenotlocked' );
- return;
+ public function onSubmit( array $data ) {
+ if ( !$data['Confirm'] ) {
+ return Status::newFatal( 'locknoconfirm' );
}
- $wgOut->addWikiMsg( 'unlockdbtext' );
+ $readOnlyFile = $this->getConfig()->get( 'ReadOnlyFile' );
+ wfSuppressWarnings();
+ $res = unlink( $readOnlyFile );
+ wfRestoreWarnings();
- if ( $err != '' ) {
- $wgOut->setSubtitle( wfMsg( 'formerror' ) );
- $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
+ if ( $res ) {
+ return Status::newGood();
+ } else {
+ return Status::newFatal( 'filedeleteerror', $readOnlyFile );
}
-
- $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> </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' )
- );
-
}
- private function doSubmit() {
- global $wgOut, $wgRequest, $wgReadOnlyFile;
-
- $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
- if ( !$wpLockConfirm ) {
- $this->showForm( wfMsg( 'locknoconfirm' ) );
- return;
- }
- if ( @!unlink( $wgReadOnlyFile ) ) {
- $wgOut->showFileDeleteError( $wgReadOnlyFile );
- return;
- }
-
- $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
+ public function onSuccess() {
+ $out = $this->getOutput();
+ $out->addSubtitle( $this->msg( 'unlockdbsuccesssub' ) );
+ $out->addWikiMsg( 'unlockdbsuccesstext' );
}
- private function showSuccess() {
- global $wgOut;
-
- $wgOut->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) );
- $wgOut->addWikiMsg( 'unlockdbsuccesstext' );
+ protected function getGroupName() {
+ return 'wiki';
}
}