Passed
Branch master (74b6f9)
by Stephan
02:33
created

getUploadSupportModuleDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 11
rs 9.4285
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
	public static function initCallback() {
33
34
			$configuration = ( new self() )->getConfiguration();
35
36
			foreach ( $configuration as $varname => $value ) {
37
				$GLOBALS[ $varname ] = array_replace_recursive( $GLOBALS[ $varname ], $value );
38
			}
39
40
	}
41
42
	/**
43
	 * @return array
44
	 */
45
	public function getConfiguration() {
46
47
		$configuration = [];
48
49
		$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadAlias' ] = __DIR__ . '/SimpleBatchUpload.alias.php';
50
		$configuration[ 'wgExtensionMessagesFiles' ][ 'SimpleBatchUploadMagic' ] = __DIR__ . '/SimpleBatchUpload.magic.php';
51
52
		$configuration[ 'wgSpecialPages' ][ 'BatchUpload' ] = '\SimpleBatchUpload\SpecialBatchUpload';
53
54
		$configuration[ 'wgHooks' ][ 'ParserFirstCallInit' ][ 'ext.simplebatchupload' ] = [ $this, 'registerParserFunction' ];
55
56
		$configuration[ 'wgResourceModules' ] = $this->getUploadSupportModuleDefinition() + $this->getUploadModuleDefinition();
57
58
		return $configuration;
59
60
	}
61
62
	/**
63
	 * @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...
64
	 * @return bool
65
	 */
66
	public function registerParserFunction( &$parser ) {
67
		$parser->setFunctionHook( 'batchupload', [ new UploadButtonRenderer( $parser->getOutput() ), 'renderParserFunction' ], SFH_OBJECT_ARGS );
0 ignored issues
show
Unused Code introduced by
The call to SimpleBatchUpload\Upload...Renderer::__construct() has too many arguments starting with $parser->getOutput(). ( Ignorable by Annotation )

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

67
		$parser->setFunctionHook( 'batchupload', [ /** @scrutinizer ignore-call */ new UploadButtonRenderer( $parser->getOutput() ), 'renderParserFunction' ], SFH_OBJECT_ARGS );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
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...
68
		return true;
69
	}
70
71
72
	/**
73
	 * @return array
74
	 */
75
	protected function getUploadSupportModuleDefinition() {
76
77
		return [ 'ext.SimpleBatchUpload.jquery-file-upload' =>
78
79
			$this->getBasePathsForComposerModules() +
80
81
			[
82
				'scripts' => [ '/vendor/blueimp/jquery-file-upload/js/jquery.fileupload.js' ],
83
				'styles' => [ '/vendor/blueimp/jquery-file-upload/css/jquery.fileupload.css' ],
84
				'position' => 'top',
85
				'dependencies' => [ 'jquery.ui.widget' ],
86
			],
87
		];
88
89
	}
90
91
	/**
92
	 * @return array
93
	 */
94
	protected function getUploadModuleDefinition() {
95
96
		return [ 'ext.SimpleBatchUpload' =>
97
98
			$this->getBasePathsForNonComposerModules() +
99
100
			[
101
				'scripts' => [ 'res/ext.SimpleBatchUpload.js' ],
102
				'styles' => [ 'res/ext.SimpleBatchUpload.css' ],
103
				'position' => 'top',
104
				'dependencies' => [ 'ext.SimpleBatchUpload.jquery-file-upload', 'mediawiki.Title', 'mediawiki.api.edit', 'mediawiki.jqueryMsg' ],
105
				'messages' => [ 'simplebatchupload-comment' ],
106
			],
107
		];
108
	}
109
110
	/**
111
	 * @return string[]
112
	 */
113
	protected function getBasePathsForNonComposerModules() {
114
		return [
115
			'localBasePath' => dirname( __DIR__ ),
116
			'remoteBasePath' => $GLOBALS[ 'wgExtensionAssetsPath' ] . '/SimpleBatchUpload',
117
		];
118
	}
119
120
	/**
121
	 * @return string[]
122
	 */
123
	protected function getBasePathsForComposerModules() {
124
125
		if ( file_exists( dirname( __DIR__ ) . '/vendor' ) ) {
126
			return $this->getBasePathsForNonComposerModules();
127
		}
128
129
		return [
130
			'localBasePath' => $GLOBALS[ 'IP' ],
131
			'remoteBasePath' => $GLOBALS[ 'wgScriptPath' ],
132
		];
133
	}
134
135
}
136