4 * A form to make the database readonly (eg for maintenance purposes).
8 class SpecialLockdb
extends SpecialPage
{
11 public function __construct() {
12 parent
::__construct( 'Lockdb', 'siteadmin' );
15 public function execute( $par ) {
16 global $wgUser, $wgOut, $wgRequest;
20 if( !$wgUser->isAllowed( 'siteadmin' ) ) {
21 $wgOut->permissionRequired( 'siteadmin' );
25 $this->outputHeader();
27 # If the lock file isn't writable, we can do sweet bugger all
28 global $wgReadOnlyFile;
29 if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
34 $action = $wgRequest->getVal( 'action' );
35 $this->reason
= $wgRequest->getVal( 'wpLockReason', '' );
37 if ( $action == 'success' ) {
39 } else if ( $action == 'submit' && $wgRequest->wasPosted() &&
40 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
47 private function showForm( $err = '' ) {
48 global $wgOut, $wgUser;
50 $wgOut->addWikiMsg( 'lockdbtext' );
53 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
54 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
58 Html
::openElement( 'form', array( 'id' => 'lockdb', 'method' => 'POST',
59 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ). "\n" .
60 wfMsgHtml( 'enterlockreason' ) . ":\n" .
61 Html
::textarea( 'wpLockReason', $this->reason
, array( 'rows' => 4 ) ). "
64 " . Html
::openElement( 'td', array( 'style' => 'text-align:right' ) ) . "
65 " . Html
::input( 'wpLockConfirm', null, 'checkbox' ) . "
67 " . Html
::openElement( 'td', array( 'style' => 'text-align:left' ) ) .
68 wfMsgHtml( 'lockconfirm' ) . "</td>
72 " . Html
::openElement( 'td', array( 'style' => 'text-align:left' ) ) . "
73 " . Html
::input( 'wpLock', wfMsg( 'lockbtn' ), 'submit' ) . "
77 Html
::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
78 Html
::closeElement( 'form' )
83 private function doSubmit() {
84 global $wgOut, $wgUser, $wgContLang, $wgRequest;
85 global $wgReadOnlyFile;
87 if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
88 $this->showForm( wfMsg( 'locknoconfirm' ) );
91 $fp = @fopen
( $wgReadOnlyFile, 'w' );
93 if ( false === $fp ) {
94 # This used to show a file not found error, but the likeliest reason for fopen()
95 # to fail at this point is insufficient permission to write to the file...good old
96 # is_writable() is plain wrong in some cases, it seems...
100 fwrite( $fp, $this->reason
);
101 fwrite( $fp, "\n<p>(by " . $wgUser->getName() . " at " .
102 $wgContLang->timeanddate( wfTimestampNow() ) . ")</p>\n" );
105 $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
108 private function showSuccess() {
111 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
112 $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) );
113 $wgOut->addWikiMsg( 'lockdbsuccesstext' );
116 public static function notWritable() {
118 $wgOut->showErrorPage( 'lockdb', 'lockfilenotwritable' );