Skip to content

Commit

Permalink
Merge pull request #17 from tosfos/master
Browse files Browse the repository at this point in the history
Add per-user group max upload configuration
  • Loading branch information
s7eph4n authored Oct 22, 2018
2 parents 5061a11 + 16c2df0 commit 1854c4f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
4 changes: 3 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
]
},
"config": {
"SimpleBatchUploadMaxFilesPerBatch": 0
"SimpleBatchUploadMaxFilesPerBatch": {
"*": 1000
}
},
"callback": "SimpleBatchUpload\\SimpleBatchUpload::initCallback",
"manifest_version": 1,
Expand Down
19 changes: 15 additions & 4 deletions res/ext.SimpleBatchUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@
'use strict';

$( function () {

var filesLimitPerBatchConfig = mw.config.get( 'simpleBatchUploadMaxFilesPerBatch' ),
userGroups = mw.config.get( 'wgUserGroups' ),
userUploadLimit = 0;

if ( filesLimitPerBatchConfig ) {
$.each( filesLimitPerBatchConfig, function ( role, limit ) {
if ( userGroups.indexOf( role ) !== -1 && ( limit > userUploadLimit ) ) {
userUploadLimit = limit;
}
} );
}

$( 'span.fileupload-container' ).each( function () {

var container = this;
Expand All @@ -40,14 +53,12 @@
dropZone: $( '.fileupload-dropzone', container ),
progressInterval: 100,


add: function ( e, data ) {

var that = this;
var filesLimitPerBatch = mw.config.get( 'simpleBatchUploadMaxFilesPerBatch' );

if ( filesLimitPerBatch && data.originalFiles.length > filesLimitPerBatch ) {
alert( mw.msg( 'simplebatchupload-max-files-alert', filesLimitPerBatch ) );
if ( data.originalFiles.length > userUploadLimit ) {
window.alert( mw.msg( 'simplebatchupload-max-files-alert', userUploadLimit ) );
return false;
}

Expand Down
23 changes: 13 additions & 10 deletions src/SimpleBatchUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
class SimpleBatchUpload {

/**
* @var integer Max files could be uploaded per batch
* @var array Max files could be uploaded per batch
*/
protected $maxFilesPerBatch;
protected $maxFilesPerBatchConfig;

public static function initCallback() {

Expand Down Expand Up @@ -134,11 +134,11 @@ protected function getBasePathsForNonComposerModules() {
}

/**
* @param array $vars
* @param array &$vars
* @param \OutputPage $out
*/
public function onMakeGlobalVariablesScript( &$vars, $out ) {
$vars['simpleBatchUploadMaxFilesPerBatch'] = $this->getMaxFilesPerBatch();
$vars['simpleBatchUploadMaxFilesPerBatch'] = $this->getMaxFilesPerBatchConfig();
}

public function onSetupAfterCache() {
Expand All @@ -149,18 +149,21 @@ public function onSetupAfterCache() {
}

/**
* @return integer
* @return array
*/
public function getMaxFilesPerBatch() {
public function getMaxFilesPerBatchConfig() {
global $wgSimpleBatchUploadMaxFilesPerBatch;
return $this->maxFilesPerBatch ? $this->maxFilesPerBatch : $wgSimpleBatchUploadMaxFilesPerBatch;
if ( $this->maxFilesPerBatchConfig === null ) {
$this->maxFilesPerBatchConfig = $wgSimpleBatchUploadMaxFilesPerBatch;
}
return $this->maxFilesPerBatchConfig;
}

/**
* @param integer $maxFilesPerBatch
* @param $maxFilesPerBatchConfig
*/
public function setMaxFilesPerBatch( $maxFilesPerBatch ) {
$this->maxFilesPerBatch = $maxFilesPerBatch;
public function setMaxFilesPerBatchConfig( $maxFilesPerBatchConfig ) {
$this->maxFilesPerBatchConfig = $maxFilesPerBatchConfig;
}

}

0 comments on commit 1854c4f

Please sign in to comment.