Greetings, all...
I ran into an issue with MediaWiki over the weekend that I wanted to
share with the group, in case it came up to bite someone else. :-)
This has been reported in the MediaWiki forums, where a number of people
have had mysterious file upload failures, typically resulting in a
message similar to "unable to create directory /public/7/7b."
As it turns out, in includes/GlobalFunctions.php, there is a subroutine
to create directory paths which is not handling the slashes well for
non-Unix systems (under MW 1.15.0 & 1.15.1, at least):
/**
* Make directory, and make all parent directories if they don't exist
*
* @param string $dir Full path to directory to create
* @param int $mode Chmod value to use, default is $wgDirectoryMode
* @param string $caller Optional caller param for debugging.
* @return bool
*/
function wfMkdirParents( $dir, $mode = null, $caller = null ) {
global $wgDirectoryMode;
if ( !is_null( $caller ) ) {
wfDebug( "$caller: called wfMkdirParents($dir)" );
}
if( strval( $dir ) === '' || file_exists( $dir ) )
return true;
if ( is_null( $mode ) )
$mode = $wgDirectoryMode;
return mkdir( $dir, $mode, true ); // PHP5 <3
}
The fix is to insert before the return statement something to swap the
slashes:
$dir = str_replace('/', '\\', $dir);
So far, the file upload & delete functions have been the only ones I've
seen so affected. BTW, this was not my hack; I stumbled upon it by sheer
luck (okay, hard hitting, investigative work):
http://www.mediawiki.org/wiki/Project:Support_desk/Archives/Uploading/002#Potential_bug_in_FSRepo.php_causes_image_uploads_to_fail_on_Windows_server:_Internal_error_-_Could_not_create_directory
What surprised me was the fact that mkdir is evidently getting passed to
the shell directly, and there is no check on the delimiter used by the
shell. Older MW code (e.g., 1.13.2) *does* appear to check to see which
path delimiter is in use.
Anyway, just wanted to share the wealth, as it were. now back to your
regularly scheduled programming. ;-)
--
Lewis
-------------------------------------------------------------
Lewis G Rosenthal, CNA, CLP, CLE
Rosenthal & Rosenthal, LLC
www.2rosenthals.com
Need a managed Wi-Fi hotspot?
www.hautspot.com
Secure, stable, operating system
www.ecomstation.com
-------------------------------------------------------------