Passed
Push — testing ( 5c3fd5...931c5b )
by Stephan
04:12
created

UploadButtonRenderer::renderSpecialPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * File containing the ParameterProvider 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
 *
13
 * This software is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20
 *
21
 * @file
22
 * @ingroup SimpleBatchUpload
23
 */
24
25
namespace SimpleBatchUpload;
26
use 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...
27
use PPFrame;
0 ignored issues
show
Bug introduced by
The type PPFrame 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...
28
29
30
/**
31
 * Class UploadButtonRenderer
32
 * @package SimpleBatchUpload
33
 */
34
class UploadButtonRenderer {
35
36
	/**
37
	 * @param Parser $parser
38
	 * @param PPFrame $frame
39
	 * @param $args
40
	 * @return array
41
	 */
42
	public function renderParserFunction( Parser $parser, PPFrame $frame, $args ) {
43
44
		$args = array_map( [ $frame, 'expand' ], $args );
45
		$output = $parser->getOutput();
46
47
		$html = $this->renderUploadButton( $args, $output );
48
49
		return [ $html, 'isHTML' => true, 'noparse' => true, 'nowiki' => false ];
50
51
	}
52
53
54
	/**
55
	 * @param SpecialBatchUpload $specialPage
56
	 * @param string $templateName
57
	 */
58
	public function renderSpecialPage( SpecialBatchUpload $specialPage, $templateName ) {
59
60
		$args = [ $templateName ];
61
		$output = $specialPage->getOutput();
62
63
		$html = $this->renderUploadButton( $args, $output );
64
65
		$output->addHTML( $html );
66
67
	}
68
69
	/**
70
	 * @param string[] $args
71
	 * @param \ParserOutput | \OutputPage $output
0 ignored issues
show
Bug introduced by
The type ParserOutput 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...
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...
72
	 * @return string
73
	 */
74
	protected function renderUploadButton( $args, $output ) {
75
76
		$paramProvider = $this->prepareParameterProvider( $args );
77
78
		$this->addModulesToOutput( $output );
79
80
		if ( method_exists( $output, 'setPageTitle' ) ) {
81
			$output->setPageTitle( $paramProvider->getSpecialPageTitle() );
82
		}
83
84
		return $this->getHtml( $paramProvider );
85
	}
86
87
	/**
88
	 * @param $paramProvider
89
	 * @return string
90
	 */
91
	protected function getHtml( ParameterProvider $paramProvider ) {
92
93
		$escapedUploadComment = $paramProvider->getEscapedUploadComment();
94
		$escapedUploadPageText = $paramProvider->getEscapedUploadPageText();
95
96
		return
97
98
			'<span class="fileupload-container"> ' .
99
			'<span class="fileupload-dropzone fileinput-button"> ' .
100
			'<i class="glyphicon glyphicon-plus"></i> ' .
101
			'<span>' . \Message::newFromKey( 'simplebatchupload-buttonlabel' )->escaped() . '</span> ' .
102
			'<!-- The file input field used as target for the file upload widget -->' .
103
			'<input class="fileupload" type="file" name="file" multiple ' .
104
			'    data-url="' . wfScript( 'api' ) . '" ' .
0 ignored issues
show
Bug introduced by
The function wfScript was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

104
			'    data-url="' . /** @scrutinizer ignore-call */ wfScript( 'api' ) . '" ' .
Loading history...
105
			'    data-comment="' . $escapedUploadComment . '" ' .
106
			'    data-text="' . $escapedUploadPageText . '" ' .
107
			'> ' .
108
			'</span><ul class="fileupload-results"></ul> ' .
109
			'</span>';
110
	}
111
112
	/**
113
	 * @param \ParserOutput | \OutputPage $output
114
	 */
115
	protected function addModulesToOutput( $output ) {
116
		$output->addModules( 'ext.SimpleBatchUpload' );
117
		$output->addModuleStyles( [ 'ext.SimpleBatchUpload', 'ext.SimpleBatchUpload.jquery-file-upload' ] );
118
	}
119
120
	/**
121
	 * @param string[] $args
122
	 * @return ParameterProvider
123
	 */
124
	protected function prepareParameterProvider( $args ) {
125
126
		$templateName = $args[ 0 ];
127
128
		$paramProvider = new ParameterProvider( $templateName );
129
130
		if ( $templateName !== '' ) {
131
			array_shift( $args );
132
			foreach ( $args as $node ) {
133
				$paramProvider->addTemplateParameter( $node );
134
			}
135
		}
136
		return $paramProvider;
137
	}
138
139
}