uploads of files starting with multibyte characters on Linux.
wfBaseName() doesn't suffer this bug, and understands backslash on
both Unix and Windows.
problem under PHP 5 with APC as opcode cache. See details:
http://mail.wikipedia.org/pipermail/wikitech-l/2006-January/033660.html
* Small changes to tabs in Monobook skin c/o Chris Ware
+* (bug 4679) Work around buggy basename() function in PHP5, which breaks
+ uploads of files starting with multibyte characters on Linux.
+ wfBaseName() doesn't suffer this bug, and understands backslash on
+ both Unix and Windows.
=== Caveats ===
return $string;
}
+/**
+ * Return the final portion of a pathname.
+ * Reimplemented because PHP5's basename() is buggy with multibyte text.
+ * http://bugs.php.net/bug.php?id=33898
+ *
+ * PHP's basename() only considers '\' a pathchar on Windows and Netware.
+ * We'll consider it so always, as we don't want \s in our Unix paths either.
+ *
+ * @param string $path
+ * @return string
+ */
+function wfBaseName( $path ) {
+ if( preg_match( '#([^/\\\\]*)[/\\\\]*$#', $path, $matches ) ) {
+ return $matches[1];
+ } else {
+ return '';
+ }
+}
?>
# Chop off any directories in the given filename
if ( $this->mDestFile ) {
- $basename = basename( $this->mDestFile );
+ $basename = wfBaseName( $this->mDestFile );
} else {
- $basename = basename( $this->mOname );
+ $basename = wfBaseName( $this->mOname );
}
/**
wfTimestamp( TS_DB, '2001-01-15 12:34:56' ),
'TS_DB to TS_DB' );
}
+
+ function testBasename() {
+ $sets = array(
+ '' => '',
+ '/' => '',
+ '\\' => '',
+ '//' => '',
+ '\\\\' => '',
+ 'a' => 'a',
+ 'aaaa' => 'aaaa',
+ '/a' => 'a',
+ '\\a' => 'a',
+ '/aaaa' => 'aaaa',
+ '\\aaaa' => 'aaaa',
+ '/aaaa/' => 'aaaa',
+ '\\aaaa\\' => 'aaaa',
+ '\\aaaa\\' => 'aaaa',
+ '/mnt/upload3/wikipedia/en/thumb/8/8b/Zork_Grand_Inquisitor_box_cover.jpg/93px-Zork_Grand_Inquisitor_box_cover.jpg' => '93px-Zork_Grand_Inquisitor_box_cover.jpg',
+ 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
+ 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
+ );
+ foreach( $sets as $from => $to ) {
+ $this->assertEquals( $to, wfBaseName( $from ),
+ "wfBaseName('$from') => '$to'");
+ }
+ }
/* TODO: many more! */
}