Changes to Special:Lockdb and Special:Unlockdb:
[lhc/web/wiklou.git] / includes / specials / SpecialUnlockdb.php
1 <?php
2
3 /**
4 * Implements Special:Unlockdb
5 *
6 * @ingroup SpecialPage
7 */
8 class SpecialUnlockdb extends SpecialPage {
9
10 public function __construct() {
11 parent::__construct( 'Unlockdb', 'siteadmin' );
12 }
13
14 public function execute( $par ) {
15 global $wgUser, $wgOut, $wgRequest;
16
17 $this->setHeaders();
18
19 if( !$wgUser->isAllowed( 'siteadmin' ) ) {
20 $wgOut->permissionRequired( 'siteadmin' );
21 return;
22 }
23
24 $this->outputHeader();
25
26 $action = $wgRequest->getVal( 'action' );
27
28 if ( $action == 'success' ) {
29 $this->showSuccess();
30 } else if ( $action == 'submit' && $wgRequest->wasPosted() &&
31 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
32 $this->doSubmit();
33 } else {
34 $this->showForm();
35 }
36 }
37
38 private function showForm( $err = '' ) {
39 global $wgOut, $wgUser;
40
41 global $wgReadOnlyFile;
42 if( !file_exists( $wgReadOnlyFile ) ) {
43 $wgOut->addWikiMsg( 'databasenotlocked' );
44 return;
45 }
46
47 $wgOut->addWikiMsg( 'unlockdbtext' );
48
49 if ( $err != '' ) {
50 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
51 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
52 }
53
54 $wgOut->addHTML(
55 Html::openElement( 'form', array( 'id' => 'unlockdb', 'method' => 'POST',
56 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ) . "
57 <table>
58 <tr>
59 " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
60 " . Html::input( 'wpLockConfirm', null, 'checkbox' ) . "
61 </td>
62 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
63 wfMsgHtml( 'unlockconfirm' ) . "</td>
64 </tr>
65 <tr>
66 <td>&#160;</td>
67 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
68 " . Html::input( 'wpLock', wfMsg( 'unlockbtn' ), 'submit' ) . "
69 </td>
70 </tr>
71 </table>\n" .
72 Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
73 Html::closeElement( 'form' )
74 );
75
76 }
77
78 private function doSubmit() {
79 global $wgOut, $wgRequest, $wgReadOnlyFile;
80
81 $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
82 if ( !$wpLockConfirm ) {
83 $this->showForm( wfMsg( 'locknoconfirm' ) );
84 return;
85 }
86 if ( @!unlink( $wgReadOnlyFile ) ) {
87 $wgOut->showFileDeleteError( $wgReadOnlyFile );
88 return;
89 }
90
91 $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
92 }
93
94 private function showSuccess() {
95 global $wgOut;
96
97 $wgOut->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) );
98 $wgOut->addWikiMsg( 'unlockdbsuccesstext' );
99 }
100 }