a5e8443a0efc1229f2c62332bf9c991d9d1ab353
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
21 * A form to make the database readonly (eg for maintenance purposes).
23 * @ingroup SpecialPage
25 class SpecialLockdb
extends SpecialPage
{
28 public function __construct() {
29 parent
::__construct( 'Lockdb', 'siteadmin' );
32 public function execute( $par ) {
33 global $wgUser, $wgOut, $wgRequest;
37 if( !$wgUser->isAllowed( 'siteadmin' ) ) {
38 $wgOut->permissionRequired( 'siteadmin' );
42 $this->outputHeader();
44 # If the lock file isn't writable, we can do sweet bugger all
45 global $wgReadOnlyFile;
46 if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
51 $action = $wgRequest->getVal( 'action' );
52 $this->reason
= $wgRequest->getVal( 'wpLockReason', '' );
54 if ( $action == 'success' ) {
56 } else if ( $action == 'submit' && $wgRequest->wasPosted() &&
57 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
64 private function showForm( $err = '' ) {
65 global $wgOut, $wgUser;
67 $wgOut->addWikiMsg( 'lockdbtext' );
70 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
71 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
75 Html
::openElement( 'form', array( 'id' => 'lockdb', 'method' => 'POST',
76 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ). "\n" .
77 wfMsgHtml( 'enterlockreason' ) . ":\n" .
78 Html
::textarea( 'wpLockReason', $this->reason
, array( 'rows' => 4 ) ). "
81 " . Html
::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
82 " . Html
::input( 'wpLockConfirm', null, 'checkbox' ) . "
84 " . Html
::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
85 wfMsgHtml( 'lockconfirm' ) . "</td>
89 " . Html
::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
90 " . Html
::input( 'wpLock', wfMsg( 'lockbtn' ), 'submit' ) . "
94 Html
::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
95 Html
::closeElement( 'form' )
100 private function doSubmit() {
101 global $wgOut, $wgUser, $wgContLang, $wgRequest;
102 global $wgReadOnlyFile;
104 if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
105 $this->showForm( wfMsg( 'locknoconfirm' ) );
108 $fp = @fopen
( $wgReadOnlyFile, 'w' );
110 if ( false === $fp ) {
111 # This used to show a file not found error, but the likeliest reason for fopen()
112 # to fail at this point is insufficient permission to write to the file...good old
113 # is_writable() is plain wrong in some cases, it seems...
117 fwrite( $fp, $this->reason
);
118 fwrite( $fp, "\n<p>(by " . $wgUser->getName() . " at " .
119 $wgContLang->timeanddate( wfTimestampNow() ) . ")</p>\n" );
122 $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
125 private function showSuccess() {
128 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
129 $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) );
130 $wgOut->addWikiMsg( 'lockdbsuccesstext' );
133 public static function notWritable() {
135 $wgOut->showErrorPage( 'lockdb', 'lockfilenotwritable' );