-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathUploadButtonRenderer.php
More file actions
138 lines (115 loc) · 4.01 KB
/
Copy pathUploadButtonRenderer.php
File metadata and controls
138 lines (115 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* File containing the ParameterProvider class
*
* @copyright (C) 2016 - 2017, Stephan Gambke
* @license GNU General Public License, version 2 (or any later version)
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
* @file
* @ingroup SimpleBatchUpload
*/
namespace MediaWiki\Extension\SimpleBatchUpload;
use MediaWiki\Html\Html;
use MediaWiki\Parser\Parser;
use MediaWiki\Parser\PPFrame;
/**
* Class UploadButtonRenderer
* @package SimpleBatchUpload
*/
class UploadButtonRenderer {
/**
* @param Parser $parser
* @param PPFrame $frame
* @param $args
* @return array
*/
public function renderParserFunction( Parser $parser, PPFrame $frame, $args ): array {
$args = array_map( [ $frame, 'expand' ], $args );
$output = $parser->getOutput();
$html = $this->renderUploadButton( $args, $output );
return [ $html, 'isHTML' => true, 'noparse' => true, 'nowiki' => false ];
}
/**
* @param SpecialBatchUpload $specialPage
* @param string $templateName
*/
public function renderSpecialPage( SpecialBatchUpload $specialPage, $templateName ) {
$args = [ $templateName ];
$output = $specialPage->getOutput();
$html = $this->renderUploadButton( $args, $output );
$output->addHTML( $html );
}
/**
* @param string[] $args
* @param \ParserOutput | \OutputPage $output
* @return string
*/
protected function renderUploadButton( $args, $output ) {
$paramProvider = $this->prepareParameterProvider( $args );
$this->addModulesToOutput( $output );
if ( method_exists( $output, 'setPageTitle' ) ) {
$output->setPageTitle( $paramProvider->getSpecialPageTitle() );
}
return $this->getHtml( $paramProvider );
}
/**
* @param $paramProvider
* @return string
*/
protected function getHtml( ParameterProvider $paramProvider ) {
$escapedUploadComment = $paramProvider->getEscapedUploadComment();
$uploadPageText = $paramProvider->getUploadPageText();
return
'<div class="fileupload-container"> ' .
'<label>' . \Message::newFromKey( 'upload-form-label-infoform-description' )->escaped() . ':<br>'.
'<span class="mw-input">' .
Html::element('textarea', ['name' => 'wfUploadDescription', 'cols' => '80', 'rows' => '8'], $uploadPageText) .
'</span>' .
'</label><br> '.
'<span class="fileupload-dropzone fileinput-button"> ' .
'<i class="glyphicon glyphicon-plus"></i> ' .
'<span>' . \Message::newFromKey( 'simplebatchupload-buttonlabel' )->escaped() . '</span> ' .
'<!-- The file input field used as target for the file upload widget -->' .
'<input class="fileupload" type="file" name="file" multiple ' .
' data-url="' . wfScript( 'api' ) . '" ' .
' data-comment="' . $escapedUploadComment . '" ' .
'> ' .
'</span><ul class="fileupload-results"></ul> ' .
'</div>';
}
/**
* @param \ParserOutput | \OutputPage $output
*/
protected function addModulesToOutput( $output ) {
$output->addModules( [ 'ext.SimpleBatchUpload' ] );
$output->addModuleStyles( [ 'ext.SimpleBatchUpload', 'ext.SimpleBatchUpload.jquery-file-upload' ] );
}
/**
* @param string[] $args
* @return ParameterProvider
*/
protected function prepareParameterProvider( $args ): ParameterProvider {
$templateName = $args[ 0 ];
$paramProvider = new ParameterProvider( $templateName );
if ( $templateName !== '' ) {
array_shift( $args );
}
foreach ( $args as $node ) {
$paramProvider->addTemplateParameter( $node );
}
return $paramProvider;
}
}