Skip to content

Commit

Permalink
ante: TranslatedPageTemplatePage improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ChlodAlejandro committed Sep 4, 2022
1 parent daa50d0 commit b7a81e4
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 14 deletions.
8 changes: 6 additions & 2 deletions i18n/ante/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
2 changes: 1 addition & 1 deletion src/modules/ante/ui/pages/CopiedTemplateRowPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}`;
Expand Down
91 changes: 80 additions & 11 deletions src/modules/ante/ui/pages/TranslatedPageTemplatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -105,7 +106,71 @@ function initTranslatedPageTemplatePage() {
* @return A <div> element.
*/
renderButtons(): JSX.Element {
const buttonSet = <div style={{ float: 'right' }}/>;
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',
Expand All @@ -117,9 +182,10 @@ function initTranslatedPageTemplatePage() {
this.translatedPageTemplate.destroy();
} );

buttonSet.appendChild( unwrapWidget( deleteButton ) );

return buttonSet;
return <div style={{ float: 'right' }}>
{ unwrapWidget( copyButton ) }
{ unwrapWidget( deleteButton ) }
</div>;
}

/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b7a81e4

Please sign in to comment.