Completed
Push — master ( 530e90...d52c01 )
by Stephan
02:28
created

SpecialBatchUpload::execute()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 1
eloc 14
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
		$paramProvider = new ParameterProvider( $subpage );
67
68
		$html = '<span id="fileupload-dropzone" class="fileinput-button">
69
        <i class="glyphicon glyphicon-plus"></i>
70
        <span>' . \Message::newFromKey( 'simplebatchupload-buttonlabel' )->escaped() . '</span>
71
        <!-- The file input field used as target for the file upload widget -->
72
        <input id="fileupload" type="file" name="file" multiple
73
            data-url="' . wfScript( 'api' ) . '"
74
            data-comment="' . $paramProvider->getEscapedUploadComment() .'"
75
            data-text="' . $paramProvider->getEscapedUploadPageText() . '"
76
        >
77
        </span><ul id="fileupload-results"></ul>';
78
79
		$output = $this->getOutput();
80
		$output->setPageTitle( $paramProvider->getSpecialPageTitle() );
81
		$output->addHTML( $html );
82
		$output->addModules( 'ext.SimpleBatchUpload' );
83
		$output->addModuleStyles( [ 'ext.SimpleBatchUpload', 'ext.SimpleBatchUpload.jquery-file-upload' ] );
84
	}
85
86
}
87