adding label atttributes for confirm checkboxes in SpecialLockdb and SpecialUnlockdb...
[lhc/web/wiklou.git] / includes / specials / SpecialUnlockdb.php
1 <?php
2 /**
3 * Implements Special:Unlockdb
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * Implements Special:Unlockdb
26 *
27 * @ingroup SpecialPage
28 */
29 class SpecialUnlockdb extends SpecialPage {
30
31 public function __construct() {
32 parent::__construct( 'Unlockdb', 'siteadmin' );
33 }
34
35 public function execute( $par ) {
36 global $wgUser, $wgRequest;
37
38 $this->setHeaders();
39
40 # Permission check
41 if( !$this->userCanExecute( $wgUser ) ) {
42 $this->displayRestrictionError();
43 return;
44 }
45
46 $this->outputHeader();
47
48 $action = $wgRequest->getVal( 'action' );
49
50 if ( $action == 'success' ) {
51 $this->showSuccess();
52 } elseif ( $action == 'submit' && $wgRequest->wasPosted() &&
53 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
54 $this->doSubmit();
55 } else {
56 $this->showForm();
57 }
58 }
59
60 private function showForm( $err = '' ) {
61 global $wgOut, $wgUser;
62
63 global $wgReadOnlyFile;
64 if( !file_exists( $wgReadOnlyFile ) ) {
65 $wgOut->addWikiMsg( 'databasenotlocked' );
66 return;
67 }
68
69 $wgOut->addWikiMsg( 'unlockdbtext' );
70
71 if ( $err != '' ) {
72 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
73 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
74 }
75
76 $wgOut->addHTML(
77 Html::openElement( 'form', array( 'id' => 'unlockdb', 'method' => 'POST',
78 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ) . "
79 <table>
80 <tr>
81 " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
82 " . Html::input( 'wpLockConfirm', null, 'checkbox', array( 'id' => 'mw-input-wpunlockconfirm' ) ) . "
83 </td>
84 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
85 Html::openElement( 'label', array( 'for' => 'mw-input-wpunlockconfirm' ) ) .
86 wfMsgHtml( 'unlockconfirm' ) . "</label></td>
87 </tr>
88 <tr>
89 <td>&#160;</td>
90 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
91 " . Html::input( 'wpLock', wfMsg( 'unlockbtn' ), 'submit' ) . "
92 </td>
93 </tr>
94 </table>\n" .
95 Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
96 Html::closeElement( 'form' )
97 );
98
99 }
100
101 private function doSubmit() {
102 global $wgOut, $wgRequest, $wgReadOnlyFile;
103
104 $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
105 if ( !$wpLockConfirm ) {
106 $this->showForm( wfMsg( 'locknoconfirm' ) );
107 return;
108 }
109
110 wfSuppressWarnings();
111 $res = unlink( $wgReadOnlyFile );
112 wfRestoreWarnings();
113
114 if ( !$res ) {
115 $wgOut->showFileDeleteError( $wgReadOnlyFile );
116 return;
117 }
118
119 $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
120 }
121
122 private function showSuccess() {
123 global $wgOut;
124
125 $wgOut->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) );
126 $wgOut->addWikiMsg( 'unlockdbsuccesstext' );
127 }
128 }