00001 <?php
00010 function wfSpecialLockdb() {
00011 global $wgUser, $wgOut, $wgRequest;
00012
00013 if( !$wgUser->isAllowed( 'siteadmin' ) ) {
00014 $wgOut->permissionRequired( 'siteadmin' );
00015 return;
00016 }
00017
00018 # If the lock file isn't writable, we can do sweet bugger all
00019 global $wgReadOnlyFile;
00020 if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
00021 DBLockForm::notWritable();
00022 return;
00023 }
00024
00025 $action = $wgRequest->getVal( 'action' );
00026 $f = new DBLockForm();
00027
00028 if ( 'success' == $action ) {
00029 $f->showSuccess();
00030 } else if ( 'submit' == $action && $wgRequest->wasPosted() &&
00031 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
00032 $f->doSubmit();
00033 } else {
00034 $f->showForm( '' );
00035 }
00036 }
00037
00042 class DBLockForm {
00043 var $reason = '';
00044
00045 function DBLockForm() {
00046 global $wgRequest;
00047 $this->reason = $wgRequest->getText( 'wpLockReason' );
00048 }
00049
00050 function showForm( $err ) {
00051 global $wgOut, $wgUser;
00052
00053 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
00054 $wgOut->addWikiMsg( 'lockdbtext' );
00055
00056 if ( "" != $err ) {
00057 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
00058 $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
00059 }
00060 $lc = htmlspecialchars( wfMsg( 'lockconfirm' ) );
00061 $lb = htmlspecialchars( wfMsg( 'lockbtn' ) );
00062 $elr = htmlspecialchars( wfMsg( 'enterlockreason' ) );
00063 $titleObj = SpecialPage::getTitleFor( 'Lockdb' );
00064 $action = $titleObj->escapeLocalURL( 'action=submit' );
00065 $reason = htmlspecialchars( $this->reason );
00066 $token = htmlspecialchars( $wgUser->editToken() );
00067
00068 $wgOut->addHTML( <<<END
00069 <form id="lockdb" method="post" action="{$action}">
00070 {$elr}:
00071 <textarea name="wpLockReason" rows="10" cols="60" wrap="virtual">{$reason}</textarea>
00072 <table border="0">
00073 <tr>
00074 <td align="right">
00075 <input type="checkbox" name="wpLockConfirm" />
00076 </td>
00077 <td align="left">{$lc}</td>
00078 </tr>
00079 <tr>
00080 <td> </td>
00081 <td align="left">
00082 <input type="submit" name="wpLock" value="{$lb}" />
00083 </td>
00084 </tr>
00085 </table>
00086 <input type="hidden" name="wpEditToken" value="{$token}" />
00087 </form>
00088 END
00089 );
00090
00091 }
00092
00093 function doSubmit() {
00094 global $wgOut, $wgUser, $wgLang, $wgRequest;
00095 global $wgReadOnlyFile;
00096
00097 if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
00098 $this->showForm( wfMsg( 'locknoconfirm' ) );
00099 return;
00100 }
00101 $fp = @fopen( $wgReadOnlyFile, 'w' );
00102
00103 if ( false === $fp ) {
00104 # This used to show a file not found error, but the likeliest reason for fopen()
00105 # to fail at this point is insufficient permission to write to the file...good old
00106 # is_writable() is plain wrong in some cases, it seems...
00107 self::notWritable();
00108 return;
00109 }
00110 fwrite( $fp, $this->reason );
00111 fwrite( $fp, "\n<p>(by " . $wgUser->getName() . " at " .
00112 $wgLang->timeanddate( wfTimestampNow() ) . ")</p>\n" );
00113 fclose( $fp );
00114
00115 $titleObj = SpecialPage::getTitleFor( 'Lockdb' );
00116 $wgOut->redirect( $titleObj->getFullURL( 'action=success' ) );
00117 }
00118
00119 function showSuccess() {
00120 global $wgOut;
00121
00122 $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
00123 $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) );
00124 $wgOut->addWikiMsg( 'lockdbsuccesstext' );
00125 }
00126
00127 public static function notWritable() {
00128 global $wgOut;
00129 $wgOut->showErrorPage( 'lockdb', 'lockfilenotwritable' );
00130 }
00131 }