Page MenuHomePhabricator

SpecialUpload.patch

Authored By
bzimport
Nov 21 2014, 9:39 PM
Size
2 KB
Referenced Files
None
Subscribers
None

SpecialUpload.patch

Index: SpecialUpload.php
===================================================================
--- SpecialUpload.php (revision 22119)
+++ SpecialUpload.php (working copy)
@@ -319,12 +319,35 @@
* 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()."]|:/", '-', $basename );
+### $filtered = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $basename );
+/**
+* Will allow categories and namespaces (e.g., ns:category:file.img)
+* will store name of file including NS & category (e.g. ns:category:file.img)
+* but will actually be in Image: ns
+* will also put ns/categories in front of file hash (e.g. ns/category/[hash]/file.img]
+*/
+ global $wgAllowImageNS;
+ $wgAllowImageNS = isset($wgAllowImageNS) ? $wgAllowImageNS : false;
+ if ($wgAllowImageNS){
+ wfDebug("Allowed Image NS.\n");
+ $filtered = preg_replace ( "/[^".Title::legalChars()."]/", '-', $basename );
+ } else {
+ wfDebug("DisAllowed Image NS.\n");
+ $filtered = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $basename );
+ }
+###
$nt = Title::newFromText( $filtered );
if( is_null( $nt ) ) {
$this->uploadError( wfMsgWikiHtml( 'illegalfilename', htmlspecialchars( $filtered ) ) );
return;
}
+### if namespace was stripped, restore
+ if ($nt->getNamespace() != NS_IMAGE) {
+ global $wgContLang;
+ $nt->setDbkeyform($wgContLang->getNsText($nt->getNamespace()).":".$nt->getDBkey());
+ $nt->setNamespace(NS_IMAGE);
+ }
+###
$nt =& Title::makeTitle( NS_IMAGE, $nt->getDBkey() );
$this->mUploadSaveName = $nt->getDBkey();
@@ -543,10 +566,14 @@
if ( !is_dir( $dest ) ) wfMkdirParents( $dest );
if ( !is_dir( $archive ) ) wfMkdirParents( $archive );
- $this->mSavedFile = "{$dest}/{$saveName}";
+### added and changed
+ $bits = explode( ':', $saveName );
+ $fileName = $bits[count($bits)-1];
+ $this->mSavedFile = "{$dest}/{$fileName}";
if( is_file( $this->mSavedFile ) ) {
- $this->mUploadOldVersion = gmdate( 'YmdHis' ) . "!{$saveName}";
+ $this->mUploadOldVersion = gmdate( 'YmdHis' ) . "!{$fileName}";
+###
wfSuppressWarnings();
$success = rename( $this->mSavedFile, "${archive}/{$this->mUploadOldVersion}" );
wfRestoreWarnings();
@@ -595,8 +622,11 @@
global $wgOut;
$archive = wfImageArchiveDir( $saveName, 'temp' );
if ( !is_dir ( $archive ) ) wfMkdirParents( $archive );
- $stash = $archive . '/' . gmdate( "YmdHis" ) . '!' . $saveName;
-
+### added for NS
+ $bits = explode( ':', $saveName );
+ $fileName = $bits[count($bits)-1];
+ $stash = $archive . '/' . gmdate( "YmdHis" ) . '!' . $fileName;
+###
$success = $this->mRemoveTempFile
? rename( $tempName, $stash )
: move_uploaded_file( $tempName, $stash );

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3424
Default Alt Text
SpecialUpload.patch (2 KB)

Event Timeline