Skip to content

Commit 5d3fdf7

Browse files
committed
Support system messages for upload text
docs: add default 'simplebatchupload-parameters' system message feat: support unordered list in customization settings feat: support system message on default upload text feat: support unnamed on parser function call
1 parent 1e53b5b commit 5d3fdf7

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

i18n/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
"batchupload": "Upload multiple files",
1111
"simplebatchupload-buttonlabel": "Select files (or drop them here)...",
1212
"simplebatchupload-comment": "Uploaded with [[mw:Special:MyLanguage/Extension:SimpleBatchUpload|SimpleBatchUpload]]",
13-
"simplebatchupload-max-files-alert": "You cannot upload more than $1 {{PLURAL:$1|file|files}} at a time."
13+
"simplebatchupload-filesummary": "<!-- Default file summary for uploaded new files via SimpleBatchUpload. -->",
14+
"simplebatchupload-max-files-alert": "You cannot upload more than $1 {{PLURAL:$1|file|files}} at a time.",
15+
"simplebatchupload-parameters": "<!-- Customization settings for SimpleBatchUpload subpages, see mw:Special:MyLanguage/Extension:SimpleBatchUpload#Customization for details. -->"
1416
}

i18n/qqq.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
"batchupload": "{{doc-special|BatchUpload}}",
1111
"simplebatchupload-buttonlabel": "The label for the upload button",
1212
"simplebatchupload-comment": "Comment saved with the upload. Do not translate '[[mw:Special:MyLanguage/Extension:SimpleBatchUpload|SimpleBatchUpload]]'",
13-
"simplebatchupload-max-files-alert": "Alert saying there are too many files in a batch"
13+
"simplebatchupload-filesummary": "Default file summary. Do not add anything outside the first comment. Do not translate 'SimpleBatchUpload'",
14+
"simplebatchupload-max-files-alert": "Alert saying there are too many files in a batch",
15+
"simplebatchupload-parameters": "Customization settings. Do not add anything outside the first comment. Do not translate 'SimpleBatchUpload' and 'mw:Special:MyLanguage/Extension:SimpleBatchUpload#Customization'"
1416
}

src/ParameterProvider.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,23 @@ public function __construct( $templateName ) {
5050

5151
public function getUploadPageText(): string {
5252

53-
if ( $this->templateName === '' ) {
54-
return '';
53+
$msgKey = 'simplebatchupload-filesummary';
54+
$templateName = $this->getParameter( self::IDX_TEMPLATENAME );
55+
$templateParams = preg_replace( '/^\|+/', '|', $this->getParameter( self::IDX_TEMPLATEPARAMETERS ) );
56+
57+
if ( $this->templateName !== '' ) {
58+
$msgKey = $msgKey . '-' . $templateName;
59+
}
60+
61+
$fileSummaryMsg = Message::newFromKey( $msgKey, $templateParams );
62+
63+
if ( $fileSummaryMsg->exists() ) {
64+
return preg_replace( '/^<!--.*?-->\n*/s', '', $fileSummaryMsg->plain() );
65+
}
66+
else {
67+
return '{{' . $templateName . $templateParams . '}}';
5568
}
5669

57-
return '{{' . $this->getParameter( self::IDX_TEMPLATENAME ) . $this->getParameter( self::IDX_TEMPLATEPARAMETERS ) . '}}';
5870
}
5971

6072
private function getEscapedParameter( int $key ): string {
@@ -83,7 +95,7 @@ private function populateParametersFromKey() {
8395

8496
if ( $paramMsg->exists() ) {
8597

86-
$paramLines = explode( "\n", $paramMsg->plain() );
98+
$paramLines = explode( "\n", str_replace( '*', '', $paramMsg->plain() ) );
8799
$paramSet = array_map( [ $this, 'parseParamLine' ], $paramLines );
88100
$paramMap = array_combine( array_column( $paramSet, 0 ), $paramSet );
89101

src/UploadButtonRenderer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,11 @@ protected function prepareParameterProvider( $args ): ParameterProvider {
127127

128128
if ( $templateName !== '' ) {
129129
array_shift( $args );
130-
foreach ( $args as $node ) {
131-
$paramProvider->addTemplateParameter( $node );
132-
}
133130
}
131+
foreach ( $args as $node ) {
132+
$paramProvider->addTemplateParameter( $node );
133+
}
134+
134135
return $paramProvider;
135136
}
136137

0 commit comments

Comments
 (0)