Passed
Pull Request — master (#16)
by
unknown
02:39
created

SimpleBatchUpload::getMaxFilesPerBatch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * File containing the SimpleBatchUpload class
4
 *
5
 * @copyright (C) 2016 - 2017, Stephan Gambke
6
 * @license   GNU General Public License, version 2 (or any later version)
7
 *
8
 * This software is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * This software is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18
 *
19
 * @file
20
 * @ingroup SimpleBatchUpload
21
 */
22
23
namespace SimpleBatchUpload;
24
25
/**
26
 * Class ExtensionManager
27
 *
28
 * @package SimpleBatchUpload
29
 */
30
class SimpleBatchUpload {
31
32
	/**
33
	 * @var integer Max files could be uploaded per batch
34
	 */
35
	protected $maxFilesPerBatch;
36
37
	public static function initCallback() {
38
39
			$configuration = ( new self() )->getConfiguration();
40
41
			foreach ( $configuration as $varname => $value ) {
42
				$GLOBALS[ $varname ] = array_replace_recursive( $GLOBALS[ $varname ], $value );
43
			}
44
45
	}
46
47
	/**
48
	 * @return array
49
	 */
50
	public function getConfiguration() {
51
52
		$configuration = [];
53
54
		$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadAlias' ] = __DIR__ . '/SimpleBatchUpload.alias.php';
55
		$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadMagic' ] = __DIR__ . '/SimpleBatchUpload.magic.php';
56
57
		$configuration[ 'wgSpecialPages' ][ 'BatchUpload' ] = '\SimpleBatchUpload\SpecialBatchUpload';
58
59
		$configuration[ 'wgHooks' ][ 'ParserFirstCallInit' ][ 'ext.simplebatchupload' ] = [ $this, 'registerParserFunction' ];
60
		$configuration[ 'wgHooks' ][ 'MakeGlobalVariablesScript' ][ 'ext.simplebatchupload' ] = [ $this, 'onMakeGlobalVariablesScript' ];
61
62
		$configuration[ 'wgResourceModules' ] = $this->getUploadSupportModuleDefinition() + $this->getUploadModuleDefinition();
63
64
		return $configuration;
65
66
	}
67
68
	/**
69
	 * @param \Parser $parser
0 ignored issues
show
Bug introduced by
The type Parser was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
70
	 *
71
	 * @return bool
72
	 * @throws \MWException
73
	 */
74
	public function registerParserFunction( &$parser ) {
75
		$parser->setFunctionHook( 'batchupload', [ new UploadButtonRenderer(), 'renderParserFunction' ], SFH_OBJECT_ARGS );
0 ignored issues
show
Bug introduced by
The constant SimpleBatchUpload\SFH_OBJECT_ARGS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
76
		return true;
77
	}
78
79
80
	/**
81
	 * @return array
82
	 */
83
	protected function getUploadSupportModuleDefinition() {
84
85
		return [ 'ext.SimpleBatchUpload.jquery-file-upload' =>
86
87
			$this->getBasePathsForComposerModules() +
88
89
			[
90
				'scripts' => [ '/vendor/blueimp/jquery-file-upload/js/jquery.fileupload.js' ],
91
				'styles' => [ '/vendor/blueimp/jquery-file-upload/css/jquery.fileupload.css' ],
92
				'position' => 'top',
93
				'dependencies' => [ 'jquery.ui.widget' ],
94
			],
95
		];
96
97
	}
98
99
	/**
100
	 * @return array
101
	 */
102
	protected function getUploadModuleDefinition() {
103
104
		return [ 'ext.SimpleBatchUpload' =>
105
106
			$this->getBasePathsForNonComposerModules() +
107
108
			[
109
				'scripts' => [ 'res/ext.SimpleBatchUpload.js' ],
110
				'styles' => [ 'res/ext.SimpleBatchUpload.css' ],
111
				'position' => 'top',
112
				'dependencies' => [ 'ext.SimpleBatchUpload.jquery-file-upload', 'mediawiki.Title', 'mediawiki.api.edit', 'mediawiki.jqueryMsg' ],
113
				'messages' => [ 'simplebatchupload-comment', 'simplebatchupload-max-files-alert' ],
114
			],
115
		];
116
	}
117
118
	/**
119
	 * @return string[]
120
	 */
121
	protected function getBasePathsForNonComposerModules() {
122
		return [
123
			'localBasePath' => dirname( __DIR__ ),
124
			'remoteBasePath' => $GLOBALS[ 'wgExtensionAssetsPath' ] . '/SimpleBatchUpload',
125
		];
126
	}
127
128
	/**
129
	 * @return string[]
130
	 */
131
	protected function getBasePathsForComposerModules() {
132
133
		if ( file_exists( dirname( __DIR__ ) . '/vendor' ) ) {
134
			return $this->getBasePathsForNonComposerModules();
135
		}
136
137
		return [
138
			'localBasePath' => $GLOBALS[ 'IP' ],
139
			'remoteBasePath' => $GLOBALS[ 'wgScriptPath' ],
140
		];
141
	}
142
143
	/**
144
	 * @param array $vars
145
	 * @param \OutputPage $out
0 ignored issues
show
Bug introduced by
The type OutputPage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
146
	 */
147
	public function onMakeGlobalVariablesScript( &$vars, $out ) {
0 ignored issues
show
Unused Code introduced by
The parameter $out is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

147
	public function onMakeGlobalVariablesScript( &$vars, /** @scrutinizer ignore-unused */ $out ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
148
		$vars['simpleBatchUploadMaxFilesPerBatch'] = $this->getMaxFilesPerBatch();
149
	}
150
151
	/**
152
	 * @return integer
153
	 */
154
	public function getMaxFilesPerBatch() {
155
		global $wgSimpleBatchUploadMaxFilesPerBatch;
156
		return $this->maxFilesPerBatch ? $this->maxFilesPerBatch : $wgSimpleBatchUploadMaxFilesPerBatch;
157
	}
158
159
	/**
160
	 * @param integer $maxFilesPerBatch
161
	 */
162
	public function setMaxFilesPerBatch( $maxFilesPerBatch ) {
163
		$this->maxFilesPerBatch = $maxFilesPerBatch;
164
	}
165
166
}
167