X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialLockdb.php;h=e57717e2d2b40b30e88dcd2ef5abd4bcce12edd6;hb=3518d9bb74a5cf2962712d6f8ecccbf2a5cbd0fa;hp=d0be5d8e7d428361c1b17f09236fa34fbe223b22;hpb=2ca68a256dae9a27b3b79f950eb7ef69c337fe60;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialLockdb.php b/includes/SpecialLockdb.php index d0be5d8e7d..e57717e2d2 100644 --- a/includes/SpecialLockdb.php +++ b/includes/SpecialLockdb.php @@ -1,8 +1,7 @@ isAllowed('siteadmin') ) { - $wgOut->developerRequired(); + if( !$wgUser->isAllowed( 'siteadmin' ) ) { + $wgOut->permissionRequired( 'siteadmin' ); return; } + + # If the lock file isn't writable, we can do sweet bugger all + global $wgReadOnlyFile; + if( !is_writable( dirname( $wgReadOnlyFile ) ) ) { + DBLockForm::notWritable(); + return; + } + $action = $wgRequest->getVal( 'action' ); $f = new DBLockForm(); @@ -29,18 +36,17 @@ function wfSpecialLockdb() { } /** - * - * @package MediaWiki - * @subpackage SpecialPage + * A form to make the database readonly (eg for maintenance purposes). + * @addtogroup SpecialPage */ class DBLockForm { var $reason = ''; - + function DBLockForm() { global $wgRequest; $this->reason = $wgRequest->getText( 'wpLockReason' ); } - + function showForm( $err ) { global $wgOut, $wgUser; @@ -54,14 +60,15 @@ class DBLockForm { $lc = htmlspecialchars( wfMsg( 'lockconfirm' ) ); $lb = htmlspecialchars( wfMsg( 'lockbtn' ) ); $elr = htmlspecialchars( wfMsg( 'enterlockreason' ) ); - $titleObj = Title::makeTitle( NS_SPECIAL, 'Lockdb' ); + $titleObj = SpecialPage::getTitleFor( 'Lockdb' ); $action = $titleObj->escapeLocalURL( 'action=submit' ); + $reason = htmlspecialchars( $this->reason ); $token = htmlspecialchars( $wgUser->editToken() ); $wgOut->addHTML( << {$elr}: - +
@@ -91,10 +98,13 @@ END $this->showForm( wfMsg( 'locknoconfirm' ) ); return; } - $fp = fopen( $wgReadOnlyFile, 'w' ); + $fp = @fopen( $wgReadOnlyFile, 'w' ); if ( false === $fp ) { - $wgOut->fileNotFoundError( $wgReadOnlyFile ); + # This used to show a file not found error, but the likeliest reason for fopen() + # to fail at this point is insufficient permission to write to the file...good old + # is_writable() is plain wrong in some cases, it seems... + $this->notWritable(); return; } fwrite( $fp, $this->reason ); @@ -102,17 +112,23 @@ END $wgLang->timeanddate( wfTimestampNow() ) . ")\n" ); fclose( $fp ); - $titleObj = Title::makeTitle( NS_SPECIAL, 'Lockdb' ); + $titleObj = SpecialPage::getTitleFor( 'Lockdb' ); $wgOut->redirect( $titleObj->getFullURL( 'action=success' ) ); } function showSuccess() { - global $wgOut, $wgUser; + global $wgOut; $wgOut->setPagetitle( wfMsg( 'lockdb' ) ); $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) ); $wgOut->addWikiText( wfMsg( 'lockdbsuccesstext' ) ); } + + public static function notWritable() { + global $wgOut; + $wgOut->errorPage( 'lockdb', 'lockfilenotwritable' ); + } + } -?> +