* (bug 6618) Improve permissions/error detection in Special:Lockdb
authorRob Church <robchurch@users.mediawiki.org>
Mon, 10 Jul 2006 08:53:42 +0000 (08:53 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Mon, 10 Jul 2006 08:53:42 +0000 (08:53 +0000)
* Add another explicit check
* Suppress errors on the fopen()
* If the fopen() fails, assume a permissions problem

RELEASE-NOTES
includes/SpecialLockdb.php
languages/Messages.php

index 4f1ebcd..1632d51 100644 (file)
@@ -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 ==
 
index ee72c65..8c58373 100644 (file)
@@ -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' );
+       }
+       
 }
 
 ?>
index 68efed8..7be2e5e 100644 (file)
@@ -1344,6 +1344,7 @@ Please confirm that this is what you intend to do.',
 'lockdbsuccesstext' => 'The database has been locked.
 <br />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',