Completed
Push — master ( a473f5...979bb4 )
by Stephan
02:24
created

SpecialBatchUpload::prepareOutput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 1
eloc 12
nc 1
nop 1
1
<?php
2
/**
3
 * File containing the SpecialBatchUpload class
4
 *
5
 * @copyright (C) 2016, 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
27
use SpecialPage;
28
29
/**
30
 * Class SpecialBatchUpload
31
 *
32
 * @package SimpleBatchUpload
33
 * @ingroup SimpleBatchUpload
34
 */
35
class SpecialBatchUpload extends SpecialPage {
36
37
	/**
38
	 * @param string $name Name of the special page, as seen in links and URLs
39
	 * @param string $restriction User right required, e.g. "block" or "delete"
40
	 * @param bool $listed Whether the page is listed in Special:Specialpages
41
	 */
42
	public function __construct( $name = '', $restriction = '', $listed = true ) {
43
		parent::__construct( 'BatchUpload', 'upload', $listed );
44
	}
45
46
	/**
47
	 * Under which header this special page is listed in Special:SpecialPages
48
	 * See messages 'specialpages-group-*' for valid names
49
	 * This method defaults to group 'other'
50
	 *
51
	 * @return string
52
	 */
53
	protected function getGroupName() {
54
		return 'media';
55
	}
56
57
	/**
58
	 * @param null|string $subpage
59
	 * @throws \MWException
60
	 */
61
	public function execute( $subpage ) {
62
63
		$this->setHeaders();
64
		$this->checkPermissions();
65
66
		$this->prepareOutput( $subpage );
67
	}
68
69
	/**
70
	 * @param string|null $subpage
71
	 */
72
	private function prepareOutput( $subpage ) {
73
		$paramProvider = new ParameterProvider( $subpage );
74
75
		$html = '<span id="fileupload-dropzone" class="fileinput-button">
76
        <i class="glyphicon glyphicon-plus"></i>
77
        <span>' . \Message::newFromKey( 'simplebatchupload-buttonlabel' )->escaped() . '</span>
78
        <!-- The file input field used as target for the file upload widget -->
79
        <input id="fileupload" type="file" name="file" multiple
80
            data-url="' . wfScript( 'api' ) . '"
81
            data-comment="' . $paramProvider->getEscapedUploadComment() . '"
82
            data-text="' . $paramProvider->getEscapedUploadPageText() . '"
83
        >
84
        </span><ul id="fileupload-results"></ul>';
85
86
		$output = $this->getOutput();
87
		$output->setPageTitle( $paramProvider->getSpecialPageTitle() );
88
		$output->addHTML( $html );
89
		$output->addModules( 'ext.SimpleBatchUpload' );
90
		$output->addModuleStyles( [ 'ext.SimpleBatchUpload', 'ext.SimpleBatchUpload.jquery-file-upload' ] );
91
	}
92
93
}
94