diff --git a/i18n/ante/en.json b/i18n/ante/en.json index dc7dc561..dc5e8597 100644 --- a/i18n/ante/en.json +++ b/i18n/ante/en.json @@ -199,11 +199,15 @@ "deputy.ante.translatedPage.insertversion.placeholder": "987654321", "deputy.ante.translatedPage.insertversion.label": "Insertion revision ID", "deputy.ante.translatedPage.insertversion.help": "The revision ID of the revision where the translated content was inserted into the page bearing this notice.", - "deputy.ante.translatedPage.section.placeholder": "Section name", + "deputy.ante.translatedPage.section.placeholder": "Section name (leave blank if N/A)", "deputy.ante.translatedPage.section.label": "Section", "deputy.ante.translatedPage.section.help": "The section of the page that was translated, if a specific section was translated. Leave blank if this does not apply, or if translation was performed on the entire page or more than one section.", "deputy.ante.translatedPage.small.label": "Small?", "deputy.ante.translatedPage.small.help": "Whether to render the template as a small message box or not. By default, a small box is used. If you have a good reason to use a full-sized banner, disable this option.", "deputy.ante.translatedPage.partial.label": "Partial?", - "deputy.ante.translatedPage.partial.help": "Whether this translation is a partial translation or not." + "deputy.ante.translatedPage.partial.help": "Whether this translation is a partial translation or not.", + + "deputy.ante.translatedPage.copy": "Copy attribution edit summary", + "deputy.ante.translatedPage.copy.lacking": "Attribution edit summary copied to clipboard with lacking properties. Ensure that `from` is supplied.", + "deputy.ante.translatedPage.copy.success": "Attribution edit summary copied to clipboard." } diff --git a/src/modules/ante/ui/pages/CopiedTemplateRowPage.tsx b/src/modules/ante/ui/pages/CopiedTemplateRowPage.tsx index ccaa44c8..90926062 100644 --- a/src/modules/ante/ui/pages/CopiedTemplateRowPage.tsx +++ b/src/modules/ante/ui/pages/CopiedTemplateRowPage.tsx @@ -171,7 +171,7 @@ function initCopiedTemplateRowPage() { framed: false } ); copyButton.on( 'click', () => { - // TODO: Find out a way to i18n-ize this. + // TODO: Find out a way to l10n-ize this. let attributionString = `[[WP:PATT|Attribution]]: Content ${ this.copiedTemplateRow.merge ? 'merged' : 'partially copied' }`; diff --git a/src/modules/ante/ui/pages/TranslatedPageTemplatePage.tsx b/src/modules/ante/ui/pages/TranslatedPageTemplatePage.tsx index af9fa139..30d509af 100644 --- a/src/modules/ante/ui/pages/TranslatedPageTemplatePage.tsx +++ b/src/modules/ante/ui/pages/TranslatedPageTemplatePage.tsx @@ -7,6 +7,7 @@ import unwrapWidget from '../../../../util/unwrapWidget'; import { renderPreviewPanel } from '../RowPageShared'; import getObjectValues from '../../../../util/getObjectValues'; import yesNo from '../../../../util/yesNo'; +import copyToClipboard from '../../../../util/copyToClipboard'; export interface TranslatedPageTemplatePageData { /** @@ -105,7 +106,71 @@ function initTranslatedPageTemplatePage() { * @return A
element. */ renderButtons(): JSX.Element { - const buttonSet =
; + const copyButton = new OO.ui.ButtonWidget( { + icon: 'quotes', + title: mw.message( 'deputy.ante.translatedPage.copy' ).text(), + framed: false + } ); + copyButton.on( 'click', () => { + // TODO: Find out a way to l10n-ize this. + let attributionString = `[[WP:PATT|Attribution]]: Content translated from [[:${ + this.translatedPageTemplate.lang + }:`; + let lacking = false; + if ( + this.translatedPageTemplate.page != null && + this.translatedPageTemplate.page.length !== 0 + ) { + attributionString += `${this.translatedPageTemplate.page}]]`; + } else { + lacking = true; + if ( this.translatedPageTemplate.version != null ) { + attributionString += `|from a page on ${ + this.translatedPageTemplate.lang + }.wikipedia]]`; + } + } + if ( this.translatedPageTemplate.version != null ) { + attributionString += ` as of revision [[:ru:Special:Diff/${ + this.translatedPageTemplate.version + }|${ + this.translatedPageTemplate.version + }]]`; + } + if ( + this.translatedPageTemplate.insertversion != null && + this.translatedPageTemplate.insertversion.length !== 0 + ) { + attributionString += ` with [[Special:Diff/${ + this.translatedPageTemplate.insertversion + }|this edit]]`; + } + if ( + this.translatedPageTemplate.page != null && + this.translatedPageTemplate.page.length !== 0 + ) { + attributionString += `; refer to that page's [[:${ + this.translatedPageTemplate.lang + }:Special:PageHistory/${ + this.translatedPageTemplate.page + }|edit history]] for additional attribution`; + } + attributionString += '.'; + + copyToClipboard( attributionString ); + + if ( lacking ) { + mw.notify( + mw.message( 'deputy.ante.translatedPage.copy.lacking' ).text(), + { title: mw.message( 'deputy.ante' ).text(), type: 'warn' } + ); + } else { + mw.notify( + mw.message( 'deputy.ante.translatedPage.copy.success' ).text(), + { title: mw.message( 'deputy.ante' ).text() } + ); + } + } ); const deleteButton = new OO.ui.ButtonWidget( { icon: 'trash', @@ -117,9 +182,10 @@ function initTranslatedPageTemplatePage() { this.translatedPageTemplate.destroy(); } ); - buttonSet.appendChild( unwrapWidget( deleteButton ) ); - - return buttonSet; + return
+ { unwrapWidget( copyButton ) } + { unwrapWidget( deleteButton ) } +
; } /** @@ -166,17 +232,19 @@ function initTranslatedPageTemplatePage() { 'deputy.ante.translatedPage.comments.placeholder' ).text() } ), - version: new OO.ui.NumberInputWidget( { - value: this.translatedPageTemplate.comments, + version: new OO.ui.TextInputWidget( { + value: this.translatedPageTemplate.version, placeholder: mw.message( 'deputy.ante.translatedPage.version.placeholder' - ).text() + ).text(), + validate: /^\d+$/gi } ), - insertversion: new OO.ui.NumberInputWidget( { - value: this.translatedPageTemplate.comments, + insertversion: new OO.ui.TextInputWidget( { + value: this.translatedPageTemplate.insertversion, placeholder: mw.message( 'deputy.ante.translatedPage.insertversion.placeholder' - ).text() + ).text(), + validate: /^[\d/]+$/gi } ), section: new OO.ui.TextInputWidget( { value: this.translatedPageTemplate.section, @@ -251,7 +319,8 @@ function initTranslatedPageTemplatePage() { if ( input instanceof OO.ui.CheckboxInputWidget ) { this.translatedPageTemplate[ field ] = value ? 'yes' : 'no'; } else { - this.translatedPageTemplate[ field ] = value; + this.translatedPageTemplate[ field ] = + typeof value === 'string' ? value.trim() : value; } this.translatedPageTemplate.save();