10 function wfSpecialLockdb() {
11 global $wgUser, $wgOut, $wgRequest;
13 if( !$wgUser->isAllowed( 'siteadmin' ) ) {
14 $wgOut->permissionRequired( 'siteadmin' );
18 # If the lock file isn't writable, we can do sweet bugger all
19 global $wgReadOnlyFile;
20 if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
21 DBLockForm
::notWritable();
25 $action = $wgRequest->getVal( 'action' );
26 $f = new DBLockForm();
28 if ( 'success' == $action ) {
30 } else if ( 'submit' == $action && $wgRequest->wasPosted() &&
31 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
39 * A form to make the database readonly (eg for maintenance purposes).
40 * @ingroup SpecialPage
45 function DBLockForm() {
47 $this->reason
= $wgRequest->getText( 'wpLockReason' );
50 function showForm( $err ) {
51 global $wgOut, $wgUser;
53 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
54 $wgOut->addWikiMsg( 'lockdbtext' );
57 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
58 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
60 $lc = htmlspecialchars( wfMsg( 'lockconfirm' ) );
61 $lb = htmlspecialchars( wfMsg( 'lockbtn' ) );
62 $elr = htmlspecialchars( wfMsg( 'enterlockreason' ) );
63 $titleObj = SpecialPage
::getTitleFor( 'Lockdb' );
64 $action = $titleObj->escapeLocalURL( 'action=submit' );
65 $reason = htmlspecialchars( $this->reason
);
66 $token = htmlspecialchars( $wgUser->editToken() );
68 $wgOut->addHTML( <<<END
69 <form id="lockdb" method="post" action="{$action}">
71 <textarea name="wpLockReason" rows="10" cols="60" wrap="virtual">{$reason}</textarea>
75 <input type="checkbox" name="wpLockConfirm" />
77 <td align="left">{$lc}</td>
82 <input type="submit" name="wpLock" value="{$lb}" />
86 <input type="hidden" name="wpEditToken" value="{$token}" />
94 global $wgOut, $wgUser, $wgLang, $wgRequest;
95 global $wgReadOnlyFile;
97 if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
98 $this->showForm( wfMsg( 'locknoconfirm' ) );
101 $fp = @fopen
( $wgReadOnlyFile, 'w' );
103 if ( false === $fp ) {
104 # This used to show a file not found error, but the likeliest reason for fopen()
105 # to fail at this point is insufficient permission to write to the file...good old
106 # is_writable() is plain wrong in some cases, it seems...
110 fwrite( $fp, $this->reason
);
111 fwrite( $fp, "\n<p>(by " . $wgUser->getName() . " at " .
112 $wgLang->timeanddate( wfTimestampNow() ) . ")</p>\n" );
115 $titleObj = SpecialPage
::getTitleFor( 'Lockdb' );
116 $wgOut->redirect( $titleObj->getFullURL( 'action=success' ) );
119 function showSuccess() {
122 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
123 $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) );
124 $wgOut->addWikiMsg( 'lockdbsuccesstext' );
127 public static function notWritable() {
129 $wgOut->showErrorPage( 'lockdb', 'lockfilenotwritable' );