User:Chlod/Scripts/Deputy.js: Difference between revisions

Content deleted Content added
(bot/CD)
(bot/CD)
Line 350:
}));
 
var version = "0.56.10";
var gitAbbrevHash = "982cf07716629e";
var gitBranch = "mainHEAD";
var gitDate = "Wed, 14 Feb 2024 1213:3613:5332 +0800";
var gitVersion = "0.56.10+g982cf07g716629e";
 
/**
Line 9,084:
*/
renderFields() {
var _a, _b, _c, _d;
// Use order: `date`, `monthday` + `year`, `year`
const rowDate = (_a = this.backwardsCopyTemplateRow.date) !== null && _a !== void 0 ? _a : (this.backwardsCopyTemplateRow.monthday ?
Line 9,102:
value: rowDate
}),
author: new OO.ui.TagMultiselectWidgetTextInputWidget({
allowArbitrary: true,
placeholder: mw.msg('deputy.ante.backwardsCopy.entry.author.placeholder'),
selectedvalue: (_d = authors[0]) !== null && _d !== void 0 ? _d : this.backwardsCopyTemplateRow.author
}),
url: new OO.ui.TextInputWidget({
Line 9,162 ⟶ 9,161:
const field = _field;
const input = inputs[field];
ifinput.on('change', (fieldvalue) === 'author')> {
inputthis.backwardsCopyTemplateRow[field] = value;
this.on('change', backwardsCopyTemplateRow.parent.save(value) => {;
if (value.length === 0}) {;
this.backwardsCopyTemplateRow.author = null;
this.backwardsCopyTemplateRow.authorlist = null;
}
else if (value.length > 1) {
this.backwardsCopyTemplateRow.author = null;
this.backwardsCopyTemplateRow.authorlist =
// TODO: ANTE l10n
value.map((v) => v.data).join('; ');
}
else {
this.backwardsCopyTemplateRow.authorlist = null;
this.backwardsCopyTemplateRow.author =
value[0].data;
}
this.backwardsCopyTemplateRow.parent.save();
});
}
else {
// Attach the change listener
input.on('change', (value) => {
this.backwardsCopyTemplateRow[field] = value;
this.backwardsCopyTemplateRow.parent.save();
});
}
if (input instanceof OO.ui.TextInputWidget) {
// Rechecks the validity of the field.
Line 12,056 ⟶ 12,031:
"deputy.ante.backwardsCopy.entry.date.help": "This is the date on which the article was first published.",
"deputy.ante.backwardsCopy.entry.author.placeholder": "Add author",
"deputy.ante.backwardsCopy.entry.author.label": "Author(s)",
"deputy.ante.backwardsCopy.entry.author.help": "A list of theThe article's authorsauthor.",
"deputy.ante.backwardsCopy.entry.url.placeholder": "https://example.com/news/a-news-article-that-copies-from-wikipedia",
"deputy.ante.backwardsCopy.entry.url.label": "URL",
Line 13,992 ⟶ 13,967:
}
}
WikiConfiguration.configVersion = 12;
WikiConfiguration.optionKey = 'userjs-deputy-wiki';
WikiConfiguration.configLocations = [
Line 14,731 ⟶ 14,706:
 
/**
* Extracts a page title from a MediaWiki anchor`<a>`. If the anchorlink does not validly linkpoint
* to a MediaWiki page, `false` is returned.
*
* The part of the anchorlink used to determine the page title depends on how trustworthy
* the data is in telling the correct title. If the anchorlink does not have an `href`, only
* two routes are available: the selflink check and the `title` attribute check.
*
Line 14,748 ⟶ 14,723:
* @return the page linked to
*/
function anchorToTitlepagelinkToTitle(el) {
const href = el.getAttribute('href');
const articlePathRegex = new RegExp(mw.util.getUrl('(.*)'));
Line 14,800 ⟶ 14,775:
}
 
/**
* Check if a given copyright problems listing is full.
*
* @param data
* @return `true` if the listing is a {@link FullCopyrightProblemsListingData}
*/
function isFullCopyrightProblemsListing(data) {
return data.basic === false;
}
/**
* Represents an <b>existing</b> copyright problems listing. To add or create new
Line 14,820 ⟶ 14,804:
this.element = data.element;
if (data.basic === false) {
this.id = else {data.id;
this.anchor = data.anchor;
this.plainlinks = data.plainlinks;
Line 14,830 ⟶ 14,815:
* This regular expression must catch three groups:
* - $1 - The initial `* `, used to keep the correct number of whitespace between parts.
* - $2 - The page title in the `id="..."`, ONLY IF the page is listed with an
* `article-cv`-like template.
* - $3 - The page title in the wikilink, ONLY IF the page is a bare link to another page and doeslisted notwith usean
* `article-cv`-like template.
* - $4 - The page title, ONLY IF the page is a bare link to another page and does not use
* `article-cv`.
*
*
* @return A regular expression.
Line 14,869 ⟶ 14,856:
// At this point, previousPivot is likely a MediaWiki level 4 heading.
const h4Anchor = previousPivot.querySelector('.mw-headline a');
listingPage = anchorToTitlepagelinkToTitle(h4Anchor);
// Identify if the page is a proper listing page (within the root page's
// pagespace)
Line 14,906 ⟶ 14,893:
// This ensures we're always using the prefixedDb version of the title (as
// provided by the anchor) for stability.
const prefixedDbid = anchor.getAttribute('id');
const title = anchorToTitlepagelinkToTitle(el);
if (title === false || prefixedDbid == null) {
// Not a valid link.
return false;
}
else if (title.getPrefixedText() !== new mw.Title(prefixedDbid).getPrefixedText()) {
// Anchor and link mismatch. Someone tampered with the template?
// In this case, rely on the link instead, as the anchor is merely invisible.
console.warn(`Anchor and link mismatch for "${title.getPrefixedText()}".`, title, prefixedDbid);
}
// Checks for the <span class="plainlinks"> element.
// This ensures that the listing came from {{article-cv}} and isn't just a
// link with an anchor.
const plainlinkselSiblings = Array.from(el.nextElementSiblingparentElement.children);
const elIndex = elSiblings.indexOf(el);
const plainlinks = el.parentElement.querySelector(`:nth-child(${elIndex}) ~ span.plainlinks`);
if (plainlinks == null ||
(plainlinks.tagName// !==`~` 'SPAN'never &&gets !plainlinks.classList.contains(an earlier element, so just check if it'plainlinks')))s more than 2 {elements
// TODO: ANTE l10naway.
elSiblings.indexOf(plainlinks) - elIndex > 2) {
return false;
}
Line 14,936 ⟶ 14,927:
return {
basic: false,
}id,
title,
listingPage,
Line 14,973 ⟶ 14,965:
}
// Attempt to extract page title.
const title = anchorToTitlepagelinkToTitle(el);
if (!title) {
return false;
Line 15,002 ⟶ 14,994:
* wikitext.
*/
get idanchorId() {
return this.title.getPrefixedDb()id + (this.i > 1 ? `-${this.i}` : '');
}
/**
Line 15,016 ⟶ 15,008:
*/
getListingWikitextLines() {
var })_a;
return __awaiter(this, void 0, void 0, function* () {
const lines = (yield this.listingPage.getWikitext()).split('\n');
Line 15,022 ⟶ 15,015:
let endLine = null;
let bulletList;
const normalizedId = normalizeTitle((_a = this.id) !== null && _a !== void 0 ? _a : this.title).getPrefixedText()) {;
const idMalformed = normalizedId !== this.title.getPrefixedText();
for (let line = 0; line < lines.length; line++) {
const lineText = lines[line];
Line 15,041 ⟶ 15,036:
.exec(lineText);
if (match != null) {
// Check if this(normalizeTitle(match[2] is|| thematch[4]).getPrefixedText() page we're looking for.!==
if (normalizeTitle(match[2] || match[3]).getPrefixedText( normalizedId) !=={
this.title.getPrefixedText()) {
continue;
}
Line 15,051 ⟶ 15,045:
skipCounter++;
continue;
allowArbitrary: true, }
else if (value.lengthidMalformed && match[2] >=== 1match[3]) {
throw new Error(`Expected malformed listing with ID "${normalizedId}" and title "${this.title.getPrefixedText()}" but got normal listing.`);
}
bulletList = /[*:]/.test((match[1] || '').trim());
Line 16,222 ⟶ 16,219:
headingSets[listingPageTitle] = {};
}
const prefixedDbid = listingData.title.getPrefixedDbnormalizeTitle(isFullCopyrightProblemsListing(listingData); ?
listingData.id }:
}listingData.title).getPrefixedDb();
const pageSet = headingSets[listingPageTitle];
if (pageSet[prefixedDbid] != null) {
pageSet[prefixedDbid]++;
}
else {
pageSet[prefixedDbid] = 1;
}
this.listingMap.set(link, new CopyrightProblemsListing(listingData, this.main ? null : this, pageSet[prefixedDbid]));
links.push(link);
}
Line 16,691 ⟶ 16,690:
 
var wikiUtil = {
anchorToTitle: anchorToTitlepagelinkToTitle,
decorateEditSummary: decorateEditSummary,
delink: delink,