User:Jpond/NSRepo/dev
< User:Jpond | NSRepo
Mod to deprecated imageURL in \filerepo\Image.php edit
Index: Image.php
===================================================================
--- Image.php (revision 22119)
+++ Image.php (working copy)
@@ -746,7 +746,12 @@
$base = $wgUploadBaseUrl;
$path = $wgUploadPath;
}
- $url = "{$base}{$path}" . wfGetHashPath($name, $fromSharedDirectory) . "{$name}";
+### $url = "{$base}{$path}" . wfGetHashPath($name, $fromSharedDirectory) . "{$name}";
+### added and changed
+ $bits = explode( ':', $name );
+ $fileName = $bits[count($bits)-1];
+ $url = "{$base}{$path}" . wfGetHashPath($name, $fromSharedDirectory) . "{$fileName}";
+###
return wfUrlencode( $url );
}
Mod to getFullPath in \filerepo\File.php edit
@@ -1238,8 +1243,14 @@
$wgUploadDirectory;
// $wgSharedUploadDirectory may be false, if thumb.php is used
+### if ( $dir ) {
+### $fullpath = $dir . wfGetHashPath($this->name, $fromSharedRepository) . $this->name;
+### added and changed
+ $bits = explode( ':', $this->name );
+ $fileName = $bits[count($bits)-1];
if ( $dir ) {
- $fullpath = $dir . wfGetHashPath($this->name, $fromSharedRepository) . $this->name;
+ $fullpath = $dir . wfGetHashPath($this->name, $fromSharedRepository) . $fileName;
+###
} else {
$fullpath = false;
}
Index: ImageFunctions.php
===================================================================
--- ImageFunctions.php (revision 22119)
+++ ImageFunctions.php (working copy)
@@ -15,7 +15,8 @@
if (!$wgHashedUploadDirectory) { return $wgUploadDirectory; }
$hash = md5( $fname );
- $dest = $wgUploadDirectory . '/' . $hash{0} . '/' . substr( $hash, 0, 2 );
+### $dest = $wgUploadDirectory . '/' . $hash{0} . '/' . substr( $hash, 0, 2 );
+ $dest = $wgUploadDirectory . '/' . wfGetNSUrl($fname) . $hash{0} . '/' . substr( $hash, 0, 2 );
return $dest;
}
@@ -67,7 +68,8 @@
if (!$hashdir) { return $dir.'/'.$subdir; }
$hash = md5( $fname );
- return $dir.'/'.$subdir.'/'.$hash[0].'/'.substr( $hash, 0, 2 );
+### return $dir.'/'.$subdir.'/'.$hash[0].'/'.substr( $hash, 0, 2 );
+ return $dir.'/'.$subdir.'/'. wfGetNSUrl($fname) . $hash[0].'/'.substr( $hash, 0, 2 );
}
@@ -82,7 +84,8 @@
function wfGetHashPath ( $dbkey, $fromSharedDirectory = false ) {
if( Image::isHashed( $fromSharedDirectory ) ) {
$hash = md5($dbkey);
- return '/' . $hash{0} . '/' . substr( $hash, 0, 2 ) . '/';
+### return '/' . $hash{0} . '/' . substr( $hash, 0, 2 ) . '/';
+ return '/' . wfGetNSUrl($dbkey) . $hash{0} . '/' . substr( $hash, 0, 2 ) . '/';
} else {
return '/';
}
@@ -100,10 +103,12 @@
if ($wgHashedUploadDirectory) {
$hash = md5( substr( $name, 15) );
- $url = $wgUploadPath.'/'.$subdir.'/' . $hash{0} . '/' .
+### $url = $wgUploadPath.'/'.$subdir.'/' . $hash{0} . '/' .
+### substr( $hash, 0, 2 ) . '/'.$name;
+ $url = $wgUploadPath.'/'.$subdir.'/' . wfGetNSUrl($name) . $hash{0} . '/' .
substr( $hash, 0, 2 ) . '/'.$name;
} else {
- $url = $wgUploadPath.'/'.$subdir.'/'.$name;
+ $url = $wgUploadPath.'/'.$subdir.'/'. wfGetNSUrl($name) .$name;
}
return wfUrlencode($url);
}
@@ -254,6 +259,27 @@
else
return $roundedUp;
}
+###
+/**
+ * If passed a filename with an intrinsic Namespace and/or categories , convert to
+ * physical directories. Only applies to image files
+ * @param $filename the filename including any namespaces and/or categories.
+ * @return $base which will have a slash at end if not empty.
+ */
-
+function wfGetNSUrl($filename){
+ global $wgContLang;
+ $base = "";
+ $bits = explode( ':', $filename );
+ for ($i=1;$i<count($bits);$i++){
+ $nsndx = $wgContLang->getNsIndex( $bits[$i-1] );
+ if ( $i == 1 && $nsndx){
+ $base = $base.sprintf("%03d",$nsndx)."/";
+ } else {
+ $base = $base.$bits[$i-1]."/";
+ }
+ }
+ return $base;
+}
+###
?>
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 );
- $nt = Title::newFromText( $filtered );
+### $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 ,NS_IMAGE);
+###
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 );
Index: Title.php
===================================================================
--- Title.php (revision 22119)
+++ Title.php (working copy)
@@ -1166,6 +1166,12 @@
return true;
}
}
+### Patched to allow confirmemail when site protected
+ $names=split("/", $name);
+ if(strcmp($names[0],"Special:Confirmemail")==0 && count($names)==2 && preg_match('/[a-f0-9]{32}/',$names[1])) {
+ return true;
+ }
+###
}
return false;
}
@@ -2548,7 +2554,17 @@
public function isContentPage() {
return Namespace::isContent( $this->getNamespace() );
}
-
+###
+ /**
+ * Added set functions for mNameSpace and mDbkeyform
+ */
+ function setNameSpace($nsInt){
+ $this->mNameSpace = $nsInt;
+ }
+ function setDbkeyform($dbKey){
+ $this->mDbkeyform = $dbKey;
+ }
+###
}
?>