From 0d8883280d1db24d19e94a926ba5c3ec7dee54d7 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Mon, 10 Jul 2006 08:53:42 +0000 Subject: [PATCH] * (bug 6618) Improve permissions/error detection in Special:Lockdb * Add another explicit check * Suppress errors on the fopen() * If the fopen() fails, assume a permissions problem --- RELEASE-NOTES | 1 + includes/SpecialLockdb.php | 20 ++++++++++++++++++-- languages/Messages.php | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 4f1ebcde7e..1632d51336 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -42,6 +42,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN the presence of large numbers of blocks; added indexes and implemented an indexed pager. * (bug 6448) Allow filtering of Special:Newpages according to username +* (bug 6618) Improve permissions/error detection in Special:Lockdb == Languages updated == diff --git a/includes/SpecialLockdb.php b/includes/SpecialLockdb.php index ee72c6551a..8c58373e22 100644 --- a/includes/SpecialLockdb.php +++ b/includes/SpecialLockdb.php @@ -15,6 +15,13 @@ function wfSpecialLockdb() { $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(); @@ -92,10 +99,13 @@ END $this->showForm( wfMsg( 'locknoconfirm' ) ); return; } - $fp = fopen( $wgReadOnlyFile, 'w' ); + $fp = @fopen( $wgReadOnlyFile, 'w' ); if ( false === $fp ) { - $wgOut->showFileNotFoundError( $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 ); @@ -114,6 +124,12 @@ END $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) ); $wgOut->addWikiText( wfMsg( 'lockdbsuccesstext' ) ); } + + function notWritable() { + global $wgOut; + $wgOut->errorPage( 'lockdb', 'lockfilenotwritable' ); + } + } ?> diff --git a/languages/Messages.php b/languages/Messages.php index 68efed8433..7be2e5e1dd 100644 --- a/languages/Messages.php +++ b/languages/Messages.php @@ -1344,6 +1344,7 @@ Please confirm that this is what you intend to do.', 'lockdbsuccesstext' => 'The database has been locked.
Remember to remove the lock after your maintenance is complete.', 'unlockdbsuccesstext' => 'The database has been unlocked.', +'lockfilenotwritable' => 'The database lock file is not writable. To lock or unlock the database, this needs to be writable by the web server.', # Make sysop 'makesysoptitle' => 'Make a user into a sysop', -- 2.20.1