adding label atttributes for confirm checkboxes in SpecialLockdb and SpecialUnlockdb...
[lhc/web/wiklou.git] / includes / specials / SpecialLockdb.php
1 <?php
2 /**
3 * Implements Special:Lockdb
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 * A form to make the database readonly (eg for maintenance purposes).
26 *
27 * @ingroup SpecialPage
28 */
29 class SpecialLockdb extends SpecialPage {
30 var $reason = '';
31
32 public function __construct() {
33 parent::__construct( 'Lockdb', 'siteadmin' );
34 }
35
36 public function execute( $par ) {
37 global $wgUser, $wgRequest;
38
39 $this->setHeaders();
40
41 # Permission check
42 if( !$this->userCanExecute( $wgUser ) ) {
43 $this->displayRestrictionError();
44 return;
45 }
46
47 $this->outputHeader();
48
49 # If the lock file isn't writable, we can do sweet bugger all
50 global $wgReadOnlyFile;
51 if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
52 self::notWritable();
53 return;
54 }
55
56 $action = $wgRequest->getVal( 'action' );
57 $this->reason = $wgRequest->getVal( 'wpLockReason', '' );
58
59 if ( $action == 'success' ) {
60 $this->showSuccess();
61 } elseif ( $action == 'submit' && $wgRequest->wasPosted() &&
62 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
63 $this->doSubmit();
64 } else {
65 $this->showForm();
66 }
67 }
68
69 private function showForm( $err = '' ) {
70 global $wgOut, $wgUser;
71
72 $wgOut->addWikiMsg( 'lockdbtext' );
73
74 if ( $err != '' ) {
75 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
76 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
77 }
78
79 $wgOut->addHTML(
80 Html::openElement( 'form', array( 'id' => 'lockdb', 'method' => 'POST',
81 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ). "\n" .
82 wfMsgHtml( 'enterlockreason' ) . ":\n" .
83 Html::textarea( 'wpLockReason', $this->reason, array( 'rows' => 4 ) ). "
84 <table>
85 <tr>
86 " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
87 " . Html::input( 'wpLockConfirm', null, 'checkbox', array( 'id' => 'mw-input-wplockconfirm' ) ) . "
88 </td>
89 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
90 Html::openElement( 'label', array( 'for' => 'mw-input-wplockconfirm' ) ) .
91
92 wfMsgHtml( 'lockconfirm' ) . "</label></td>
93 </tr>
94 <tr>
95 <td>&#160;</td>
96 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
97 " . Html::input( 'wpLock', wfMsg( 'lockbtn' ), 'submit' ) . "
98 </td>
99 </tr>
100 </table>\n" .
101 Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
102 Html::closeElement( 'form' )
103 );
104
105 }
106
107 private function doSubmit() {
108 global $wgOut, $wgUser, $wgContLang, $wgRequest;
109 global $wgReadOnlyFile;
110
111 if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
112 $this->showForm( wfMsg( 'locknoconfirm' ) );
113 return;
114 }
115
116 wfSuppressWarnings();
117 $fp = fopen( $wgReadOnlyFile, 'w' );
118 wfRestoreWarnings();
119
120 if ( false === $fp ) {
121 # This used to show a file not found error, but the likeliest reason for fopen()
122 # to fail at this point is insufficient permission to write to the file...good old
123 # is_writable() is plain wrong in some cases, it seems...
124 self::notWritable();
125 return;
126 }
127 fwrite( $fp, $this->reason );
128 $timestamp = wfTimestampNow();
129 fwrite( $fp, "\n<p>" . wfMsgExt(
130 'lockedbyandtime',
131 array( 'content', 'parsemag' ),
132 $wgUser->getName(),
133 $wgContLang->date( $timestamp ),
134 $wgContLang->time( $timestamp )
135 ) . "</p>\n" );
136 fclose( $fp );
137
138 $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
139 }
140
141 private function showSuccess() {
142 global $wgOut;
143
144 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
145 $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) );
146 $wgOut->addWikiMsg( 'lockdbsuccesstext' );
147 }
148
149 public static function notWritable() {
150 global $wgOut;
151 $wgOut->showErrorPage( 'lockdb', 'lockfilenotwritable' );
152 }
153 }