Skip to content

Conversation

@bilintsui
Copy link

@bilintsui bilintsui commented Dec 25, 2023

Currently, the default upload text for new files is very simple, they simply just add a template using subpage name, and using additional parameters when call through parser function.

On some wikis, uploaded files need to be tagged with copyright information. which is mandatory or recommended. Currently, SimpleBatchUpload do not have the ability to set a default upload text on root page, it means editors needs to write the upload text manually, and there is usually someone forget it, increases workload for maintenance on forementioned wikis.

This PR allows administrators set default texts for root page and subpages, at MediaWiki:Simplebatchupload-filesummary and MediaWiki:Simplebatchupload-filesummary-<subpagename> respectively, the message for the root page is also registered in the message file. Additionally, optional template parameters passed through parser functions can be substituted on $1 in these system messages (prefix | included).

Some other changes are also made in this PR:

  • Registered simplebatchupload-parameters system message in the message file, a message for an existing feature.
  • Added support for unordered list in simplebatchupload-parameters system message, prettier in format, like the format in MediaWiki:Gadgets-definition.
  • Added support for unnamed parser function call (e.g. {{#batchupload:|arg1|arg2}}).
  • Added special page aliases for Chinese variants (zh-hans, zh-hant, zh-hk).

This PR should be compatible with existing usages.

Summary by CodeRabbit

  • New Features

    • SimpleBatchUpload now supports Simplified Chinese (zh-hans), Traditional Chinese (zh-hant), and Traditional Chinese (Hong Kong)
    • Added localization strings enabling customizable default file summaries and configuration parameters for enhanced flexibility
  • Improvements

    • Enhanced parameter parsing logic for more robust and flexible customization options while maintaining backward compatibility

✏️ Tip: You can customize this high-level summary in your review settings.

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
@coderabbitai
Copy link

coderabbitai bot commented Jan 13, 2026

📝 Walkthrough

Walkthrough

This pull request introduces Chinese language aliases for SimpleBatchUpload, adds two new translation keys with documentation, refactors the parameter provider's message lookup flow with dynamic fallback logic, and adjusts parameter handling in the upload button renderer to process parameters unconditionally.

Changes

Cohort / File(s) Summary
Translation and Documentation
i18n/en.json, i18n/qqq.json
Added two new translation keys: simplebatchupload-filesummary (default file summary) and simplebatchupload-parameters (customization settings). Both include HTML comment-based documentation.
Locale Aliases
src/SimpleBatchUpload.alias.php
Added three new language alias mappings for BatchUpload: Simplified Chinese (zh-hans → 批量上传), Traditional Chinese (zh-hant → 批次上傳), and Hong Kong Chinese (zh-hk → 批次上載).
Parameter Provider Logic
src/ParameterProvider.php
Replaced early return for empty template name with dynamic message key lookup. Now preprocesses parameters by removing bullet prefixes and stripping HTML comments, then returns plaintext message or template-like placeholder fallback.
Upload Button Rendering
src/UploadButtonRenderer.php
Moved parameter addition loop outside conditional block, allowing template parameters to be processed even when template name is empty.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Support system messages for upload text' accurately describes the main objective of the PR, which is to add support for configurable default upload text via MediaWiki system messages.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/SimpleBatchUpload.alias.php (1)

2-23: Minor: File header references "ExtensionManager" instead of "SimpleBatchUpload".

The file header comment and @ingroup tag reference "ExtensionManager" (lines 3, 22), which appears to be a copy-paste artifact from another extension. Consider updating these to reference "SimpleBatchUpload" for accuracy.

src/ParameterProvider.php (1)

98-98: Complex one-liner could benefit from decomposition for readability.

This line performs multiple operations: strips HTML comment, explodes into lines, then strips bullet prefixes. While functionally correct (PHP's preg_replace handles arrays), this could be clearer:

Optional refactor for readability
-			$paramLines = preg_replace( '/^\*\s*/', '', explode( "\n", preg_replace( '/^[\s\n]*<!--[\s\S]*?-->[\s\n]*/', '', $paramMsg->plain() ) ) );
+			$rawText = $paramMsg->plain();
+			$textWithoutComment = preg_replace( '/^[\s\n]*<!--[\s\S]*?-->[\s\n]*/', '', $rawText );
+			$lines = explode( "\n", $textWithoutComment );
+			$paramLines = preg_replace( '/^\*\s*/', '', $lines );
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00e9a71 and 91c09e6.

📒 Files selected for processing (5)
  • i18n/en.json
  • i18n/qqq.json
  • src/ParameterProvider.php
  • src/SimpleBatchUpload.alias.php
  • src/UploadButtonRenderer.php
🧰 Additional context used
🧬 Code graph analysis (1)
src/UploadButtonRenderer.php (1)
src/ParameterProvider.php (1)
  • addTemplateParameter (137-144)
🔇 Additional comments (5)
i18n/en.json (1)

13-15: LGTM! Using HTML comments as default values for customizable system messages.

The approach of using HTML comment placeholders as default values is appropriate for messages intended to be customized by wiki administrators. The code in ParameterProvider.php correctly strips these comments when processing the messages.

i18n/qqq.json (1)

13-15: LGTM! Clear documentation for translators.

The instructions properly guide translators to preserve the HTML comment structure needed by the code's regex-based stripping logic.

src/SimpleBatchUpload.alias.php (1)

33-49: LGTM! Chinese locale aliases follow MediaWiki conventions.

The aliases for zh-hans, zh-hant, and zh-hk are correctly structured and use appropriate translations for "BatchUpload" in each Chinese variant.

src/ParameterProvider.php (1)

63-64: Verify the regex handles edge cases correctly.

The regex /^[\s\n]*<!--[\s\S]*?-->[\s\n]*/ uses a non-greedy match (*?) which correctly stops at the first -->. However, if the message contains multiple HTML comments, only the first one is stripped.

Per the qqq.json documentation ("Do not add anything outside the first comment"), this behavior is intentional. Just confirm this aligns with expected usage.

src/UploadButtonRenderer.php (1)

128-133: Behavioral change: Template parameters now added unconditionally.

The loop is now outside the if ($templateName !== '') block, meaning when templateName is empty, the empty string at $args[0] is also added as a template parameter. This appears intentional to support unnamed parser function calls like {{#batchupload:|arg1|arg2}}.

However, when templateName is empty:

  • $args[0] (the empty string) is not shifted off
  • The empty string gets added as a parameter via addTemplateParameter('')
  • This produces templateParameters = '|' initially

The normalization in ParameterProvider::getUploadPageText() (line 55: preg_replace('/^\|+/', '|', ...)) handles the resulting ||arg1|arg2 by collapsing leading pipes. Confirm this is the intended behavior for backward compatibility.

Comment on lines 51 to 68
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\S]*?-->[\s\n]*/', '', $fileSummaryMsg->plain() );
}
else {
return '{{' . $templateName . $templateParams . '}}';
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Potential malformed wikitext when templateName is empty and message doesn't exist.

When $this->templateName is empty and the simplebatchupload-filesummary message doesn't exist (or is disabled), the fallback on line 67 returns '{{' . $templateName . $templateParams . '}}'. Since $templateName would be empty and $templateParams could be |param1|param2, this produces malformed wikitext like {{|param1|param2}}.

Consider returning an empty string or just the parameters without the template wrapper when $templateName is empty:

Proposed fix
 		if ( $fileSummaryMsg->exists() ) {
 			return preg_replace( '/^[\s\n]*<!--[\s\S]*?-->[\s\n]*/', '', $fileSummaryMsg->plain() );
 		}
 		else {
+			if ( $templateName === '' ) {
+				return '';
+			}
 			return '{{' . $templateName . $templateParams . '}}';
 		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant