*/
function wfVarDump( $var ) {
global $wgOut;
- $s = str_replace("\n","<br />\n", var_export( $var, true ) . "\n");
+ ob_start();
+ var_dump( $var );
+ $s = str_replace("\n","<br />\n", ob_get_contents() . "\n");
+ ob_end_clean();
if ( headers_sent() || !@is_object( $wgOut ) ) {
print $s;
} else {
return md5( mt_rand( 0, 0x7fffffff ) . $salt );
}
+
+/**
+ * Replace all invalid characters with -
+ * @param mixed $title Filename to process
+ */
+function wfStripIllegalFilenameChars( $name ) {
+ $name = wfBaseName( $name );
+ $name = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $name );
+ return $name;
+}
if( $nt->getNamespace() != NS_IMAGE ) {
$errors[] = array('imagenocrossnamespace');
}
+ if( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) {
+ $errors[] = array('imageinvalidfilename');
+ }
if( !File::checkExtensionCompatibility( $file, $nt->getDbKey() ) ) {
$errors[] = array('imagetypemismatch');
}
return self::BEFORE_PROCESSING;
}
- # Chop off any directories in the given filename
+ /**
+ * Chop off any directories in the given filename. Then
+ * filter out illegal characters, and try to make a legible name
+ * out of it. We'll strip some silently that Title would die on.
+ */
if( $this->mDesiredDestName ) {
$basename = $this->mDesiredDestName;
} else {
$basename = $this->mSrcName;
}
- $filtered = wfBaseName( $basename );
+ $filtered = wfStripIllegalFilenameChars( $basename );
/**
* We'll want to blacklist against *any* 'extension', and use
return self::MIN_LENGHT_PARTNAME;
}
- /**
- * Filter out illegal characters, and try to make a legible name
- * out of it. We'll strip some silently that Title would die on.
- */
- $filtered = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $filtered );
+
$nt = Title::makeTitleSafe( NS_IMAGE, $filtered );
if( is_null( $nt ) ) {
$resultDetails = array( 'filtered' => $filtered );
cannot move pages from and into that namespace.',
'imagenocrossnamespace' => 'Cannot move file to non-file namespace',
'imagetypemismatch' => 'The new file extension does not match its type',
+'imageinvalidfilename' => 'Target image file name is invalid',
# Export
'export' => 'Export pages',
'immobile_namespace',
'imagenocrossnamespace',
'imagetypemismatch',
+ 'imageinvalidfilename',
),
'export' => array(
'export',