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' ) . "
89 " . Html
::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
90 wfMsgHtml( 'lockconfirm' ) . "</td>
94 " . Html
::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
95 " . Html
::input( 'wpLock', wfMsg( 'lockbtn' ), 'submit' ) . "
99 Html
::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
100 Html
::closeElement( 'form' )
105 private function doSubmit() {
106 global $wgOut, $wgUser, $wgContLang, $wgRequest;
107 global $wgReadOnlyFile;
109 if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
110 $this->showForm( wfMsg( 'locknoconfirm' ) );
114 wfSuppressWarnings();
115 $fp = fopen( $wgReadOnlyFile, 'w' );
118 if ( false === $fp ) {
119 # This used to show a file not found error, but the likeliest reason for fopen()
120 # to fail at this point is insufficient permission to write to the file...good old
121 # is_writable() is plain wrong in some cases, it seems...
125 fwrite( $fp, $this->reason
);
126 $timestamp = wfTimestampNow();
127 fwrite( $fp, "\n<p>" . wfMsgExt(
129 array( 'content', 'parsemag' ),
131 $wgContLang->date( $timestamp ),
132 $wgContLang->time( $timestamp )
136 $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
139 private function showSuccess() {
142 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
143 $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) );
144 $wgOut->addWikiMsg( 'lockdbsuccesstext' );
147 public static function notWritable() {
149 $wgOut->showErrorPage( 'lockdb', 'lockfilenotwritable' );