[MediaWiki-commits] [Gerrit] mediawiki...BlueSpiceFoundation[REL1_23]: Add checking for warnings before uploading

2017-07-14 Thread Robert Vogel (Code Review)
Robert Vogel has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/365205 )

Change subject: Add checking for warnings before uploading
..


Add checking for warnings before uploading

Add $bIgnoreWarnings param that can be passed to uploadLocalFile to
indicate wether warnings (if exist) should be returned or not

This is a late commit to REL1_23 because this change was not previoursly
merget to REL1_23 (conflict on cherry-pick)

Change-Id: I171d2fb4eb93adbd750d340dd3d3b52d1df21b74
ERM: #4275
---
M includes/utility/FileSystemHelper.class.php
1 file changed, 24 insertions(+), 12 deletions(-)

Approvals:
  Robert Vogel: Verified; Looks good to me, approved



diff --git a/includes/utility/FileSystemHelper.class.php 
b/includes/utility/FileSystemHelper.class.php
index 6748b6c..8d5a46e 100644
--- a/includes/utility/FileSystemHelper.class.php
+++ b/includes/utility/FileSystemHelper.class.php
@@ -550,44 +550,56 @@
}
}
 
-   public static function uploadLocalFile($sFilename, $bDeleteSrc = false, 
$sComment = "", $sPageText = "", $bWatch = false){
+   public static function uploadLocalFile($sFilename, $bDeleteSrc = false, 
$sComment = "", $sPageText = "", $bWatch = false, $bIgnoreWarnings = true ){
global $wgLocalFileRepo, $wgUser;
-   $oUploadStash = new UploadStash(new 
LocalRepo($wgLocalFileRepo));
+   $oUploadStash = new UploadStash( new LocalRepo( 
$wgLocalFileRepo ) );
$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());
+   return Status::newFailure( wfMessage( 
'bs-filesystemhelper-upload-local-error-stash-file' )->plain() );
}
 
$oUploadFromStash = new UploadFromStash( $wgUser, 
$oUploadStash, $wgLocalFileRepo );
$oUploadFromStash->initialize( $oUploadFile->getFileKey(), 
$sTargetFileName );
$aStatus = $oUploadFromStash->verifyUpload();
-   if ($aStatus['status'] != UploadBase::OK) {
+
+   if( $bIgnoreWarnings === false ) {
+   $aWarnings = $oUploadFromStash->checkWarnings();
+   if( !empty( $aWarnings ) ) {
+   $oStatus = new Status();
+   foreach( $aWarnings as $sKey => $vValue ) {
+   $oStatus->warning( $sKey, $vValue );
+   }
+   return $oStatus;
+   }
+   }
+
+   if ( $aStatus['status'] != UploadBase::OK ) {
return Status::newFatal(
-   
wfMessage('bs-filesystemhelper-upload-err-code', '{{int:' . 
UploadBase::getVerificationErrorCode($aStatus['status']) . '}}')->parse()
+   wfMessage( 
'bs-filesystemhelper-upload-err-code', '{{int:' . 
UploadBase::getVerificationErrorCode($aStatus['status'] ) . '}}' )->parse()
);
}
-   $status = $oUploadFromStash->performUpload($sComment, 
$sPageText, $bWatch, $wgUser);
+   $status = $oUploadFromStash->performUpload( $sComment, 
$sPageText, $bWatch, $wgUser );
$oUploadFromStash->cleanupTempFile();
 
-   if (file_exists($sFilename) && $bDeleteSrc) {
-   unlink($sFilename);
+   if ( file_exists( $sFilename ) && $bDeleteSrc ) {
+   unlink( $sFilename );
}
 
$oRepoFile = wfFindFile( $sTargetFileName );
-   if ($status->isGood() && $oRepoFile !== false){
+   if ( $status->isGood() && $oRepoFile !== false ){
$oPage = WikiPage::factory( $oRepoFile->getTitle() );
$oPage->doEditContent( new WikitextContent( $sPageText 
), '' );
if ( BsExtensionManager::isContextActive( 
'MW::SecureFileStore::Active' ) ) {
-   return 
Status::newGood(SecureFileStore::secureStuff($oRepoFile->getUrl(), true));
+   return Status::newGood( 
SecureFileStore::secureStuff($oRepoFile->getUrl(), true) );
}
else{
-   return Status::newGood($oRepoFile->getUrl(), 
true);
+   return Status::newGood( $oRepoFile->getUrl(), 
true );
}
}
else{
-   return Status::newFatal 
(wfMessage('bs-filesystemhelper-upload-local-error-create')->plain());
+ 

[MediaWiki-commits] [Gerrit] mediawiki...BlueSpiceFoundation[REL1_23]: Add checking for warnings before uploading

2017-07-14 Thread ItSpiderman (Code Review)
ItSpiderman has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/365205 )

Change subject: Add checking for warnings before uploading
..

Add checking for warnings before uploading

Add $bIgnoreWarnings param that can be passed to uploadLocalFile to
indicate wether warnings (if exist) should be returned or not

This is a late commit to REL1_23 because this change was not previoursly
merget to REL1_23 (conflict on cherry-pick)

Change-Id: I171d2fb4eb93adbd750d340dd3d3b52d1df21b74
ERM: #4275
---
M includes/utility/FileSystemHelper.class.php
1 file changed, 24 insertions(+), 12 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceFoundation 
refs/changes/05/365205/1

diff --git a/includes/utility/FileSystemHelper.class.php 
b/includes/utility/FileSystemHelper.class.php
index 6748b6c..8d5a46e 100644
--- a/includes/utility/FileSystemHelper.class.php
+++ b/includes/utility/FileSystemHelper.class.php
@@ -550,44 +550,56 @@
}
}
 
-   public static function uploadLocalFile($sFilename, $bDeleteSrc = false, 
$sComment = "", $sPageText = "", $bWatch = false){
+   public static function uploadLocalFile($sFilename, $bDeleteSrc = false, 
$sComment = "", $sPageText = "", $bWatch = false, $bIgnoreWarnings = true ){
global $wgLocalFileRepo, $wgUser;
-   $oUploadStash = new UploadStash(new 
LocalRepo($wgLocalFileRepo));
+   $oUploadStash = new UploadStash( new LocalRepo( 
$wgLocalFileRepo ) );
$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());
+   return Status::newFailure( wfMessage( 
'bs-filesystemhelper-upload-local-error-stash-file' )->plain() );
}
 
$oUploadFromStash = new UploadFromStash( $wgUser, 
$oUploadStash, $wgLocalFileRepo );
$oUploadFromStash->initialize( $oUploadFile->getFileKey(), 
$sTargetFileName );
$aStatus = $oUploadFromStash->verifyUpload();
-   if ($aStatus['status'] != UploadBase::OK) {
+
+   if( $bIgnoreWarnings === false ) {
+   $aWarnings = $oUploadFromStash->checkWarnings();
+   if( !empty( $aWarnings ) ) {
+   $oStatus = new Status();
+   foreach( $aWarnings as $sKey => $vValue ) {
+   $oStatus->warning( $sKey, $vValue );
+   }
+   return $oStatus;
+   }
+   }
+
+   if ( $aStatus['status'] != UploadBase::OK ) {
return Status::newFatal(
-   
wfMessage('bs-filesystemhelper-upload-err-code', '{{int:' . 
UploadBase::getVerificationErrorCode($aStatus['status']) . '}}')->parse()
+   wfMessage( 
'bs-filesystemhelper-upload-err-code', '{{int:' . 
UploadBase::getVerificationErrorCode($aStatus['status'] ) . '}}' )->parse()
);
}
-   $status = $oUploadFromStash->performUpload($sComment, 
$sPageText, $bWatch, $wgUser);
+   $status = $oUploadFromStash->performUpload( $sComment, 
$sPageText, $bWatch, $wgUser );
$oUploadFromStash->cleanupTempFile();
 
-   if (file_exists($sFilename) && $bDeleteSrc) {
-   unlink($sFilename);
+   if ( file_exists( $sFilename ) && $bDeleteSrc ) {
+   unlink( $sFilename );
}
 
$oRepoFile = wfFindFile( $sTargetFileName );
-   if ($status->isGood() && $oRepoFile !== false){
+   if ( $status->isGood() && $oRepoFile !== false ){
$oPage = WikiPage::factory( $oRepoFile->getTitle() );
$oPage->doEditContent( new WikitextContent( $sPageText 
), '' );
if ( BsExtensionManager::isContextActive( 
'MW::SecureFileStore::Active' ) ) {
-   return 
Status::newGood(SecureFileStore::secureStuff($oRepoFile->getUrl(), true));
+   return Status::newGood( 
SecureFileStore::secureStuff($oRepoFile->getUrl(), true) );
}
else{
-   return Status::newGood($oRepoFile->getUrl(), 
true);
+   return Status::newGood( $oRepoFile->getUrl(), 
true );
}
}
else{
-   return Status::newFatal