diff --git a/i18n/en.json b/i18n/en.json index f8b688a..c526b0e 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -10,5 +10,7 @@ "batchupload": "Upload multiple files", "simplebatchupload-buttonlabel": "Select files (or drop them here)...", "simplebatchupload-comment": "Uploaded with [[mw:Special:MyLanguage/Extension:SimpleBatchUpload|SimpleBatchUpload]]", - "simplebatchupload-max-files-alert": "You cannot upload more than $1 {{PLURAL:$1|file|files}} at a time." + "simplebatchupload-filesummary": "", + "simplebatchupload-max-files-alert": "You cannot upload more than $1 {{PLURAL:$1|file|files}} at a time.", + "simplebatchupload-parameters": "" } diff --git a/i18n/qqq.json b/i18n/qqq.json index 41e78cc..b3083f9 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -10,5 +10,7 @@ "batchupload": "{{doc-special|BatchUpload}}", "simplebatchupload-buttonlabel": "The label for the upload button", "simplebatchupload-comment": "Comment saved with the upload. Do not translate '[[mw:Special:MyLanguage/Extension:SimpleBatchUpload|SimpleBatchUpload]]'", - "simplebatchupload-max-files-alert": "Alert saying there are too many files in a batch" + "simplebatchupload-filesummary": "Default file summary. Do not add anything outside the first comment. Do not translate 'SimpleBatchUpload'", + "simplebatchupload-max-files-alert": "Alert saying there are too many files in a batch", + "simplebatchupload-parameters": "Customization settings. Do not add anything outside the first comment. Do not translate 'SimpleBatchUpload' and 'mw:Special:MyLanguage/Extension:SimpleBatchUpload#Customization'" } diff --git a/src/ParameterProvider.php b/src/ParameterProvider.php index 919c420..547f827 100644 --- a/src/ParameterProvider.php +++ b/src/ParameterProvider.php @@ -50,11 +50,23 @@ public function __construct( $templateName ) { public function getUploadPageText(): string { - if ( $this->templateName === '' ) { - return ''; + $msgKey = 'simplebatchupload-filesummary'; + $templateName = $this->getParameter( self::IDX_TEMPLATENAME ); + $templateParams = preg_replace( '/^\|+/', '|', $this->getParameter( self::IDX_TEMPLATEPARAMETERS ) ); + + if ( $this->templateName !== '' ) { + $msgKey = $msgKey . '-' . $templateName; + } + + $fileSummaryMsg = Message::newFromKey( $msgKey, $templateParams ); + + if ( $fileSummaryMsg->exists() ) { + return preg_replace( '/^[\s\n]*[\s\n]*/', '', $fileSummaryMsg->plain() ); + } + else { + return '{{' . $templateName . $templateParams . '}}'; } - return '{{' . $this->getParameter( self::IDX_TEMPLATENAME ) . $this->getParameter( self::IDX_TEMPLATEPARAMETERS ) . '}}'; } private function getEscapedParameter( int $key ): string { @@ -83,7 +95,7 @@ private function populateParametersFromKey() { if ( $paramMsg->exists() ) { - $paramLines = explode( "\n", $paramMsg->plain() ); + $paramLines = preg_replace( '/^\*\s*/', '', explode( "\n", preg_replace( '/^[\s\n]*[\s\n]*/', '', $paramMsg->plain() ) ) ); $paramSet = array_map( [ $this, 'parseParamLine' ], $paramLines ); $paramMap = array_combine( array_column( $paramSet, 0 ), $paramSet ); diff --git a/src/SimpleBatchUpload.alias.php b/src/SimpleBatchUpload.alias.php index ab41208..eac5b4f 100644 --- a/src/SimpleBatchUpload.alias.php +++ b/src/SimpleBatchUpload.alias.php @@ -29,3 +29,21 @@ $specialPageAliases['en'] = [ 'BatchUpload' => [ 'BatchUpload' ], ]; + +/** Simplified Chinese + */ +$specialPageAliases['zh-hans'] = [ + 'BatchUpload' => [ '批量上传' ], +]; + +/** Traditional Chinese + */ +$specialPageAliases['zh-hant'] = [ + 'BatchUpload' => [ '批次上傳' ], +]; + +/** Traditional Chinese, Hong Kong + */ +$specialPageAliases['zh-hk'] = [ + 'BatchUpload' => [ '批次上載' ], +]; diff --git a/src/UploadButtonRenderer.php b/src/UploadButtonRenderer.php index a96d23b..e030375 100644 --- a/src/UploadButtonRenderer.php +++ b/src/UploadButtonRenderer.php @@ -127,10 +127,11 @@ protected function prepareParameterProvider( $args ): ParameterProvider { if ( $templateName !== '' ) { array_shift( $args ); - foreach ( $args as $node ) { - $paramProvider->addTemplateParameter( $node ); - } } + foreach ( $args as $node ) { + $paramProvider->addTemplateParameter( $node ); + } + return $paramProvider; }