Fix bug that brakes the 'jquery.tabIndex > firstTabIndex' test in IE8/IE9. Some value...
[mediawiki.git] / includes / specials / SpecialLockdb.php
blob609b9c543c4eef0fd344371e7054e6e72488b1a4
1 <?php
2 /**
3 * Implements Special:Lockdb
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.
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.
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
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * A form to make the database readonly (eg for maintenance purposes).
27 * @ingroup SpecialPage
29 class SpecialLockdb extends SpecialPage {
30 var $reason = '';
32 public function __construct() {
33 parent::__construct( 'Lockdb', 'siteadmin' );
36 public function execute( $par ) {
37 global $wgUser, $wgOut, $wgRequest;
39 $this->setHeaders();
41 if( !$wgUser->isAllowed( 'siteadmin' ) ) {
42 $wgOut->permissionRequired( 'siteadmin' );
43 return;
46 $this->outputHeader();
48 # If the lock file isn't writable, we can do sweet bugger all
49 global $wgReadOnlyFile;
50 if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
51 self::notWritable();
52 return;
55 $action = $wgRequest->getVal( 'action' );
56 $this->reason = $wgRequest->getVal( 'wpLockReason', '' );
58 if ( $action == 'success' ) {
59 $this->showSuccess();
60 } else if ( $action == 'submit' && $wgRequest->wasPosted() &&
61 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
62 $this->doSubmit();
63 } else {
64 $this->showForm();
68 private function showForm( $err = '' ) {
69 global $wgOut, $wgUser;
71 $wgOut->addWikiMsg( 'lockdbtext' );
73 if ( $err != '' ) {
74 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
75 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
78 $wgOut->addHTML(
79 Html::openElement( 'form', array( 'id' => 'lockdb', 'method' => 'POST',
80 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ). "\n" .
81 wfMsgHtml( 'enterlockreason' ) . ":\n" .
82 Html::textarea( 'wpLockReason', $this->reason, array( 'rows' => 4 ) ). "
83 <table>
84 <tr>
85 " . Html::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
86 " . Html::input( 'wpLockConfirm', null, 'checkbox' ) . "
87 </td>
88 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
89 wfMsgHtml( 'lockconfirm' ) . "</td>
90 </tr>
91 <tr>
92 <td>&#160;</td>
93 " . Html::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
94 " . Html::input( 'wpLock', wfMsg( 'lockbtn' ), 'submit' ) . "
95 </td>
96 </tr>
97 </table>\n" .
98 Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
99 Html::closeElement( 'form' )
104 private function doSubmit() {
105 global $wgOut, $wgUser, $wgContLang, $wgRequest;
106 global $wgReadOnlyFile;
108 if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
109 $this->showForm( wfMsg( 'locknoconfirm' ) );
110 return;
113 wfSuppressWarnings();
114 $fp = fopen( $wgReadOnlyFile, 'w' );
115 wfRestoreWarnings();
117 if ( false === $fp ) {
118 # This used to show a file not found error, but the likeliest reason for fopen()
119 # to fail at this point is insufficient permission to write to the file...good old
120 # is_writable() is plain wrong in some cases, it seems...
121 self::notWritable();
122 return;
124 fwrite( $fp, $this->reason );
125 fwrite( $fp, "\n<p>" . wfMsgExt(
126 'lockedbyandtime',
127 'content',
128 $wgUser->getName(),
129 $wgContLang->date( wfTimestampNow() ),
130 $wgContLang->time( wfTimestampNow() )
131 ) . "</p>\n" );
132 fclose( $fp );
134 $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
137 private function showSuccess() {
138 global $wgOut;
140 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
141 $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) );
142 $wgOut->addWikiMsg( 'lockdbsuccesstext' );
145 public static function notWritable() {
146 global $wgOut;
147 $wgOut->showErrorPage( 'lockdb', 'lockfilenotwritable' );