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

SimpleBatchUpload   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 120
rs 10
c 0
b 0
f 0
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfiguration() 0 18 1
A onMakeGlobalVariablesScript() 0 3 1
A getBasePathsForNonComposerModules() 0 4 1
A registerParserFunction() 0 6 1
A getUploadSupportModuleDefinition() 0 11 1
A getUploadModuleDefinition() 0 17 1
A getBasePathsForComposerModules() 0 8 2
A initCallback() 0 5 2
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
	public static function initCallback() {
33
		$configuration = ( new self() )->getConfiguration();
34
35
		foreach ( $configuration as $varname => $value ) {
36
			$GLOBALS[$varname] = array_replace_recursive( $GLOBALS[$varname], $value );
37
		}
38
	}
39
40
	/**
41
	 * @return array
42
	 */
43
	public function getConfiguration() {
44
		$configuration = [];
45
46
		$configuration['wgExtensionMessagesFiles']['SimpleBatchUploadAlias'] = __DIR__ . '/SimpleBatchUpload.alias.php';
47
		$configuration['wgExtensionMessagesFiles']['SimpleBatchUploadMagic'] = __DIR__ . '/SimpleBatchUpload.magic.php';
48
49
		$configuration['wgSpecialPages']['BatchUpload'] = '\SimpleBatchUpload\SpecialBatchUpload';
50
51
		$configuration['wgHooks']['ParserFirstCallInit']['ext.simplebatchupload'] = [ $this, 'registerParserFunction' ];
52
		$configuration['wgHooks']['MakeGlobalVariablesScript']['ext.simplebatchupload'] = [
53
			$this,
54
			'onMakeGlobalVariablesScript'
55
		];
56
57
		$configuration['wgResourceModules'] = $this->getUploadSupportModuleDefinition() +
58
											  $this->getUploadModuleDefinition();
59
60
		return $configuration;
61
	}
62
63
	/**
64
	 * @return array
65
	 */
66
	protected function getUploadSupportModuleDefinition() {
67
		return [
68
			'ext.SimpleBatchUpload.jquery-file-upload' =>
69
70
				$this->getBasePathsForComposerModules() +
71
72
				[
73
					'scripts' => [ '/vendor/blueimp/jquery-file-upload/js/jquery.fileupload.js' ],
74
					'styles' => [ '/vendor/blueimp/jquery-file-upload/css/jquery.fileupload.css' ],
75
					'position' => 'top',
76
					'dependencies' => [ 'jquery.ui.widget' ],
77
				],
78
		];
79
	}
80
81
	/**
82
	 * @return string[]
83
	 */
84
	protected function getBasePathsForComposerModules() {
85
		if ( file_exists( dirname( __DIR__ ) . '/vendor' ) ) {
86
			return $this->getBasePathsForNonComposerModules();
87
		}
88
89
		return [
90
			'localBasePath' => $GLOBALS['IP'],
91
			'remoteBasePath' => $GLOBALS['wgScriptPath'],
92
		];
93
	}
94
95
	/**
96
	 * @return string[]
97
	 */
98
	protected function getBasePathsForNonComposerModules() {
99
		return [
100
			'localBasePath' => dirname( __DIR__ ),
101
			'remoteBasePath' => $GLOBALS['wgExtensionAssetsPath'] . '/SimpleBatchUpload',
102
		];
103
	}
104
105
	/**
106
	 * @return array
107
	 */
108
	protected function getUploadModuleDefinition() {
109
		return [
110
			'ext.SimpleBatchUpload' =>
111
112
				$this->getBasePathsForNonComposerModules() +
113
114
				[
115
					'scripts' => [ 'res/ext.SimpleBatchUpload.js' ],
116
					'styles' => [ 'res/ext.SimpleBatchUpload.css' ],
117
					'position' => 'top',
118
					'dependencies' => [
119
						'ext.SimpleBatchUpload.jquery-file-upload',
120
						'mediawiki.Title',
121
						'mediawiki.api.edit',
122
						'mediawiki.jqueryMsg'
123
					],
124
					'messages' => [ 'simplebatchupload-comment', 'simplebatchupload-max-files-alert' ],
125
				],
126
		];
127
	}
128
129
	/**
130
	 * @param array &$vars
131
	 * @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...
132
	 */
133
	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

133
	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...
134
		global $wgSimpleBatchUploadMaxFilesPerBatch;
135
		$vars['wgSimpleBatchUploadMaxFilesPerBatch'] = $wgSimpleBatchUploadMaxFilesPerBatch;
136
	}
137
138
	/**
139
	 * @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...
140
	 *
141
	 * @return bool
142
	 * @throws \MWException
143
	 */
144
	public function registerParserFunction( &$parser ) {
145
		$parser->setFunctionHook( 'batchupload', [
146
			new UploadButtonRenderer(),
147
			'renderParserFunction'
148
		], 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...
149
		return true;
150
	}
151
152
}
153