Tweichart has submitted this change and it was merged.
Change subject: BsFileSystemHelper: Quickfix to support NSFileRepo
......................................................................
BsFileSystemHelper: Quickfix to support NSFileRepo
This is just a quickfix to allow upload of namespace prefixed files. Such
file uploads do only appear in context with NSFileRepo extension.
For the future: It might be a good idea to have an additional parameter to
'uploadLocalFile' that allows to habe a target name that does not depend
on the real file name.
Change-Id: Ibe05998cf9d062400536676b5a3408fc322aca1b
---
M includes/utility/FileSystemHelper.class.php
1 file changed, 50 insertions(+), 18 deletions(-)
Approvals:
Tweichart: Verified; Looks good to me, approved
diff --git a/includes/utility/FileSystemHelper.class.php
b/includes/utility/FileSystemHelper.class.php
index dd1190e..4972536 100644
--- a/includes/utility/FileSystemHelper.class.php
+++ b/includes/utility/FileSystemHelper.class.php
@@ -513,46 +513,78 @@
return $path;
}
+ public static $aFSCharMap = array(
+ ':' => '_COLON_' //MediaWiki NSFileRepo makes it possible to
have filenames with colons. Unfortunately we cannot have a colon in a
filesystem path
+ );
+ protected static function makeTmpFileName( $sFileName ) {
+ $sTmpFileName = $sFileName;
+ foreach( self::$aFSCharMap as $search => $replace ) {
+ $sTmpFileName = str_replace($search, $replace,
$sTmpFileName);
+ }
+ return $sTmpFileName;
+ }
+
+ protected static function restoreFileName( $sTmpFileName ) {
+ $sFileName = $sTmpFileName;
+ foreach( self::$aFSCharMap as $replace => $search ) {
+ $sFileName = str_replace($search, $replace, $sFileName);
+ }
+ return $sFileName;
+ }
+
public static function saveBase64ToTmp($sFileName, $sFileContent){
+ $sFileName = self::makeTmpFileName($sFileName);
$sFileName = wfTempDir() . DS . basename($sFileName);
$sFileContent = preg_replace("#^data:.*?;base64,#", "",
$sFileContent);
$sFileContent = str_replace(' ', '+', $sFileContent);
$sFileContent = base64_decode($sFileContent);
+
$bFile = file_put_contents($sFileName, $sFileContent);
- if ($bFile === 0 || $bFile === false)
+ if ($bFile === 0 || $bFile === false) {
return
Status::newFatal(wfMessage('bs-filesystemhelper-save-base64-error')->plain());
- else
+ }
+ else {
return Status::newGood($sFileName);
+ }
}
public static function uploadLocalFile($sFilename, $bDeleteSrc = false,
$sComment = "", $sPageText = "", $bWatch = false){
global $wgLocalFileRepo, $wgUser;
$oUploadStash = new UploadStash(new
LocalRepo($wgLocalFileRepo));
- $oFile = $oUploadStash->stashFile($sFilename, "file");
- if ($oFile === false)
+ $oUploadFile = $oUploadStash->stashFile( $sFilename, "file" );
+ $sTargetFileName = basename( self::restoreFileName( $sFilename
) );
+
+ if ($oUploadFile === false) {
return
Status::newFailure(wfMessage('bs-filesystemhelper-upload-local-error-stash-file')->plain());
- $oUploadFromStash = new UploadFromStash($wgUser, $oUploadStash,
$wgLocalFileRepo);
- $oUploadFromStash->initialize($oFile->getFileKey(),
basename($sFilename));
+ }
+
+ $oUploadFromStash = new UploadFromStash( $wgUser,
$oUploadStash, $wgLocalFileRepo );
+ $oUploadFromStash->initialize( $oUploadFile->getFileKey(),
$sTargetFileName );
$aStatus = $oUploadFromStash->verifyUpload();
if ($aStatus['status'] != UploadBase::OK) {
- return
Status::newFatal(wfMessage('bs-filesystemhelper-upload-err-code', '{{int:' .
UploadBase::getVerificationErrorCode($aStatus['status']) . '}}')->parse());
+ return Status::newFatal(
+
wfMessage('bs-filesystemhelper-upload-err-code', '{{int:' .
UploadBase::getVerificationErrorCode($aStatus['status']) . '}}')->parse()
+ );
}
$status = $oUploadFromStash->performUpload($sComment,
$sPageText, $bWatch, $wgUser);
$oUploadFromStash->cleanupTempFile();
- if (file_exists($sFilename) && $bDeleteSrc)
+ if (file_exists($sFilename) && $bDeleteSrc) {
unlink($sFilename);
- $oFile = wfFindFile(basename($sFilename));
- if ($status->isGood() && $oFile !== false){
- if ( BsExtensionManager::isContextActive(
'MW::SecureFileStore::Active' ) ) {
- return
Status::newGood(SecureFileStore::secureStuff($oFile->getUrl(), true));
- }
- else
- return Status::newGood($oFile->getUrl(), true);
}
- else
- return Status::newFatal
(wfMessage('bs-filesystemhelper-upload-local-error-create')->plain());
- }
+ $oRepoFile = wfFindFile( $sTargetFileName );
+ if ($status->isGood() && $oRepoFile !== false){
+ if ( BsExtensionManager::isContextActive(
'MW::SecureFileStore::Active' ) ) {
+ return
Status::newGood(SecureFileStore::secureStuff($oRepoFile->getUrl(), true));
+ }
+ else{
+ return Status::newGood($oRepoFile->getUrl(),
true);
+ }
+ }
+ else{
+ return Status::newFatal
(wfMessage('bs-filesystemhelper-upload-local-error-create')->plain());
+ }
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/191051
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibe05998cf9d062400536676b5a3408fc322aca1b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Robert Vogel <[email protected]>
Gerrit-Reviewer: Mglaser <[email protected]>
Gerrit-Reviewer: Pigpen <[email protected]>
Gerrit-Reviewer: Tweichart <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits