From 6d4b3584a13d0cd86bde2b182171cd22935e6d15 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sun, 15 May 2011 12:51:52 +0000 Subject: [PATCH] (bug 23464) File: prefixes are now chopped off during uploading. --- RELEASE-NOTES-1.19 | 1 + includes/upload/UploadBase.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 4b9012a987..63fe431f01 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -51,6 +51,7 @@ used in Tiff files. make the width be the max SVG size, not the natrual width of the SVG. * (bug 1780) Uploading files with non-ascii characters are now forbidden on Windows. +* (bug 23464) File: prefixes are now chopped off during uploading. === API changes in 1.19 === * (bug 27790) add query type for querymodules to action=paraminfo diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 2d351ac512..8efe94d354 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -599,13 +599,23 @@ abstract class UploadBase { if ( $this->mTitle !== false ) { return $this->mTitle; } + + /* Assume that if a user specified File:Something.jpg, this is an error + * and that the namespace prefix needs to be stripped of. + */ + $title = Title::newFromText( $this->mDesiredDestName ); + if ( $title->getNamespace() == NS_FILE ) { + $this->mFilteredName = $title->getDBkey(); + } else { + $this->mFilteredName = $this->mDesiredDestName; + } /** * 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. */ - $this->mFilteredName = wfStripIllegalFilenameChars( $this->mDesiredDestName ); + $this->mFilteredName = wfStripIllegalFilenameChars( $this->mFilteredName ); /* Normalize to title form before we do any further processing */ $nt = Title::makeTitleSafe( NS_FILE, $this->mFilteredName ); if( is_null( $nt ) ) { -- 2.20.1