Skip to content

Commit

Permalink
finish support for {{split article}}
Browse files Browse the repository at this point in the history
  • Loading branch information
ChlodAlejandro committed Jul 28, 2022
1 parent c59da30 commit a33afa2
Show file tree
Hide file tree
Showing 20 changed files with 682 additions and 300 deletions.
49 changes: 38 additions & 11 deletions i18n/cte/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"deputy.cte.close": "Close",
"deputy.cte.save": "Save",
"deputy.cte.add": "Add a notice",
"deputy.cte.merge": "Merge all notices",
"deputy.cte.merge.confirm": "You are about to merge $1 {{PLURAL:$1|notice|notices}}. Continue?",
"deputy.cte.mergeAll": "Merge all notices",
"deputy.cte.mergeAll.confirm": "You are about to merge $1 {{PLURAL:$1|notice|notices}}. Continue?",
"deputy.cte.reset": "Reset all changes",
"deputy.cte.reset.confirm": "This will reset all changes. Proceed?",
"deputy.cte.delete": "Delete all notices",
Expand All @@ -23,15 +23,16 @@
"deputy.cte.empty.add": "Add a notice",
"deputy.cte.noSpot": "Sorry, but a notice cannot be automatically added. Please contact the developer to possibly add support for this talk page.",

"deputy.cte.merge": "Merge",
"deputy.cte.merge.title": "Merge notices",
"deputy.cte.merge.from.label": "Notices to merge",
"deputy.cte.merge.from.select": "Select a notice",
"deputy.cte.merge.from.empty": "No notices to merge",
"deputy.cte.merge.all": "Merge all",
"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.copied.label": "Copied $1",
"deputy.cte.copied.merge": "Merge",
"deputy.cte.copied.merge.title": "Merge 'copied' templates",
"deputy.cte.copied.merge.from.label": "Notices to merge",
"deputy.cte.copied.merge.from.select": "Select a notice",
"deputy.cte.copied.merge.from.empty": "No notices to merge",
"deputy.cte.copied.merge.all": "Merge all",
"deputy.cte.copied.merge.all.confirm": "You are about to merge $1 'copied' {{PLURAL:$1|notice|notices}} into this notice. Continue?",
"deputy.cte.copied.merge.button": "Merge",

"deputy.cte.copied.remove": "Remove notice",
"deputy.cte.copied.remove.confirm": "This will destroy $1 {{PLURAL:$1|entry|entries}}. Continue?",
Expand All @@ -44,6 +45,9 @@
"deputy.cte.copied.entry.copy.lacking": "Attribution edit summary copied to clipboard with lacking properties. Ensure that `from` is supplied.",
"deputy.cte.copied.entry.copy.success": "Attribution edit summary copied to clipboard.",

"deputy.cte.copied.collapse": "Collapse",
"deputy.cte.copied.small": "Small",

"deputy.cte.copied.from.placeholder": "Page A",
"deputy.cte.copied.from.label": "Page copied from",
"deputy.cte.copied.from.help": "This is the page from which the content was copied from.",
Expand Down Expand Up @@ -74,5 +78,28 @@
"deputy.cte.copied.diffDeprecate.replace": "The current value of '$1', \"$2\", will be replaced with \"$3\". Continue?",
"deputy.cte.copied.diffDeprecate.failed": "Cannot convert `diff` parameter to URL. See your browser console for more details.",

"deputy.cte.splitArticle.label": "Split article $1"
"deputy.cte.splitArticle.label": "Split article $1",

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

"deputy.cte.splitArticle.entry.label": "Template entry",
"deputy.cte.splitArticle.entry.remove": "Remove entry",

"deputy.cte.splitArticle.collapse": "Collapse",
"deputy.cte.splitArticle.from": "From",
"deputy.cte.splitArticle.from.help": "This is the page where the content was split from. In most cases, this is the current page, and can be left blank.",

"deputy.cte.splitArticle.to.placeholder": "Subpage A",
"deputy.cte.splitArticle.to.label": "Page split to",
"deputy.cte.splitArticle.to.help": "This is the name of page that material was copied to; the \"merge target\".",
"deputy.cte.splitArticle.from_oldid.placeholder": "from_oldid",
"deputy.cte.splitArticle.from_oldid.label": "As of revision ID",
"deputy.cte.splitArticle.from_oldid.help": "The revision ID of the original page prior to the split. This is the revision that still contains content that will eventually become part of the split, with the following revision (or succeeding revisions) progressively transferring content to the other pages.",
"deputy.cte.splitArticle.date.label": "Date of split",
"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."
}
9 changes: 8 additions & 1 deletion src/modules/cte/CopiedTemplateEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ export default class CopiedTemplateEditor {
mw.hook( 'wikipage.content' ).add( () => {
// Find all {{copied}} templates and append our special button.
// This runs on the actual document, not the Parsoid document.
document.querySelectorAll( '.copiednotice > tbody > tr' )
document.querySelectorAll(
[ 'copiednotice', 'box-split-article' ].map(
( v ) => `.${v} > tbody > tr`
).join( ', ' )
)
.forEach( ( e ) => {
if ( e.classList.contains( 'cte-upgraded' ) ) {
return;
Expand Down Expand Up @@ -175,6 +179,9 @@ export default class CopiedTemplateEditor {
'mediawiki.widgets.datetime',
'jquery.makeCollapsible'
], async () => {
OO.ui.WindowManager.static.sizes.huge = {
width: 1100
};
mw.util.addCSS( cteStyles );
await WikiAttributionNotices.init();

Expand Down
21 changes: 17 additions & 4 deletions src/modules/cte/css/copied-template-editor.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
.copied-template-editor .oo-ui-window-frame {
width: 1000px !important;
}

.copied-template-editor .oo-ui-menuLayout > .oo-ui-menuLayout-menu {
height: 20em;
width: 20em;
}

.copied-template-editor .oo-ui-menuLayout > .oo-ui-menuLayout-content {
left: 20em;
}

.cte-preview .copiednotice {
margin-left: 0;
margin-right: 0;
Expand Down Expand Up @@ -31,11 +44,11 @@

.cte-templateOptions {
margin: 8px;
display: flex;
}

.cte-templateOptions > div {
width: 50%;
display: inline-block;
.cte-templateOptions > * {
flex: 1;
}

.cte-fieldset {
Expand Down Expand Up @@ -64,7 +77,7 @@
margin-right: 16px;
}

.cte-fieldset-date .oo-ui-iconElement-icon {
.copied-template-editor .mw-widgets-datetime-dateTimeInputWidget-handle .oo-ui-iconElement-icon {
left: 0.5em;
width: 1em;
height: 1em;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/cte/models/AttributionNotice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CTEParsoidDocument from './CTEParsoidDocument';
import { MediaWikiData, TemplateData, TemplateDataModifier } from './MediaWikiData';
import { AttributionNoticePageLayout } from '../ui/pages/AttributionNoticePageLayout';
import { AttributionNoticePageGenerator } from '../ui/pages/AttributionNoticePageGenerator';
import { AttributionNoticePageGenerator } from '../ui/AttributionNoticePageGenerator';
import { CTEParsoidTransclusionTemplateNode } from './CTEParsoidTransclusionTemplateNode';

/**
Expand Down
39 changes: 35 additions & 4 deletions src/modules/cte/models/AttributionNoticeRow.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
import type AttributionNotice from './AttributionNotice';
import { AttributionNoticePageGenerator } from '../ui/pages/AttributionNoticePageGenerator';
import { AttributionNoticePageGenerator } from '../ui/AttributionNoticePageGenerator';
import { AttributionNoticePageLayout } from '../ui/pages/AttributionNoticePageLayout';

export interface AttributionNoticeRowParent {
addRow( row: any ): void;
deleteRow( row: any ): void;
}

/**
* An attribution notice's row or entry.
*/
export abstract class AttributionNoticeRow<T extends AttributionNotice>
export abstract class AttributionNoticeRow<T extends AttributionNoticeRowParent>
implements AttributionNoticePageGenerator {

protected _parent: T;
/**
* @return The parent of this attribution notice row.
*/
abstract get parent(): T;
get parent(): T {
return this._parent;
}

/**
* Sets the parent. Automatically moves this template from one
* parent's row set to another.
*
* @param newParent The new parent.
*/
set parent( newParent ) {
this._parent.deleteRow( this );
newParent.addRow( this );
this._parent = newParent;
}

abstract generatePage( dialog: any ): AttributionNoticePageLayout;

/**
* Clones this row.
*
* @param parent The parent of this new row.
* @return The cloned row
*/
clone( parent: T ): AttributionNoticeRow<T> {
// noinspection JSCheckFunctionSignatures
return new ( this.constructor as any )( this, parent );
}

}
17 changes: 11 additions & 6 deletions src/modules/cte/models/CTEParsoidDocument.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import ParsoidDocument from '@chlodalejandro/parsoid';
import last from '../../../util/last';
import AttributionNotice from './AttributionNotice';
import WikiAttributionNotices, { SupportedAttributionNoticeType } from './WikiAttributionNotices';
import CopiedTemplate from './templates/CopiedTemplate';
import WikiAttributionNotices, {
AttributionNoticeTypeClass,
SupportedAttributionNoticeType
} from './WikiAttributionNotices';
import TemplateInsertEvent from '../events/TemplateInsertEvent';
import { CTEParsoidTransclusionTemplateNode } from './CTEParsoidTransclusionTemplateNode';
import TemplateFactory from './TemplateFactory';
Expand Down Expand Up @@ -52,7 +54,7 @@ export default class CTEParsoidDocument extends ParsoidDocument {
return;
}

const notices = this.findCopiedNotices();
const notices = this.findNoticeType( 'copied' );
this.originalCount = notices.length;
} );
}
Expand Down Expand Up @@ -102,13 +104,16 @@ export default class CTEParsoidDocument extends ParsoidDocument {
/**
* Finds this document's {{copied}} notices.
*
* @param type
* @return An array of all CopiedTemplate objects found
*/
findCopiedNotices(): CopiedTemplate[] {
findNoticeType<T extends SupportedAttributionNoticeType>(
type: T
): AttributionNoticeTypeClass<T>[] {
return this.findNotices().filter(
( notice ) => notice instanceof
WikiAttributionNotices.attributionNoticeClasses.copied
) as CopiedTemplate[];
WikiAttributionNotices.attributionNoticeClasses[ type ]
) as AttributionNoticeTypeClass<T>[];
}

/**
Expand Down
41 changes: 39 additions & 2 deletions src/modules/cte/models/RowedAttributionNotice.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import AttributionNotice from './AttributionNotice';
import RowChangeEvent from '../events/RowChangeEvent';
import { AttributionNoticeRow, AttributionNoticeRowParent } from './AttributionNoticeRow';

/**
* This is a sub-abstract class of {@link AttributionNotice} that represents any
* attribution notice template that can contain multiple entries (or rows).
*/
export default abstract class RowedAttributionNotice<RowClass>
extends AttributionNotice {
export default abstract class RowedAttributionNotice<
RowClass extends AttributionNoticeRow<RowedAttributionNotice<RowClass>>
> extends AttributionNotice {

/**
* All the rows of this template.
Expand Down Expand Up @@ -96,6 +98,41 @@ export default abstract class RowedAttributionNotice<RowClass>
this.save();
this.dispatchEvent( new RowChangeEvent( 'rowDelete', row ) );
}

if ( this._rows.length === 0 ) {
this.destroy();
}
}

/**
* Copies in the rows of another {@link SplitArticleTemplate}, and
* optionally deletes that template or clears its contents.
*
* @param template The template to copy from.
* @param options Options for this merge.
* @param options.delete
* Whether the reference template will be deleted after merging.
* @param options.clear
* Whether the reference template's rows will be cleared after merging.
*/
merge(
template: RowedAttributionNotice<RowClass>,
options: { delete?: boolean, clear?: boolean } = {}
) {
if ( template.rows === undefined || template === this ) {
// Deleted or self
return;
}
for ( const row of template.rows ) {
if ( options.clear ) {
row.parent = this;
} else {
( this as AttributionNoticeRowParent ).addRow( row.clone( this ) );
}
}
if ( options.delete ) {
template.destroy();
}
}

}
8 changes: 5 additions & 3 deletions src/modules/cte/models/TemplateFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class TemplateFactory {
* @return A new CopiedTemplate
*/
static copied( document: CTEParsoidDocument ): CopiedTemplate {
const templateWikitext = this.getTemplateWikitext( 'copied' );
const templateWikitext = TemplateFactory.getTemplateWikitext( 'copied' );
const node = CTEParsoidTransclusionTemplateNode.fromNew(
document,
templateWikitext,
Expand All @@ -59,12 +59,14 @@ export default class TemplateFactory {
* @return A new SplitArticleTemplate
*/
static splitArticle( document: CTEParsoidDocument ): SplitArticleTemplate {
const templateWikitext = this.getTemplateWikitext( 'splitArticle' );
const templateWikitext = TemplateFactory.getTemplateWikitext( 'splitArticle' );
const node = CTEParsoidTransclusionTemplateNode.fromNew(
document,
templateWikitext,
{
from: new mw.Title( document.getPage() ).getSubjectPage().getPrefixedText()
from: new mw.Title( document.getPage() ).getSubjectPage().getPrefixedText(),
// Blank string to trigger row creation
to: ''
}
);
node.element.setAttribute( 'about', `N${TemplateFactory.noticeCount++}` );
Expand Down
3 changes: 3 additions & 0 deletions src/modules/cte/models/WikiAttributionNotices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,6 @@ export default class WikiAttributionNotices {
}

}

export type AttributionNoticeTypeClass<T extends SupportedAttributionNoticeType> =
InstanceType<typeof WikiAttributionNotices.attributionNoticeClasses[T]>;
6 changes: 3 additions & 3 deletions src/modules/cte/models/templates/CopiedTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CopiedTemplateRow, {
} from './CopiedTemplateRow';
import { AttributionNoticePageLayout } from '../../ui/pages/AttributionNoticePageLayout';
import CopiedTemplatePage from '../../ui/pages/CopiedTemplatePage';
import { AttributionNoticePageGenerator } from '../../ui/pages/AttributionNoticePageGenerator';
import { AttributionNoticePageGenerator } from '../../ui/AttributionNoticePageGenerator';
import RowedAttributionNotice from '../RowedAttributionNotice';

/**
Expand Down Expand Up @@ -129,10 +129,10 @@ export default class CopiedTemplate
* Destroys this template completely.
*/
destroy() {
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
Loading

0 comments on commit a33afa2

Please sign in to comment.