Skip to content

Commit 6bef573

Browse files
translated page support
1 parent a6aed63 commit 6bef573

16 files changed

+598
-40
lines changed

i18n/cte/en.json

+34-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
"deputy.cte.delete": "Delete all notices",
1313
"deputy.cte.delete.confirm": "You are about to delete $1 {{PLURAL:$1|notice|notices}}. Continue?",
1414

15+
"deputy.cte.nocat.head": "<code>nocat</code> is enabled",
16+
"deputy.cte.nocat.help": "This notice has the <code>nocat</code> parameter enabled and, as an effect, is not being tracked in categories. This usually means that the template is for demonstration purposes only.",
17+
"deputy.cte.nocat.clear": "Restore tracking",
18+
"deputy.cte.demo.head": "<code>demo</code> is enabled",
19+
"deputy.cte.demo.help": "This notice has the <code>demo</code> parameter enabled. This usually means that the template is for demonstration purposes only.",
20+
"deputy.cte.demo.clear": "Clear demo mode",
21+
1522
"deputy.cte.invalid": "Some fields are still invalid.",
1623
"deputy.cte.adding": "Adding content attribution notices",
1724
"deputy.cte.modifying": "Modifying content attribution notices",
@@ -165,5 +172,31 @@
165172
"deputy.cte.backwardsCopy.entry.url.help": "A URL to the published media, if it exists as an online resource. If this is not an online resource (newspaper media, other printed media), leave this blank.",
166173
"deputy.cte.backwardsCopy.entry.org.placeholder": "Example Publishing",
167174
"deputy.cte.backwardsCopy.entry.org.label": "Publisher",
168-
"deputy.cte.backwardsCopy.entry.org.help": "The publisher of the media. This may be a news company or a book publishing company."
175+
"deputy.cte.backwardsCopy.entry.org.help": "The publisher of the media. This may be a news company or a book publishing company.",
176+
177+
"deputy.cte.translatedPage.label": "Translated from $1:$2",
178+
"deputy.cte.translatedPage.remove": "Remove notice",
179+
180+
"deputy.cte.translatedPage.lang.placeholder": "en, de, fr, es, etc.",
181+
"deputy.cte.translatedPage.lang.label": "Language code",
182+
"deputy.cte.translatedPage.lang.help": "The language code of the wiki that the page was translated from. This is the \"en\" of the English Wikipedia, or the \"fr\" of the French Wikipedia.",
183+
"deputy.cte.translatedPage.page.placeholder": "Page on other wiki",
184+
"deputy.cte.translatedPage.page.label": "Source page",
185+
"deputy.cte.translatedPage.page.help": "The page on the other wiki that the content was copied from. Do not translate the page title.",
186+
"deputy.cte.translatedPage.comments.placeholder": "Additional comments",
187+
"deputy.cte.translatedPage.comments.label": "Comments",
188+
"deputy.cte.translatedPage.comments.help": "Additional comments that are pertinent to translation.",
189+
"deputy.cte.translatedPage.version.placeholder": "123456789",
190+
"deputy.cte.translatedPage.version.label": "Source revision ID",
191+
"deputy.cte.translatedPage.version.help": "The revision ID of the source page at the time of translation.",
192+
"deputy.cte.translatedPage.insertversion.placeholder": "987654321",
193+
"deputy.cte.translatedPage.insertversion.label": "Insertion revision ID",
194+
"deputy.cte.translatedPage.insertversion.help": "The revision ID of the revision where the translated content was inserted into the page bearing this notice.",
195+
"deputy.cte.translatedPage.section.placeholder": "Section name",
196+
"deputy.cte.translatedPage.section.label": "Section",
197+
"deputy.cte.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.",
198+
"deputy.cte.translatedPage.small.label": "Small?",
199+
"deputy.cte.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.",
200+
"deputy.cte.translatedPage.partial.label": "Partial?",
201+
"deputy.cte.translatedPage.partial.help": "Whether this translation is a partial translation or not."
169202
}

src/modules/cte/css/copied-template-editor.css

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
background-color: #ddf7ff;
5757
padding: 16px;
5858
min-width: 200px;
59+
clear: both;
5960
}
6061

6162
.cte-fieldset-date {

src/modules/cte/models/AttributionNotice.ts

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export default abstract class AttributionNotice
111111

112112
/**
113113
* Extracts the parameters from this notice and stores them in the object.
114+
* This must NEVER destroy unknown parameters. This function does not always
115+
* pull all parameters from the template, only those that are known.
114116
*
115117
* This should be implemented by subclasses.
116118
*/

src/modules/cte/models/CTEParsoidDocument.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ export default class CTEParsoidDocument extends ParsoidDocument {
131131
splitArticle: 1,
132132
mergedFrom: 2,
133133
mergedTo: 3,
134-
backwardsCopy: 4
134+
backwardsCopy: 4,
135+
translatedPage: 5
135136
};
136137
const positionIndex = positionIndices[ type ];
137138
const variableSpots: [InsertPosition, HTMLElement|null][] = [
@@ -165,12 +166,11 @@ export default class CTEParsoidDocument extends ParsoidDocument {
165166
last( this.document.querySelectorAll( '.box-backwards-copy' ) ) :
166167
this.document.querySelector( '.box-backwards-copy' )
167168
],
168-
// TODO: replace `copied` with `translatedPage` when it's available.
169169
[
170-
positionIndex >= positionIndices.copied ? 'afterend' : 'beforebegin',
171-
positionIndex >= positionIndices.copied ?
172-
last( this.document.querySelectorAll( '.box-merged-to' ) ) :
173-
this.document.querySelector( '.box-merged-to' )
170+
positionIndex >= positionIndices.translatedPage ? 'afterend' : 'beforebegin',
171+
positionIndex >= positionIndices.translatedPage ?
172+
last( this.document.querySelectorAll( '.box-translated-page' ) ) :
173+
this.document.querySelector( '.box-translated-page' )
174174
]
175175
];
176176

@@ -245,7 +245,8 @@ export default class CTEParsoidDocument extends ParsoidDocument {
245245
splitArticle: TemplateFactory.splitArticle,
246246
mergedFrom: TemplateFactory.mergedFrom,
247247
mergedTo: TemplateFactory.mergedTo,
248-
backwardsCopy: TemplateFactory.backwardsCopy
248+
backwardsCopy: TemplateFactory.backwardsCopy,
249+
translatedPage: TemplateFactory.translatedPage
249250
} )[ type ]( this );
250251

251252
// Insert.

src/modules/cte/models/TemplateFactory.ts

+18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import SplitArticleTemplate from './templates/SplitArticleTemplate';
77
import MergedFromTemplate from './templates/MergedFromTemplate';
88
import MergedToTemplate from './templates/MergedToTemplate';
99
import BackwardsCopyTemplate from './templates/BackwardsCopyTemplate';
10+
import TranslatedPageTemplate from './templates/TranslatedPageTemplate';
1011

1112
/**
1213
* Creates blank attribution notices. Its own class to avoid circular dependencies.
@@ -134,4 +135,21 @@ export default class TemplateFactory {
134135
return new BackwardsCopyTemplate( node );
135136
}
136137

138+
/**
139+
* Creates a new {@link TranslatedPageTemplate}
140+
*
141+
* @param document
142+
* @return A new MergedToTemplate
143+
*/
144+
static translatedPage( document: CTEParsoidDocument ): TranslatedPageTemplate {
145+
const templateWikitext = TemplateFactory.getTemplateWikitext( 'translatedPage' );
146+
const node = CTEParsoidTransclusionTemplateNode.fromNew(
147+
document,
148+
templateWikitext
149+
);
150+
node.element.setAttribute( 'about', `N${TemplateFactory.noticeCount++}` );
151+
node.element.classList.add( 'box-translated-page' );
152+
return new TranslatedPageTemplate( node );
153+
}
154+
137155
}

src/modules/cte/models/WikiAttributionNotices.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import SplitArticleTemplate from './templates/SplitArticleTemplate';
77
import MergedFromTemplate from './templates/MergedFromTemplate';
88
import MergedToTemplate from './templates/MergedToTemplate';
99
import BackwardsCopyTemplate from './templates/BackwardsCopyTemplate';
10+
import TranslatedPageTemplate from './templates/TranslatedPageTemplate';
1011

1112
/**
1213
* An object mapping notice types to their expected on-wiki page titles.
@@ -16,8 +17,8 @@ export const attributionNoticeTemplatePages = {
1617
splitArticle: 'Split article',
1718
mergedFrom: 'Merged-from',
1819
mergedTo: 'Merged-to',
19-
backwardsCopy: 'Backwards copy'
20-
// translatedPage: 'Translated page'
20+
backwardsCopy: 'Backwards copy',
21+
translatedPage: 'Translated page'
2122
};
2223

2324
/**
@@ -60,9 +61,8 @@ export default class WikiAttributionNotices {
6061
splitArticle: SplitArticleTemplate,
6162
mergedFrom: MergedFromTemplate,
6263
mergedTo: MergedToTemplate,
63-
backwardsCopy: BackwardsCopyTemplate
64-
// TODO: Implement
65-
// translatedPage: class Null {}
64+
backwardsCopy: BackwardsCopyTemplate,
65+
translatedPage: TranslatedPageTemplate
6666
};
6767

6868
/**

src/modules/cte/models/templates/CopiedTemplate.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ export default class CopiedTemplate
3535
}
3636

3737
/**
38-
* Parses parameters into class properties. This WILL destroy unknown
39-
* parameters and parameters in the incorrect order!
40-
*
41-
* This function does not modify the template data.
38+
* @inheritDoc
4239
*/
4340
parse() {
4441
if ( this.node.getParameter( 'collapse' ) ) {
@@ -88,7 +85,7 @@ export default class CopiedTemplate
8885
}
8986

9087
/**
91-
* Saves the current template data to the Parsoid element.
88+
* @inheritDoc
9289
*/
9390
save() {
9491
if ( this.collapsed !== undefined ) {
@@ -131,7 +128,7 @@ export default class CopiedTemplate
131128
}
132129

133130
/**
134-
* Destroys this template completely.
131+
* @inheritDoc
135132
*/
136133
destroy() {
137134
this.node.destroy();

src/modules/cte/models/templates/MergedFromTemplate.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import CopiedTemplateRow from './CopiedTemplateRow';
21
import { AttributionNoticePageLayout } from '../../ui/pages/AttributionNoticePageLayout';
32
import { AttributionNoticePageGenerator } from '../../ui/AttributionNoticePageGenerator';
4-
import RowedAttributionNotice from '../RowedAttributionNotice';
53
import MergedFromTemplatePage from '../../ui/pages/MergedFromTemplatePage';
64
import yesNo from '../../../../util/yesNo';
5+
import AttributionNotice from '../AttributionNotice';
76

87
export interface RawMergedFromTemplate {
98
/**
@@ -36,7 +35,7 @@ export type MergedFromTemplateParameter = keyof RawMergedFromTemplate;
3635
* Represents a single {{merged-from}} template in the Parsoid document.
3736
*/
3837
export default class MergedFromTemplate
39-
extends RowedAttributionNotice<CopiedTemplateRow>
38+
extends AttributionNotice
4039
implements AttributionNoticePageGenerator, RawMergedFromTemplate {
4140

4241
// TEMPLATE OPTIONS
@@ -52,10 +51,7 @@ export default class MergedFromTemplate
5251
afd?: string;
5352

5453
/**
55-
* Parses parameters into class properties. This WILL destroy unknown
56-
* parameters and parameters in the incorrect order!
57-
*
58-
* This function does not modify the template data.
54+
* @inheritDoc
5955
*/
6056
parse() {
6157
if ( this.node.hasParameter( '1' ) ) {
@@ -76,7 +72,7 @@ export default class MergedFromTemplate
7672
}
7773

7874
/**
79-
* Saves the current template data to the Parsoid element.
75+
* @inheritDoc
8076
*/
8177
save() {
8278
this.node.setParameter( '1', this.article );
@@ -97,7 +93,7 @@ export default class MergedFromTemplate
9793
}
9894

9995
/**
100-
* Destroys this template completely.
96+
* @inheritDoc
10197
*/
10298
destroy() {
10399
this.node.destroy();

src/modules/cte/models/templates/MergedToTemplate.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import CopiedTemplateRow from './CopiedTemplateRow';
21
import { AttributionNoticePageLayout } from '../../ui/pages/AttributionNoticePageLayout';
32
import { AttributionNoticePageGenerator } from '../../ui/AttributionNoticePageGenerator';
4-
import RowedAttributionNotice from '../RowedAttributionNotice';
53
import MergedToTemplatePage from '../../ui/pages/MergedToTemplatePage';
64
import yesNo from '../../../../util/yesNo';
5+
import AttributionNotice from '../AttributionNotice';
76

87
export interface RawMergedToTemplate {
98
/**
@@ -22,10 +21,10 @@ export interface RawMergedToTemplate {
2221
export type MergedToTemplateParameter = keyof RawMergedToTemplate;
2322

2423
/**
25-
* Represents a single {{merged-from}} template in the Parsoid document.
24+
* Represents a single {{merged-to}} template in the Parsoid document.
2625
*/
2726
export default class MergedToTemplate
28-
extends RowedAttributionNotice<CopiedTemplateRow>
27+
extends AttributionNotice
2928
implements AttributionNoticePageGenerator, RawMergedToTemplate {
3029

3130
// TEMPLATE OPTIONS
@@ -37,10 +36,7 @@ export default class MergedToTemplate
3736
small?: string;
3837

3938
/**
40-
* Parses parameters into class properties. This WILL destroy unknown
41-
* parameters and parameters in the incorrect order!
42-
*
43-
* This function does not modify the template data.
39+
* inheritDoc
4440
*/
4541
parse() {
4642
if ( this.node.hasParameter( 'to' ) ) {
@@ -59,7 +55,7 @@ export default class MergedToTemplate
5955
}
6056

6157
/**
62-
* Saves the current template data to the Parsoid element.
58+
* @inheritDoc
6359
*/
6460
save() {
6561
// Reset named parameters
@@ -78,7 +74,7 @@ export default class MergedToTemplate
7874
}
7975

8076
/**
81-
* Destroys this template completely.
77+
* @inheritDoc
8278
*/
8379
destroy() {
8480
this.node.destroy();

src/modules/cte/models/templates/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The following paradigms are used for the development of template and template ro
1717
- Template models should embody global parameters for row-based templates, or all parameters for simple templates.
1818
- By embody, this means the parameter should be a field in the class.
1919
- The field on the class must be a string.
20+
- If the parameter is positional (`1`, `2`, etc.), fall back to a fitting variable name.
2021
- Template row models should embody each row parameter without its numbered suffix.
2122
- By embody, this means the parameter should be a field in the class and a key in the raw row interface.
2223
- The field on the class must be a string.

src/modules/cte/models/templates/SplitArticleTemplate.ts

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export default class SplitArticleTemplate
6767
}
6868

6969
/**
70-
*
7170
* @inheritDoc
7271
*/
7372
save(): void {

0 commit comments

Comments
 (0)