Skip to content

Commit

Permalink
ui for merged-from
Browse files Browse the repository at this point in the history
  • Loading branch information
ChlodAlejandro committed Jul 31, 2022
1 parent f077059 commit 333c07d
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 100 deletions.
25 changes: 23 additions & 2 deletions i18n/cte/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
"deputy.cte.merge.all.confirm": "You are about to merge $1 'copied' {{PLURAL:$1|notice|notices}} into this notice. Continue?",
"deputy.cte.merge.button": "Merge",

"deputy.cte.templateOptions": "Template options",

"deputy.cte.copied.label": "Copied $1",

"deputy.cte.copied.remove": "Remove notice",
"deputy.cte.copied.remove.confirm": "This will destroy $1 {{PLURAL:$1|entry|entries}}. Continue?",
"deputy.cte.copied.add": "Add entry",

"deputy.cte.copied.entry.label": "Template entry",
"deputy.cte.copied.entry.short": "$1 to $2",

"deputy.cte.copied.entry.remove": "Remove entry",
"deputy.cte.copied.entry.copy": "Copy attribution edit summary",
Expand Down Expand Up @@ -66,7 +69,7 @@
"deputy.cte.copied.diff.placeholder": "https://en.wikipedia.org/w/index.php?diff=123456",
"deputy.cte.copied.diff.label": "Diff URL",
"deputy.cte.copied.diff.help": "The URL of the diff. Using <code>to_diff</code> and <code>to_oldid</code> is preferred, although supplying this parameter will override both.",
"deputy.cte.copied.merge.label": "Merged",
"deputy.cte.copied.merge.label": "Merged?",
"deputy.cte.copied.merge.help": "Whether the copying was done as a result of merging two pages.",
"deputy.cte.copied.afd.placeholder": "AfD page (without Wikipedia:Articles for deletion/)",
"deputy.cte.copied.afd.label": "AfD page",
Expand All @@ -86,6 +89,7 @@

"deputy.cte.splitArticle.entry.label": "Template entry",
"deputy.cte.splitArticle.entry.remove": "Remove entry",
"deputy.cte.splitArticle.entry.short": "$1 on $2",

"deputy.cte.splitArticle.collapse": "Collapse",
"deputy.cte.splitArticle.from": "From",
Expand All @@ -101,5 +105,22 @@
"deputy.cte.splitArticle.date.help": "The date that the split occurred.",
"deputy.cte.splitArticle.diff.placeholder": "https://en.wikipedia.org/w/index.php?diff=123456&oldid=123455",
"deputy.cte.splitArticle.diff.label": "Diff URL",
"deputy.cte.splitArticle.diff.help": "The diff URL of the split."
"deputy.cte.splitArticle.diff.help": "The diff URL of the split.",

"deputy.cte.mergedFrom.label": "Merged from $1",
"deputy.cte.mergedFrom.remove": "Remove notice",

"deputy.cte.mergedFrom.article.placeholder": "Page A",
"deputy.cte.mergedFrom.article.label": "Original article",
"deputy.cte.mergedFrom.article.help": "This is the page where the merged content is or used to be.",
"deputy.cte.mergedFrom.date.label": "Date",
"deputy.cte.mergedFrom.date.help": "The date (in UTC) when the content was merged into this page.",
"deputy.cte.mergedFrom.talk.label": "Link to talk?",
"deputy.cte.mergedFrom.talk.help": "Whether to link to the original article's talk page or not.",
"deputy.cte.mergedFrom.target.placeholder": "Page B",
"deputy.cte.mergedFrom.target.label": "Merge target",
"deputy.cte.mergedFrom.target.help": "The page that the content was merged into. Used if the page that the content was merged into was the talk page.",
"deputy.cte.mergedFrom.afd.placeholder": "Wikipedia:Articles for deletion/Page A",
"deputy.cte.mergedFrom.afd.label": "AfD",
"deputy.cte.mergedFrom.afd.help": "The AfD discussion that led to the merge. If this merge was not the result of an AfD discussion, leave this blank."
}
5 changes: 4 additions & 1 deletion src/modules/cte/CopiedTemplateEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ export default class CopiedTemplateEditor {
// Find all {{copied}} templates and append our special button.
// This runs on the actual document, not the Parsoid document.
document.querySelectorAll(
[ 'copiednotice', 'box-split-article' ].map(
[
'copiednotice', 'box-split-article', 'box-merged-from',
'box-merged-to', 'box-backwards-copy', 'box-translated-page'
].map(
( v ) => `.${v} > tbody > tr`
).join( ', ' )
)
Expand Down
5 changes: 3 additions & 2 deletions src/modules/cte/css/copied-template-editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@
padding-right: 0;
}

.cte-page-template,
.cte-page-row,
.cte-page-template:not(:last-child),
.cte-fieldset-date.oo-ui-actionFieldLayout.oo-ui-fieldLayout-align-top .oo-ui-fieldLayout-header {
padding-bottom: 0 !important;
}

.cte-page-row {
.cte-page-template + .cte-page-row {
padding-top: 0 !important;
}

Expand Down
10 changes: 5 additions & 5 deletions src/modules/cte/models/RowedAttributionNotice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ export default abstract class RowedAttributionNotice<
if ( this.node.hasParameter( key ) !== undefined ) {
row[ key ] = this.node.getParameter( key );
} else if (
suffix === '' && this.node.getParameter( `${key}1` ) !== undefined
suffix === '' && this.node.hasParameter( `${key}1` )
) {
// Non-numbered parameter not found but a numbered parameter with
// an index of 1 was. Fall back to that value.
row[ key ] = this.node.getParameter( `${key}1` );
// an index of 1 was found. Fall back to that value.
row[ key ] = this.node.getParameter( `${key}1` ).trim();
} else if (
suffix === 1 && this.node.getParameter( `${key}` )
suffix === 1 && this.node.hasParameter( `${key}` )
) {
// This is i = 1, so fall back to a non-numbered parameter (if exists)
const unnumberedParamValue = this.node.getParameter( `${key}` );
const unnumberedParamValue = this.node.getParameter( `${key}` ).trim();
if ( unnumberedParamValue !== undefined ) {
row[ key ] = unnumberedParamValue;
}
Expand Down
5 changes: 3 additions & 2 deletions src/modules/cte/models/templates/CopiedTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AttributionNoticePageLayout } from '../../ui/pages/AttributionNoticePag
import CopiedTemplatePage from '../../ui/pages/CopiedTemplatePage';
import { AttributionNoticePageGenerator } from '../../ui/AttributionNoticePageGenerator';
import RowedAttributionNotice from '../RowedAttributionNotice';
import yesNo from '../../../../util/yesNo';

/**
* Represents a single {{copied}} template in the Parsoid document.
Expand Down Expand Up @@ -41,10 +42,10 @@ export default class CopiedTemplate
*/
parse() {
if ( this.node.getParameter( 'collapse' ) ) {
this.collapsed = this.node.getParameter( 'collapse' ).trim().length > 0;
this.collapsed = yesNo( this.node.getParameter( 'collapse' ).trim() );
}
if ( this.node.getParameter( 'small' ) ) {
this.small = this.node.getParameter( 'small' ).trim().length > 0;
this.small = yesNo( this.node.getParameter( 'small' ).trim() );
}

// Extract {{copied}} rows.
Expand Down
47 changes: 28 additions & 19 deletions src/modules/cte/models/templates/MergedFromTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import CopiedTemplateRow, {
copiedTemplateRowParameters,
RawCopiedTemplateRow
} from './CopiedTemplateRow';
import CopiedTemplateRow from './CopiedTemplateRow';
import { AttributionNoticePageLayout } from '../../ui/pages/AttributionNoticePageLayout';
import CopiedTemplatePage from '../../ui/pages/CopiedTemplatePage';
import { AttributionNoticePageGenerator } from '../../ui/AttributionNoticePageGenerator';
import RowedAttributionNotice from '../RowedAttributionNotice';
import MergedFromTemplatePage from '../../ui/pages/MergedFromTemplatePage';
import yesNo from '../../../../util/yesNo';

/**
* Represents a single {{merged-from}} template in the Parsoid document.
*/
export default class MergedFromTemplate
extends RowedAttributionNotice<CopiedTemplateRow>
implements AttributionNoticePageGenerator {

// TEMPLATE OPTIONS
export interface RawMergedFromTemplate {
/**
* The article that content from the target page was originally from.
*/
Expand All @@ -25,9 +15,7 @@ export default class MergedFromTemplate
*/
date: string;
/**
* If the merge discussion occurred on a talk page that is not the target
* page's talk page, this should be supplied with the page title of that talk
* page.
* Whether to link to the original article's talk page or not.
*/
talk?: string;
/**
Expand All @@ -41,6 +29,27 @@ export default class MergedFromTemplate
* @example "Wikipedia:Articles for deletion/Wikipedia"
*/
afd?: string;
}
export type MergedFromTemplateParameter = keyof RawMergedFromTemplate;

/**
* Represents a single {{merged-from}} template in the Parsoid document.
*/
export default class MergedFromTemplate
extends RowedAttributionNotice<CopiedTemplateRow>
implements AttributionNoticePageGenerator, RawMergedFromTemplate {

// TEMPLATE OPTIONS
/** @inheritDoc */
article: string;
/** @inheritDoc */
date: string;
/** @inheritDoc */
talk?: string;
/** @inheritDoc */
target?: string;
/** @inheritDoc */
afd?: string;

/**
* Parses parameters into class properties. This WILL destroy unknown
Expand Down Expand Up @@ -73,13 +82,13 @@ export default class MergedFromTemplate
this.node.setParameter( '1', this.article.trim() );
this.node.setParameter( '2', this.date.trim() );
this.node.setParameter(
'talk', this.talk.trim().length > 0 ? this.talk.trim() : null
'talk', yesNo( this.talk ) ? null : 'no'
);
this.node.setParameter(
'target', this.target.trim().length > 0 ? this.target.trim() : null
'target', ( this.target ?? '' ).trim().length > 0 ? this.target.trim() : null
);
this.node.setParameter(
'afd', this.afd.trim().length > 0 ? this.afd.trim() : null
'afd', ( this.afd ?? '' ).trim().length > 0 ? this.afd.trim() : null
);

this.dispatchEvent( new Event( 'save' ) );
Expand Down
7 changes: 4 additions & 3 deletions src/modules/cte/models/templates/SplitArticleTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import SplitArticleTemplateRow, {
} from './SplitArticleTemplateRow';
import RowedAttributionNotice from '../RowedAttributionNotice';
import SplitArticleTemplatePage from '../../ui/pages/SplitArticleTemplatePage';
import yesNo from '../../../../util/yesNo';

/**
* Represents a single {{split article}} template.
Expand All @@ -26,7 +27,7 @@ export default class SplitArticleTemplate
this.from = this.node.getParameter( 'from' ).trim();
}
if ( this.node.hasParameter( 'collapse' ) ) {
this.collapse = this.node.getParameter( 'collapse' ).trim().length > 0;
this.collapse = yesNo( this.node.getParameter( 'collapse' ) );
}

// Extract {{copied}} rows.
Expand Down Expand Up @@ -94,10 +95,10 @@ export default class SplitArticleTemplate
* @inheritDoc
*/
destroy(): void {
this.dispatchEvent( new Event( 'destroy' ) );
this.accessTemplateData( () => undefined );
this.node.destroy();
// Self-destruct
Object.keys( this ).forEach( ( k ) => delete ( this as any )[ k ] );
this.dispatchEvent( new Event( 'destroy' ) );
}

/**
Expand Down
35 changes: 22 additions & 13 deletions src/modules/cte/ui/pages/CopiedTemplateRowPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import copyToClipboard from '../../../../util/copyToClipboard';
import getObjectValues from '../../../../util/getObjectValues';
import CopiedTemplateEditorDialog from '../CopiedTemplateEditorDialog';
import { AttributionNoticePageLayout } from './AttributionNoticePageLayout';
import yesNo from '../../../../util/yesNo';

export interface CopiedTemplateRowPageData {
/**
Expand Down Expand Up @@ -77,14 +78,13 @@ function initCopiedTemplateRowPage() {
}

const finalConfig = {
label: `${copiedTemplateRow.from || '???'} to ${copiedTemplateRow.to || '???'}`,
classes: [ 'cte-page-row' ]
};
super( copiedTemplateRow.id, finalConfig );

this.parent = parent;
this.copiedTemplateRow = copiedTemplateRow;
this.label = finalConfig.label;
this.refreshLabel();

this.copiedTemplateRow.parent.addEventListener( 'destroy', () => {
parent.rebuildPages();
Expand All @@ -96,6 +96,20 @@ function initCopiedTemplateRowPage() {
this.$element.append( this.render().$element );
}

/**
* Refreshes the page's label
*/
refreshLabel(): void {
this.label = mw.message(
'deputy.cte.copied.entry.short',
this.copiedTemplateRow.from || '???',
this.copiedTemplateRow.to || '???'
).text();
if ( this.outlineItem ) {
this.outlineItem.setLabel( this.label );
}
}

/**
* Renders this page. Returns a FieldsetLayout OOUI widget.
*
Expand Down Expand Up @@ -260,7 +274,7 @@ function initCopiedTemplateRowPage() {
value: copiedTemplateRow.diff
} ),
merge: new OO.ui.CheckboxInputWidget( {
value: copiedTemplateRow.merge !== undefined
value: yesNo( copiedTemplateRow.merge )
} ),
afd: new OO.ui.TextInputWidget( {
placeholder: mw.message( 'deputy.cte.copied.afd.placeholder' ).text(),
Expand Down Expand Up @@ -332,9 +346,9 @@ function initCopiedTemplateRowPage() {
} ),
merge: new OO.ui.FieldLayout( this.inputs.merge, {
$overlay: this.parent.$overlay,
label: mw.message( 'deputy.cte.merge.label' ).text(),
label: mw.message( 'deputy.cte.copied.merge.label' ).text(),
align: 'inline',
help: mw.message( 'deputy.cte.merge.help' ).text()
help: mw.message( 'deputy.cte.copied.merge.help' ).text()
} ),
afd: new OO.ui.FieldLayout( this.inputs.afd, {
$overlay: this.parent.$overlay,
Expand Down Expand Up @@ -426,16 +440,10 @@ function initCopiedTemplateRowPage() {
);
} );
this.inputs.from.on( 'change', () => {
/** @member any */
this.outlineItem.setLabel(
`${this.inputs.from.value || '???'} to ${this.inputs.to.value || '???'}`
);
this.refreshLabel();
} );
this.inputs.to.on( 'change', () => {
/** @member any */
this.outlineItem.setLabel(
`${this.inputs.from.value || '???'} to ${this.inputs.to.value || '???'}`
);
this.refreshLabel();
} );

for ( const _field in this.inputs ) {
Expand All @@ -448,6 +456,7 @@ function initCopiedTemplateRowPage() {
// Attach the change listener
input.on( 'change', ( value: string ) => {
if ( input instanceof OO.ui.CheckboxInputWidget ) {
// Specific to `merge`. Watch out before adding more checkboxes.
this.copiedTemplateRow[ field ] = value ? 'yes' : '';
} else if ( input instanceof mw.widgets.datetime.DateTimeInputWidget ) {
this.copiedTemplateRow[ field ] =
Expand Down
Loading

0 comments on commit 333c07d

Please sign in to comment.