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
21 * @ingroup SpecialPage
25 * A form to make the database readonly (eg for maintenance purposes).
27 * @ingroup SpecialPage
29 class SpecialLockdb
extends SpecialPage
{
32 public function __construct() {
33 parent
::__construct( 'Lockdb', 'siteadmin' );
36 public function execute( $par ) {
37 global $wgUser, $wgRequest;
42 if( !$this->userCanExecute( $wgUser ) ) {
43 $this->displayRestrictionError();
47 $this->outputHeader();
49 # If the lock file isn't writable, we can do sweet bugger all
50 global $wgReadOnlyFile;
51 if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
56 $action = $wgRequest->getVal( 'action' );
57 $this->reason
= $wgRequest->getVal( 'wpLockReason', '' );
59 if ( $action == 'success' ) {
61 } elseif ( $action == 'submit' && $wgRequest->wasPosted() &&
62 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
69 private function showForm( $err = '' ) {
70 global $wgOut, $wgUser;
72 $wgOut->addWikiMsg( 'lockdbtext' );
75 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
76 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
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 ) ). "
86 " . Html
::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
87 " . Html
::input( 'wpLockConfirm', null, 'checkbox', array( 'id' => 'mw-input-wplockconfirm' ) ) . "
89 " . Html
::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
90 Html
::openElement( 'label', array( 'for' => 'mw-input-wplockconfirm' ) ) .
92 wfMsgHtml( 'lockconfirm' ) . "</label></td>
96 " . Html
::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
97 " . Html
::input( 'wpLock', wfMsg( 'lockbtn' ), 'submit' ) . "
101 Html
::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
102 Html
::closeElement( 'form' )
107 private function doSubmit() {
108 global $wgOut, $wgUser, $wgContLang, $wgRequest;
109 global $wgReadOnlyFile;
111 if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
112 $this->showForm( wfMsg( 'locknoconfirm' ) );
116 wfSuppressWarnings();
117 $fp = fopen( $wgReadOnlyFile, 'w' );
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...
127 fwrite( $fp, $this->reason
);
128 $timestamp = wfTimestampNow();
129 fwrite( $fp, "\n<p>" . wfMsgExt(
131 array( 'content', 'parsemag' ),
133 $wgContLang->date( $timestamp ),
134 $wgContLang->time( $timestamp )
138 $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
141 private function showSuccess() {
144 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
145 $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) );
146 $wgOut->addWikiMsg( 'lockdbsuccesstext' );
149 public static function notWritable() {
151 $wgOut->showErrorPage( 'lockdb', 'lockfilenotwritable' );