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

Content deleted Content added
(bot/CD)
(bot/CD)
 
(35 intermediate revisions by the same user not shown)
Line 28:
*
* https://github.com/ChlodAlejandro/deputy
*
* ------------------------------------------------------------------------
*
* This script compiles with the following dependencies:
* * [https://github.com/Microsoft/tslib tslib] - 0BSD, Microsoft
* * [https://github.com/jakearchibald/idb idb] - ISC, Jake Archibald
* * [https://github.com/JSmith01/broadcastchannel-polyfill broadcastchannel-polyfill] - Unlicense, Joshua Bell
* * [https://github.com/Lusito/tsx-dom tsx-dom] - MIT, Santo Pfingsten
*
*/
// <nowiki>
/*!
* @package idb
* @version 7.1.0
* @license ISC
* @author Jake Archibald
* @url https://github.com/jakearchibald/idb
*//*!
* @package tsx-dom
* @version 1.4.0
* @license MIT
* @author Santo Pfingsten
* @url https://github.com/Lusito/tsx-dom
*//*!
* @package broadcastchannel-polyfill
* @version 1.0.1
* @license Unlicense
* @author Joshua Bell
* @url https://github.com/JSmith01/broadcastchannel-polyfill
*//*!
* @package @chlodalejandro/parsoid
* @version 2.0.1-37ea110
* @license MIT
* @author Chlod Alejandro
* @url https://github.com/ChlodAlejandro/parsoid-document
*/
(function () {
'use strict';
Line 73 ⟶ 56:
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
 
 
function __awaiter(thisArg, _arguments, P, generator) {
Line 113 ⟶ 98:
]));
}
const cursorRequestMap = new WeakMap();
const transactionDoneMap = new WeakMap();
const transactionStoreNamesMap = new WeakMap();
const transformCache = new WeakMap();
const reverseTransformCache = new WeakMap();
Line 135 ⟶ 118:
request.addEventListener('error', error);
});
promise
.then((value) => {
// Since cursoring reuses the IDBRequest (*sigh*), we cache it for later retrieval
// (see wrapFunction).
if (value instanceof IDBCursor) {
cursorRequestMap.set(value, request);
}
// Catching to avoid "Uncaught Promise exceptions"
})
.catch(() => { });
// This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This
// is because we create many promises from a single IDBRequest.
Line 181 ⟶ 154:
if (prop === 'done')
return transactionDoneMap.get(target);
// Polyfill for objectStoreNames because of Edge.
if (prop === 'objectStoreNames') {
return target.objectStoreNames || transactionStoreNamesMap.get(target);
}
// Make tx.store return the only store in the transaction, or undefined if there are many.
if (prop === 'store') {
Line 213 ⟶ 182:
// Due to expected object equality (which is enforced by the caching in `wrap`), we
// only create one new func per func.
// Edge doesn't support objectStoreNames (booo), so we polyfill it here.
if (func === IDBDatabase.prototype.transaction &&
!('objectStoreNames' in IDBTransaction.prototype)) {
return function (storeNames, ...args) {
const tx = func.call(unwrap(this), storeNames, ...args);
transactionStoreNamesMap.set(tx, storeNames.sort ? storeNames.sort() : [storeNames]);
return wrap(tx);
};
}
// Cursor methods are special, as the behaviour is a little more different to standard IDB. In
// IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
Line 232 ⟶ 192:
// the original object.
func.apply(unwrap(this), args);
return wrap(cursorRequestMap.get(this).request);
};
}
Line 350 ⟶ 310:
}));
 
const advanceMethodProps = ['continue', 'continuePrimaryKey', 'advance'];
var version = "0.5.1";
varconst gitAbbrevHashmethodMap = "548da87"{};
const advanceResults = new WeakMap();
const ittrProxiedCursorToOriginalProxy = new WeakMap();
const cursorIteratorTraps = {
get(target, prop) {
if (!advanceMethodProps.includes(prop))
return target[prop];
let cachedFunc = methodMap[prop];
if (!cachedFunc) {
cachedFunc = methodMap[prop] = function (...args) {
advanceResults.set(this, ittrProxiedCursorToOriginalProxy.get(this)[prop](...args));
};
}
return cachedFunc;
},
};
async function* iterate(...args) {
// tslint:disable-next-line:no-this-assignment
let cursor = this;
if (!(cursor instanceof IDBCursor)) {
cursor = await cursor.openCursor(...args);
}
if (!cursor)
return;
cursor = cursor;
const proxiedCursor = new Proxy(cursor, cursorIteratorTraps);
ittrProxiedCursorToOriginalProxy.set(proxiedCursor, cursor);
// Map this double-proxy back to the original, so other cursor methods work.
reverseTransformCache.set(proxiedCursor, unwrap(cursor));
while (cursor) {
yield proxiedCursor;
// If one of the advancing methods was not called, call continue().
cursor = await (advanceResults.get(proxiedCursor) || cursor.continue());
advanceResults.delete(proxiedCursor);
}
}
function isIteratorProp(target, prop) {
return ((prop === Symbol.asyncIterator &&
instanceOfAny(target, [IDBIndex, IDBObjectStore, IDBCursor])) ||
(prop === 'iterate' && instanceOfAny(target, [IDBIndex, IDBObjectStore])));
}
replaceTraps((oldTraps) => ({
...oldTraps,
get(target, prop, receiver) {
if (isIteratorProp(target, prop))
return iterate;
return oldTraps.get(target, prop, receiver);
},
has(target, prop) {
return isIteratorProp(target, prop) || oldTraps.has(target, prop);
},
}));
 
var version = "0.9.0";
var gitAbbrevHash = "317b503";
var gitBranch = "HEAD";
var gitDate = "ThuWed, 2119 DecFeb 20232025 1400:3113:4753 +0800";
var gitVersion = "0.59.10+g548da87g317b503";
 
/**
Line 390 ⟶ 404:
}
MwApi.USER_AGENT = `Deputy/${version} (https://w.wiki/7NWR; User:Chlod; wiki@chlod.net)`;
 
/**
* Log to the console.
*
* @param {...any} data
*/
function log(...data) {
console.log('[Deputy]', ...data);
}
 
/**
Line 405 ⟶ 428:
upgrade(db, oldVersion, newVersion) {
let currentVersion = oldVersion;
// Adding new stores? Make sure to also add it in `reset()`!
const upgrader = {
0: () => {
Line 429 ⟶ 453:
while (currentVersion < newVersion) {
upgrader[`${currentVersion}`]();
console.log(`[deputy] upgradedUpgraded database from ${currentVersion} to ${currentVersion + 1}`);
currentVersion++;
}
Line 492 ⟶ 516:
}
}
});
}
/**
* Reset the Deputy database. Very dangerous!
*/
reset() {
return __awaiter(this, void 0, void 0, function* () {
yield this.db.clear('keyval');
yield this.db.clear('casePageCache');
yield this.db.clear('diffCache');
yield this.db.clear('diffStatus');
yield this.db.clear('pageStatus');
yield this.db.clear('tagCache');
});
}
Line 625 ⟶ 662:
this.broadcastChannel.addEventListener('message', (event) => {
// TODO: debug
console.log(Date.now() - start, '[deputycomms comms]in: in', event.data);
if (event.data && typeof event.data === 'object' && event.data._deputy) {
this.dispatchEvent(Object.assign(new Event(event.data.type), {
Line 644 ⟶ 681:
this.broadcastChannel.postMessage(message);
// TODO: debug
console.log(Date.now() - start, '[deputy comms]: out:', data);
return message;
}
Line 678 ⟶ 715:
};
handlers.listener = ((event) => {
console.log(event);
if (event.data._deputyRespondsTo === message._deputyMessageId &&
event.data.type === OneWayDeputyMessageMap[data.type]) {
Line 709 ⟶ 746:
*
* @param title The title to normalize. Default is current page.
* @return {mw.Title} A mw.Title object. `null` if not a valid title.
* @private
*/
Line 846 ⟶ 883:
}
});
}
}
 
/**
* @param element The element to get the name of
* @return the name of a section from its section heading.
*/
function sectionHeadingName(element) {
var _a, _b;
try {
return (_b = (_a = element.querySelector('.mw-headline')) === null || _a === void 0 ? void 0 : _a.innerText) !== null && _b !== void 0 ? _b : element.innerText;
}
catch (e) {
console.error('Error getting section name', e, element);
throw e;
}
}
Line 886 ⟶ 908:
*/
class DeputyCase {
/**
* @param pageId The page ID of the case page.
* @param title The title of the case page.
*/
constructor(pageId, title) {
this.pageId = pageId;
this.title = title;
}
/**
* @return the title of the case page
Line 939 ⟶ 953:
return new DeputyCase(pageId, title);
});
}
/**
* @param pageId The page ID of the case page.
* @param title The title of the case page.
*/
constructor(pageId, title) {
this.pageId = pageId;
this.title = title;
}
/**
Line 951 ⟶ 973:
 
/**
* @paramReturns elementthe Thelast elementitem toof getan the name ofarray.
*
* @return the ID of the section heading.
* @param array The array to get the last element from
* @return The last element of the array
*/
function sectionHeadingIdlast(elementarray) {
tryreturn {array[array.length - 1];
}
return element.querySelector('.mw-headline')
 
.getAttribute('id');
/**
* Each WikiHeadingType implies specific fields in {@link WikiHeading}:
*
* - `PARSOID` implies that there is no headline element, and that the `h`
* element is the root heading element. This means `h.innerText` will be
* "Section title".
* - `OLD` implies that there is a headline element and possibly an editsection
* element, and that the `h` is the root heading element. This means that
* `h.innerText` will be "Section title[edit | edit source]" or similar.
* - `NEW` implies that there is a headline element and possibly an editsection
* element, and that a `div` is the root heading element. This means that
* `h.innerText` will be "Section title".
*/
var WikiHeadingType;
(function (WikiHeadingType) {
WikiHeadingType[WikiHeadingType["PARSOID"] = 0] = "PARSOID";
WikiHeadingType[WikiHeadingType["OLD"] = 1] = "OLD";
WikiHeadingType[WikiHeadingType["NEW"] = 2] = "NEW";
})(WikiHeadingType || (WikiHeadingType = {}));
/**
* Get relevant information from an H* element in a section heading.
*
* @param headingElement The heading element
* @return An object containing the relevant {@link WikiHeading} fields.
*/
function getHeadingElementInfo(headingElement) {
return {
h: headingElement,
id: headingElement.id,
title: headingElement.innerText,
level: +last(headingElement.tagName)
};
}
/**
* Annoyingly, there are many different ways that a heading can be parsed
* into depending on the version and the parser used for given wikitext.
*
* In order to properly perform such wiki heading checks, we need to identify
* if a given element is part of a wiki heading, and perform a normalization
* if so.
*
* Since this function needs to check many things before deciding if a given
* HTML element is part of a section heading or not, this also acts as an
* `isWikiHeading` check.
*
* The layout for a heading differs depending on the MediaWiki version:
*
* <b>On 1.43+ (Parser)</b>
* ```html
* <div class="mw-heading mw-heading2">
* <h2 id="Parsed_wikitext...">Parsed <i>wikitext</i>...</h2>
* <span class="mw-editsection>...</span>
* </div>
* ```
*
* <b>On Parsoid</b>
* ```html
* <h2 id="Parsed_wikitext...">Parsed <i>wikitext</i>...</h2>
* ```
*
* <b>On pre-1.43</b>
* ```html
* <h2>
* <span class="mw-headline" id="Parsed_wikitext...">Parsed <i>wikitext</i>...</span>
* <span class="mw-editsection">...</span>
* </h2>
* ```
*
* <b>Worst case execution time</b> would be if this was run with an element which was
* outside a heading and deeply nested within the page.
*
* Backwards-compatibility support may be removed in the future. This function does not
* support Parsoid specification versions lower than 2.0.
*
* @param node The node to check for
* @param ceiling An element which `node` must be in to be a valid heading.
* This is set to the `.mw-parser-output` element by default.
* @return The root heading element (can be an &lt;h2&gt; or &lt;div&gt;),
* or `null` if it is not a valid heading.
*/
function normalizeWikiHeading(node, ceiling) {
var _a;
if (node == null) {
// Not valid input, obviously.
return null;
}
catchconst rootNode = node.getRootNode(e) {;
// Break out of console.error('Errortext gettingnodes sectionuntil headingwe ID',hit e,an element); node.
while (node.nodeType !== node.ELEMENT_NODE) {
throw e;
node = node.parentNode;
if (node === rootNode) {
// We've gone too far and hit the root. This is not a wiki heading.
return null;
}
}
// node is now surely an element.
let elementNode = node;
// If this node is the 1.43+ heading root, return it immediately.
if (elementNode.classList.contains('mw-heading')) {
return Object.assign({ type: WikiHeadingType.NEW, root: elementNode }, getHeadingElementInfo(Array.from(elementNode.children)
.find(v => /^H[123456]$/.test(v.tagName))));
}
// Otherwise, we're either inside or outside a mw-heading.
// To determine if we are inside or outside, we keep climbing up until
// we either hit an <hN> or a given stop point.
// The default stop point differs on Parsoid and standard parser:
// - On Parsoid, `<body>` will be `.mw-body-content.mw-parser-output`.
// - On standard parser, we want `div.mw-body-content > div.mw-parser.output`.
// If such an element doesn't
// exist in this document, we just stop at the root element.
ceiling = (_a = ceiling !== null && ceiling !== void 0 ? ceiling : elementNode.ownerDocument.querySelector('.mw-body-content > .mw-parser-output, .mw-body-content.mw-parser-output')) !== null && _a !== void 0 ? _a : elementNode.ownerDocument.documentElement;
// While we haven't hit a heading, keep going up.
while (elementNode !== ceiling) {
if (/^H[123456]$/.test(elementNode.tagName)) {
// This element is a heading!
// Now determine if this is a MediaWiki heading.
if (elementNode.parentElement.classList.contains('mw-heading')) {
// This element's parent is a `div.mw-heading`!
return Object.assign({ type: WikiHeadingType.NEW, root: elementNode.parentElement }, getHeadingElementInfo(elementNode));
}
else {
const headline = elementNode.querySelector(':scope > .mw-headline');
if (headline != null) {
// This element has a `.mw-headline` child!
return {
type: WikiHeadingType.OLD,
root: elementNode,
h: elementNode,
id: headline.id,
title: headline.innerText,
level: +last(elementNode.tagName)
};
}
else if (elementNode.parentElement.tagName === 'SECTION' &&
elementNode.parentElement.firstElementChild === elementNode) {
// A <section> element is directly above this element, and it is the
// first element of that section!
// This is a specific format followed by the 2.8.0 MediaWiki Parsoid spec.
// https://www.mediawiki.org/wiki/Specs/HTML/2.8.0#Headings_and_Sections
return {
type: WikiHeadingType.PARSOID,
root: elementNode,
h: elementNode,
id: elementNode.id,
title: elementNode.innerText,
level: +last(elementNode.tagName)
};
}
else {
// This is a heading, but we can't figure out how it works.
// This usually means something inserted an <h2> into the DOM, and we
// accidentally picked it up.
// In that case, discard it.
return null;
}
}
}
else if (elementNode.classList.contains('mw-heading')) {
// This element is the `div.mw-heading`!
// This usually happens when we selected an element from inside the
// `span.mw-editsection` span.
return Object.assign({ type: WikiHeadingType.NEW, root: elementNode }, getHeadingElementInfo(Array.from(elementNode.children)
.find(v => /^H[123456]$/.test(v.tagName))));
}
else {
// Haven't reached the top part of a heading yet, or we are not
// in a heading. Keep climbing up the tree until we hit the ceiling.
elementNode = elementNode.parentElement;
}
}
// We hit the ceiling. This is not a wiki heading.
return null;
}
 
/**
* Check if a given parameter is a wikitext heading parsed into HTML.
*
* Alias for `normalizeWikiHeading( el ) != null`.
*
* @param el The element to check
* @return `true` if the element is a heading, `false` otherwise
*/
function isWikiHeading(el) {
return normalizeWikiHeading(el) != null;
}
 
/**
* Finds section elements from a given section heading (and optionally a predicate)
*
* @param sectionHeading
* @param sectionHeadingPredicate A function which returns `true` if the section should stop here
* @return Section headings.
*/
function getSectionElements(sectionHeading, sectionHeadingPredicate = isWikiHeading) {
const sectionMembers = [];
let nextSibling = sectionHeading.nextElementSibling;
while (nextSibling != null && !sectionHeadingPredicate(nextSibling)) {
sectionMembers.push(nextSibling);
nextSibling = nextSibling.nextElementSibling;
}
return sectionMembers;
}
 
Line 971 ⟶ 1,191:
*/
class DeputyCasePage extends DeputyCase {
/**
* @param pageId The page ID of the case page.
* @param title The title of the page being accessed
* @param document The document to be used as a reference.
* @param parsoid Whether this is a Parsoid document or not.
* @param lastActive
* @param lastActiveSessions
*/
constructor(pageId, title, document, parsoid, lastActive, lastActiveSessions) {
super(pageId !== null && pageId !== void 0 ? pageId : window.deputy.currentPageId, title !== null && title !== void 0 ? title : window.deputy.currentPage);
/**
* A timestamp of when this case page was last worked on.
*/
this.lastActive = Date.now();
/**
* The sections last worked on for this case page.
*/
this.lastActiveSections = [];
this.document = document !== null && document !== void 0 ? document : window.document;
this.parsoid = parsoid !== null && parsoid !== void 0 ? parsoid : /mw: http:\/\/mediawiki.org\/rdf\//.test(this.document.documentElement.getAttribute('prefix'));
this.wikitext = new DeputyCasePageWikitext(this);
this.lastActive = lastActive !== null && lastActive !== void 0 ? lastActive : Date.now();
this.lastActiveSections = lastActiveSessions !== null && lastActiveSessions !== void 0 ? lastActiveSessions : [];
}
/**
* @param pageId The page ID of the case page.
Line 1,026 ⟶ 1,222:
}
});
}
/**
* @param pageId The page ID of the case page.
* @param title The title of the page being accessed
* @param document The document to be used as a reference.
* @param parsoid Whether this is a Parsoid document or not.
* @param lastActive
* @param lastActiveSessions
*/
constructor(pageId, title, document, parsoid, lastActive, lastActiveSessions) {
super(pageId !== null && pageId !== void 0 ? pageId : window.deputy.currentPageId, title !== null && title !== void 0 ? title : window.deputy.currentPage);
/**
* A timestamp of when this case page was last worked on.
*/
this.lastActive = Date.now();
/**
* The sections last worked on for this case page.
*/
this.lastActiveSections = [];
this.document = document !== null && document !== void 0 ? document : window.document;
this.parsoid = parsoid !== null && parsoid !== void 0 ? parsoid : /mw: http:\/\/mediawiki.org\/rdf\//.test(this.document.documentElement.getAttribute('prefix'));
this.wikitext = new DeputyCasePageWikitext(this);
this.lastActive = lastActive !== null && lastActive !== void 0 ? lastActive : Date.now();
this.lastActiveSections = lastActiveSessions !== null && lastActiveSessions !== void 0 ? lastActiveSessions : [];
}
/**
Line 1,037 ⟶ 1,257:
return false;
}
//const Allheading headings= normalizeWikiHeading(h1, h2, h3, h4, h5, h6el);
//return TODO:heading l10n!= null &&
const headlineElement = // Require that this.parsoid ?heading is already normalized.
el// TODO: Remove at some point.
el.querySelector(// This shouldn'.mwt be required if double-headlinenormalization wasn');t a thing.
// Handle DiscussionTools case (.mw-el === heading).h &&
// eslint-disable-next-line security/detect-non-literal-regexp
return (el.classList.contains('mw-heading') || /^H\d$/.test(el.tagName)) &&
new RegExp(window.deputy.wikiConfig.cci.headingMatch.get()).test(heading.title);
headlineElement != null &&
/(Page|Article|Local file|File)s? \d+ (to|through) \d+$/.test(headlineElement.innerText);
}
/**
Line 1,053 ⟶ 1,272:
* @return The <h*> element of the heading.
*/
findFirstContributionSurveyHeadingfindFirstContributionSurveyHeadingElement() {
return this.findContributionSurveyHeadings()[0];
}
Line 1,065 ⟶ 1,284:
*/
findContributionSurveyHeading(sectionIdentifier, useId = false) {
// No need to perform .mw-headline existence check here, already
// done by `findContributionSurveyHeadings`
return this.findContributionSurveyHeadings()
.find((v) => normalizeWikiHeading(v)[useId ? 'id' : 'title'] === sectionIdentifier);
sectionHeadingId(v) === sectionIdentifier :
sectionHeadingName(v) === sectionIdentifier);
}
/**
Line 1,091 ⟶ 1,306:
.filter((h) => this.isContributionSurveyHeading(h));
}
}
/**
* Normalizes a section heading. On some pages, DiscussionTools wraps the heading
* around in a div, which breaks some assumptions with the DOM tree (e.g. that the
* heading is immediately followed by section elements).
*
* This returns the element at the "root" level, i.e. the wrapping <div> when
* DiscussionTools is active, or the <h2> when it is not.
* @param heading
*/
normalizeSectionHeading(heading) {
if (!this.isContributionSurveyHeading(heading)) {
if (!this.isContributionSurveyHeading(heading.parentElement)) {
throw new Error('Provided section heading is not a valid section heading.');
}
else {
heading = heading.parentElement;
}
}
// When DiscussionTools is being used, the header is wrapped in a div.
if (heading.parentElement.classList.contains('mw-heading')) {
heading = heading.parentElement;
}
return heading;
}
/**
Line 1,132 ⟶ 1,323:
*/
getContributionSurveySection(sectionHeading) {
//const Normalizeheading "= normalizeWikiHeading(sectionHeading" to use the h* element and not the .mw-heading span.);
sectionHeadingconst ceiling = thisheading.root.normalizeSectionHeading(sectionHeading)parentElement;
constreturn sectionMembersgetSectionElements(heading.root, (el) => [];{
let nextSibling = sectionHeading.nextSibling var _a, _b;
// TODO: Avoid double normalization
while (nextSibling != null && !this.isContributionSurveyHeading(nextSibling)) {
sectionMembers.pushconst norm = normalizeWikiHeading(nextSiblingel, ceiling);
return (heading.level >= ((_a = norm === null || norm === void 0 ? void 0 : norm.level) !== null && _a !== void 0 ? _a : Infinity)) ||
nextSibling = nextSibling.nextSibling;
this.isContributionSurveyHeading((_b = norm === null || norm === void 0 ? void 0 : norm.h) !== null && _b !== void 0 ? _b : el);
}
return sectionMembers});
}
/**
Line 1,297 ⟶ 1,488:
h_1("a", { onClick: () => __awaiter(this, void 0, void 0, function* () {
if (casePage && casePage.lastActiveSections.length > 0) {
const headingId = sectionHeadingId(heading).id;
if (window.deputy.config.cci.openOldOnContinue.get()) {
if (casePage.lastActiveSections.indexOf(headingId) === -1) {
Line 1,309 ⟶ 1,500:
}
else {
yield window.deputy.session.DeputyRootSession.startSession(heading.h);
}
}) }, mw.message(casePage && casePage.lastActiveSections.length > 0 ?
Line 1,326 ⟶ 1,517:
var _a;
return (_a = element === null || element === void 0 ? void 0 : element.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(element);
}
 
/**
* Log errors to the console.
*
* @param {...any} data
*/
function error(...data) {
console.error('[Deputy]', ...data);
}
 
Line 1,337 ⟶ 1,537:
function unwrapWidget (el) {
if (el.$element == null) {
console.error(el);
throw new Error('Element is not an OOUI Element!');
}
Line 1,456 ⟶ 1,656:
const diffMatch =
// [[Special:Diff/12345|6789]]
(_b = this.eatExpressionMatch(/\s*(?:'''?)?\[\[Special:Diff\/(\d+)(?:\|([^\]]*))?]](?:'''?)?/g)) !== null && _b !== void 0 ? _b :
// {{dif|12345|6789}}
this.eatExpressionMatch(/\s*(?:'''?)?{{dif\|(\d+)\|([^}]+)}}(?:'''?)?/g);
diff = diffMatch === null || diffMatch === void 0 ? void 0 : diffMatch[1];
if (diff != null) {
Line 1,654 ⟶ 1,854:
ContributionSurveyRowSort[ContributionSurveyRowSort["Bytes"] = 2] = "Bytes";
})(ContributionSurveyRowSort || (ContributionSurveyRowSort = {}));
 
/**
* Sleep for an specified amount of time.
*
* @param ms Milliseconds to sleep for.
*/
function sleep(ms) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((res) => {
setTimeout(res, ms);
});
});
}
 
/**
* Handles requests that might get hit by a rate limit. Wraps around
* `fetch` and ensures that all users of the Requester only request
* a single time per 100 ms on top of the time it takes to load
* previous requests. Also runs on four "threads", allowing at
* least a certain level of asynchronicity.
*
* Particularly used when a multitude of requests have a chance to
* DoS a service.
*/
class Requester {
/**
* Processes things in the fetchQueue.
*/
static processFetch() {
return __awaiter(this, void 0, void 0, function* () {
if (Requester.fetchActive >= Requester.maxThreads) {
return;
}
Requester.fetchActive++;
const next = Requester.fetchQueue.shift();
if (next) {
const data =
// eslint-disable-next-line prefer-spread
yield fetch.apply(null, next[1])
.then((res) => {
// Return false for survivable cases. In this case, we'll re-queue
// the request.
if (res.status === 429 || res.status === 502) {
return res.status;
}
else {
return res;
}
}, next[0][1]);
if (data instanceof Response) {
next[0][0](data);
}
else if (typeof data === 'number') {
Requester.fetchQueue.push(next);
}
}
yield sleep(Requester.minTime);
Requester.fetchActive--;
setTimeout(Requester.processFetch, 0);
});
}
}
/**
* Maximum number of requests to be processed simultaneously.
*/
Requester.maxThreads = 4;
/**
* Minimum amount of milliseconds to wait between each request.
*/
Requester.minTime = 100;
/**
* Requests to be performed. Takes tuples containing a resolve-reject pair and arguments
* to be passed into the fetch function.
*/
Requester.fetchQueue = [];
/**
* Number of requests currently being processed. Must be lower than
* {@link maxThreads}.
*/
Requester.fetchActive = 0;
Requester.fetch = (...args) => {
let res, rej;
const fakePromise = new Promise((_res, _rej) => {
res = _res;
rej = _rej;
});
Requester.fetchQueue.push([[res, rej], args]);
setTimeout(Requester.processFetch, 0);
return fakePromise;
};
 
/**
* Transforms the `redirects` object returned by MediaWiki's `query` action into an
* object instead of an array.
*
* @param redirects
* @param normalized
* @return Redirects as an object
*/
function toRedirectsObject(redirects, normalized) {
var _a;
if (redirects == null) {
return {};
}
const out = {};
for (const redirect of redirects) {
out[redirect.from] = redirect.to;
}
// Single-level redirect-normalize loop check
for (const normal of normalized) {
out[normal.from] = (_a = out[normal.to]) !== null && _a !== void 0 ? _a : normal.to;
}
return out;
}
 
/**
* A configuration. Defines settings and setting groups.
*/
class ConfigurationBase {
// eslint-disable-next-line jsdoc/require-returns-check
/**
* @return the configuration from the current wiki.
*/
static load() {
throw new Error('Unimplemented method.');
}
/**
* Creates a new Configuration.
*/
constructor() { }
/**
* Deserializes a JSON configuration into this configuration. This WILL overwrite
* past settings.
*
* @param serializedData
*/
deserialize(serializedData) {
var _a;
for (const group in this.all) {
const groupObject = this.all[group];
for (const key in this.all[group]) {
const setting = groupObject[key];
if (((_a = serializedData === null || serializedData === void 0 ? void 0 : serializedData[group]) === null || _a === void 0 ? void 0 : _a[key]) !== undefined) {
setting.set(setting.deserialize ?
// Type-checked upon declaration, just trust it to skip errors.
setting.deserialize(serializedData[group][key]) :
serializedData[group][key]);
}
}
}
}
/**
* @return the serialized version of the configuration. All `undefined` values are stripped
* from output. If a category remains unchanged from defaults, it is skipped. If the entire
* configuration remains unchanged, `null` is returned.
*/
serialize() {
const config = {};
for (const group of Object.keys(this.all)) {
const groupConfig = {};
const groupObject = this.all[group];
for (const key in this.all[group]) {
const setting = groupObject[key];
if (setting.get() === setting.defaultValue && !setting.alwaysSave) {
continue;
}
const serialized = setting.serialize ?
// Type-checked upon declaration, just trust it to skip errors.
setting.serialize(setting.get()) : setting.get();
if (serialized !== undefined) {
groupConfig[key] = serialized;
}
}
if (Object.keys(groupConfig).length > 0) {
config[group] = groupConfig;
}
}
if (Object.keys(config).length > 0) {
return config;
}
else {
return null;
}
}
}
 
/**
* Works like `Object.values`.
*
* @param obj The object to get the values of.
* @return The values of the given object as an array
*/
function getObjectValues(obj) {
return Object.keys(obj).map((key) => obj[key]);
}
 
/**
* Log warnings to the console.
*
* @param {...any} data
*/
function warn(...data) {
console.warn('[Deputy]', ...data);
}
 
/**
* Refers to a specific setting on the configuration. Should be initialized with
* a raw (serialized) type and an actual (deserialized) type.
*
* This is used for both client and wiki-wide configuration.
*/
class Setting {
/**
* @param options
* @param options.serialize Serialization function. See {@link Setting#serialize}
* @param options.deserialize Deserialization function. See {@link Setting#deserialize}
* @param options.alwaysSave See {@link Setting#alwaysSave}.
* @param options.defaultValue Default value. If not supplied, `undefined` is used.
* @param options.displayOptions See {@link Setting#displayOptions}
* @param options.allowedValues See {@link Setting#allowedValues}
*/
constructor(options) {
var _a, _b;
this.serialize = options.serialize;
this.deserialize = options.deserialize;
this.displayOptions = options.displayOptions;
this.allowedValues = options.allowedValues;
this.value = this.defaultValue = options.defaultValue;
this.alwaysSave = options.alwaysSave;
this.isDisabled = ((_a = options.displayOptions) === null || _a === void 0 ? void 0 : _a.disabled) != null ?
(typeof options.displayOptions.disabled === 'function' ?
options.displayOptions.disabled.bind(this) :
() => options.displayOptions.disabled) : () => false;
this.isHidden = ((_b = options.displayOptions) === null || _b === void 0 ? void 0 : _b.hidden) != null ?
(typeof options.displayOptions.hidden === 'function' ?
options.displayOptions.hidden.bind(this) :
() => options.displayOptions.hidden) : () => false;
}
/**
* @return `true` if `this.value` is not null or undefined.
*/
ok() {
return this.value != null;
}
/**
* @return The current value of this setting.
*/
get() {
return this.value;
}
/**
* Sets the value and performs validation. If the input is an invalid value, and
* `throwOnInvalid` is false, the value will be reset to default.
*
* @param v
* @param throwOnInvalid
*/
set(v, throwOnInvalid = false) {
if (this.locked) {
warn('Attempted to modify locked setting.');
return;
}
if (this.allowedValues) {
const keys = Array.isArray(this.allowedValues) ?
this.allowedValues : getObjectValues(this.allowedValues);
if (Array.isArray(v)) {
if (v.some((v1) => keys.indexOf(v1) === -1)) {
if (throwOnInvalid) {
throw new Error('Invalid value');
}
v = this.value;
}
}
else {
if (this.allowedValues && keys.indexOf(v) === -1) {
if (throwOnInvalid) {
throw new Error('Invalid value');
}
v = this.value;
}
}
}
this.value = v;
}
/**
* Resets this setting to its original value.
*/
reset() {
this.set(this.defaultValue);
}
/**
* Parses a given raw value and mutates the setting.
*
* @param raw The raw value to parse.
* @return The new value.
*/
load(raw) {
return (this.value = this.deserialize(raw));
}
/**
* Prevents the value of the setting from being changed. Used for debugging.
*/
lock() {
this.locked = true;
}
/**
* Allows the value of the setting to be changed. Used for debugging.
*/
unlock() {
this.locked = false;
}
}
Setting.basicSerializers = {
serialize: (value) => value,
deserialize: (value) => value
};
 
/**
* Checks if two MediaWiki page titles are equal.
*
* @param title1
* @param title2
* @return `true` if `title1` and `title2` refer to the same page
*/
function equalTitle(title1, title2) {
return normalizeTitle(title1).getPrefixedDb() === normalizeTitle(title2).getPrefixedDb();
}
 
var deputySettingsStyles = ".deputy-setting {margin-bottom: 1em;}.deputy-setting > .oo-ui-fieldLayout-align-top .oo-ui-fieldLayout-header .oo-ui-labelElement-label {font-weight: bold;}.dp-mb {margin-bottom: 1em;}.deputy-about {display: flex;}.deputy-about > :first-child {flex: 0;}.deputy-about > :first-child > img {height: 5em;width: auto;}.ltr .deputy-about > :first-child {margin-right: 1em;}.rtl .deputy-about > :first-child {margin-left: 1em;}.deputy-about > :nth-child(2) {flex: 1;}.deputy-about > :nth-child(2) > :first-child > * {display: inline;}.deputy-about > :nth-child(2) > :first-child > :first-child {font-weight: bold;font-size: 2em;}.deputy-about > :nth-child(2) > :first-child > :nth-child(2) {color: gray;vertical-align: bottom;margin-left: 0.4em;}.deputy-about > :nth-child(2) > :not(:first-child) {margin-top: 0.5em;}.ltr .deputy-about + div > :not(:last-child) {margin-right: 0.5em;}.rtl .deputy-about + div > :not(:last-child) {margin-left: 0.5em;}.ltr .deputy-about + div {text-align: right;}.rtl .deputy-about + div {text-align: left;}";
 
/**
* Works like `Object.fromEntries`
*
* @param obj The object to get the values of.
* @return The values of the given object as an array
*/
function fromObjectEntries(obj) {
const i = {};
for (const [key, value] of obj) {
i[key] = value;
}
return i;
}
 
/**
* Generates serializer and deserializer for serialized <b>string</b> enums.
*
* Trying to use anything that isn't a string enum here (union enum, numeral enum)
* will likely cause serialization/deserialization failures.
*
* @param _enum
* @param defaultValue
* @return An object containing a `serializer` and `deserializer`.
*/
function generateEnumSerializers(_enum, defaultValue) {
return {
serialize: (value) => value === defaultValue ? undefined : value,
deserialize: (value) => value
};
}
/**
* Generates configuration properties for serialized <b>string</b> enums.
*
* Trying to use anything that isn't a string enum here (union enum, numeral enum)
* will likely cause serialization/deserialization failures.
*
* @param _enum
* @param defaultValue
* @return Setting properties.
*/
function generateEnumConfigurationProperties(_enum, defaultValue) {
return Object.assign(Object.assign({}, generateEnumSerializers(_enum, defaultValue)), { displayOptions: {
type: 'radio'
}, allowedValues: fromObjectEntries(Array.from(new Set(Object.keys(_enum)).values())
.map((v) => [_enum[v], _enum[v]])), defaultValue: defaultValue });
}
var PortletNameView;
(function (PortletNameView) {
PortletNameView["Full"] = "full";
PortletNameView["Short"] = "short";
PortletNameView["Acronym"] = "acronym";
})(PortletNameView || (PortletNameView = {}));
 
var CompletionAction;
(function (CompletionAction) {
CompletionAction["Nothing"] = "nothing";
CompletionAction["Reload"] = "reload";
})(CompletionAction || (CompletionAction = {}));
var TripleCompletionAction;
(function (TripleCompletionAction) {
TripleCompletionAction["Nothing"] = "nothing";
TripleCompletionAction["Reload"] = "reload";
TripleCompletionAction["Redirect"] = "redirect";
})(TripleCompletionAction || (TripleCompletionAction = {}));
 
var ContributionSurveyRowSigningBehavior;
(function (ContributionSurveyRowSigningBehavior) {
ContributionSurveyRowSigningBehavior["Always"] = "always";
ContributionSurveyRowSigningBehavior["AlwaysTrace"] = "alwaysTrace";
ContributionSurveyRowSigningBehavior["AlwaysTraceLastOnly"] = "alwaysTraceLastOnly";
ContributionSurveyRowSigningBehavior["LastOnly"] = "lastOnly";
ContributionSurveyRowSigningBehavior["Never"] = "never";
})(ContributionSurveyRowSigningBehavior || (ContributionSurveyRowSigningBehavior = {}));
 
var DeputyPageToolbarState;
(function (DeputyPageToolbarState) {
DeputyPageToolbarState[DeputyPageToolbarState["Open"] = 0] = "Open";
DeputyPageToolbarState[DeputyPageToolbarState["Collapsed"] = 1] = "Collapsed";
DeputyPageToolbarState[DeputyPageToolbarState["Hidden"] = 2] = "Hidden";
})(DeputyPageToolbarState || (DeputyPageToolbarState = {}));
 
/**
* A button that performs an action when clicked. Shown in the preferences screen,
* and acts exactly like a setting, but always holds a value of 'null'.
*/
class Action extends Setting {
/**
* @param onClick
* @param displayOptions
*/
constructor(onClick, displayOptions = {}) {
super({
serialize: () => undefined,
deserialize: () => undefined,
displayOptions: Object.assign({}, displayOptions, { type: 'button' })
});
this.onClick = onClick;
}
}
 
/**
* A configuration. Defines settings and setting groups.
*/
class UserConfiguration extends ConfigurationBase {
/**
* @return the configuration from the current wiki.
*/
static load() {
const config = new UserConfiguration();
try {
if (mw.user.options.get(UserConfiguration.optionKey)) {
const decodedOptions = JSON.parse(mw.user.options.get(UserConfiguration.optionKey));
config.deserialize(decodedOptions);
}
}
catch (e) {
error(e, mw.user.options.get(UserConfiguration.optionKey));
mw.hook('deputy.i18nDone').add(function notifyConfigFailure() {
mw.notify(mw.msg('deputy.loadError.userConfig'), {
type: 'error'
});
mw.hook('deputy.i18nDone').remove(notifyConfigFailure);
});
config.save();
}
return config;
}
/**
* Creates a new Configuration.
*
* @param serializedData
*/
constructor(serializedData = {}) {
var _a;
super();
this.core = {
/**
* Numerical code that identifies this config version. Increments for every breaking
* configuration file change.
*/
configVersion: new Setting({
defaultValue: UserConfiguration.configVersion,
displayOptions: { hidden: true },
alwaysSave: true
}),
language: new Setting({
defaultValue: mw.config.get('wgUserLanguage'),
displayOptions: { type: 'select' }
}),
modules: new Setting({
defaultValue: ['cci', 'ante', 'ia'],
displayOptions: { type: 'checkboxes' },
allowedValues: ['cci', 'ante', 'ia']
}),
portletNames: new Setting(generateEnumConfigurationProperties(PortletNameView, PortletNameView.Full)),
seenAnnouncements: new Setting({
defaultValue: [],
displayOptions: { hidden: true }
}),
dangerMode: new Setting({
defaultValue: false,
displayOptions: {
type: 'checkbox'
}
}),
resetDatabase: new Action(() => __awaiter(this, void 0, void 0, function* () {
yield window.deputy.storage.reset();
}), {
disabled: () => !window.deputy,
extraOptions: {
flags: ['destructive']
}
}),
resetPreferences: new Action(() => __awaiter(this, void 0, void 0, function* () {
yield MwApi.action.saveOption(UserConfiguration.optionKey, null);
}), {
extraOptions: {
flags: ['destructive']
}
})
};
this.cci = {
enablePageToolbar: new Setting({
defaultValue: true,
displayOptions: {
type: 'checkbox'
}
}),
showCvLink: new Setting({
defaultValue: true,
displayOptions: {
type: 'checkbox'
}
}),
showUsername: new Setting({
defaultValue: false,
displayOptions: {
type: 'checkbox'
}
}),
autoCollapseRows: new Setting({
defaultValue: false,
displayOptions: {
type: 'checkbox'
}
}),
autoShowDiff: new Setting({
defaultValue: false,
displayOptions: {
type: 'checkbox'
}
}),
maxRevisionsToAutoShowDiff: new Setting({
defaultValue: 2,
displayOptions: {
type: 'number',
// Force any due to self-reference
disabled: (config) => !config.cci.autoShowDiff.get(),
extraOptions: {
min: 1
}
}
}),
maxSizeToAutoShowDiff: new Setting({
defaultValue: 500,
displayOptions: {
type: 'number',
// Force any due to self-reference
disabled: (config) => !config.cci.autoShowDiff.get(),
extraOptions: {
min: -1
}
}
}),
forceUtc: new Setting({
defaultValue: false,
displayOptions: {
type: 'checkbox'
}
}),
signingBehavior: new Setting(generateEnumConfigurationProperties(ContributionSurveyRowSigningBehavior, ContributionSurveyRowSigningBehavior.Always)),
signSectionArchive: new Setting({
defaultValue: true,
displayOptions: {
type: 'checkbox'
}
}),
openOldOnContinue: new Setting({
defaultValue: false,
displayOptions: {
type: 'checkbox'
}
}),
toolbarInitialState: new Setting(Object.assign(Object.assign({}, generateEnumSerializers(DeputyPageToolbarState, DeputyPageToolbarState.Open)), { defaultValue: DeputyPageToolbarState.Open, displayOptions: { hidden: true } }))
};
this.ante = {
enableAutoMerge: new Setting({
defaultValue: false,
displayOptions: {
type: 'checkbox',
disabled: 'unimplemented'
}
}),
onSubmit: new Setting(generateEnumConfigurationProperties(CompletionAction, CompletionAction.Reload))
};
this.ia = {
responses: new Setting(Object.assign(Object.assign({}, Setting.basicSerializers), { defaultValue: null, displayOptions: {
disabled: 'unimplemented',
type: 'unimplemented'
} })),
enablePageToolbar: new Setting({
defaultValue: true,
displayOptions: {
type: 'checkbox',
disabled: 'unimplemented'
}
}),
defaultEntirePage: new Setting({
defaultValue: true,
displayOptions: {
type: 'checkbox'
}
}),
defaultFromUrls: new Setting({
defaultValue: true,
displayOptions: {
type: 'checkbox'
}
}),
onHide: new Setting(generateEnumConfigurationProperties(TripleCompletionAction, TripleCompletionAction.Reload)),
onSubmit: new Setting(generateEnumConfigurationProperties(TripleCompletionAction, TripleCompletionAction.Reload)),
onBatchSubmit: new Setting(generateEnumConfigurationProperties(CompletionAction, CompletionAction.Reload))
};
this.type = 'user';
this.all = { core: this.core, cci: this.cci, ante: this.ante, ia: this.ia };
if (serializedData) {
this.deserialize(serializedData);
}
if (mw.storage.get(`mw-${UserConfiguration.optionKey}-lastVersion`) !== version) ;
mw.storage.set(`mw-${UserConfiguration.optionKey}-lastVersion`, version);
if ((_a = window.deputy) === null || _a === void 0 ? void 0 : _a.comms) {
window.deputy.comms.addEventListener('userConfigUpdate', (e) => {
// Update the configuration based on another tab's message.
this.deserialize(e.data.config);
});
}
}
/**
* Saves the configuration.
*/
save() {
return __awaiter(this, void 0, void 0, function* () {
yield MwApi.action.saveOption(UserConfiguration.optionKey, JSON.stringify(this.serialize()));
});
}
}
UserConfiguration.configVersion = 1;
UserConfiguration.optionKey = 'userjs-deputy';
 
let InternalConfigurationGroupTabPanel$1;
/**
* Initializes the process element.
*/
function initConfigurationGroupTabPanel$1() {
InternalConfigurationGroupTabPanel$1 = class ConfigurationGroupTabPanel extends OO.ui.TabPanelLayout {
/**
* @return The {@Link Setting}s for this group.
*/
get settings() {
return this.config.config.all[this.config.group];
}
/**
* @param config Configuration to be passed to the element.
*/
constructor(config) {
super(`configurationGroupPage_${config.group}`);
this.config = config;
this.mode = config.config instanceof UserConfiguration ? 'user' : 'wiki';
if (this.mode === 'wiki') {
this.$element.append(new OO.ui.MessageWidget({
classes: [
'deputy', 'dp-mb'
],
type: 'warning',
label: mw.msg('deputy.settings.dialog.wikiConfigWarning')
}).$element);
}
for (const settingKey of Object.keys(this.settings)) {
const setting = this.settings[settingKey];
if (setting.isHidden(this.config.config)) {
continue;
}
switch (setting.displayOptions.type) {
case 'checkbox':
this.$element.append(this.newCheckboxField(settingKey, setting));
break;
case 'checkboxes':
this.$element.append(this.newCheckboxesField(settingKey, setting));
break;
case 'radio':
this.$element.append(this.newRadioField(settingKey, setting));
break;
case 'text':
this.$element.append(this.newStringField(settingKey, setting, setting.displayOptions.extraOptions));
break;
case 'number':
this.$element.append(this.newNumberField(settingKey, setting, setting.displayOptions.extraOptions));
break;
case 'page':
this.$element.append(this.newPageField(settingKey, setting, setting.displayOptions.extraOptions));
break;
case 'code':
this.$element.append(this.newCodeField(settingKey, setting, setting.displayOptions.extraOptions));
break;
case 'button':
this.$element.append(this.newButtonField(settingKey, setting, setting.displayOptions.extraOptions));
break;
default:
this.$element.append(this.newUnimplementedField(settingKey));
break;
}
}
}
/**
* Sets up the tab item
*/
setupTabItem() {
this.tabItem.setLabel(this.getMsg(this.config.group));
return this;
}
/**
* @return the i18n message for this setting tab.
*
* @param messageKey
*/
getMsg(messageKey) {
return mw.msg(`deputy.setting.${this.mode}.${messageKey}`);
}
/**
* Gets the i18n message for a given setting.
*
* @param settingKey
* @param key
* @return A localized string
*/
getSettingMsg(settingKey, key) {
return this.getMsg(`${this.config.group}.${settingKey}.${key}`);
}
/**
* @param settingKey
* @param allowedValues
* @return a tuple array of allowed values that can be used in OOUI `items` parameters.
*/
getAllowedValuesArray(settingKey, allowedValues) {
const items = [];
if (Array.isArray(allowedValues)) {
for (const key of allowedValues) {
const message = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.${key}`);
items.push([key, message.exists() ? message.text() : key]);
}
}
else {
for (const key of Object.keys(allowedValues)) {
const message = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.${key}`);
items.push([key, message.exists() ? message.text() : key]);
}
}
return items;
}
/**
* Creates an unimplemented setting notice.
*
* @param settingKey
* @return An HTMLElement of the given setting's field.
*/
newUnimplementedField(settingKey) {
const desc = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.description`);
return h_1("div", { class: "deputy-setting" },
h_1("b", null, this.getSettingMsg(settingKey, 'name')),
desc.exists() ? h_1("p", { style: { fontSize: '0.925em', color: '#54595d' } }, desc.text()) : '',
h_1("p", null, mw.msg('deputy.settings.dialog.unimplemented')));
}
/**
* Creates a checkbox field.
*
* @param settingKey
* @param setting
* @return An HTMLElement of the given setting's field.
*/
newCheckboxField(settingKey, setting) {
const isDisabled = setting.isDisabled(this.config.config);
const desc = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.description`);
const field = new OO.ui.CheckboxInputWidget({
selected: setting.get(),
disabled: isDisabled !== undefined && isDisabled !== false
});
const layout = new OO.ui.FieldLayout(field, {
align: 'inline',
label: this.getSettingMsg(settingKey, 'name'),
help: typeof isDisabled === 'string' ?
this.getSettingMsg(settingKey, isDisabled) :
desc.exists() ? desc.text() : undefined,
helpInline: true
});
field.on('change', () => {
setting.set(field.isSelected());
this.emit('change');
});
// Attach disabled re-checker
this.on('change', () => {
field.setDisabled(!!setting.isDisabled(this.config.config));
});
return h_1("div", { class: "deputy-setting" }, unwrapWidget(layout));
}
/**
* Creates a new checkbox set field.
*
* @param settingKey
* @param setting
* @return An HTMLElement of the given setting's field.
*/
newCheckboxesField(settingKey, setting) {
const isDisabled = setting.isDisabled(this.config.config);
const desc = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.description`);
const field = new OO.ui.CheckboxMultiselectInputWidget({
value: setting.get(),
disabled: isDisabled !== undefined && isDisabled !== false,
options: this.getAllowedValuesArray(settingKey, setting.allowedValues)
.map(([key, label]) => ({ data: key, label }))
});
const layout = new OO.ui.FieldLayout(field, {
align: 'top',
label: this.getSettingMsg(settingKey, 'name'),
help: typeof isDisabled === 'string' ?
this.getSettingMsg(settingKey, isDisabled) :
desc.exists() ? desc.text() : undefined,
helpInline: true
});
// TODO: @types/oojs-ui limitation
field.on('change', (items) => {
const finalData = Array.isArray(setting.allowedValues) ?
items :
field.getValue().map((v) => setting.allowedValues[v]);
setting.set(finalData);
this.emit('change');
});
// Attach disabled re-checker
this.on('change', () => {
field.setDisabled(!!setting.isDisabled(this.config.config));
});
return h_1("div", { class: "deputy-setting" }, unwrapWidget(layout));
}
/**
* Creates a new radio set field.
*
* @param settingKey
* @param setting
* @return An HTMLElement of the given setting's field.
*/
newRadioField(settingKey, setting) {
var _a;
const isDisabled = setting.isDisabled(this.config.config);
const desc = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.description`);
const field = new OO.ui.RadioSelectWidget({
disabled: isDisabled !== undefined && isDisabled !== false &&
!((_a = setting.displayOptions.readOnly) !== null && _a !== void 0 ? _a : false),
items: this.getAllowedValuesArray(settingKey, setting.allowedValues)
.map(([key, label]) => new OO.ui.RadioOptionWidget({
data: key,
label: label,
selected: setting.get() === key
})),
multiselect: false
});
const layout = new OO.ui.FieldLayout(field, {
align: 'top',
label: this.getSettingMsg(settingKey, 'name'),
help: typeof isDisabled === 'string' ?
this.getSettingMsg(settingKey, isDisabled) :
desc.exists() ? desc.text() : undefined,
helpInline: true
});
// OOUIRadioInputWidget
field.on('select', (items) => {
const finalData = Array.isArray(setting.allowedValues) ?
items.data :
setting.allowedValues[items.data];
setting.set(finalData);
this.emit('change');
});
// Attach disabled re-checker
this.on('change', () => {
field.setDisabled(!!setting.isDisabled(this.config.config));
});
return h_1("div", { class: "deputy-setting" }, unwrapWidget(layout));
}
/**
* Creates a new field that acts like a string field.
*
* @param FieldClass
* @param settingKey
* @param setting
* @param extraFieldOptions
* @return A Deputy setting field
*/
newStringLikeField(FieldClass, settingKey, setting, extraFieldOptions = {}) {
var _a, _b, _c;
const isDisabled = setting.isDisabled(this.config.config);
const desc = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.description`);
const field = new FieldClass(Object.assign({ readOnly: (_a = setting.displayOptions.readOnly) !== null && _a !== void 0 ? _a : false, value: (_c = (_b = setting.serialize) === null || _b === void 0 ? void 0 : _b.call(setting, setting.get())) !== null && _c !== void 0 ? _c : setting.get(), disabled: isDisabled !== undefined && isDisabled !== false }, extraFieldOptions));
const layout = new OO.ui.FieldLayout(field, {
align: 'top',
label: this.getSettingMsg(settingKey, 'name'),
help: typeof isDisabled === 'string' ?
this.getSettingMsg(settingKey, isDisabled) :
desc.exists() ? desc.text() : undefined,
helpInline: true
});
if (FieldClass === OO.ui.NumberInputWidget) {
field.on('change', (value) => {
setting.set(+value);
this.emit('change');
});
}
else {
field.on('change', (value) => {
setting.set(value);
this.emit('change');
});
}
// Attach disabled re-checker
this.on('change', () => {
field.setDisabled(setting.isDisabled(this.config.config));
});
return h_1("div", { class: "deputy-setting" }, unwrapWidget(layout));
}
/**
* Creates a new string setting field.
*
* @param settingKey
* @param setting
* @param extraFieldOptions
* @return An HTMLElement of the given setting's field.
*/
newStringField(settingKey, setting, extraFieldOptions) {
return this.newStringLikeField(OO.ui.TextInputWidget, settingKey, setting, extraFieldOptions);
}
/**
* Creates a new number setting field.
*
* @param settingKey
* @param setting
* @param extraFieldOptions
* @return An HTMLElement of the given setting's field.
*/
newNumberField(settingKey, setting, extraFieldOptions) {
return this.newStringLikeField(OO.ui.NumberInputWidget, settingKey, setting, extraFieldOptions);
}
/**
* Creates a new page title setting field.
*
* @param settingKey
* @param setting
* @param extraFieldOptions
* @return An HTMLElement of the given setting's field.
*/
newPageField(settingKey, setting, extraFieldOptions) {
return this.newStringLikeField(mw.widgets.TitleInputWidget, settingKey, setting, extraFieldOptions);
}
/**
* Creates a new code setting field.
*
* @param settingKey
* @param setting
* @param extraFieldOptions
* @return An HTMLElement of the given setting's field.
*/
newCodeField(settingKey, setting, extraFieldOptions) {
return this.newStringLikeField(OO.ui.MultilineTextInputWidget, settingKey, setting, extraFieldOptions);
}
/**
* Creates a new button setting field.
*
* @param settingKey
* @param setting
* @param extraFieldOptions
* @return An HTMLElement of the given setting's field.
*/
newButtonField(settingKey, setting, extraFieldOptions) {
const isDisabled = setting.isDisabled(this.config.config);
const msgPrefix = `deputy.setting.${this.mode}.${this.config.group}.${settingKey}`;
const desc = mw.message(`${msgPrefix}.description`);
const field = new OO.ui.ButtonWidget(Object.assign({ label: this.getSettingMsg(settingKey, 'name'), disabled: isDisabled !== undefined && isDisabled !== false }, extraFieldOptions));
const layout = new OO.ui.FieldLayout(field, {
align: 'top',
label: this.getSettingMsg(settingKey, 'name'),
help: typeof isDisabled === 'string' ?
this.getSettingMsg(settingKey, isDisabled) :
desc.exists() ? desc.text() : undefined,
helpInline: true
});
field.on('click', () => __awaiter(this, void 0, void 0, function* () {
try {
if (yield OO.ui.confirm(mw.msg(`${msgPrefix}.confirm`))) {
yield setting.onClick();
OO.ui.alert(mw.msg(`${msgPrefix}.success`));
}
}
catch (e) {
OO.ui.alert(mw.msg(`${msgPrefix}.failed`));
}
}));
return h_1("div", { class: "deputy-setting" }, unwrapWidget(layout));
}
};
}
/**
* Creates a new ConfigurationGroupTabPanel.
*
* @param config Configuration to be passed to the element.
* @return A ConfigurationGroupTabPanel object
*/
function ConfigurationGroupTabPanel (config) {
if (!InternalConfigurationGroupTabPanel$1) {
initConfigurationGroupTabPanel$1();
}
return new InternalConfigurationGroupTabPanel$1(config);
}
 
let windowManager;
/**
* Opens a temporary window. Use this for dialogs that are immediately destroyed
* after running. Do NOT use this for re-openable dialogs, such as the main ANTE
* dialog.
*
* @param window
* @return A promise. Resolves when the window is closed.
*/
function openWindow(window) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((res) => {
var _a;
if (!windowManager) {
windowManager = new OO.ui.WindowManager();
const parent = (_a = document.getElementById('mw-teleport-target')) !== null && _a !== void 0 ? _a : document.getElementsByTagName('body')[0];
parent.appendChild(unwrapWidget(windowManager));
}
windowManager.addWindows([window]);
windowManager.openWindow(window);
windowManager.on('closing', (win, closed) => {
closed.then(() => {
if (windowManager) {
const _wm = windowManager;
windowManager = null;
removeElement(unwrapWidget(_wm));
_wm.destroy();
res();
}
});
});
});
});
}
 
var deputySettingsEnglish = {
"deputy.about.version": "v$1 ($2)",
"deputy.about": "About",
"deputy.about.homepage": "Homepage",
"deputy.about.openSource": "Source",
"deputy.about.contact": "Contact",
"deputy.about.credit": "Deputy was made with the help of the English Wikipedia Copyright Cleanup WikiProject and the Wikimedia Foundation.",
"deputy.about.license": "Deputy is licensed under the [$1 Apache License 2.0]. The source code for Deputy is available on [$2 GitHub], and is free for everyone to view and suggest changes.",
"deputy.about.thirdParty": "Deputy is bundled with third party libraries to make development easier. All libraries have been vetted for user security and license compatibility. For more information, see the [$1 Licensing] section on Deputy's README.",
"deputy.about.buildInfo": "Deputy v$1 ($2), committed $3.",
"deputy.about.footer": "Made with love, coffee, and the tears of copyright editors.",
"deputy.settings.portlet": "Deputy preferences",
"deputy.settings.portlet.tooltip": "Opens a dialog to modify Deputy preferences",
"deputy.settings.wikiEditIntro.title": "This is a Deputy configuration page",
"deputy.settings.wikiEditIntro.current": "Deputy's active configuration comes from this page. Changing this page will affect the settings of all Deputy users on this wiki. Edit responsibly, and avoid making significant changes without prior discussion.",
"deputy.settings.wikiEditIntro.other": "This is a valid Deputy configuration page, but the configuration is currently being loaded from [[$1]]. If this becomes the active configuration page, changing it will affect the settings of all Deputy users on this wiki. Edit responsibly, and avoid making significant changes without prior discussion.",
"deputy.settings.wikiEditIntro.edit.current": "Modify configuration",
"deputy.settings.wikiEditIntro.edit.other": "Modify this configuration",
"deputy.settings.wikiEditIntro.edit.otherCurrent": "Modify the active configuration",
"deputy.settings.wikiEditIntro.edit.protected": "This page's protection settings do not allow you to edit the page.",
"deputy.settings.wikiOutdated": "Outdated configuration",
"deputy.settings.wikiOutdated.help": "Deputy has detected a change in this wiki's configuration for all Deputy users. We've automatically downloaded the changes for you, but you have to reload to apply the changes.",
"deputy.settings.wikiOutdated.reload": "Reload",
"deputy.settings.dialog.title": "Deputy Preferences",
"deputy.settings.dialog.unimplemented": "A way to modify this setting has not yet been implemented. Check back later!",
"deputy.settings.saved": "Preferences saved. Please refresh the page to see changes.",
"deputy.settings.dialog.wikiConfigWarning": "You are currently editing a wiki-wide Deputy configuration page. Changes made to this page may affect the settings of all Deputy users on this wiki. Edit responsibly, and avoid making significant changes without prior discussion.",
"deputy.setting.user.core": "Deputy",
"deputy.setting.user.core.language.name": "Language",
"deputy.setting.user.core.language.description": "Deputy's interface language. English (US) is used by default, and is used as a fallback if no translations are available. If the content of the wiki you work on is in a different language from the interface language, Deputy will need to load additional data to ensure edit summaries, text, etc., saved on-wiki match the wiki's content language. For this reason, we suggest keeping the interface language the same as the wiki's content language.",
"deputy.setting.user.core.modules.name": "Modules",
"deputy.setting.user.core.modules.description": "Choose the enabled Deputy modules. By default, all modules are enabled.\nDisabling specific modules won't make Deputy load faster, but it can remove\nUI features added by Deputy which may act as clutter when unused.",
"deputy.setting.user.core.modules.cci": "Contributor Copyright Investigations",
"deputy.setting.user.core.modules.ante": "{{int:deputy.ante}}",
"deputy.setting.user.core.modules.ia": "{{int:deputy.ia}}",
"deputy.setting.user.core.portletNames.name": "Portlet names",
"deputy.setting.user.core.portletNames.description": "Choose which names appear in the Deputy portlet (toolbox) links.",
"deputy.setting.user.core.portletNames.full": "Full names (e.g. Attribution Notice Template Editor)",
"deputy.setting.user.core.portletNames.short": "Shortened names (e.g. Attrib. Template Editor)",
"deputy.setting.user.core.portletNames.acronym": "Acronyms (e.g. ANTE)",
"deputy.setting.user.core.dangerMode.name": "Danger mode",
"deputy.setting.user.core.dangerMode.description": "Live on the edge. This disables most confirmations and warnings given by Deputy, only leaving potentially catastrophic actions, such as page edits which break templates. It also adds extra buttons meant for rapid case processing. Intended for clerk use; use with extreme caution.",
"deputy.setting.user.core.resetDatabase.name": "Reset database",
"deputy.setting.user.core.resetDatabase.description": "Resets the Deputy internal database. This clears all cached data, including saved page and revision statuses that haven't been saved on-wiki. This does not clear your Deputy preferences.",
"deputy.setting.user.core.resetDatabase.confirm": "Are you sure you want to reset the Deputy database? This action cannot be undone.",
"deputy.setting.user.core.resetDatabase.success": "Database reset successfully. Please refresh the page to see changes.",
"deputy.setting.user.core.resetDatabase.failed": "Could not reset the database. If this error persists, please contact the Deputy maintainers.",
"deputy.setting.user.core.resetPreferences.name": "Reset preferences",
"deputy.setting.user.core.resetPreferences.description": "Resets your Deputy preferences. This clears all settings you have saved in Deputy across all browsers.",
"deputy.setting.user.core.resetPreferences.confirm": "Are you sure you want to reset your Deputy preferences? This action cannot be undone.",
"deputy.setting.user.core.resetPreferences.success": "Preferences reset successfully. Please refresh the page to see changes.",
"deputy.setting.user.core.resetPreferences.failed": "Could not reset preferences. If this error persists, please contact the Deputy maintainers.",
"deputy.setting.user.cci": "CCI",
"deputy.setting.user.cci.enablePageToolbar.name": "Enable page toolbar",
"deputy.setting.user.cci.enablePageToolbar.description": "Enables the page toolbar, which is used to quickly show tools, analysis options, and related case information on a page that is the subject of a CCI investigation.",
"deputy.setting.user.cci.showCvLink.name": "Show \"cv\" (\"copyvios\") link for revisions",
"deputy.setting.user.cci.showCvLink.description": "Show a \"cv\" link next to \"cur\" and \"prev\" on revision rows. This link will only appear if this wiki is configured to use Earwig's Copyvio Detector.",
"deputy.setting.user.cci.showUsername.name": "Show username",
"deputy.setting.user.cci.showUsername.description": "Show the username of the user who made the edit on revision rows. This may be redundant for cases which only have one editor.",
"deputy.setting.user.cci.autoCollapseRows.name": "Automatically collapse rows",
"deputy.setting.user.cci.autoCollapseRows.description": "Automatically collapse rows when the page is loaded. This is useful for cases where each row has many revisions, but may be annoying for cases where each row has few revisions.",
"deputy.setting.user.cci.autoShowDiff.name": "Automatically show diffs",
"deputy.setting.user.cci.autoShowDiff.description": "Enabling automatic loading of diffs. Configurable with two additional options to avoid loading too much content.",
"deputy.setting.user.cci.maxRevisionsToAutoShowDiff.name": "Maximum revisions to automatically show diff",
"deputy.setting.user.cci.maxRevisionsToAutoShowDiff.description": "The maximum number of revisions for a given page to automatically show the diff for each revision in the main interface.",
"deputy.setting.user.cci.maxSizeToAutoShowDiff.name": "Maximum size to automatically show diff",
"deputy.setting.user.cci.maxSizeToAutoShowDiff.description": "The maximum size of a diff to be automatically shown, if the diff will be automatically shown (see \"Maximum revisions to automatically show diff\"). Prevents extremely large diffs from opening. Set to -1 to show regardless of size.",
"deputy.setting.user.cci.forceUtc.name": "Force UTC time",
"deputy.setting.user.cci.forceUtc.description": "Forces Deputy to use UTC time whenever displaying dates and times, irregardless of your system's timezone or your MediaWiki time settings.",
"deputy.setting.user.cci.signingBehavior.name": "Row signing behavior",
"deputy.setting.user.cci.signingBehavior.description": "Choose how Deputy should behave when signing rows. By default, all rows are always signed with your signature (~~~~). You may configure Deputy to only sign the last row or never sign. You can also configure Deputy to leave a hidden trace behind (<!-- User:Example|2016-05-28T14:32:12Z -->), which helps Deputy (for other users) determine who assessed a row.",
"deputy.setting.user.cci.signingBehavior.always": "Always sign rows",
"deputy.setting.user.cci.signingBehavior.alwaysTrace": "Always leave a trace",
"deputy.setting.user.cci.signingBehavior.alwaysTraceLastOnly": "Always leave a trace, but sign the last row modified",
"deputy.setting.user.cci.signingBehavior.lastOnly": "Only sign the last row modified (prevents assessor recognition)",
"deputy.setting.user.cci.signingBehavior.never": "Never sign rows (prevents assessor recognition)",
"deputy.setting.user.cci.signSectionArchive.name": "Sign by default when archiving CCI sections",
"deputy.setting.user.cci.signSectionArchive.description": "If enabled, Deputy will enable the \"include my signature\" checkbox by default when archiving a CCI section.",
"deputy.setting.user.cci.openOldOnContinue.name": "Open old versions on continue",
"deputy.setting.user.cci.openOldOnContinue.description": "If enabled, all previously-open sections of a given case page will also be opened alongside the section where the \"continue CCI session\" link was clicked.",
"deputy.setting.user.ante": "ANTE",
"deputy.setting.user.ante.enableAutoMerge.name": "Merge automatically on run",
"deputy.setting.user.ante.enableAutoMerge.description": "If enabled, templates that can be merged will automatically be merged when the dialog opens.",
"deputy.setting.user.ante.enableAutoMerge.unimplemented": "This feature has not yet been implemented.",
"deputy.setting.user.ante.onSubmit.name": "Action on submit",
"deputy.setting.user.ante.onSubmit.description": "Choose what to do after editing attribution notice templates.",
"deputy.setting.user.ante.onSubmit.nothing": "Do nothing",
"deputy.setting.user.ante.onSubmit.reload": "Reload the page",
"deputy.setting.user.ia": "IA",
"deputy.setting.user.ia.responses.name": "Custom responses",
"deputy.setting.user.ia.responses.description": "A custom set of responses, or overrides for existing responses. If an entry\nwith the same key on both the wiki-wide configuration and the user configuration\nexists, the user configuration will override the wiki-wide configuration. Wiki-wide configuration responses can also be disabled locally. If this setting is empty, no overrides are made.",
"deputy.setting.user.ia.enablePageToolbar.name": "Enable page toolbar",
"deputy.setting.user.ia.enablePageToolbar.description": "If enabled, the page toolbar will be shown when dealing with CP cases. The IA page toolbar works slightly differently from the CCI page toolbar. Namely, it shows a button for responding instead of a status dropdown.",
"deputy.setting.user.ia.enablePageToolbar.unimplemented": "This feature has not yet been implemented.",
"deputy.setting.user.ia.defaultEntirePage.name": "Hide entire page by default",
"deputy.setting.user.ia.defaultEntirePage.description": "If enabled, the Infringement Assistant reporting window will hide the entire page by default.",
"deputy.setting.user.ia.defaultFromUrls.name": "Use URLs by default",
"deputy.setting.user.ia.defaultFromUrls.description": "If enabled, the Infringement Assistant reporting window will use URL inputs by default.",
"deputy.setting.user.ia.onHide.name": "Action on hide",
"deputy.setting.user.ia.onHide.description": "Choose what to do after the \"Hide content only\" button is selected and the relevant content is hidden from the page.",
"deputy.setting.user.ia.onHide.nothing": "Do nothing",
"deputy.setting.user.ia.onHide.reload": "Reload the page",
"deputy.setting.user.ia.onHide.redirect": "Redirect to the noticeboard page",
"deputy.setting.user.ia.onSubmit.name": "Action on submit",
"deputy.setting.user.ia.onSubmit.description": "Choose what to do after the \"Submit\" button is selected, the relevant content is hidden from the page, and the page is reported.",
"deputy.setting.user.ia.onSubmit.nothing": "Do nothing",
"deputy.setting.user.ia.onSubmit.reload": "Reload the page",
"deputy.setting.user.ia.onSubmit.redirect": "Redirect to the noticeboard page",
"deputy.setting.user.ia.onBatchSubmit.name": "Action on batch listing submit",
"deputy.setting.user.ia.onBatchSubmit.description": "When reporting a batch of pages, choose what to do after the \"Report\" button is selected and the pages are reported.",
"deputy.setting.user.ia.onBatchSubmit.nothing": "Do nothing",
"deputy.setting.user.ia.onBatchSubmit.reload": "Reload the noticeboard page",
"deputy.setting.wiki.core": "Core",
"deputy.setting.wiki.core.lastEdited.name": "Configuration last edited",
"deputy.setting.wiki.core.lastEdited.description": "The last time that this configuration was edited, as a timestamp. This is a way to ensure that all users are on the correct wiki-wide configuration version before changes are made. Checks are performed on every page load with Deputy.",
"deputy.setting.wiki.core.dispatchRoot.name": "Deputy Dispatch root URL",
"deputy.setting.wiki.core.dispatchRoot.description": "The URL to a Deputy Dispatch instance that can handle this wiki. Deputy Dispatch is a webserver responsible for centralizing and optimizing data used by Deputy, and can be used to reduce load on wikis. More information can be found at https://github.com/ChlodAlejandro/deputy-dispatch.",
"deputy.setting.wiki.core.changeTag.name": "Change tag",
"deputy.setting.wiki.core.changeTag.description": "Tag to use for all Deputy edits.",
"deputy.setting.wiki.cci": "CCI",
"deputy.setting.wiki.cci.enabled.name": "Enable contributor copyright investigations assistant",
"deputy.setting.wiki.cci.enabled.description": "Enables the CCI workflow assistant. This allows Deputy to replace the contribution survey found on CCI case pages with a graphical interface which works with other tabs to make the CCI workflow easier.",
"deputy.setting.wiki.cci.rootPage.name": "Root page",
"deputy.setting.wiki.cci.rootPage.description": "The main page that holds all subpages containing valid contribution copyright investigation cases.",
"deputy.setting.wiki.cci.headingMatch.name": "Heading title regular expression",
"deputy.setting.wiki.cci.headingMatch.description": "A regular expression that will be used to detect valid contribution surveyor heading. Since its usage is rather technical, this value should be edited by someone with technical knowledge of regular expressions.",
"deputy.setting.wiki.cci.collapseTop.name": "Collapsible wikitext (top)",
"deputy.setting.wiki.cci.collapseTop.description": "Placed just below a section heading when closing a contributor survey section. Use \"$1\" to denote user comments and signature. On the English Wikipedia, this is {{Template:collapse top}}. Other wikis may have an equivalent template. This should go hand in hand with \"{{int:deputy.setting.wiki.cci.collapseBottom.name}}\", as they are used as a pair.",
"deputy.setting.wiki.cci.collapseBottom.name": "Collapsible wikitext (bottom)",
"deputy.setting.wiki.cci.collapseBottom.description": "Placed at the end of a section when closing a contributor survey section. On the English Wikipedia, this is {{Template:collapse bottom}}. Other wikis may have an equivalent template.",
"deputy.setting.wiki.cci.earwigRoot.name": "Earwig's Copyvio Detector root URL",
"deputy.setting.wiki.cci.earwigRoot.description": "The URL to an instance of Earwig's Copyvio Detector that can handle this wiki. The official copyvio detector (copyvios.toolforge.org) can only handle Wikimedia wikis — you may change this behavior by specifying a custom instance that can process this wiki here.",
"deputy.setting.wiki.cci.resortRows.name": "Resort rows",
"deputy.setting.wiki.cci.resortRows.description": "Resort rows when saving the page. This is useful for cases where rows are added out of order, or when rows are added in a different order than they should be displayed.",
"deputy.setting.wiki.ante": "ANTE",
"deputy.setting.wiki.ante.enabled.name": "Enable the Attribution Notice Template Editor",
"deputy.setting.wiki.ante.enabled.description": "Enables ANTE for all users. ANTE is currently the least-optimized module for localization, and may not work for all wikis.",
"deputy.setting.wiki.ia": "IA",
"deputy.setting.wiki.ia.enabled.name": "Enable the Infringement Assistant",
"deputy.setting.wiki.ia.enabled.description": "Enables IA for all users. IA allows users to easily and graphically report pages with suspected or complicated copyright infringements.",
"deputy.setting.wiki.ia.rootPage.name": "Root page",
"deputy.setting.wiki.ia.rootPage.description": "The root page for Infringement Assistant. This should be the copyright problems noticeboard for this specific wiki. IA will only show quick response links for the root page and its subpages.",
"deputy.setting.wiki.ia.subpageFormat.name": "Subpage format",
"deputy.setting.wiki.ia.subpageFormat.description": "The format to use for subpages of the root page. This is a moment.js format string.",
"deputy.setting.wiki.ia.preload.name": "Preload",
"deputy.setting.wiki.ia.preload.description": "Defines the page content to preload the page with if a given subpage does not exist yet. This should be an existing page on-wiki. Leave blank to avoid using a preload entirely.",
"deputy.setting.wiki.ia.allowPresumptive.name": "Allow presumptive deletions",
"deputy.setting.wiki.ia.allowPresumptive.description": "Allows users to file listings for presumptive deletions. Note that the CCI setting \"Root page\" must be set for this to work, even if the \"CCI\" module is disabled entirely.",
"deputy.setting.wiki.ia.listingWikitext.name": "Listing wikitext",
"deputy.setting.wiki.ia.listingWikitext.description": "Defines the wikitext that will be used when adding listings to a noticeboard page. You may use \"$1\" to denote the page being reported, and \"$2\" for user comments (which shouldn't contain the signature).",
"deputy.setting.wiki.ia.listingWikitextMatch.name": "Regular expression for listings",
"deputy.setting.wiki.ia.listingWikitextMatch.description": "A regular expression that will be used to parse and detect listings on a given noticeboard page. Since its usage is rather technical, this value should be edited by someone with technical knowledge of regular expressions. This regular expression must provide three captured groups: group \"$1\" will catch any bullet point, space, or prefix, \"$2\" will catch the page title ONLY if the given page matches \"{{int:deputy.setting.wiki.ia.listingWikitext.name}}\" or \"{{int:deputy.setting.wiki.ia.batchListingWikitext.name}}\", and \"$3\" will catch the page title ONLY IF the page wasn't caught in \"$2\" (such as in cases where there is only a bare link to the page).",
"deputy.setting.wiki.ia.batchListingWikitext.name": "Batch listing wikitext",
"deputy.setting.wiki.ia.batchListingWikitext.description": "Defines the wikitext that will be used when adding batch listings to a noticeboard page. You may use \"$1\" to denote the page being reported, and \"$2\" for the list of pages (as determined by \"{{int:deputy.setting.wiki.ia.batchListingPageWikitext.name}}\") and \"$3\" for user comments (which doesn't contain the signature).",
"deputy.setting.wiki.ia.batchListingPageWikitext.name": "Batch listing page wikitext",
"deputy.setting.wiki.ia.batchListingPageWikitext.description": "Wikitext to use for every row of text in \"{{int:deputy.setting.wiki.ia.batchListingWikitext.name}}\". No line breaks are automatically added; these must be added into this string.",
"deputy.setting.wiki.ia.hideTemplate.name": "Content hiding wikitext (top)",
"deputy.setting.wiki.ia.hideTemplate.description": "Wikitext to hide offending content with. On the English Wikipedia, this is a usage of {{Template:copyvio}}. Other wikis may have an equivalent template. This should go hand in hand with \"{{int:deputy.setting.wiki.ia.hideTemplateBottom.name}}\", as they are used as a pair.",
"deputy.setting.wiki.ia.hideTemplateBottom.name": "Content hiding wikitext (bottom)",
"deputy.setting.wiki.ia.hideTemplateBottom.description": "Placed at the end of hidden content to hide only part of a page. On the English Wikipedia, this is {{Template:copyvio/bottom}}. Other wikis may have an equivalent template.",
"deputy.setting.wiki.ia.entirePageAppendBottom.name": "Append content hiding wikitext (bottom) when hiding an entire page",
"deputy.setting.wiki.ia.entirePageAppendBottom.description": "If enabled, the content hiding wikitext (bottom) will be appended to the end of the page when hiding the entire page. This avoids the \"missing end tag\" lint error, if the template is properly formatted.",
"deputy.setting.wiki.ia.responses.name": "Responses",
"deputy.setting.wiki.ia.responses.description": "Quick responses for copyright problems listings. Used by clerks to resolve specific listings or provide more information about the progress of a given listing."
};
 
/**
* Handles resource fetching operations.
*/
class DeputyResources {
/**
* Loads a resource from the provided resource root.
*
* @param path A path relative to the resource root.
* @return A Promise that resolves to the resource's content as a UTF-8 string.
*/
static loadResource(path) {
return __awaiter(this, void 0, void 0, function* () {
switch (this.root.type) {
case 'url': {
const headers = new Headers();
headers.set('Origin', window.___location.origin);
return fetch((new URL(path, this.root.url)).href, {
method: 'GET',
headers
}).then((r) => r.text());
}
case 'wiki': {
this.assertApi();
return getPageContent(this.root.prefix.replace(/\/$/, '') + '/' + path, {}, this.api);
}
}
});
}
/**
* Ensures that `this.api` is a valid ForeignApi.
*/
static assertApi() {
if (this.root.type !== 'wiki') {
return;
}
if (!this.api) {
this.api = new mw.ForeignApi(this.root.wiki.toString(), {
// Force anonymous mode. Deputy doesn't need user data anyway,
// so this should be fine.
anonymous: true
});
}
}
}
/**
* The root of all Deputy resources. This should serve static data that Deputy will
* use to load resources such as language files.
*/
DeputyResources.root = {
type: 'url',
url: new URL('https://tools-static.wmflabs.org/deputy/')
};
 
var _a;
const USER_LOCALE = (_a = window.deputyLang) !== null && _a !== void 0 ? _a : mw.config.get('wgUserLanguage');
 
/**
* Handles internationalization and localization for Deputy and sub-modules.
*/
class DeputyLanguage {
/**
* Loads the language for this Deputy interface.
*
* @param module The module to load a language pack for.
* @param fallback A fallback language pack to load. Since this is an actual
* `Record`, this relies on the language being bundled with the userscript. This ensures
* that a language pack is always available, even if a language file could not be loaded.
*/
static load(module, fallback) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const lang = (_a = window.deputyLang) !== null && _a !== void 0 ? _a : 'en';
// The loaded language resource file. Forced to `null` if using English, since English
// is our fallback language.
const langResource = lang === 'en' ? null :
yield DeputyResources.loadResource(`i18n/${module}/${lang}.json`)
.catch(() => {
// Could not find requested language file.
return null;
});
if (!langResource) {
// Fall back.
for (const key in fallback) {
mw.messages.set(key, fallback[key]);
}
return;
}
try {
const langData = JSON.parse(langResource);
for (const key in langData) {
mw.messages.set(key, langData[key]);
}
}
catch (e) {
error(e);
mw.notify(
// No languages to fall back on. Do not translate this string.
'Deputy: Requested language page is not a valid JSON file.', { type: 'error' });
// Fall back.
for (const key in fallback) {
mw.messages.set(key, fallback[key]);
}
}
if (lang !== mw.config.get('wgUserLanguage')) {
yield DeputyLanguage.loadSecondary();
}
});
}
/**
* Loads a specific moment.js locale. It's possible for nothing to be loaded (e.g. if the
* locale is not supported by moment.js), in which case nothing happens and English is
* likely used.
*
* @param locale The locale to load. `window.deputyLang` by default.
*/
static loadMomentLocale(locale = USER_LOCALE) {
return __awaiter(this, void 0, void 0, function* () {
if (locale === 'en') {
// Always loaded.
return;
}
if (mw.loader.getState('moment') !== 'ready') {
// moment.js is not yet loaded.
warn('Deputy tried loading moment.js locales but moment.js is not yet ready.');
return;
}
if (window.moment.locales().indexOf(locale) !== -1) {
// Already loaded.
return;
}
yield mw.loader.using('moment')
.then(() => true, () => null);
yield mw.loader.getScript(new URL(`resources/lib/moment/locale/${locale}.js`, new URL(mw.util.wikiScript('index'), window.___location.href)).href).then(() => true, () => null);
});
}
/**
* There are times when the user interface language do not match the wiki content
* language. Since Deputy's edit summary and content strings are found in the
* i18n files, however, there are cases where the wrong language would be used.
*
* This solves this problem by manually overriding content-specific i18n keys with
* the correct language. By default, all keys that match `deputy.*.content.**` get
* overridden.
*
* There are no fallbacks for this. If it fails, the user interface language is
* used anyway. In the event that the user interface language is not English,
* this will cause awkward situations. Whether or not something should be done to
* catch this specific edge case will depend on how frequent it happens.
*
* @param locale
* @param match
*/
static loadSecondary(locale = mw.config.get('wgContentLanguage'), match = /^deputy\.(?:[^.]+)?\.content\./g) {
return __awaiter(this, void 0, void 0, function* () {
// The loaded language resource file. Forced to `null` if using English, since English
// is our fallback language.
const langResource = locale === 'en' ? null :
yield DeputyResources.loadResource(`i18n/${module}/${locale}.json`)
.catch(() => {
// Could not find requested language file.
return null;
});
if (!langResource) {
return;
}
try {
const langData = JSON.parse(langResource);
for (const key in langData) {
if (cloneRegex$1(match).test(key)) {
mw.messages.set(key, langData[key]);
}
}
}
catch (e) {
// Silent failure.
error('Deputy: Requested language page is not a valid JSON file.', e);
}
});
}
}
 
/**
* Get the nodes from a JQuery object and wraps it in an element.
*
* @param element The element to add the children into
* @param $j The JQuery object
* @return The original element, now with children
*/
function unwrapJQ(element = h_1("span", null), $j) {
$j.each((i, e) => element.append(e));
return element;
}
 
let InternalConfigurationGroupTabPanel;
/**
* Initializes the process element.
*/
function initConfigurationGroupTabPanel() {
var _a;
InternalConfigurationGroupTabPanel = (_a = class ConfigurationGroupTabPanel extends OO.ui.TabPanelLayout {
/**
* @return The {@Link Setting}s for this group.
*/
get settings() {
return this.config.config.all[this.config.group];
}
/**
*/
constructor() {
super('configurationGroupPage_About');
this.$element.append(h_1("div", null,
h_1("div", { class: "deputy-about" },
h_1("div", { style: "flex: 0" },
h_1("img", { src: ConfigurationGroupTabPanel.logoUrl, alt: "Deputy logo" })),
h_1("div", { style: "flex: 1" },
h_1("div", null,
h_1("div", null, mw.msg('deputy.name')),
h_1("div", null, mw.msg('deputy.about.version', version, gitAbbrevHash))),
h_1("div", null, mw.msg('deputy.description')))),
h_1("div", null,
h_1("a", { href: "https://w.wiki/7NWR", target: "_blank" }, unwrapWidget(new OO.ui.ButtonWidget({
label: mw.msg('deputy.about.homepage'),
flags: ['progressive']
}))),
h_1("a", { href: "https://github.com/ChlodAlejandro/deputy", target: "_blank" }, unwrapWidget(new OO.ui.ButtonWidget({
label: mw.msg('deputy.about.openSource'),
flags: ['progressive']
}))),
h_1("a", { href: "https://w.wiki/7NWS", target: "_blank" }, unwrapWidget(new OO.ui.ButtonWidget({
label: mw.msg('deputy.about.contact'),
flags: ['progressive']
})))),
unwrapJQ(h_1("p", null), mw.message('deputy.about.credit').parseDom()),
unwrapJQ(h_1("p", null), mw.message('deputy.about.license', 'https://www.apache.org/licenses/LICENSE-2.0', 'https://github.com/ChlodAlejandro/deputy').parseDom()),
unwrapJQ(h_1("p", null), mw.message('deputy.about.thirdParty', 'https://github.com/ChlodAlejandro/deputy#licensing').parseDom()),
unwrapJQ(h_1("p", { style: { fontSize: '0.9em', color: 'darkgray' } }), mw.message('deputy.about.buildInfo', gitVersion, gitBranch, new Date(gitDate).toLocaleString()).parseDom()),
unwrapJQ(h_1("p", { style: { fontSize: '0.9em', color: 'darkgray' } }), mw.message('deputy.about.footer').parseDom())));
}
/**
* Sets up the tab item
*/
setupTabItem() {
this.tabItem.setLabel(mw.msg('deputy.about'));
return this;
}
},
_a.logoUrl = 'https://upload.wikimedia.org/wikipedia/commons/2/2b/Deputy_logo.svg',
_a);
}
/**
* Creates a new ConfigurationGroupTabPanel.
*
* @return A ConfigurationGroupTabPanel object
*/
function ConfigurationAboutTabPanel () {
if (!InternalConfigurationGroupTabPanel) {
initConfigurationGroupTabPanel();
}
return new InternalConfigurationGroupTabPanel();
}
 
let InternalConfigurationDialog;
/**
* Initializes the process element.
*/
function initConfigurationDialog() {
var _a;
InternalConfigurationDialog = (_a = class ConfigurationDialog extends OO.ui.ProcessDialog {
/**
* @param data
*/
constructor(data) {
super();
this.config = data.config;
}
/**
* @return The body height of this dialog.
*/
getBodyHeight() {
return 900;
}
/**
* Initializes the dialog.
*/
initialize() {
super.initialize();
this.layout = new OO.ui.IndexLayout();
this.layout.addTabPanels(this.generateGroupLayouts());
if (this.config instanceof UserConfiguration) {
this.layout.addTabPanels([ConfigurationAboutTabPanel()]);
}
this.$body.append(this.layout.$element);
return this;
}
/**
* Generate TabPanelLayouts for each configuration group.
*
* @return An array of TabPanelLayouts
*/
generateGroupLayouts() {
return Object.keys(this.config.all).map((group) => ConfigurationGroupTabPanel({
$overlay: this.$overlay,
config: this.config,
group
}));
}
/**
* @param action
* @return An OOUI Process.
*/
getActionProcess(action) {
const process = super.getActionProcess();
if (action === 'save') {
process.next(this.config.save());
process.next(() => {
var _a, _b;
mw.notify(mw.msg('deputy.settings.saved'), {
type: 'success'
});
if (this.config.type === 'user') {
// Override local Deputy option, just in case the user wishes to
// change the configuration again.
mw.user.options.set(UserConfiguration.optionKey, this.config.serialize());
if ((_a = window.deputy) === null || _a === void 0 ? void 0 : _a.comms) {
window.deputy.comms.send({
type: 'userConfigUpdate',
config: this.config.serialize()
});
}
}
else if (this.config.type === 'wiki') {
// We know it is a WikiConfiguration, the instanceof check here
// is just for type safety.
if ((_b = window.deputy) === null || _b === void 0 ? void 0 : _b.comms) {
window.deputy.comms.send({
type: 'wikiConfigUpdate',
config: {
title: this.config.sourcePage.getPrefixedText(),
editable: this.config.editable,
wt: this.config.serialize()
}
});
}
// Reload the page.
window.___location.reload();
}
});
}
process.next(() => {
this.close();
});
return process;
}
},
_a.static = Object.assign(Object.assign({}, OO.ui.ProcessDialog.static), { name: 'configurationDialog', title: mw.msg('deputy.settings.dialog.title'), size: 'large', actions: [
{
flags: ['safe', 'close'],
icon: 'close',
label: mw.msg('deputy.ante.close'),
title: mw.msg('deputy.ante.close'),
invisibleLabel: true,
action: 'close'
},
{
action: 'save',
label: mw.msg('deputy.save'),
flags: ['progressive', 'primary']
}
] }),
_a);
}
/**
* Creates a new ConfigurationDialog.
*
* @param data
* @return A ConfigurationDialog object
*/
function ConfigurationDialogBuilder(data) {
if (!InternalConfigurationDialog) {
initConfigurationDialog();
}
return new InternalConfigurationDialog(data);
}
let attached = false;
/**
* Spawns a new configuration dialog.
*
* @param config
*/
function spawnConfigurationDialog(config) {
mw.loader.using([
'oojs-ui-core', 'oojs-ui-windows', 'oojs-ui-widgets', 'mediawiki.widgets'
], () => {
const dialog = ConfigurationDialogBuilder({ config });
openWindow(dialog);
});
}
/**
* Attaches the "Deputy preferences" portlet link in the toolbox. Ensures that it doesn't
* get attached twice.
*/
function attachConfigurationDialogPortletLink() {
return __awaiter(this, void 0, void 0, function* () {
if (document.querySelector('#p-deputy-config') || attached) {
return;
}
attached = true;
mw.util.addCSS(deputySettingsStyles);
yield DeputyLanguage.load('settings', deputySettingsEnglish);
mw.util.addPortletLink('p-tb', '#', mw.msg('deputy.settings.portlet'), 'deputy-config', mw.msg('deputy.settings.portlet.tooltip')).addEventListener('click', () => {
// Load a fresh version of the configuration - this way we can make
// modifications live to the configuration without actually affecting
// tool usage.
spawnConfigurationDialog(UserConfiguration.load());
});
});
}
 
let InternalDeputyMessageWidget;
/**
* Initializes the process element.
*/
function initDeputyMessageWidget() {
InternalDeputyMessageWidget = class DeputyMessageWidget extends OO.ui.MessageWidget {
/**
* @param config Configuration to be passed to the element.
*/
constructor(config) {
var _a;
super(config);
this.$element.addClass('dp-messageWidget');
const elLabel = this.$label[0];
if (!config.label) {
if (config.title) {
elLabel.appendChild(h_1("b", { style: { display: 'block' } }, config.title));
}
if (config.message) {
elLabel.appendChild(h_1("p", { class: "dp-messageWidget-message" }, config.message));
}
}
if (config.actions || config.closable) {
const actionContainer = h_1("div", { class: "dp-messageWidget-actions" });
for (const action of ((_a = config.actions) !== null && _a !== void 0 ? _a : [])) {
if (action instanceof OO.ui.Element) {
actionContainer.appendChild(unwrapWidget(action));
}
else {
actionContainer.appendChild(action);
}
}
if (config.closable) {
const closeButton = new OO.ui.ButtonWidget({
label: mw.msg('deputy.dismiss')
});
closeButton.on('click', () => {
removeElement(unwrapWidget(this));
this.emit('close');
});
actionContainer.appendChild(unwrapWidget(closeButton));
}
elLabel.appendChild(actionContainer);
}
}
};
}
/**
* Creates a new DeputyMessageWidget. This is an extension of the default
* OOUI MessageWidget. It includes support for a title, a message, and button
* actions.
*
* @param config Configuration to be passed to the element.
* @return A DeputyMessageWidget object
*/
function DeputyMessageWidget (config) {
if (!InternalDeputyMessageWidget) {
initDeputyMessageWidget();
}
return new InternalDeputyMessageWidget(config);
}
 
/**
* @param config The current configuration (actively loaded, not the one being viewed)
* @return An HTML element consisting of an OOUI MessageWidget
*/
function WikiConfigurationEditIntro(config) {
const current = config.onConfigurationPage();
let buttons;
if (current) {
const editCurrent = new OO.ui.ButtonWidget({
flags: ['progressive', 'primary'],
label: mw.msg('deputy.settings.wikiEditIntro.edit.current'),
disabled: !mw.config.get('wgIsProbablyEditable'),
title: mw.config.get('wgIsProbablyEditable') ?
undefined : mw.msg('deputy.settings.wikiEditIntro.edit.protected')
});
editCurrent.on('click', () => {
spawnConfigurationDialog(config);
});
buttons = [editCurrent];
}
else {
const editCurrent = new OO.ui.ButtonWidget({
flags: ['progressive', 'primary'],
label: mw.msg('deputy.settings.wikiEditIntro.edit.otherCurrent'),
disabled: !config.editable,
title: config.editable ?
undefined : mw.msg('deputy.settings.wikiEditIntro.edit.protected')
});
editCurrent.on('click', () => __awaiter(this, void 0, void 0, function* () {
spawnConfigurationDialog(config);
}));
const editOther = new OO.ui.ButtonWidget({
flags: ['progressive'],
label: mw.msg('deputy.settings.wikiEditIntro.edit.other'),
disabled: !mw.config.get('wgIsProbablyEditable'),
title: mw.config.get('wgIsProbablyEditable') ?
undefined : mw.msg('deputy.settings.wikiEditIntro.edit.protected')
});
editOther.on('click', () => __awaiter(this, void 0, void 0, function* () {
spawnConfigurationDialog(yield config.static.load(normalizeTitle()));
}));
buttons = [editCurrent, editOther];
}
const messageBox = DeputyMessageWidget({
classes: [
'deputy', 'dp-mb'
],
type: 'notice',
title: mw.msg('deputy.settings.wikiEditIntro.title'),
message: current ?
mw.msg('deputy.settings.wikiEditIntro.current') :
unwrapJQ(h_1("span", null), mw.message('deputy.settings.wikiEditIntro.other', config.sourcePage.getPrefixedText()).parseDom()),
actions: buttons
});
const box = unwrapWidget(messageBox);
box.classList.add('deputy', 'deputy-wikiConfig-intro');
return box;
}
 
/* eslint-disable max-len */
/*
* Replacement polyfills for wikis that have no configured templates.
* Used in WikiConfiguration, to permit a seamless OOB experience.
*/
/** `{{collapse top}}` equivalent */
const collapseTop = `
{| class="mw-collapsible mw-collapsed" style="border:1px solid #C0C0C0;width:100%"
! <div style="background:#CCFFCC;">$1</div>
|-
|
`.trimStart();
/** `{{collapse bottom}}` equivalent */
const collapseBottom = `
|}`;
/** `* {{subst:article-cv|1=$1}} $2 ~~~~` equivalent */
const listingWikitext = '* [[$1]] $2 ~~~~';
/**
* Polyfill for the following:
* `; {{anchor|1={{delink|$1}}}} $1
* $2
* $3 ~~~~`
*/
const batchListingWikitext = `*; <span style="display: none;" id="$1"></span> $1
$2
$3`;
/**
* Inserted and chained as part of $2 in `batchListingWikitext`.
* Equivalent of `* {{subst:article-cv|1=$1}}\n`. Newline is intentional.
*/
const batchListingPageWikitext = '* [[$1]]\n';
/**
* `{{subst:copyvio|url=$1|fullpage=$2}}` equivalent
*/
const copyvioTop = `<div style="padding: 8px; border: 4px solid #0298b1;">
<div style="font-size: 1.2rem"><b>{{int:deputy.ia.content.copyvio}}</b></div>
<div>{{int:deputy.ia.content.copyvio.help}}</div>
{{if:$1|<div>{{if:$presumptive|{{int:deputy.ia.content.copyvio.from.pd}} $1|{{int:deputy.ia.content.copyvio.from}} $1}}</div>}}
</div>
<!-- {{int:deputy.ia.content.copyvio.content}} -->
<div class="copyvio" style="display: none">`;
/**
* `{{subst:copyvio/bottom}}` equivalent.
*/
const copyvioBottom = `
</div>`;
 
/**
* @return A MessageWidget for reloading a page with an outdated configuration.
*/
function ConfigurationReloadBanner() {
const reloadButton = new OO.ui.ButtonWidget({
flags: ['progressive', 'primary'],
label: mw.msg('deputy.settings.wikiOutdated.reload')
});
const messageBox = DeputyMessageWidget({
classes: [
'deputy', 'dp-mb', 'dp-wikiConfigUpdateMessage'
],
type: 'notice',
title: mw.msg('deputy.settings.wikiOutdated'),
message: mw.msg('deputy.settings.wikiOutdated.help'),
actions: [reloadButton]
});
reloadButton.on('click', () => __awaiter(this, void 0, void 0, function* () {
window.___location.reload();
}));
const box = unwrapWidget(messageBox);
box.style.fontSize = 'calc(1em * 0.875)';
return box;
}
 
var WikiConfigurationLocations = [
'MediaWiki:Deputy-config.json',
// Prioritize interface protected page over Project namespace
'User:Chlod/Scripts/Deputy/configuration.json',
'Project:Deputy/configuration.json'
];
 
/**
* Automatically applies a change tag to edits made by the user if
* a change tag was provided in the configuration.
*
* @param config
* @return A spreadable Object containing the `tags` parameter for `action=edit`.
*/
function changeTag(config) {
return config.core.changeTag.get() ?
{ tags: config.core.changeTag.get() } :
{};
}
 
/**
* Wiki-wide configuration. This is applied to all users of the wiki, and has
* the potential to break things for EVERYONE if not set to proper values.
*
* As much as possible, the correct configuration ___location should be protected
* to avoid vandalism or bad-faith changes.
*
* This configuration works if specific settings are set. In other words, some
* features of Deputy are disabled unless Deputy has been configured. This is
* to avoid messing with existing on-wiki processes.
*/
class WikiConfiguration extends ConfigurationBase {
/**
* Loads the configuration from a set of possible sources.
*
* @param sourcePage The specific page to load from
* @return A WikiConfiguration object
*/
static load(sourcePage) {
return __awaiter(this, void 0, void 0, function* () {
if (sourcePage) {
// Explicit source given. Do not load from local cache.
return this.loadFromWiki(sourcePage);
}
else {
return this.loadFromLocal();
}
});
}
/**
* Loads the wiki configuration from localStorage and/or MediaWiki
* settings. This allows for faster loads at the expense of a (small)
* chance of outdated configuration.
*
* The localStorage layer allows fast browser-based caching. If a user
* is logging in again on another device, the user configuration
* will automatically be sent to the client, lessening turnaround time.
* If all else fails, the configuration will be loaded from the wiki.
*
* @return A WikiConfiguration object.
*/
static loadFromLocal() {
return __awaiter(this, void 0, void 0, function* () {
let configInfo;
// If `mw.storage.get` returns `false` or `null`, it'll be thrown up.
let rawConfigInfo = mw.storage.get(WikiConfiguration.optionKey);
// Try to grab it from user options, if it exists.
if (!rawConfigInfo) {
rawConfigInfo = mw.user.options.get(WikiConfiguration.optionKey);
}
if (typeof rawConfigInfo === 'string') {
try {
configInfo = JSON.parse(rawConfigInfo);
}
catch (e) {
// Bad local! Switch to non-local.
error('Failed to get Deputy wiki configuration', e);
return this.loadFromWiki();
}
}
else {
log('No locally-cached Deputy configuration, pulling from wiki.');
return this.loadFromWiki();
}
if (configInfo) {
return new WikiConfiguration(new mw.Title(configInfo.title.title, configInfo.title.namespace), JSON.parse(configInfo.wt), configInfo.editable);
}
else {
return this.loadFromWiki();
}
});
}
/**
* Loads the configuration from the current wiki.
*
* @param sourcePage The specific page to load from
* @return A WikiConfiguration object
*/
static loadFromWiki(sourcePage) {
return __awaiter(this, void 0, void 0, function* () {
const configPage = sourcePage ? Object.assign({ title: sourcePage }, yield (() => __awaiter(this, void 0, void 0, function* () {
const content = yield getPageContent(sourcePage, {
prop: 'revisions|info',
intestactions: 'edit',
fallbacktext: '{}'
});
return {
wt: content,
editable: content.page.actions.edit
};
}))()) : yield this.loadConfigurationWikitext();
try {
// Attempt save of configuration to local options (if not explicitly loaded)
if (sourcePage == null) {
mw.storage.set(WikiConfiguration.optionKey, JSON.stringify(configPage));
}
return new WikiConfiguration(configPage.title, JSON.parse(configPage.wt), configPage.editable);
}
catch (e) {
error(e, configPage);
mw.hook('deputy.i18nDone').add(function notifyConfigFailure() {
mw.notify(mw.msg('deputy.loadError.wikiConfig'), {
type: 'error'
});
mw.hook('deputy.i18nDone').remove(notifyConfigFailure);
});
return null;
}
});
}
/**
* Loads the wiki-wide configuration from a set of predefined locations.
* See {@link WikiConfiguration#configLocations} for a full list.
*
* @return The string text of the raw configuration, or `null` if a configuration was not found.
*/
static loadConfigurationWikitext() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield MwApi.action.get({
action: 'query',
prop: 'revisions|info',
rvprop: 'content',
rvslots: 'main',
rvlimit: 1,
intestactions: 'edit',
redirects: true,
titles: WikiConfiguration.configLocations.join('|')
});
const redirects = toRedirectsObject(response.query.redirects, response.query.normalized);
for (const page of WikiConfiguration.configLocations) {
const title = normalizeTitle(redirects[page] || page).getPrefixedText();
const pageInfo = response.query.pages.find((p) => p.title === title);
if (!pageInfo.missing) {
return {
title: normalizeTitle(pageInfo.title),
wt: pageInfo.revisions[0].slots.main.content,
editable: pageInfo.actions.edit
};
}
}
return null;
});
}
/**
* Check if the current page being viewed is a valid configuration page.
*
* @param page
* @return `true` if the current page is a valid configuration page.
*/
static isConfigurationPage(page) {
if (page == null) {
page = new mw.Title(mw.config.get('wgPageName'));
}
return this.configLocations.some((v) => equalTitle(page, normalizeTitle(v)));
}
/**
* @param sourcePage
* @param serializedData
* @param editable Whether the configuration is editable by the current user or not.
*/
constructor(sourcePage, serializedData, editable) {
var _a;
super();
this.sourcePage = sourcePage;
this.serializedData = serializedData;
this.editable = editable;
// Used to avoid circular dependencies.
this.static = WikiConfiguration;
this.core = {
/**
* Numerical code that identifies this config version. Increments for every breaking
* configuration file change.
*/
configVersion: new Setting({
defaultValue: WikiConfiguration.configVersion,
displayOptions: { hidden: true },
alwaysSave: true
}),
lastEdited: new Setting({
defaultValue: 0,
displayOptions: { hidden: true },
alwaysSave: true
}),
dispatchRoot: new Setting({
serialize: (v) => v.href,
deserialize: (v) => new URL(v),
defaultValue: new URL('https://deputy.toolforge.org/'),
displayOptions: { type: 'text' },
alwaysSave: true
}),
changeTag: new Setting({
defaultValue: null,
displayOptions: { type: 'text' }
})
};
this.cci = {
enabled: new Setting({
defaultValue: false,
displayOptions: { type: 'checkbox' }
}),
rootPage: new Setting({
serialize: (v) => v === null || v === void 0 ? void 0 : v.getPrefixedText(),
deserialize: (v) => new mw.Title(v),
defaultValue: null,
displayOptions: { type: 'page' }
}),
headingMatch: new Setting({
defaultValue: '(Page|Article|Local file|File)s? \\d+ (to|through) \\d+',
displayOptions: { type: 'text' }
}),
collapseTop: new Setting({
defaultValue: collapseTop,
displayOptions: { type: 'code' }
}),
collapseBottom: new Setting({
defaultValue: collapseBottom,
displayOptions: { type: 'code' }
}),
earwigRoot: new Setting({
serialize: (v) => v.href,
deserialize: (v) => new URL(v),
defaultValue: new URL('https://copyvios.toolforge.org/'),
displayOptions: { type: 'text' },
alwaysSave: true
}),
resortRows: new Setting({
defaultValue: true,
displayOptions: { type: 'checkbox' }
})
};
this.ante = {
enabled: new Setting({
defaultValue: false,
displayOptions: { type: 'checkbox' }
})
};
this.ia = {
enabled: new Setting({
defaultValue: false,
displayOptions: { type: 'checkbox' }
}),
rootPage: new Setting({
serialize: (v) => v === null || v === void 0 ? void 0 : v.getPrefixedText(),
deserialize: (v) => new mw.Title(v),
defaultValue: null,
displayOptions: { type: 'page' }
}),
subpageFormat: new Setting({
defaultValue: 'YYYY MMMM D',
displayOptions: { type: 'text' }
}),
preload: new Setting({
serialize: (v) => { var _a, _b; return ((_b = (_a = v === null || v === void 0 ? void 0 : v.trim()) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 0 ? null : v.trim(); },
defaultValue: null,
displayOptions: { type: 'page' }
}),
allowPresumptive: new Setting({
defaultValue: true,
displayOptions: { type: 'checkbox' }
}),
listingWikitext: new Setting({
defaultValue: listingWikitext,
displayOptions: { type: 'code' }
}),
/**
* $1 - Title of the batch
* $2 - List of pages (newlines should be added in batchListingPageWikitext).
* $3 - User comment
*/
batchListingWikitext: new Setting({
defaultValue: batchListingWikitext,
displayOptions: { type: 'code' }
}),
/**
* $1 - Page to include
*/
batchListingPageWikitext: new Setting({
defaultValue: batchListingPageWikitext,
displayOptions: { type: 'code' }
}),
/**
* @see {@link CopyrightProblemsListing#articleCvRegex}
*
* This should match both normal and batch listings.
*/
listingWikitextMatch: new Setting({
defaultValue: '(\\*\\s*)?\\[\\[([^\\]]+)\\]\\]',
displayOptions: { type: 'code' }
}),
hideTemplate: new Setting({
defaultValue: copyvioTop,
displayOptions: { type: 'code' }
}),
hideTemplateBottom: new Setting({
defaultValue: copyvioBottom,
displayOptions: { type: 'code' }
}),
entirePageAppendBottom: new Setting({
defaultValue: true,
displayOptions: { type: 'checkbox' }
}),
responses: new Setting(Object.assign(Object.assign({}, Setting.basicSerializers), { defaultValue: null, displayOptions: { type: 'unimplemented' } }))
};
this.type = 'wiki';
this.all = { core: this.core, cci: this.cci, ante: this.ante, ia: this.ia };
/**
* Set to true when this configuration is outdated based on latest data. Usually adds banners
* to UI interfaces saying a new version of the configuration is available, and that it should
* be used whenever possible.
*
* TODO: This doesn't do what the documentations says yet.
*/
this.outdated = false;
if (serializedData) {
this.deserialize(serializedData);
}
if ((_a = window.deputy) === null || _a === void 0 ? void 0 : _a.comms) {
// Communications is available. Register a listener.
window.deputy.comms.addEventListener('wikiConfigUpdate', (e) => {
this.update(Object.assign({}, e.data.config, {
title: normalizeTitle(e.data.config.title)
}));
});
}
}
/**
* Check for local updates, and update the local configuration as needed.
*
* @param sourceConfig A serialized version of the configuration based on a wiki
* page configuration load.
*/
update(sourceConfig) {
return __awaiter(this, void 0, void 0, function* () {
// Asynchronously load from the wiki.
let fromWiki;
if (sourceConfig) {
fromWiki = sourceConfig;
}
else {
// Asynchronously load from the wiki.
fromWiki = yield WikiConfiguration.loadConfigurationWikitext();
if (fromWiki == null) {
// No configuration found on the wiki.
return;
}
}
const liveWikiConfig = JSON.parse(fromWiki.wt);
// Attempt save if on-wiki config found and doesn't match local.
// Doesn't need to be from the same config page, since this usually means a new config
// page was made, and we need to switch to it.
if (this.core.lastEdited.get() < liveWikiConfig.core.lastEdited) {
if (liveWikiConfig.core.configVersion > WikiConfiguration.configVersion) {
// Don't update if the config version is higher than ours. We don't want
// to load in the config of a newer version, as it may break things.
// Deputy should load in the newer version of the script soon enough,
// and the config will be parsed by a version that supports it.
warn(`Expected wiki configuration version ${this.core.configVersion.get()}, but found ${liveWikiConfig.core.configVersion}. New configuration will not be loaded.`);
return;
}
else if (liveWikiConfig.core.configVersion < WikiConfiguration.configVersion) {
// Version change detected.
// Do nothing... for now.
// HINT: Update configuration
warn(`Expected wiki configuration version ${this.core.configVersion.get()}, but found ${liveWikiConfig.core.configVersion}. Proceeding anyway...`);
}
const onSuccess = () => {
var _a;
// Only mark outdated after saving, so we don't indirectly cause a save operation
// to cancel.
this.outdated = true;
// Attempt to add site notice.
if (document.querySelector('.dp-wikiConfigUpdateMessage') == null) {
(_a = document.getElementById('siteNotice')) === null || _a === void 0 ? void 0 : _a.insertAdjacentElement('afterend', ConfigurationReloadBanner());
}
};
// If updated from a source config (other Deputy tab), do not attempt to save
// to MediaWiki settings. This is most likely already saved by the original tab
// that sent the comms message.
if (!sourceConfig) {
// Use `liveWikiConfig`, since this contains the compressed version and is more
// bandwidth-friendly.
const rawConfigInfo = JSON.stringify({
title: fromWiki.title,
editable: fromWiki.editable,
wt: JSON.stringify(liveWikiConfig)
});
// Save to local storage.
mw.storage.set(WikiConfiguration.optionKey, rawConfigInfo);
// Save to user options (for faster first-load times).
yield MwApi.action.saveOption(WikiConfiguration.optionKey, rawConfigInfo).then(() => {
var _a;
if ((_a = window.deputy) === null || _a === void 0 ? void 0 : _a.comms) {
// Broadcast the update to other tabs.
window.deputy.comms.send({
type: 'wikiConfigUpdate',
config: {
title: fromWiki.title.getPrefixedText(),
editable: fromWiki.editable,
wt: liveWikiConfig
}
});
}
onSuccess();
}).catch(() => {
// silently fail
});
}
else {
onSuccess();
}
}
});
}
/**
* Saves the configuration on-wiki. Does not automatically generate overrides.
*/
save() {
return __awaiter(this, void 0, void 0, function* () {
// Update last edited number
this.core.lastEdited.set(Date.now());
yield MwApi.action.postWithEditToken(Object.assign(Object.assign({}, changeTag(yield window.deputy.getWikiConfig())), { action: 'edit', title: this.sourcePage.getPrefixedText(), text: JSON.stringify(this.serialize()) }));
});
}
/**
* Check if the current page being viewed is the active configuration page.
*
* @param page
* @return `true` if the current page is the active configuration page.
*/
onConfigurationPage(page) {
return equalTitle(page !== null && page !== void 0 ? page : mw.config.get('wgPageName'), this.sourcePage);
}
/**
* Actually displays the banner which allows an editor to modify the configuration.
*/
displayEditBanner() {
return __awaiter(this, void 0, void 0, function* () {
mw.loader.using(['oojs', 'oojs-ui'], () => {
if (document.getElementsByClassName('deputy-wikiConfig-intro').length > 0) {
return;
}
document.getElementById('mw-content-text').insertAdjacentElement('afterbegin', WikiConfigurationEditIntro(this));
});
});
}
/**
* Shows the configuration edit intro banner, if applicable on this page.
*
* @return void
*/
prepareEditBanners() {
return __awaiter(this, void 0, void 0, function* () {
if (['view', 'diff'].indexOf(mw.config.get('wgAction')) === -1) {
return;
}
if (document.getElementsByClassName('deputy-wikiConfig-intro').length > 0) {
return;
}
if (this.onConfigurationPage()) {
return this.displayEditBanner();
}
else if (WikiConfiguration.isConfigurationPage()) {
return this.displayEditBanner();
}
});
}
}
WikiConfiguration.configVersion = 2;
WikiConfiguration.optionKey = 'userjs-deputy-wiki';
WikiConfiguration.configLocations = WikiConfigurationLocations;
 
/**
* API communication class
*/
class Dispatch {
/**
* Creates a Deputy API instance.
*/
constructor() { }
/**
* Logs the user out of the API.
*/
logout() {
return __awaiter(this, void 0, void 0, function* () {
// TODO: Make logout API request
yield window.deputy.storage.setKV('api-token', null);
});
}
/**
* Logs in the user. Optional: only used for getting data on deleted revisions.
*/
login() {
return __awaiter(this, void 0, void 0, function* () {
Dispatch.token = yield window.deputy.storage.getKV('api-token');
// TODO: If token, set token
// TODO: If no token, start OAuth flow and make login API request
throw new Error('Unimplemented method.');
});
}
/**
* Returns a fully-formed HTTP URL from a given endpoint. This uses the wiki's
* set Dispatch endpoint and a given target (such as `/v1/revisions`) to get
* the full URL.
*
* @param endpoint The endpoint to get
*/
getEndpoint(endpoint) {
return __awaiter(this, void 0, void 0, function* () {
return new URL(endpoint.replace(/^\/+/, ''), (yield WikiConfiguration.load()).core.dispatchRoot.get()
.href
.replace(/\/+$/, ''));
});
}
}
/**
* Singleton instance.
*/
Dispatch.i = new Dispatch();
 
/**
*
*/
class DispatchRevisions {
/**
*
*/
constructor() { }
/**
* Gets expanded revision data from the API. This returns a response similar to the
* `revisions` object provided by action=query, but also includes additional information
* relevant (such as the parsed (HTML) comment, diff size, etc.)
*
* @param revisions The revisions to get the data for
* @return An object of expanded revision data mapped by revision IDs
*/
get(revisions) {
return __awaiter(this, void 0, void 0, function* () {
return Requester.fetch(yield Dispatch.i.getEndpoint(`v1/revisions/${mw.config.get('wgWikiID')}`), {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Api-User-Agent': `Deputy/${version} (${window.___location.hostname})`
},
body: 'revisions=' + revisions.join('|')
})
.then((r) => r.json())
.then((j) => {
if (j.error) {
throw new Error(j.error.info);
}
return j;
})
.then((j) => j.revisions);
});
}
}
/**
* Singleton instance
*/
DispatchRevisions.i = new DispatchRevisions();
 
var ContributionSurveyRowStatus;
Line 1,670 ⟶ 4,281:
ContributionSurveyRowStatus[ContributionSurveyRowStatus["PresumptiveRemoval"] = 5] = "PresumptiveRemoval";
})(ContributionSurveyRowStatus || (ContributionSurveyRowStatus = {}));
 
/**
* Represents a contribution survey row. This is an abstraction of the row that can
Line 1,676 ⟶ 4,288:
*/
class ContributionSurveyRow {
/**
* Creates a new contribution survey row from MediaWiki parser output.
*
* @param casePage The case page of this row
* @param wikitext The wikitext of the row
*/
constructor(casePage, wikitext) {
this.data = new ContributionSurveyRowParser(wikitext).parse();
this.casePage = casePage;
this.wikitext = wikitext;
this.title = new mw.Title(this.data.page);
this.extras = this.data.extras;
this.comment = this.data.comments;
this.status = this.originalStatus = this.data.comments == null ?
ContributionSurveyRowStatus.Unfinished :
ContributionSurveyRow.identifyCommentStatus(this.data.comments);
if (ContributionSurveyRow.commentMatchRegex[this.status] != null) {
if (cloneRegex$1((ContributionSurveyRow.commentMatchRegex)[this.status], { pre: '^' }).test(this.comment)) {
this.statusIsolated = 'start';
}
else if (cloneRegex$1((ContributionSurveyRow.commentMatchRegex)[this.status], { post: '$' }).test(this.comment)) {
this.statusIsolated = 'end';
}
else {
this.statusIsolated = false;
}
}
}
/**
* Identifies a row's current status based on the comment's contents.
Line 1,729 ⟶ 4,313:
let dateReverseScore = 1;
let byteScore = 1;
let dateStreak = 0;
let dateReverseStreak = 0;
let byteStreak = 0;
for (const diff of diffs) {
if (last == null) {
Line 1,736 ⟶ 4,323:
const diffTimestamp = new Date(diff.timestamp).getTime();
const lastTimestamp = new Date(last.timestamp).getTime();
dateScore// =The (dateScoreuse +of (diffTimestampthe >OR lastTimestampoperator ?here 1has :a 0))specific / 2;purpose:
dateReverseScore// =* (dateReverseScoreOn +the (diffTimestampfirst <iteration, lastTimestampwe ?want 1all :streak 0))values /to 2;be 1
byteScore// =* (byteScoreOn +any (diff.diffsizeother <iteration, last.diffsizewe ?want 1it :to 0))increment /the streak by 1 if a 2;streak
// exists, or set it to 1 if a streak was broken.
dateStreak =
diffTimestamp > lastTimestamp ? dateStreak + 1 : 0;
dateReverseStreak =
diffTimestamp < lastTimestamp ? dateReverseStreak + 1 : 0;
byteStreak =
diff.diffsize <= last.diffsize ? byteStreak + 1 : 0;
dateScore = (dateScore + ((diffTimestamp > lastTimestamp ? 1 : 0) * (1 + dateStreak * 0.3))) / 2;
dateReverseScore = (dateReverseScore + ((diffTimestamp < lastTimestamp ? 1 : 0) * (1 + dateReverseStreak * 0.3))) / 2;
byteScore = (byteScore + ((diff.diffsize <= last.diffsize ? 1 : 0) * (1 + byteStreak * 0.3))) / 2;
last = diff;
}
}
// Multiply by weights to remove ties
dateScore *= 1.105;
dateReverseScore *= 1.05025;
switch (Math.max(dateScore, dateReverseScore, byteScore)) {
case byteScore:
Line 1,805 ⟶ 4,402:
return this.status !== ContributionSurveyRowStatus.Unfinished &&
this.diffs.size === 0;
}
/**
* Creates a new contribution survey row from MediaWiki parser output.
*
* @param casePage The case page of this row
* @param wikitext The wikitext of the row
*/
constructor(casePage, wikitext) {
this.data = new ContributionSurveyRowParser(wikitext).parse();
this.type = this.data.type;
this.casePage = casePage;
this.wikitext = wikitext;
this.title = new mw.Title(this.data.page);
this.extras = this.data.extras;
this.comment = this.data.comments;
this.status = this.originalStatus = this.data.comments == null ?
ContributionSurveyRowStatus.Unfinished :
ContributionSurveyRow.identifyCommentStatus(this.data.comments);
if (ContributionSurveyRow.commentMatchRegex[this.status] != null) {
if (cloneRegex$1((ContributionSurveyRow.commentMatchRegex)[this.status], { pre: '^' }).test(this.comment)) {
this.statusIsolated = 'start';
}
else if (cloneRegex$1((ContributionSurveyRow.commentMatchRegex)[this.status], { post: '$' }).test(this.comment)) {
this.statusIsolated = 'end';
}
else {
this.statusIsolated = false;
}
}
}
/**
Line 1,830 ⟶ 4,456:
}
if (toCache.length > 0) {
const expandedData = yield windowDispatchRevisions.deputyi.dispatch.getExpandedRevisionDataget(toCache);
for (const revisionID in expandedData) {
revisionData.set(+revisionID, new ContributionSurveyRevision(this, expandedData[revisionID]));
Line 1,853 ⟶ 4,479:
amenableparser: true
});
// Sort the rows (if rearranging is enabled)
const sortOrder = ContributionSurveyRow.guessSortOrder(revisionData.values());
if (window.deputy.wikiConfig.cci.resortRows.get()) {
// Sort from most bytes to least.
return this.diffs const sortOrder = new MapContributionSurveyRow.guessSortOrder([...revisionData.entriesvalues()].sort(ContributionSurveyRow.getSorterFunction(sortOrder, 'value')));
return this.diffs = new Map([...revisionData.entries()].sort(ContributionSurveyRow.getSorterFunction(sortOrder, 'value')));
}
else {
return this.diffs = new Map([...revisionData.entries()]);
}
});
}
Line 1,908 ⟶ 4,539:
}
catch (e) {
console.error(e, { element1, element2 });
// Caught for debug only. Rethrow.
throw e;
Line 1,991 ⟶ 4,622:
function nsId(namespace) {
return mw.config.get('wgNamespaceIds')[namespace.toLowerCase().replace(/ /g, '_')];
}
 
/**
* Evaluates any string using `mw.msg`. This handles internationalization of strings
* that are loaded outside the script or asynchronously.
*
* @param string The string to evaluate
* @param {...any} parameters Parameters to pass, if any
* @return A mw.Message
*/
function msgEval(string, ...parameters) {
// Named parameters
let named = {};
if (typeof parameters[0] === 'object') {
named = parameters.shift();
}
const m = new mw.Map();
for (const [from, to] of Object.entries(named)) {
string = string.replace(new RegExp(`\\$${from}`, 'g'), to);
}
m.set('msg', string);
return new mw.Message(m, 'msg', parameters);
}
 
/**
* Mixes values together into a string for the `class` attribute.
*
* @param {...any} classes
* @return string
*/
function classMix (...classes) {
const processedClasses = [];
for (const _class of classes) {
if (Array.isArray(_class)) {
processedClasses.push(..._class);
}
else {
processedClasses.push(_class);
}
}
return processedClasses.filter((v) => v != null && !!v).join(' ');
}
 
Line 2,006 ⟶ 4,678:
getRevisionDiffURL(_parentid, _revid);
let cv;
if (window.deputy &&
window.deputy.config.cci.showCvLink &&
window.deputy.wikiConfig.cci.earwigRoot) {
cv = new URL('', window.deputy.wikiConfig.cci.earwigRoot.get());
const selfUrl = new URL(window.___location.href);
Line 2,023 ⟶ 4,697:
return h_1("span", { class: "mw-changeslist-links" },
h_1("span", null,
h_1("a", { rel: "noopener", href: cur, title: mw.msg('deputy.session.revision.cur.tooltip'), target: "_blank" }, mw.msg('deputy.session.revision.cur'))),
h_1("span", null, (!_parentid && !missing) ?
mw.msg('deputy.session.revision.prev') :
h_1("a", { rel: "noopener", href: prev, title: mw.msg('deputy.session.revision.prev.tooltip'), target: "_blank" }, mw.msg('deputy.session.revision.prev'))),
!!window.deputy.config.cci.showCvLink &&
cv &&
Line 2,036 ⟶ 4,710:
*/
function NewPageIndicator() {
return h_1("abbr", { class: "newpage", title: mw.msg('deputy.session.revision.new.tooltip') }, mw.msg('deputy.session.revision.new'));
}
/**
Line 2,045 ⟶ 4,719:
function ChangesListTime({ timestamp }) {
const time = new Date(timestamp);
const formattedTime = time.toLocaleTimeString(window.deputyLangUSER_LOCALE, {
hourCycle: 'h24',
timeStyle: mw.user.options.get('date') === 'ISO 8601' ? 'long' : 'short'
Line 2,054 ⟶ 4,728:
* @param root0
* @param root0.revision
* @param root0.link
* @return HTML element
*/
function ChangesListDate({ revision, link }) {
var _a;
// `texthidden` would be indeterminate if the `{timestamp}` type was used
if (revision.texthidden) {
// Don't give out a link if the revision was deleted
link = false;
}
const time = new Date(revision.timestamp);
let now = window.moment(time);
if (window.deputy && window.deputy.config.cci.forceUtc.get()) {
now = now.utc();
}
const formattedTime = time.toLocaleTimeString(window.deputyLangUSER_LOCALE, {
hourCycle: 'h24',
timeStyle: mw.user.options.get('date') === 'ISO 8601' ? 'long' : 'short',
timeZone: ((_a = window.deputy) === null || _a === void 0 ? void 0 : _a.config.cci.forceUtc.get()) ? 'UTC' : undefined
});
const formattedDate = now.locale(window.deputyLangUSER_LOCALE).format({
dmy: 'D MMMM YYYY',
mdy: 'MMMM D, Y',
Line 2,074 ⟶ 4,755:
}[mw.user.options.get('date')]);
const comma = mw.msg('comma-separator');
return link !== false ?
h_1("a", { class: "mw-changeslist-date", href: getRevisionURL(revision.revid, revision.page.title) },
formattedTime,
comma,
formattedDate); :
h_1("span", { class: classMix('mw-changeslist-date', revision.texthidden && 'history-deleted') },
formattedTime,
comma,
formattedDate);
}
/**
* @param root0
* @param root0.userrevision
* @return HTML element
*/
function ChangesListUser({ userrevision }) {
const { user, userhidden } = revision;
if (userhidden) {
return h_1("span", { class: "history-user" },
h_1("span", { class: "history-deleted mw-userlink" }, mw.msg('deputy.revision.removed.user')));
}
const userPage = new mw.Title(user, nsId('user'));
const userTalkPage = new mw.Title(user, nsId('user_talk'));
Line 2,093 ⟶ 4,784:
h_1("span", { class: "mw-usertoollinks mw-changeslist-links" },
h_1("span", null,
h_1("a", { class: "mw-usertoollinks-talk", target: "_blank", rel: "noopener", href: mw.format(mw.config.get('wgArticlePath'), userTalkPage.getPrefixedDb()), title: userTalkPage.getPrefixedText() }, mw.msg('deputy.session.revision.talk'))),
" ",
h_1("span", null,
h_1("a", { class: "mw-usertoollinks-contribs", target: "_blank", rel: "noopener", href: mw.format(mw.config.get('wgArticlePath'), userContribsPage.getPrefixedDb()), title: userContribsPage.getPrefixedText() }, mw.msg('deputy.session.revision.contribs')))));
}
/**
Line 2,104 ⟶ 4,795:
*/
function ChangesListBytes({ size }) {
return h_1("span", { class: "history-size mw-diff-bytes", "data-mw-bytes": size }, mw.message('deputy.session.revision.bytes', size.toString()).text());
}
/**
Line 2,116 ⟶ 4,807:
'strong' :
'span');
return h_1(DiffTag, { class: `mw-plusminus-${!diffsize === 0 ? 'null' :
(diffsize > 0 ? 'pos' : 'neg')} mw-diff-bytes`, title: mw.message('deputy.session.revision.byteChange', size.toString()).text() }, mw.message(`deputy.${diffsize <== 0null ? 'negative' : 'positive'}Diff`, diffsize.toString()).text());
mw.msg('deputy.brokenDiff.explain') :
mw.message('deputy.revision.byteChange', size.toString()).text() }, diffsize == null ?
mw.msg('deputy.brokenDiff') :
// Messages that can be used here:
// * deputy.negativeDiff
// * deputy.positiveDiff
// * deputy.zeroDiff
mw.message(`deputy.${{
'-1': 'negative',
1: 'positive',
0: 'zero'
}[Math.sign(diffsize)]}Diff`, diffsize.toString()).text());
}
/**
* @param root0
* @param root0.page
* @param root0.page.title
* @param root0.page.ns
* @return HTML element
*/
function ChangesListPage({ page }) {
const pageTitle = new mw.Title(page.title, page.ns).getPrefixedText();
return h_1("a", { class: "mw-contributions-title", href: mw.util.getUrl(pageTitle), title: pageTitle }, pageTitle);
}
/**
Line 2,126 ⟶ 4,840:
function ChangesListTags({ tags }) {
return h_1("span", { class: "mw-tag-markers" },
h_1("a", { rel: "noopener", href: mw.format(mw.config.get('wgArticlePath'), 'Special:Tags'), title: "Special:Tags", target: "_blank" }, mw.message('deputy.session.revision.tags', tags.length.toString()).text()),
tags.map((v) => {
// eslint-disable-next-line mediawiki/msg-doc
const tagMessage = mw.message(`tag-${v}`).parseparseDom();
return [
return tagMessage !== '-' && h_1("span", { class: `mw-tag-marker mw-tag-marker-${v}`, dangerouslySetInnerHTML: tagMessage });
' ',
tagMessage.text() !== '-' && unwrapJQ(h_1("span", { class: `mw-tag-marker mw-tag-marker-${v}` }), tagMessage)
];
}));
}
 
/**
* Unwraps an element into its child elements. This entirely discards
* the parent element.
*
* @param el The element to unwrap.root0
* @returnparam The unwrapped elementroot0.revision
*/
function unwrapElement ChangesListMissingRow(el{ revision }) {
return Array.fromh_1(el.childNodes).map(v => v instanceof HTMLElement ? v"span", :null,
h_1(ChangesListLinks, { revid: revision.revid, parentid: revision.parentid, missing: true }),
(v instanceof Text ? v.textContent : undefined)).filter(v => v !== undefined);
' ',
h_1("i", { dangerouslySetInnerHTML: mw.message('deputy.session.revision.missing', revision.revid).parse() }));
}
 
/**
* @param root0
* Mixes values together into a string for the `class` attribute.
* @param root0.revision
* @param {root0...any} classesformat
* @return stringA changes list row.
*/
function classMix ChangesListRow(...classes{ revision, format }) {
constvar processedClasses_a, = []_b;
forif (const _class of classes!format) {
ifformat (Array.isArray(_class))= {'history';
processedClasses.push(..._class);
}
else {
processedClasses.push(_class);
}
}
returnlet processedClasses.filter((v)commentElement => v != null && !!v).join(' ');
if (revision.commenthidden) {
}
commentElement = h_1("span", { class: "history-deleted comment" }, mw.msg('deputy.revision.removed.comment'));
 
let InternalDeputyMessageWidget;
/**
* Initializes the process element.
*/
function initDeputyMessageWidget() {
InternalDeputyMessageWidget = class DeputyMessageWidget extends OO.ui.MessageWidget {
/**
* @param config Configuration to be passed to the element.
*/
constructor(config) {
var _a;
super(config);
this.$element.addClass('dp-messageWidget');
const elLabel = this.$label[0];
if (!config.label) {
if (config.title) {
elLabel.appendChild(h_1("b", { style: { display: 'block' } }, config.title));
}
if (config.message) {
elLabel.appendChild(h_1("p", { class: "dp-messageWidget-message" }, config.message));
}
}
if (config.actions || config.closable) {
const actionContainer = h_1("div", { class: "dp-messageWidget-actions" });
for (const action of ((_a = config.actions) !== null && _a !== void 0 ? _a : [])) {
if (action instanceof OO.ui.Element) {
actionContainer.appendChild(unwrapWidget(action));
}
else {
actionContainer.appendChild(action);
}
}
if (config.closable) {
const closeButton = new OO.ui.ButtonWidget({
label: mw.msg('deputy.dismiss')
});
closeButton.on('click', () => {
removeElement(unwrapWidget(this));
this.emit('close');
});
actionContainer.appendChild(unwrapWidget(closeButton));
}
elLabel.appendChild(actionContainer);
}
}
};
}
/**
* Creates a new DeputyMessageWidget. This is an extension of the default
* OOUI MessageWidget. It includes support for a title, a message, and button
* actions.
*
* @param config Configuration to be passed to the element.
* @return A DeputyMessageWidget object
*/
function DeputyMessageWidget (config) {
if (!InternalDeputyMessageWidget) {
initDeputyMessageWidget();
}
else if (revision.parsedcomment) {
return new InternalDeputyMessageWidget(config);
commentElement = h_1("span", { class: "comment comment--without-parentheses",
/** Stranger danger! Yes. */
dangerouslySetInnerHTML: revision.parsedcomment });
}
else if (revision.comment) {
const comment = revision.comment
// Insert Word-Joiner to avoid parsing "templates".
.replace(/{/g, '{\u2060')
.replace(/}/g, '\u2060}');
commentElement = unwrapJQ(h_1("span", { class: "comment comment--without-parentheses" }), msgEval(comment).parseDom());
}
return h_1("span", null,
h_1(ChangesListLinks, { revid: revision.revid, parentid: revision.parentid }),
" ",
!revision.parentid && h_1(NewPageIndicator, null),
h_1(ChangesListTime, { timestamp: revision.timestamp }),
h_1(ChangesListDate, { revision: revision }),
" ",
format === 'history' && h_1(ChangesListUser, { revision: revision }),
" ",
h_1("span", { class: "mw-changeslist-separator" }),
" ",
format === 'history' && h_1(ChangesListBytes, { size: revision.size }),
" ",
h_1(ChangesListDiff, { size: revision.size, diffsize: revision.diffsize }),
" ",
h_1("span", { class: "mw-changeslist-separator" }),
" ",
format === 'contribs' && h_1(ChangesListPage, { page: revision.page }),
" ",
commentElement,
" ",
((_b = (_a = revision.tags) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : -1) > 0 &&
h_1(ChangesListTags, { tags: revision.tags }));
}
 
Line 2,249 ⟶ 4,935:
*/
class DeputyContributionSurveyRevision extends EventTarget {
/**
* @return `true` the current revision has been checked by the user or `false` if not.
*/
get completed() {
var _a, _b;
return (_b = (_a = this.completedCheckbox) === null || _a === void 0 ? void 0 : _a.isSelected()) !== null && _b !== void 0 ? _b : false;
}
/**
* Set the value of the completed checkbox.
*
* @param value The new value
*/
set completed(value) {
var _a;
(_a = this.completedCheckbox) === null || _a === void 0 ? void 0 : _a.setSelected(value);
}
/**
* @return The hash used for autosave keys
*/
get autosaveHash() {
return `CASE--${this.uiRow.row.casePage.title.getPrefixedDb()}+PAGE--${this.uiRow.row.title.getPrefixedDb()}+REVISION--${this.revision.revid}`;
}
/**
* @param revision
Line 2,262 ⟶ 4,970:
* The diff view of the given revision. May also be "loading" text, or
* null if the diff view has not yet been set.
*
* @private
*/
Line 2,274 ⟶ 4,983:
}), 500);
}
}
/**
* @return `true` the current revision has been checked by the user or `false` if not.
*/
get completed() {
var _a, _b;
return (_b = (_a = this.completedCheckbox) === null || _a === void 0 ? void 0 : _a.isSelected()) !== null && _b !== void 0 ? _b : false;
}
/**
* Set the value of the completed checkbox.
*
* @param value The new value
*/
set completed(value) {
var _a;
(_a = this.completedCheckbox) === null || _a === void 0 ? void 0 : _a.setSelected(value);
}
/**
* @return The hash used for autosave keys
*/
get autosaveHash() {
return `CASE--${this.uiRow.row.casePage.title.getPrefixedDb()}+PAGE--${this.uiRow.row.title.getPrefixedDb()}+REVISION--${this.revision.revid}`;
}
/**
Line 2,385 ⟶ 5,072:
const handleDiffToggle = (active) => {
this.diffToggle.setIndicator(active ? 'up' : 'down');
if (!active && this.diff.classList.contains('dp-cs-rev-diff--errored')) {
// Remake this.diff.classList.toggle('dp-cs-rev-diff--hidden', paneltrue);
return;
}
if (this.diff.classList.contains('dp-cs-rev-diff--errored')) {
// Error occurred previously, remake diff panel
this.diff = swapElements(this.diff, h_1("div", { class: "dp-cs-rev-diff" }));
}
else if (loaded) {
this.diff.classList.toggle('dp-cs-rev-diff--hidden', !activefalse);
}
if (active && !loaded) {
Line 2,429 ⟶ 5,120:
}
// Delete all no-change rows (gray rows)
//if !(tr.querySelector('td.diff-markers with a markercontext')) = no change for row{
if (!tr.querySelector('td.diff-marker[data-marker]')) {
removeElement(tr);
}
Line 2,459 ⟶ 5,149:
}
});
}
/**
* Renders revision info. This is only called if the revision exists.
*/
renderRevisionInfo() {
var _a, _b;
const commentElement = h_1("span", { class: "comment comment--without-parentheses",
/** Stranger danger! Yes. */
dangerouslySetInnerHTML: this.revision.parsedcomment });
return h_1("span", null,
!this.revision.parentid && h_1(NewPageIndicator, null),
" ",
h_1(ChangesListTime, { timestamp: this.revision.timestamp }),
h_1(ChangesListDate, { revision: this.revision }),
" ",
window.deputy.config.cci.showUsername.get() && h_1(ChangesListUser, { user: this.revision.user }),
" ",
h_1("span", { class: "mw-changeslist-separator" }),
" ",
h_1(ChangesListBytes, { size: this.revision.size }),
" ",
h_1(ChangesListDiff, { size: this.revision.size, diffsize: this.revision.diffsize }),
" ",
h_1("span", { class: "mw-changeslist-separator" }),
" ",
commentElement,
" ",
((_b = (_a = this.revision.tags) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : -1) > 0 &&
h_1(ChangesListTags, { tags: this.revision.tags }));
}
/**
* Renders a placeholder for missing revisions.
*/
renderMissingRevisionInfo() {
return h_1("span", null,
' ',
h_1("i", { dangerouslySetInnerHTML: mw.message('deputy.session.revision.missing', this.revision.revid).parse() }));
}
/**
Line 2,509 ⟶ 5,162:
unwrapWidget(this.completedCheckbox),
unwrapWidget(this.diffToggle),
h_1(ChangesListLinks, { revid: this.revision.revid, parentid: this.revision.parentid, missing: this.revision.missing }),?
unwrapElement h_1(ChangesListMissingRow, { revision: this.revision.missing ?}) :
this.renderMissingRevisionInfoh_1()ChangesListRow, { revision: this.revision }),
this.renderRevisionInfo()),
this.diff);
}
Line 2,612 ⟶ 5,264:
}
catch (e) {
console.warn('Failed to parse user signature.', e);
}
if (!parsedComment) {
Line 2,643 ⟶ 5,295:
h_1("span", { class: "mw-usertoollinks mw-changeslist-links" },
h_1("span", null,
h_1("a", { class: "mw-usertoollinks-talk", target: "_blank", rel: "noopener", href: mw.util.getUrl(talkPage.getPrefixedDb()), title: talkPage.getPrefixedText() }, mw.msg('deputy.session.revision.talk'))),
h_1("span", null,
h_1("a", { class: "mw-usertoollinks-contribs", target: "_blank", rel: "noopener", href: mw.util.getUrl(contribsPage.getPrefixedDb()), title: contribsPage.getPrefixedText() }, mw.msg('deputy.session.revision.contribs')))))).outerHTML
];
if (this.timestamp) {
Line 2,651 ⟶ 5,303:
.toLocaleString('en-US', { dateStyle: 'long', timeStyle: 'short' }), this.timestamp.toNow(true));
}
return unwrapJQ(h_1("i", { dangerouslySetInnerHTML:null), mw.message(this.timestamp ?
'deputy.session.row.checkedComplete' :
'deputy.session.row.checked', ...params).textparseDom() });
}
else {
Line 2,665 ⟶ 5,317:
*/
class DeputyCCIStatusDropdown extends EventTarget {
/**
* @return The currently-selected status of this dropdown.
*/
get status() {
var _a, _b;
return (_b = (_a = this.dropdown.getMenu().findSelectedItem()) === null || _a === void 0 ? void 0 : _a.getData()) !== null && _b !== void 0 ? _b : null;
}
/**
* Sets the currently-selected status of this dropdown.
*/
set status(status) {
this.dropdown.getMenu().selectItemByData(status);
this.setOptionDisabled(ContributionSurveyRowStatus.Unknown, status !== ContributionSurveyRowStatus.Unknown, false);
this.refresh();
}
/**
* Create a new DeputyCCIStatusDropdown object.
Line 2,676 ⟶ 5,343:
* @param row.title The title of the row (page) that this dropdown accesses
* @param options Additional construction options, usually used by the root session.
* @param row.type
*/
constructor(row, options = {}) {
Line 2,789 ⟶ 5,457:
unwrapWidget(this.dropdown.getMenu()).style.width = '20em';
});
}
/**
* @return The currently-selected status of this dropdown.
*/
get status() {
var _a, _b;
return (_b = (_a = this.dropdown.getMenu().findSelectedItem()) === null || _a === void 0 ? void 0 : _a.getData()) !== null && _b !== void 0 ? _b : null;
}
/**
* Sets the currently-selected status of this dropdown.
*/
set status(status) {
this.dropdown.getMenu().selectItemByData(status);
this.setOptionDisabled(ContributionSurveyRowStatus.Unknown, status !== ContributionSurveyRowStatus.Unknown, false);
this.refresh();
}
/**
Line 2,901 ⟶ 5,554:
*
* For
* - Unfinished: WithoutViolations, unless it's `pageonly`, on which it'll be kept as is.
* - Unknown: Unfinished
* - WithViolations: _usually not disabled, kept as is_
Line 2,912 ⟶ 5,565:
selectNextBestValue(status) {
if (status === ContributionSurveyRowStatus.Unfinished) {
if (this.row.type === 'pageonly') {
// Leave it alone.
return;
}
this.status = ContributionSurveyRowStatus.WithoutViolations;
}
Line 2,929 ⟶ 5,586:
 
/**
* ReturnsShows a confirmation dialog, if the lastuser does not itemhave ofdanger anmode arrayenabled.
* If the user has danger mode enabled, this immediately resolves to true, letting
* the action run immediately.
*
* Do not use this with any action that can potentially break templates, user data,
* @param array The array to get the last element from
* @returnor Thecause lastirreversible elementdata of the arrayloss.
*
* @param config The user's configuration
* @param message See {@link OO.ui.MessageDialog}'s parameters.
* @param options See {@link OO.ui.MessageDialog}'s parameters.
* @return Promise resolving to a true/false boolean.
*/
function lastdangerModeConfirm(arrayconfig, message, options) {
if (config.all.core.dangerMode.get()) {
return array[array.length - 1];
return $.Deferred().resolve(true);
}
else {
return OO.ui.confirm(message, options);
}
}
 
Line 2,966 ⟶ 5,635:
*/
class DeputyContributionSurveyRow extends EventTarget {
/**
* Creates a new DeputyContributionSurveyRow object.
*
* @param row The contribution survey row data
* @param originalElement
* @param originalWikitext
* @param section The section that this row belongs to
*/
constructor(row, originalElement, originalWikitext, section) {
super();
/**
* The state of this element.
*/
this.state = DeputyContributionSurveyRowState.Loading;
/**
* Responder for session requests.
*/
this.statusRequestResponder = this.sendStatusResponse.bind(this);
this.nextRevisionRequestResponder = this.sendNextRevisionResponse.bind(this);
this.row = row;
this.originalElement = originalElement;
this.additionalComments = this.extractAdditionalComments();
this.originalWikitext = originalWikitext;
this.section = section;
}
/**
* @return `true` if:
Line 3,069 ⟶ 5,713:
}
if (this.wasFinished == null) {
console.warn('Could not determine if this is an originally-finished or ' +
'originally-unfinished row. Assuming unfinished and moving on...');
}
const finished = (_a = this.wasFinished) !== null && _a !== void 0 ? _a : false;
// "* "
let result = this.row.data.bullet;
Line 3,084 ⟶ 5,727:
result += `${this.row.extras}`;
}
const unfinishedDiffs = (_d_c = (_c_b = (_b_a = this.revisions) === null || _b_a === void 0 ? void 0 : _b_a.filter((v) => !v.completed)) === null || _c_b === void 0 ? void 0 : _c_b.sort((a, b) => ContributionSurveyRow.getSorterFunction(this.sortOrder)(a.revision, b.revision))) !== null && _d_c !== void 0 ? _d_c : [];
let diffsText = '';
if (unfinishedDiffs.length > 0) {
diffsText += unfinishedDiffs.map((v) => {
return mw.format(this.row.data.diffTemplate, String(v.revision.revid), v.revision.diffsize == null ?
// For whatever reason, diffsize is missing. Fall back to the text we had
// previously.
v.uiRow.row.data.revidText[v.revision.revid] :
String(v.revision.diffsize > 0 ?
'+' + v.revision.diffsize : v.revision.diffsize));
}).join('');
Line 3,144 ⟶ 5,787:
result += ' ~~~~';
};
if (finishedthis.statusModified) {
if// (thisModified.statusModified) {Use user data.
// Modified. Use user data.
useUserData();
}
else {
// No changes. Just append original closure comments.
result += this.row.comment;
}
}
else {
useUserData();
}
else if ((_d = this.wasFinished) !== null && _d !== void 0 ? _d : false) {
// No changes. Just append original closure comments.
result += this.row.comment;
}
// Otherwise, leave this row unchanged.
}
return result;
Line 3,164 ⟶ 5,803:
*/
get autosaveHash() {
return `CASE--${this.row.casePage.title.getPrefixedDb()}+H--${this.section.headingName}-${this.section.headingN}+PAGE--${this.row.title.getPrefixedDb()}`;
}
/**
* Creates a new DeputyContributionSurveyRow object.
*
* @param row The contribution survey row data
* @param originalElement
* @param originalWikitext
* @param section The section that this row belongs to
*/
constructor(row, originalElement, originalWikitext, section) {
super();
/**
* The state of this element.
*/
this.state = DeputyContributionSurveyRowState.Loading;
/**
* Responder for session requests.
*/
this.statusRequestResponder = this.sendStatusResponse.bind(this);
this.nextRevisionRequestResponder = this.sendNextRevisionResponse.bind(this);
this.row = row;
this.originalElement = originalElement;
this.additionalComments = this.extractAdditionalComments();
this.originalWikitext = originalWikitext;
this.section = section;
}
/**
Line 3,256 ⟶ 5,920:
}
catch (e) {
console.error('Caught exception while loading data', e);
this.state = DeputyContributionSurveyRowState.Broken;
this.renderRow(null, unwrapWidget(new OO.ui.MessageWidget({
Line 3,277 ⟶ 5,941:
}
if (this.revisions && this.statusDropdown) {
if (this.row.type !== 'pageonly') {
this.statusDropdown.setOptionDisabled(ContributionSurveyRowStatus.Unfinished, this.completed, true);
// Only disable this option if the row isn't already finished.
this.statusDropdown.setOptionDisabled(ContributionSurveyRowStatus.Unfinished, this.completed, true);
}
const unfinishedWithStatus = this.statusModified && !this.completed;
if (this.unfinishedMessageBox) {
this.unfinishedMessageBox.toggle(unfinishedWithStatus);
// If using danger mode, this should always be enabled.
!window.deputy.config.core.dangerMode.get() &&
unfinishedWithStatus);
}
this.statusAutosaveFunction();
Line 3,302 ⟶ 5,972:
*/
getSavedStatus() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
return (_a = yield window.deputy.storage.db.get('pageStatus', this.autosaveHash);) !== null && _a !== void 0 ? _a :
// Old hash (< v0.9.0)
yield window.deputy.storage.db.get('pageStatus', `CASE--${this.row.casePage.title.getPrefixedDb()}+PAGE--${this.row.title.getPrefixedDb()}`);
});
}
Line 3,319 ⟶ 5,992:
}
});
}
/**
* Mark all revisions of this section as finished.
*/
markAllAsFinished() {
if (!this.revisions) {
// If `renderUnfinished` was never called, this will be undefined.
// We want to skip over instead.
return;
}
this.revisions.forEach((revision) => {
revision.completed = true;
});
this.onUpdate();
}
/**
Line 3,378 ⟶ 6,065:
revisionList.appendChild(unwrapWidget(this.unfinishedMessageBox));
revisionList.appendChild(unwrapWidget(this.renderCommentsTextInput(this.row.comment)));
constif maxSize(this.row.type === window.deputy.config.cci.maxSizeToAutoShowDiff.get('pageonly'); {
for (const revision of diffsrevisionList.valuesappendChild())h_1("div", { class: "dp-cs-row-pageonly" },
const revisionUIEl = new DeputyContributionSurveyRevisionh_1(revision"i", thisnull, {mw.msg('deputy.session.row.pageonly'))));
}
expanded: window.deputy.config.cci.autoShowDiff.get() &&
else {
diffs.size < window.deputy.config.cci.maxRevisionsToAutoShowDiff.get() &&
const (maxSizecciConfig === -1 || Mathwindow.abs(revisiondeputy.diffsize) < maxSize)config.cci;
}const maxSize = cciConfig.maxSizeToAutoShowDiff.get();
revisionUIEl.addEventListenerfor ('update',const revision of diffs.values() =>) {
//const RecheckrevisionUIEl options= firstnew toDeputyContributionSurveyRevision(revision, avoidthis, "Unfinished" being selected when done.{
this expanded: cciConfig.onUpdateautoShowDiff.get(); &&
} diffs.size < cciConfig.maxRevisionsToAutoShowDiff.get(); &&
yield revisionUIEl (maxSize === -1 || Math.prepareabs(revision.diffsize) < maxSize);
revisionList.appendChild(revisionUIEl.render() });
this revisionUIEl.revisions.pushaddEventListener('update', (revisionUIEl); => {
// Recheck options first to avoid "Unfinished" being selected when done.
this.onUpdate();
});
yield revisionUIEl.prepare();
revisionList.appendChild(revisionUIEl.render());
this.revisions.push(revisionUIEl);
}
}
return revisionList;
Line 3,448 ⟶ 6,142:
.revid);
parts.push(
// eslint-disable-next-lineMessages mediawiki/msg-docthat can be used here:
// * deputy.negativeDiff
mw.message(`deputy.${largestDiff.diffsize < 0 ? 'negative' : 'positive'}Diff`, largestDiff.diffsize.toString()).text());
// * deputy.positiveDiff
// * deputy.zeroDiff
mw.message(`deputy.${{
'-1': 'negative',
1: 'positive',
0: 'zero'
}[Math.sign(largestDiff.diffsize)]}Diff`, largestDiff.diffsize.toString()).text());
}
const spliced = [];
Line 3,477 ⟶ 6,178:
requireAcknowledge: false
});
if ((diffs && diffsthis.sizerow.type =!== 0)'pageonly' || this.wasFinished) {&&
((diffs && diffs.size === 0) || this.wasFinished)) {
// If there are no diffs found or `this.wasFinished` is set (both meaning there are
// no diffs and this is an already-assessed row), then the "Unfinished" option will
// be disabled. This does not apply for page-only rows, which never have diffs.
this.statusDropdown.setOptionDisabled(ContributionSurveyRowStatus.Unfinished, true);
}
Line 3,496 ⟶ 6,198:
});
this.checkAllButton.on('click', () => {
OOdangerModeConfirm(window.uideputy.confirm(config, mw.msg('deputy.session.row.checkAll.confirm')).done((confirmed) => {
if (confirmed) {
this.revisions.forEachmarkAllAsFinished((revision) => {;
revision.completed = true;
});
this.onUpdate();
}
});
Line 3,513 ⟶ 6,212:
framed: false
});
let contentToggled = !window.deputy.prefsconfig.get('cci.contentDefault'autoCollapseRows.get();
/**
* Toggles the content.
Line 3,528 ⟶ 6,227:
'deputy.session.row.content.open').text());
contentContainer.style.display = show ? 'block' : 'none';
contentToggled = !contentToggledshow;
};
toggleContent(contentToggled);
Line 3,559 ⟶ 6,258:
}
/**
*
* @param diffs
* @param content
Line 3,628 ⟶ 6,326:
status: this.status,
enabledStatuses: this.statusDropdown.getEnabledOptions(),
rowType: this.row.type,
revisionStatus: rev ? rev.completed : undefined,
revision: event.data.revision,
Line 3,636 ⟶ 6,335:
}
/**
*
* @param event
*/
Line 3,786 ⟶ 6,484:
}
else {
// noinspection JSXDomNesting
this.element = swapElements(this.element, h_1("table", { class: "diff" },
h_1("colgroup", null,
Line 3,905 ⟶ 6,604:
*
* @param editSummary The edit summary
* @param config The user's configuration. Used to get the "danger mode" setting.
* @return The decorated edit summary (in wikitext)
*/
function decorateEditSummary (editSummary, config) {
var _a;
return `${editSummary} ([[Wikipedia:Deputy|Deputy]] v${version})`;
const dangerMode = (_a = config === null || config === void 0 ? void 0 : config.core.dangerMode.get()) !== null && _a !== void 0 ? _a : false;
return `${editSummary} ([[Wikipedia:Deputy|Deputy]] v${version}${dangerMode ? '!' : ''})`;
}
 
/**
* Evaluates any string using `mw.msg`. This handles internationalization of strings
* that are loaded outside the script or asynchronously.
*
* @param string The string to evaluate
* @param {...any} parameters Parameters to pass, if any
* @return A mw.Message
*/
function msgEval(string, ...parameters) {
// Named parameters
let named = {};
if (typeof parameters[0] === 'object') {
named = parameters.shift();
}
const m = new mw.Map();
for (const [from, to] of Object.entries(named)) {
string = string.replace(new RegExp(`\\$${from}`, 'g'), to);
}
m.set('msg', string);
return new mw.Message(m, 'msg', parameters);
}
 
var ContributionSurveyRowSigningBehavior;
(function (ContributionSurveyRowSigningBehavior) {
ContributionSurveyRowSigningBehavior["Always"] = "always";
ContributionSurveyRowSigningBehavior["AlwaysTrace"] = "alwaysTrace";
ContributionSurveyRowSigningBehavior["AlwaysTraceLastOnly"] = "alwaysTraceLastOnly";
ContributionSurveyRowSigningBehavior["LastOnly"] = "lastOnly";
ContributionSurveyRowSigningBehavior["Never"] = "never";
})(ContributionSurveyRowSigningBehavior || (ContributionSurveyRowSigningBehavior = {}));
 
/**
Line 3,959 ⟶ 6,630:
*
* @param heading The heading to check
* @param headingName The name of the heading to check
* @return The n, a number
*/
function sectionHeadingN (heading, headingName) {
try {
const headingNameEndPattern = /(?:\s|_)(\d+)/g;
const headingIdEndPattern = /_(\d+)/g;
const headingId = sectionHeadingId(heading).id;
const headingIdMatches = headingId.match(headingIdEndPattern);
const headingNameMatches = headingNameheading.title.match(headingNameEndPattern);
if (headingIdMatches == null) {
return 1;
Line 3,985 ⟶ 6,655:
}
catch (e) {
console.error('Error getting section number', e, heading);
throw e;
}
}
 
/**
* Automatically applies a change tag to edits made by the user if
* a change tag was provided in the configuration.
*
* @param config
* @return A spreadable Object containing the `tags` parameter for `action=edit`.
*/
function changeTag(config) {
return config.core.changeTag.get() ?
{ tags: config.core.changeTag.get() } :
{};
}
 
Line 4,014 ⟶ 6,671:
children.forEach(child => container.appendChild(child.cloneNode(true)));
return container;
}
 
/**
* What it says on the tin. Attempt to parse out a `title`, `diff`,
* or `oldid` from a URL. This is useful for converting diff URLs into actual
* diff information, and especially useful for {{copied}} templates.
*
* If diff parameters were not found (no `diff` or `oldid`), they will be `null`.
*
* @param url The URL to parse
* @return Parsed info: `diff` or `oldid` revision IDs, and/or the page title.
*/
function parseDiffUrl(url) {
if (typeof url === 'string') {
url = new URL(url);
}
// Attempt to get values from URL parameters (when using `/w/index.php?action=diff`)
let oldid = url.searchParams.get('oldid');
let diff = url.searchParams.get('diff');
let title = url.searchParams.get('title');
// Attempt to get information from this URL.
tryConvert: {
if (title && oldid && diff) {
// Skip if there's nothing else we need to get.
break tryConvert;
}
// Attempt to get values from Special:Diff short-link
const diffSpecialPageCheck =
// eslint-disable-next-line security/detect-unsafe-regex
/\/wiki\/Special:Diff\/(prev|next|\d+)(?:\/(prev|next|\d+))?/i.exec(url.pathname);
if (diffSpecialPageCheck != null) {
if (diffSpecialPageCheck[1] != null &&
diffSpecialPageCheck[2] == null) {
// Special:Diff/diff
diff = diffSpecialPageCheck[1];
}
else if (diffSpecialPageCheck[1] != null &&
diffSpecialPageCheck[2] != null) {
// Special:Diff/oldid/diff
oldid = diffSpecialPageCheck[1];
diff = diffSpecialPageCheck[2];
}
break tryConvert;
}
// Attempt to get values from Special:PermanentLink short-link
const permanentLinkCheck = /\/wiki\/Special:Perma(nent)?link\/(\d+)/i.exec(url.pathname);
if (permanentLinkCheck != null) {
oldid = permanentLinkCheck[2];
break tryConvert;
}
// Attempt to get values from article path with ?oldid or ?diff
// eslint-disable-next-line security/detect-non-literal-regexp
const articlePathRegex = new RegExp(mw.util.getUrl('(.*)'))
.exec(url.pathname);
if (articlePathRegex != null) {
title = decodeURIComponent(articlePathRegex[1]);
break tryConvert;
}
}
// Convert numbers to numbers
if (oldid != null && !isNaN(+oldid)) {
oldid = +oldid;
}
if (diff != null && !isNaN(+diff)) {
diff = +diff;
}
// Try to convert a page title
try {
title = new mw.Title(title).getPrefixedText();
}
catch (e) {
warn('Failed to normalize page title during diff URL conversion.');
}
return {
diff: diff,
oldid: oldid,
title: title
};
}
 
Line 4,023 ⟶ 6,758:
*/
class DeputyContributionSurveySection {
/**
* Creates a DeputyContributionSurveySection from a given heading.
*
* @param casePage
* @param heading
*/
constructor(casePage, heading) {
this.casePage = casePage;
this.heading = casePage.normalizeSectionHeading(heading);
this.sectionNodes = casePage.getContributionSurveySection(heading);
}
/**
* @return `true` if this section has been modified
Line 4,134 ⟶ 6,858:
}
if (this.closed) {
if (!this._section.originallyClosed) {
final.splice(1, 0, msgEval(window.deputy.wikiConfig.cci.collapseTop.get(), (((_a = this.comments) !== null && _a !== void 0 ? _a : '') + ' ~~~~').trim()).plain());
if let closingComments = (final[final.length(_a -= 1]this.trim(comments).length !== null && _a !== void 0) {? _a : '').trim();
finalif (this.popclosingCommentsSign.isSelected();) {
closingComments += ' ~~~~';
}
final.splice(1, 0, msgEval(window.deputy.wikiConfig.cci.collapseTop.get(), closingComments).plain());
if (final[final.length - 1].trim().length === 0) {
final.pop();
}
final.push(window.deputy.wikiConfig.cci.collapseBottom.get());
}
// If the section was originally closed, don't allow the archiving
final.push(window.deputy.wikiConfig.cci.collapseBottom.get());
// message to be edited.
}
return final.join('\n');
Line 4,198 ⟶ 6,930:
*/
get headingName() {
return sectionHeadingName(this.heading).title;
}
/**
Line 4,204 ⟶ 6,936:
*/
get headingN() {
return sectionHeadingN(this.heading, this.headingName);
}
/**
* Creates a DeputyContributionSurveySection from a given heading.
*
* @param casePage
* @param heading
*/
constructor(casePage, heading) {
this.casePage = casePage;
this.heading = normalizeWikiHeading(heading);
this.sectionNodes = casePage.getContributionSurveySection(heading);
}
/**
Line 4,227 ⟶ 6,970:
*/
prepare() {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
constlet targetSectionNodes = this.sectionNodes;
let listElements = this.sectionNodes.filter((el) => el instanceof HTMLElement && el.tagName === 'UL');
if (listElements.length === 0) {
// NotNo alist validfound section! MightIs bethis closeda already.valid section?
return// false;Check for a collapsible section.
const collapsible = (_b = (_a = this.sectionNodes.find((v) => v instanceof HTMLElement && v.querySelector('.mw-collapsible'))) === null || _a === void 0 ? void 0 : _a.querySelector('.mw-collapsible')) !== null && _b !== void 0 ? _b : null;
if (collapsible) {
// This section has a collapsible. It's possible that it's a closed section.
// From here, use a different `sectionNodes` (specifically targeting all nodes
// inside that collapsible), and then locate all ULs inside that collapsible.
targetSectionNodes = Array.from(collapsible.childNodes);
listElements = Array.from(collapsible.querySelectorAll('ul'));
}
else {
// No collapsible found. Give up.
warn('Could not find valid ULs in CCI section.', targetSectionNodes);
return false;
}
}
const rowElements = {};
Line 4,244 ⟶ 7,002:
// Avoid enlisting if the anchor can't be found (invalid row).
if (anchor) {
rowElements[const anchorLinkTarget = parseDiffUrl(new mw.TitleURL(anchor.innerText).getPrefixedTextgetAttribute('href')], =window.___location.href)).title;
if (!anchorLinkTarget) li;{
warn('Could not parse target of anchor', anchor);
}
else {
rowElements[new mw.Title(anchorLinkTarget).getPrefixedText()] =
li;
}
}
}
Line 4,267 ⟶ 7,031:
else {
// Element somehow not in list. Just keep line as-is.
warn(`Could not find row element for "${csr.title.getPrefixedText()}"`);
rowElement = line;
}
Line 4,274 ⟶ 7,039:
if (/^\*[^*:]+/.test(line)) {
// Only trigger on actual bulleted lists.
console.warn('Could not parse row.', line, e);
// For debugging and tests.
mw.hook('deputy.errors.cciRowParse').fire({
Line 4,299 ⟶ 7,064:
lastNode != null &&
// The node is part of this section
this.sectionNodestargetSectionNodes.includes(lastNode) &&
(
// The node is not an element
Line 4,322 ⟶ 7,087:
// Array of Nodes
this.wikitextLines.push(line);
this.rowElements.push(DeputyExtraneousElementif (rowElement.length !== 0)); {
// Only append the row element if it has contents.
// Otherwise, there will be a blank blue box.
this.rowElements.push(DeputyExtraneousElement(rowElement));
}
}
else if (typeof rowElement === 'string') {
Line 4,336 ⟶ 7,105:
* Toggle section elements. Removes the section elements (but preservers them in
* `this.sectionElements`) if `false`, re-appends them to the DOM if `true`.
*
* @param toggle
*/
toggleSectionElements(toggle) {
var _a;
const bottom = (_a = this.heading.root.nextSibling) !== null && _a !== void 0 ? _a : null;
for (const sectionElement of this.sectionNodes) {
if (toggle) {
this.heading.root.parentNode.insertBefore(sectionElement, bottom);
}
else {
Line 4,365 ⟶ 7,135:
}
/**
* Toggles the closing comments input box. Thisand willsignature disable the input box ANDcheckbox.
* This will disable the input box AND hide the element from view.
*
* @param show
*/
toggleClosingCommentstoggleClosingElements(show) {
this.closingComments.setDisabled(!show);
this.closingComments.toggle(show);
this.closingCommentsSign.setDisabled(!show);
this.closingCommentsSign.toggle(show);
}
/**
Line 4,380 ⟶ 7,152:
*/
setDisabled(disabled) {
var _a, _b, _c, _d, _e, _f, _g;
(_a = this.closeButton) === null || _a === void 0 ? void 0 : _a.setDisabled(disabled);
(_b = this.reviewButton) === null || _b === void 0 ? void 0 : _b.setDisabled(disabled);
Line 4,386 ⟶ 7,158:
(_d = this.closingCheckbox) === null || _d === void 0 ? void 0 : _d.setDisabled(disabled);
(_e = this.closingComments) === null || _e === void 0 ? void 0 : _e.setDisabled(disabled);
(_f = this.rowsclosingCommentsSign) === null || _f === void 0 ? void 0 : _f.forEach((row) => row.setDisabled(disabled));
(_g = this.rows) === null || _g === void 0 ? void 0 : _g.forEach((row) => row.setDisabled(disabled));
this.disabled = disabled;
}
Line 4,400 ⟶ 7,173:
throw new Error(mw.msg('deputy.session.section.missingSection'));
}
if (this.closed && this.rows.some(r => !r.completed)) {
!this._section.originallyClosed &&
!window.deputy.config.core.dangerMode.get() &&
this.rows.some(r => !r.completed)) {
throw new Error(mw.msg('deputy.session.section.sectionIncomplete'));
}
return MwApi.action.postWithEditToken(Object.assign(Object.assign({}, changeTag(yield window.deputy.getWikiConfig())), { action: 'edit', pageid: this.casePage.pageId, section: sectionId, text: this.wikitext, baserevid: this.revid, summary: decorateEditSummary(this.editSummary, window.deputy.config) })).then(function (data) {
return data;
}, (code, data) => {
Line 4,443 ⟶ 7,219:
*/
render() {
this.closingCheckboxconst dangerMode = new OOwindow.deputy.config.core.uidangerMode.CheckboxInputWidgetget();
this.closingCheckbox = new OO.ui.CheckboxInputWidget({
selected: this._section.originallyClosed,
disabled: this._section.originallyClosed
});
this.closingComments = new OO.ui.TextInputWidget({
placeholder: mw.msg('deputy.session.section.closeComments'),
value: this._section.closingComments,
disabled: true
});
this.closeButtonclosingCommentsSign = new OO.ui.ButtonWidgetCheckboxInputWidget({
labelselected: mwwindow.msg('deputy.sessionconfig.sectioncci.stop'signSectionArchive.get(),
}); disabled: true
this.reviewButton = new OO.ui.ButtonWidget({
label: mw.msg('deputy.review')
});
this.closeButton = new OO.ui.ButtonWidget(Object.assign({ label: mw.msg('deputy.session.section.stop'), title: mw.msg('deputy.session.section.stop.title') }, (dangerMode ? { invisibleLabel: true, icon: 'pause' } : {})));
this.reviewButton = new OO.ui.ButtonWidget(Object.assign({ label: mw.msg('deputy.review'), title: mw.msg('deputy.review.title') }, (dangerMode ? { invisibleLabel: true, icon: 'eye' } : {})));
this.saveButton = new OO.ui.ButtonWidget({
label: mw.msg('deputy.save'),
Line 4,463 ⟶ 7,244:
this.closeButton.on('click', () => __awaiter(this, void 0, void 0, function* () {
if (this.wikitext !== (yield this.getSection()).originalWikitext) {
OOdangerModeConfirm(window.uideputy.confirm(config, mw.msg('deputy.session.section.closeWarn')).done((confirmed) => {
if (confirmed) {
this.close();
Line 4,489 ⟶ 7,270:
const sectionId = yield getSectionId(this.casePage.title, this.headingName, this.headingN);
yield this.save(sectionId).then((result) => __awaiter(this, void 0, void 0, function* () {
var _a, _b;
if (result) {
mw.notify(mw.msg('deputy.session.section.saved'));
Line 4,497 ⟶ 7,278:
// Remove whatever section elements are still there.
// They may have been greatly modified by the save.
const sectionElements = this.casePage.getContributionSurveySection(this.heading.root);
sectionElements.forEach((el) => removeElement(el));
// Clear out section elements and re-append new ones to the DOM.
this.sectionNodes = [];
// Heading is preserved to avoid messing with IDs.
const heading = this.heading.root;
const insertRef = (_a = heading.nextSibling) !== null && _a !== void 0 ? _a : null;
for (const child of Array.from(element.childNodes)) {
if (!this.casePage.isContributionSurveyHeading((_b = normalizeWikiHeading(child)), {
// We're using elements that aren't currently appended to the
// DOM, so we have to manually set the ceiling. Otherwise, we'll
// get the wrong element and ceiling checks will always be false.
element)) === null || _b === void 0 ? void 0 : _b.h)) {
heading.parentNode.insertBefore(child, insertRef);
this.sectionNodes.push(child);
// noinspection JSUnresolvedReference
$(child).children('.mw-collapsible').makeCollapsible();
}
}
Line 4,514 ⟶ 7,301:
yield this.getSection(Object.assign(wikitext, { revid }));
yield this.prepare();
if (heading.parentElement.classList.containsinsertAdjacentElement('mw-headingafterend', this.render()) {;
// Intentional recursive call
heading.parentElement.insertAdjacentElement('afterend', this.render());
}
else {
// Intentional recursive call
heading.insertAdjacentElement('afterend', this.render());
}
// Run this asynchronously.
setTimeout(this.loadData.bind(this), 0);
}
else {
this.close();
yield window.deputy.session.rootSession.closeSection(this);
}
}
Line 4,530 ⟶ 7,314:
title: mw.msg('deputy.session.section.failed')
});
console.error(err);
saveContainer.classList.remove('active');
this.setDisabled(false);
Line 4,537 ⟶ 7,321:
this.setDisabled(false);
}));
// Section closing (archive/ctop) elements
const closingWarning = DeputyMessageWidget({
classes: ['dp-cs-section-unfinishedWarning'],
Line 4,545 ⟶ 7,330:
const updateClosingWarning = (() => {
const incomplete = this.rows.some((row) => !row.completed);
thisif (window.saveButtondeputy.setDisabledconfig.core.dangerMode.get(incomplete);) {
this.saveButton.setDisabled(false);
closingWarning.setLabel(mw.msg('deputy.session.section.closeError.danger'));
}
else {
closingWarning.setLabel(mw.msg('deputy.session.section.closeError'));
this.saveButton.setDisabled(incomplete);
}
closingWarning.toggle(incomplete);
});
const closingCommentsField = new OO.ui.FieldLayout(this.closingComments, {
align: 'top',
label: mw.msg('Closing commentsdeputy.session.section.closeComments'),
invisibleLabel: true,
help: mw.msg('deputy.session.section.closeHelp'),
helpInline: true,
classes: ['dp-cs-section-closingCommentsField']
});
const closingCommentsSignField = new OO.ui.FieldLayout(this.closingCommentsSign, {
// Hide by default.
closingCommentsField.toggle(false); align: 'inline',
label: mw.msg('deputy.session.section.closeCommentsSign')
closingCommentsField.on('change', (v) => {
this.comments = v;
});
const closingFields = h_1("div", { class: "dp-cs-section-closing", style: { display: 'none' } },
this.toggleClosingComments(false);
unwrapWidget(closingWarning),
this.closingCheckbox.on('change', (v) => {
unwrapWidget(closingCommentsField),
unwrapWidget(closingCommentsSignField));
const updateClosingFields = (v) => {
this.closed = v;
closingCommentsField.toggleif (vthis._section.originallyClosed); {
// This section was originally closed. Hide everything.
this.toggleClosingComments(v);
v = false;
}
closingFields.style.display = v ? '' : 'none';
this.toggleClosingElements(v);
if (v) {
updateClosingWarning();
Line 4,579 ⟶ 7,376:
});
}
});
this.closingCheckbox.on('change', updateClosingFields);
updateClosingFields(this.closed);
this.closingComments.on('change', (v) => {
this.comments = v;
});
// Danger mode buttons
return this.container = h_1("div", { class: "deputy dp-cs-section" },
const dangerModeElements = [];
if (dangerMode) {
const markAllFinishedButton = new OO.ui.ButtonWidget({
flags: ['destructive'],
icon: 'checkAll',
label: mw.msg('deputy.session.section.markAllFinished'),
title: mw.msg('deputy.session.section.markAllFinished'),
invisibleLabel: true
});
markAllFinishedButton.on('click', () => {
this.rows.forEach(v => v.markAllAsFinished());
});
const instantArchiveButton = new OO.ui.ButtonWidget({
flags: ['destructive', 'primary'],
label: mw.msg('deputy.session.section.instantArchive'),
title: mw.msg('deputy.session.section.instantArchive.title')
});
instantArchiveButton.on('click', () => {
this.closingCheckbox.setSelected(true);
this.saveButton.emit('click');
});
const dangerModeButtons = [
unwrapWidget(markAllFinishedButton),
unwrapWidget(instantArchiveButton)
];
dangerModeElements.push(h_1("div", { class: "dp-cs-section-danger--separator" }, mw.msg('deputy.session.section.danger')), dangerModeButtons);
// Remove spacing from save button
unwrapWidget(this.saveButton).style.marginRight = '0';
}
// Actual element
return this.container = h_1("div", { class: classMix('deputy', 'dp-cs-section', this._section.originallyClosed && 'dp-cs-section-archived') },
this._section.originallyClosed && h_1("div", { class: "dp-cs-section-archived-warn" }, unwrapWidget(new OO.ui.MessageWidget({
type: 'warning',
label: mw.msg('deputy.session.section.closed')
}))),
h_1("div", null, this.rowElements.map((row) => row instanceof HTMLElement ? row : row.render())),
h_1("div", { class: "dp-cs-section-footer" },
h_1("div", { style: { display: 'flex' } },
h_1("div", { style: {
flex: '1 1 100%',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center'
} },
unwrapWidget(new OO.ui.FieldLayout(this.closingCheckbox, {
Line 4,597 ⟶ 7,430:
label: mw.msg('deputy.session.section.close')
})),
unwrapWidget(closingWarningclosingFields),
h_1("div", { style: unwrapWidget(closingCommentsField)),{
h_1("div", { style: { display: 'flex', alignItems: 'end' } },
alignContent: 'end',
justifyContent: 'end',
flexWrap: dangerMode ? 'wrap' : 'nowrap',
maxWidth: '320px'
} },
unwrapWidget(this.closeButton),
unwrapWidget(this.reviewButton),
unwrapWidget(this.saveButton))),
dangerModeElements)),
saveContainer));
}
Line 4,628 ⟶ 7,467:
*/
class DeputyRootSession {
/*
* =========================================================================
* INSTANCE AND ACTIVE SESSION FUNCTIONS
* =========================================================================
*/
/**
* @param session
* @param casePage
*/
constructor(session, casePage) {
/**
* Responder for session requests.
*/
this.sessionRequestResponder = this.sendSessionResponse.bind(this);
this.sessionStopResponder = this.handleStopRequest.bind(this);
this.session = session;
this.casePage = casePage;
}
/*
* =========================================================================
Line 4,664 ⟶ 7,485:
casePage.findContributionSurveyHeadings()
.forEach((heading) => {
const linknormalizedHeading = DeputyCCISessionStartLinknormalizeWikiHeading(heading, casePage);
const link = DeputyCCISessionStartLink(normalizedHeading, casePage);
startLink.push(link);
headingnormalizedHeading.root.appendChild(link);
});
window.deputy.comms.addEventListener('sessionStarted', () => {
Line 4,687 ⟶ 7,509:
return __awaiter(this, void 0, void 0, function* () {
yield mw.loader.using(['oojs-ui-core', 'oojs-ui.styles.icons-content'], () => {
const firstHeading = casePage.findFirstContributionSurveyHeadingfindFirstContributionSurveyHeadingElement();
if (firstHeading) {
const stopButton = new OO.ui.ButtonWidget({
Line 4,721 ⟶ 7,543:
window.deputy.session.init();
});
normalizeWikiHeading(firstHeading).root.insertAdjacentElement('beforebegin', unwrapWidget(messageBox));
}
});
Line 4,740 ⟶ 7,562:
mw.loader.using(['oojs-ui-core', 'oojs-ui.styles.icons-content'], () => {
const lastActiveSection = DeputyRootSession.findFirstLastActiveSection(casePage);
const firstSection = normalizeWikiHeading(casePage.findFirstContributionSurveyHeadingfindFirstContributionSurveyHeadingElement());
// Insert element directly into widget (not as text, or else event
// handlers will be destroyed).
Line 4,757 ⟶ 7,579:
'deputy.session.continue.help' :
'deputy.session.continue.help.fromStart', lastActiveSection ?
sectionHeadingNamenormalizeWikiHeading(lastActiveSection).title :
casePage.lastActiveSections[0]
.replace(/_/g, ' '), sectionHeadingName(firstSection).title),
actions: [continueButton],
closable: true
Line 4,774 ⟶ 7,596:
else {
DeputyRootSession.continueSession(casePage, [
sectionHeadingId(firstSection).id
]);
}
window.deputy.comms.removeEventListener('sessionStarted', sessionStartListener);
});
firstSection.root.insertAdjacentElement('beforebegin', unwrapWidget(messageBox));
window.deputy.comms.addEventListener('sessionStarted', sessionStartListener, { once: true });
})
Line 4,795 ⟶ 7,617:
return __awaiter(this, void 0, void 0, function* () {
const casePage = _casePage !== null && _casePage !== void 0 ? _casePage : yield DeputyCasePage.build();
returnyield mw.loader.using(['oojs-ui-core', 'oojs-ui.styles.icons-content'], () => {
const firstHeading = casePage.findFirstContributionSurveyHeadingfindFirstContributionSurveyHeadingElement();
if (firstHeading) {
const messageBox = DeputyMessageWidget({
Line 4,807 ⟶ 7,629:
closable: true
});
normalizeWikiHeading(firstHeading).root.insertAdjacentElement('beforebegin', unwrapWidget(messageBox));
window.deputy.comms.addEventListener('sessionClosed', () => __awaiter(this, void 0, void 0, function* () {
removeElement(unwrapWidget(messageBox));
Line 4,828 ⟶ 7,650:
for (const lastActiveSection of casePage.lastActiveSections) {
for (const heading of csHeadings) {
if (sectionHeadingIdnormalizeWikiHeading(heading).id === lastActiveSection) {
return heading;
}
Line 4,843 ⟶ 7,665:
static startSession(section, _casePage) {
return __awaiter(this, void 0, void 0, function* () {
const sectionIds = (Array.isArray(section) ? section : [section]).map((_section) => sectionHeadingIdnormalizeWikiHeading(_section).id);
// Save session to storage
const casePage = _casePage !== null && _casePage !== void 0 ? _casePage : yield DeputyCasePage.build();
Line 4,891 ⟶ 7,713:
return (yield window.deputy.storage.setKV('session', session)) ? session : null;
});
}
/*
* =========================================================================
* INSTANCE AND ACTIVE SESSION FUNCTIONS
* =========================================================================
*/
/**
* @param session
* @param casePage
*/
constructor(session, casePage) {
/**
* Responder for session requests.
*/
this.sessionRequestResponder = this.sendSessionResponse.bind(this);
this.sessionStopResponder = this.handleStopRequest.bind(this);
this.session = session;
this.casePage = casePage;
}
/**
Line 4,931 ⟶ 7,771:
'oojs-ui.styles.icons-media',
'oojs-ui.styles.icons-movement',
'ext.discussionTools.init',
'jquery.makeCollapsible'
], (require) => __awaiter(this, void 0, void 0, function* () {
// Instantiate the parser
Line 4,942 ⟶ 7,783:
const activeSectionPromises = [];
for (const heading of this.casePage.findContributionSurveyHeadings()) {
const headingId = sectionHeadingIdnormalizeWikiHeading(heading).id;
if (this.session.caseSections.indexOf(headingId) !== -1) {
activeSectionPromises.push(this.activateSection(this.casePage, heading)
Line 5,001 ⟶ 7,842:
addSectionOverlay(casePage, heading) {
var _a, _b, _c;
const sectionnormalizedHeading = casePage.getContributionSurveySectionnormalizeWikiHeading(heading).root;
const section = casePage.getContributionSurveySection(normalizedHeading);
const list = section.find((v) => v instanceof HTMLElement && v.tagName === 'UL');
const headingTop = window.scrollY +
heading normalizedHeading.getBoundingClientRect().bottom;
const sectionBottom = window.scrollY + ((_c = (_b = (_a = findNextSiblingElement(last(section))) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.top) !== null && _c !== void 0 ? _c : headingnormalizedHeading.parentElement.getBoundingClientRect().bottom);
const overlayHeight = sectionBottom - headingTop;
if (list != null) {
Line 5,057 ⟶ 7,900:
return false;
}
const sectionId = sectionHeadingIdnormalizeWikiHeading(heading).id;
this.sections.push(el);
const lastActiveSession = this.session.caseSections.indexOf(sectionId);
Line 5,065 ⟶ 7,908:
}
yield casePage.addActiveSection(sectionId);
if normalizeWikiHeading(heading).parentElementroot.classList.containsinsertAdjacentElement('mw-headingafterend', el.render()) {;
heading.parentElement.insertAdjacentElement('afterend', el.render());
}
else {
heading.insertAdjacentElement('afterend', el.render());
}
yield el.loadData();
mw.hook('deputy.load.cci.session').fire();
Line 5,090 ⟶ 7,928:
e0.casePage : e0;
const heading = e0 instanceof DeputyContributionSurveySection ?
e0.heading : normalizeWikiHeading(e1);
const sectionId = sectionHeadingId(heading).id;
const sectionListIndex = this.sections.indexOf(el);
if (el != null && sectionListIndex !== -1) {
Line 5,108 ⟶ 7,946:
yield DeputyRootSession.setSession(this.session);
yield casePage.removeActiveSection(sectionId);
this.addSectionOverlay(casePage, heading.h);
}
}
Line 5,131 ⟶ 7,969:
*/
class FakeDocument {
/**
* @param data Data to include in the iframe
*/
constructor(data) {
this.ready = false;
this.iframe = document.createElement('iframe');
this.iframe.style.display = 'none';
this.iframe.addEventListener('load', () => {
this.ready = true;
});
this.iframe.src = URL.createObjectURL(data instanceof Blob ? data : new Blob(data));
// Disables JavaScript, modals, popups, etc., but allows same-origin access.
this.iframe.setAttribute('sandbox', 'allow-same-origin');
document.getElementsByTagName('body')[0].appendChild(this.iframe);
}
/**
* Creates a fake document and waits for the `document` to be ready.
Line 5,163 ⟶ 7,986:
get document() {
return this.iframe.contentDocument;
}
/**
* @param data Data to include in the iframe
*/
constructor(data) {
this.ready = false;
this.iframe = document.createElement('iframe');
this.iframe.style.display = 'none';
this.iframe.addEventListener('load', () => {
this.ready = true;
});
this.iframe.src = URL.createObjectURL(data instanceof Blob ? data : new Blob(data));
// Disables JavaScript, modals, popups, etc., but allows same-origin access.
this.iframe.setAttribute('sandbox', 'allow-same-origin');
document.getElementsByTagName('body')[0].appendChild(this.iframe);
}
/**
Line 5,475 ⟶ 8,313:
constructor(options) {
var _a;
this.state = DeputyPageToolbarState.Open;
this.instanceId = generateId();
this.revisionStatusUpdateListener = this.onRevisionStatusUpdate.bind(this);
Line 5,481 ⟶ 8,320:
this.revision = (_a = options.revision) !== null && _a !== void 0 ? _a : mw.config.get('wgRevisionId');
}
this.state = window.deputy.config.cci.toolbarInitialState.get();
this.runAsyncJobs();
}
Line 5,499 ⟶ 8,339:
this.row = {
casePage: yield DeputyCase.build(this.options.caseId, normalizeTitle(this.options.caseTitle)),
title: normalizeTitle(this.options.title),
type: this.options.rowType
};
});
Line 5,623 ⟶ 8,464:
*/
renderRevisionNavigationButtons() {
if (this.row.type === 'pageonly') {
return h_1("div", { class: "dp-pt-section" }, unwrapWidget(new OO.ui.PopupButtonWidget({
icon: 'info',
framed: false,
label: mw.msg('deputy.session.page.pageonly.title'),
popup: {
head: true,
icon: 'infoFilled',
label: mw.msg('deputy.session.page.pageonly.title'),
$content: $(h_1("p", null, mw.msg('deputy.session.page.pageonly.help'))),
padded: true
}
})));
}
const getButtonClickHandler = (button, reverse) => {
return () => __awaiter(this, void 0, void 0, function* () {
Line 5,651 ⟶ 8,506:
}
catch (e) {
console.error(e);
this.setDisabled(false);
}
Line 5,711 ⟶ 8,566:
this.renderMenu(mw.msg('deputy.session.page.analysis'), deputyPageAnalysisOptions()),
this.renderMenu(mw.msg('deputy.session.page.tools'), deputyPageTools())));
}
/**
* Rends the page toolbar actions and main section, if the dropdown is open.
*/
renderOpen() {
return [
h_1("div", { class: "dp-pageToolbar-actions" },
h_1("div", { class: "dp-pageToolbar-close", role: "button", title: mw.msg('deputy.session.page.close'), onClick: () => this.setState(DeputyPageToolbarState.Hidden) }),
h_1("div", { class: "dp-pageToolbar-collapse", role: "button", title: mw.msg('deputy.session.page.collapse'), onClick: () => this.setState(DeputyPageToolbarState.Collapsed) })),
h_1("div", { class: "dp-pageToolbar-main" },
this.renderStatusDropdown(),
this.renderCaseInfo(),
this.renderRevisionInfo(),
this.revisionNavigationSection =
this.renderRevisionNavigationButtons(),
this.renderMenus())
];
}
/**
* Renders the collapsed toolbar button.
*
* @return The render button, to be included in the main toolbar.
*/
renderCollapsed() {
return h_1("div", { class: "dp-pageToolbar-collapsed", role: "button", title: mw.msg('deputy.session.page.expand'), onClick: () => this.setState(DeputyPageToolbarState.Open) });
}
/**
Line 5,716 ⟶ 8,596:
*/
render() {
console.log(this.state);
if (this.state === DeputyPageToolbarState.Hidden) {
const portletLink = mw.util.addPortletLink('p-tb', '#', mw.msg('deputy.session.page.open'), 'pt-dp-pt', mw.msg('deputy.session.page.open.tooltip'));
portletLink.querySelector('a').addEventListener('click', (event) => {
event.preventDefault();
this.setState(DeputyPageToolbarState.Open);
return false;
});
// Placeholder element
return this.element = h_1("div", { class: "deputy" });
}
else {
const toolbar = document.getElementById('pt-dp-pt');
if (toolbar) {
removeElement(toolbar);
}
}
return this.element = h_1("div", { class: "deputy dp-pageToolbar" },
this.renderStatusDropdownstate === DeputyPageToolbarState.Open && this.renderOpen(),
this.renderCaseInfostate === DeputyPageToolbarState.Collapsed && this.renderCollapsed(),);
this.renderRevisionInfo(),
this.revisionNavigationSection = this.renderRevisionNavigationButtons(),
this.renderMenus());
}
/**
Line 5,734 ⟶ 8,628:
(_c = this.previousRevisionButton) === null || _c === void 0 ? void 0 : _c.setDisabled(disabled);
(_d = this.nextRevisionButton) === null || _d === void 0 ? void 0 : _d.setDisabled(disabled);
}
/**
* Sets the display state of the toolbar. This will also set the
* initial state configuration option for the user.
*
* @param state
*/
setState(state) {
this.state = state;
window.deputy.config.cci.toolbarInitialState.set(state);
window.deputy.config.save();
swapElements(this.element, this.render());
}
/**
Line 5,758 ⟶ 8,664:
this.options.nextRevision = data.nextRevision;
// Re-render button.
swapElements(this.revisionNavigationSection, this.revisionNavigationSection =
this.renderRevisionNavigationButtons());
}
}
Line 5,792 ⟶ 8,699:
}
/**
*
* @param data
*/
Line 6,035 ⟶ 8,941:
}
}
 
/**
* Sleep for an specified amount of time.
*
* @param ms Milliseconds to sleep for.
*/
function sleep(ms) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((res) => {
setTimeout(res, ms);
});
});
}
 
/**
* Handles requests that might get hit by a rate limit. Wraps around
* `fetch` and ensures that all users of the Requester only request
* a single time per 100 ms on top of the time it takes to load
* previous requests. Also runs on four "threads", allowing at
* least a certain level of asynchronicity.
*
* Particularly used when a multitude of requests have a chance to
* DoS a service.
*/
class Requester {
/**
* Processes things in the fetchQueue.
*/
static processFetch() {
return __awaiter(this, void 0, void 0, function* () {
if (Requester.fetchActive >= Requester.maxThreads) {
return;
}
Requester.fetchActive++;
const next = Requester.fetchQueue.shift();
if (next) {
const data =
// eslint-disable-next-line prefer-spread
yield fetch.apply(null, next[1])
.then((res) => {
// Return false for survivable cases. In this case, we'll re-queue
// the request.
if (res.status === 429 || res.status === 502) {
return res.status;
}
else {
return res;
}
}, next[0][1]);
if (data instanceof Response) {
next[0][0](data);
}
else if (typeof data === 'number') {
Requester.fetchQueue.push(next);
}
}
yield sleep(Requester.minTime);
Requester.fetchActive--;
setTimeout(Requester.processFetch, 0);
});
}
}
/**
* Maximum number of requests to be processed simultaneously.
*/
Requester.maxThreads = 4;
/**
* Minimum amount of milliseconds to wait between each request.
*/
Requester.minTime = 100;
/**
* Requests to be performed. Takes tuples containing a resolve-reject pair and arguments
* to be passed into the fetch function.
*/
Requester.fetchQueue = [];
/**
* Number of requests currently being processed. Must be lower than
* {@link maxThreads}.
*/
Requester.fetchActive = 0;
Requester.fetch = (...args) => {
let res, rej;
const fakePromise = new Promise((_res, _rej) => {
res = _res;
rej = _rej;
});
Requester.fetchQueue.push([[res, rej], args]);
setTimeout(Requester.processFetch, 0);
return fakePromise;
};
 
/**
* API communication class
*/
class DeputyDispatch {
/**
* Creates a Deputy API instance.
*/
constructor() { }
/**
* Logs the user out of the API.
*/
logout() {
return __awaiter(this, void 0, void 0, function* () {
// TODO: Make logout API request
yield window.deputy.storage.setKV('api-token', null);
});
}
/**
* Logs in the user. Optional: only used for getting data on deleted revisions.
*/
login() {
return __awaiter(this, void 0, void 0, function* () {
this.token = yield window.deputy.storage.getKV('api-token');
// TODO: If token, set token
// TODO: If no token, start OAuth flow and make login API request
throw new Error('Unimplemented method.');
});
}
/**
* Returns a fully-formed HTTP URL from a given endpoint. This uses the wiki's
* set Dispatch endpoint and a given target (such as `/v1/revisions`) to get
* the full URL.
*
* @param endpoint The endpoint to get
*/
getEndpoint(endpoint) {
return __awaiter(this, void 0, void 0, function* () {
return `${(yield window.deputy.getWikiConfig()).core.dispatchRoot.get()
.href
.replace(/\/+$/, '')}/${endpoint.replace(/^\/+/, '')}`;
});
}
/**
* Gets expanded revision data from the API. This returns a response similar to the
* `revisions` object provided by action=query, but also includes additional information
* relevant (such as the parsed (HTML) comment, diff size, etc.)
*
* @param revisions The revisions to get the data for
* @return An object of expanded revision data mapped by revision IDs
*/
getExpandedRevisionData(revisions) {
return __awaiter(this, void 0, void 0, function* () {
return Requester.fetch(yield this.getEndpoint(`v1/revisions/${mw.config.get('wgWikiID')} `), {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'revisions=' + revisions.join('|')
})
.then((r) => r.json())
.then((j) => {
if (j.error) {
throw new Error(j.error.info);
}
return j;
})
.then((j) => j.revisions);
});
}
}
 
/**
*
*/
class DeputyPreferences {
constructor() {
this.preferences = DeputyPreferences.default;
}
/**
* @param id
* @return value
*/
get(id) {
var _a;
const idParts = id.split('.');
let current = this.preferences;
for (const part of idParts) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
current = (_a = current === null || current === void 0 ? void 0 : current[part]) !== null && _a !== void 0 ? _a : null;
}
return current;
}
}
DeputyPreferences.default = {
configVersion: 0,
lastVersion: '0.1.0',
cci: {
contentDefault: 'expanded'
}
};
 
/**
Line 6,234 ⟶ 8,948:
*/
function performHacks () {
var _a;
const HtmlEmitter = (_a = mw.jqueryMsg.HtmlEmitter) !== null && _a !== void 0 ? _a : {
prototype: Object.getPrototypeOf(new mw.jqueryMsg.Parser().emitter)
};
// This applies the {{int:message}} parser function with "MediaWiki:". This
// is due to VisualEditor using "MediaWiki:" in message values instead of "int:"
mw.jqueryMsg.HtmlEmitter.prototype.mediawiki =
mw.jqueryMsg.HtmlEmitter.prototype.int;
/**
* Performs a simple if check. Works just like the Extension:ParserFunctions
Line 6,250 ⟶ 8,968:
* @return see function description
*/
mw.jqueryMsg.HtmlEmitter.prototype.if = function (nodes) {
var _a, _b;
return (nodes[0].trim() ? ((_a = nodes[1]) !== null && _a !== void 0 ? _a : '') : ((_b = nodes[2]) !== null && _b !== void 0 ? _b : ''));
Line 6,260 ⟶ 8,978:
*
* @param nodes
* @return `{{text}}`
*/
mw.jqueryMsg.HtmlEmitter.prototype.template = function (nodes) {
return `{{${nodes.join('|')}}}`;
};
Line 6,269 ⟶ 8,987:
*
* @param nodes
* @return `{{text}}`
*/
mw.jqueryMsg.HtmlEmitter.prototype.subst = function (nodes) {
return `{{subst:${nodes.map((v) => typeof v === 'string' ? v : v.text()).join('|')}}}`;
};
Line 6,280 ⟶ 8,998:
* @see https://www.mediawiki.org/wiki/Help:Magic_words#URL_data
* @param nodes
* @return `/wiki/{page}?{query}`
*/
mw.jqueryMsg.HtmlEmitter.prototype.localurl = function (nodes) {
return mw.util.getUrl(nodes[0]) + '?' + nodes[1];
};
}
 
/**
* Works like `Object.values`.
*
* @param obj The object to get the values of.
* @return The values of the given object as an array
*/
function getObjectValues(obj) {
return Object.keys(obj).map((key) => obj[key]);
}
 
/**
* Transforms the `redirects` object returned by MediaWiki's `query` action into an
* object instead of an array.
*
* @param redirects
* @param normalized
* @return Redirects as an object
*/
function toRedirectsObject(redirects, normalized) {
var _a;
if (redirects == null) {
return {};
}
const out = {};
for (const redirect of redirects) {
out[redirect.from] = redirect.to;
}
// Single-level redirect-normalize loop check
for (const normal of normalized) {
out[normal.from] = (_a = out[normal.to]) !== null && _a !== void 0 ? _a : normal.to;
}
return out;
}
 
Line 6,370 ⟶ 9,054:
+value !== 1);
}
}
 
/**
* Checks if two MediaWiki page titles are equal.
*
* @param title1
* @param title2
* @return `true` if `title1` and `title2` refer to the same page
*/
function equalTitle(title1, title2) {
return normalizeTitle(title1).getPrefixedDb() === normalizeTitle(title2).getPrefixedDb();
}
 
Line 6,418 ⟶ 9,091:
setDateFromRevision() {
return __awaiter(this, void 0, void 0, function* () {
const revid = this.revisionInputWidget.getValue();
if (isNaN(+revid)) {
mw.notify(mw.msg('deputy.ante.dateAuto.invalid'), { type: 'error' });
this.updateButton();
return;
}
this
.setIcon('ellipsis')
.setDisabled(true);
this.dateInputWidget.setDisabled(true);
const revid = this.revisionInputWidget.getValue();
yield MwApi.action.get({
action: 'query',
Line 6,981 ⟶ 9,659:
*/
convertDeprecatedDiff() {
constreturn value__awaiter(this, =void 0, void 0, function* this.inputs.diff.getValue(); {
try { const value = this.inputs.diff.getValue();
try {
const url = new URL(value, window.___location.href);
if (!value) {
return;
}
if (url.host === window.___location.host) {
console.warn('Attempted to convert a diff URL from another wiki.');
}
// From the same wiki, accept deprecation
// Attempt to get values from URL parameters (when using `/w/index.php?action=diff`)
let oldid = url.searchParams.get('oldid');
let diff = url.searchParams.get('diff');
const title = url.searchParams.get('title');
// Attempt to get values from Special:Diff short-link
const diffSpecialPageCheck = /\/wiki\/Special:Diff\/(prev|next|\d+)(?:\/(prev|next|\d+))?/.exec(url.pathname);
if (diffSpecialPageCheck != null) {
if (diffSpecialPageCheck[1] != null &&
diffSpecialPageCheck[2] == null) {
// Special:Diff/diff
diff = diffSpecialPageCheck[1];
}
else if (diffSpecialPageCheck[1]url.host !== nullwindow.___location.host) &&{
diffSpecialPageCheck[2]if (!=(yield nullOO.ui.confirm(mw.msg('deputy.ante.copied.diffDeprecate.warnHost')))) {
// Special:Diff/oldid/diff return;
oldid = diffSpecialPageCheck[1];}
diff = diffSpecialPageCheck[2];
}
} // From the same wiki, accept deprecation immediately.
const confirmProcess = new OO.ui.Process();// Parse out info from this diff URL
for (const [_rowName, newValue] ofconst [parseInfo = parseDiffUrl(url);
['to_oldid'let { diff, oldid], } = parseInfo;
['to_diff',const diff],{ title } = parseInfo;
['to'// If only an oldid was provided, title]and no diff
] if (oldid && !diff) {
const rowName diff = _rowNameoldid;
if (newValue == null) {oldid = undefined;
continue;
}
ifconst confirmProcess = new OO.ui.Process();
// FieldLooping hasover anthe existingrow name and the value that will replace it.
this.copiedTemplateRowfor (const [rowName_rowName, newValue] !=of null &&[
this.copiedTemplateRow[rowName'to_oldid', oldid].length > 0 &&,
this.copiedTemplateRow[rowName'to_diff', diff] !== newValue) {,
confirmProcess.next(() => __awaiter(this['to', void 0, void 0, function* () {title]
]) {
const confirmPromise = OO.ui.confirm(mw.message('deputy.ante.copied.diffDeprecate.replace', rowName, this.copiedTemplateRow[rowName], newValue).text());
const confirmPromise.done((confirmed)rowName => {_rowName;
if (newValue == if (confirmednull) {
this.inputs[rowName].setValue(newValue)continue;
}
if });(
// Field has an returnexisting confirmPromise;value
}));this.copiedTemplateRow[rowName] != null &&
} this.copiedTemplateRow[rowName].length > 0 &&
else this.copiedTemplateRow[rowName] !== newValue) {
this confirmProcess.inputs[rowName].setValuenext(() => __awaiter(this, void 0, void 0, function* (newValue); {
const confirmPromise = dangerModeConfirm(window.CopiedTemplateEditor.config, mw.message('deputy.ante.copied.diffDeprecate.replace', rowName, this.copiedTemplateRow[rowName], newValue).text());
confirmPromise.done((confirmed) => {
if (confirmed) {
this.inputs[rowName].setValue(newValue);
this.fieldLayouts[rowName].toggle(true);
}
});
return confirmPromise;
}));
}
else {
this.inputs[rowName].setValue(newValue);
this.fieldLayouts[rowName].toggle(true);
}
}
confirmProcess.next(() => {
this.copiedTemplateRow.parent.save();
this.inputs.diff.setValue('');
if (!this.inputs.toggle.getValue()) {
this.fieldLayouts.diff.toggle(false);
}
});
confirmProcess.execute();
}
catch (e) {
error('Cannot convert `diff` parameter to URL.', e);
OO.ui.alert(mw.msg('deputy.ante.copied.diffDeprecate.failed'));
}
confirmProcess.next((}) => {;
this.copiedTemplateRow.parent.save();
this.inputs.diff.setValue('');
if (!this.inputs.toggle.getValue()) {
this.fieldLayouts.diff.toggle(false);
}
});
confirmProcess.execute();
}
catch (e) {
console.error('Cannot convert `diff` parameter to URL.', e);
OO.ui.alert(mw.msg('deputy.ante.copied.diffDeprecate.failed'));
}
}
/**
Line 7,085 ⟶ 9,760:
*/
class AttributionNoticeRow {
/**
*
* @param parent
*/
constructor(parent) {
this._parent = parent;
const r = window.btoa((Math.random() * 10000).toString()).slice(0, 6);
this.name = this.parent.name + '#' + r;
this.id = window.btoa(parent.node.getTarget().wt) + '-' + this.name;
}
/**
* @return The parent of this attribution notice row.
Line 7,111 ⟶ 9,776:
newParent.addRow(this);
this._parent = newParent;
}
/**
*
* @param parent
*/
constructor(parent) {
this._parent = parent;
const r = window.btoa((Math.random() * 10000).toString()).slice(0, 6);
this.name = this.parent.name + '#' + r;
this.id = window.btoa(parent.node.getTarget().wt) + '-' + this.name;
}
/**
Line 7,250 ⟶ 9,925:
const notices = parentTemplate.parsoid.findNoticeType(type);
// Confirm before merging.
OOdangerModeConfirm(window.uiCopiedTemplateEditor.confirm(config, mw.message('deputy.ante.merge.all.confirm', `${notices.length - 1}`).text()).done((confirmed) => {
if (confirmed) {
// Recursively merge all templates
Line 7,432 ⟶ 10,107:
deleteButton.on('click', () => {
if (this.copiedTemplate.rows.length > 0) {
OOdangerModeConfirm(window.uiCopiedTemplateEditor.confirm(config, mw.message('deputy.ante.copied.remove.confirm', `${this.copiedTemplate.rows.length}`).text()).done((confirmed) => {
if (confirmed) {
this.copiedTemplate.destroy();
Line 7,561 ⟶ 10,236:
*/
class AttributionNotice extends EventTarget {
/**
* Super constructor for AttributionNotice subclasses.
*
* @param node
* The ParsoidTransclusionTemplateNode of this notice.
*/
constructor(node) {
super();
this.node = node;
this.name = this.element.getAttribute('about')
.replace(/^#mwt/, '') + '-' + this.i;
this.id = window.btoa(node.getTarget().wt) + '-' + this.name;
this.parse();
}
/**
* @return The ParsoidDocument handling this notice (specifically its node).
Line 7,593 ⟶ 10,254:
get i() {
return this.node.i;
}
/**
* Super constructor for AttributionNotice subclasses.
*
* @param node
* The ParsoidTransclusionTemplateNode of this notice.
*/
constructor(node) {
super();
this.node = node;
this.name = this.element.getAttribute('about')
.replace(/^#mwt/, '') + '-' + this.i;
this.id = window.btoa(node.getTarget().wt) + '-' + this.name;
this.parse();
}
/**
Line 8,263 ⟶ 10,938:
deleteButton.on('click', () => {
if (this.splitArticleTemplate.rows.length > 0) {
OOdangerModeConfirm(window.uiCopiedTemplateEditor.confirm(config, mw.message('deputy.ante.splitArticle.remove.confirm', `${this.splitArticleTemplate.rows.length}`).text()).done((confirmed) => {
if (confirmed) {
this.splitArticleTemplate.destroy();
Line 9,054 ⟶ 11,729:
*/
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,072 ⟶ 11,747:
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,132 ⟶ 11,806:
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 9,349 ⟶ 11,999:
deleteButton.on('click', () => {
if (this.backwardsCopyTemplate.rows.length > 0) {
OOdangerModeConfirm(window.uiCopiedTemplateEditor.confirm(config, mw.message('deputy.ante.copied.remove.confirm', `${this.backwardsCopyTemplate.rows.length}`).text()).done((confirmed) => {
if (confirmed) {
this.backwardsCopyTemplate.destroy();
Line 9,777 ⟶ 12,427:
value: this.translatedPageTemplate.version,
placeholder: mw.msg('deputy.ante.translatedPage.version.placeholder'),
validate: /^\d+*$/gi
}),
insertversion: new OO.ui.TextInputWidget({
value: this.translatedPageTemplate.insertversion,
placeholder: mw.msg('deputy.ante.translatedPage.insertversion.placeholder'),
validate: /^[\d/]+*$/gi
}),
section: new OO.ui.TextInputWidget({
Line 11,446 ⟶ 14,096:
unblockExit: unblockExit
});
 
/**
* Opens a temporary window. Use this for dialogs that are immediately destroyed
* after running. Do NOT use this for re-openable dialogs, such as the main ANTE
* dialog.
*
* @param window
* @return A promise. Resolves when the window is closed.
*/
function openWindow(window) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((res) => {
let wm = new OO.ui.WindowManager();
document.getElementsByTagName('body')[0].appendChild(unwrapWidget(wm));
wm.addWindows([window]);
wm.openWindow(window);
wm.on('closing', (win, closed) => {
closed.then(() => {
if (wm) {
const _wm = wm;
wm = null;
removeElement(unwrapWidget(_wm));
_wm.destroy();
res();
}
});
});
});
});
}
 
let InternalCopiedTemplateEditorDialog;
Line 11,618 ⟶ 14,238:
.reduce((p, n) => p + n.length, 0);
return noticeCount ?
OOdangerModeConfirm(window.uiCopiedTemplateEditor.confirm(config, mw.message('deputy.ante.mergeAll.confirm', `${noticeCount}`).text()).done((confirmed) => {
if (!confirmed) {
return;
Line 11,626 ⟶ 14,246:
}
}) :
// TODO: i18n
OO.ui.alert('There are no templates to merge.');
});
Line 11,636 ⟶ 14,257:
});
resetButton.on('click', () => {
return OOdangerModeConfirm(window.uiCopiedTemplateEditor.confirm(config, mw.msg('deputy.ante.reset.confirm')).done((confirmed) => {
if (confirmed) {
this.loadTalkPage().then(() => {
Line 11,656 ⟶ 14,277:
// Original copied notice count.
const notices = this.parsoid.findNotices();
return OOdangerModeConfirm(window.uiCopiedTemplateEditor.confirm(config, mw.message('deputy.ante.delete.confirm', `${notices.length}`).text()).done((confirmed) => {
if (confirmed) {
for (const notice of notices) {
Line 11,715 ⟶ 14,336:
if (this.parsoid.getPage() !== talkPage) {
// Ask for user confirmation.
yield OOdangerModeConfirm(window.uiCopiedTemplateEditor.confirm(config, mw.message('deputy.ante.loadRedirect.message', talkPage, this.parsoid.getPage()).text(), {
title: mw.msg('deputy.ante.loadRedirect.title'),
actions: [
Line 11,794 ⟶ 14,415:
if (unwrapWidget(this.layout)
.querySelector('.oo-ui-flaggedElement-invalid') != null) {
return new OO.ui.Processalert(mw.msg('deputy.ante.invalid')) => {;
return OO.ui.alert(mw.msg('deputy.ante.invalid'))process;
});
}
// Saves the page.
Line 11,802 ⟶ 14,422:
return new mw.Api().postWithEditToken(Object.assign(Object.assign({}, changeTag(yield window.CopiedTemplateEditor.getWikiConfig())), { action: 'edit', format: 'json', formatversion: '2', utf8: 'true', title: this.parsoid.getPage(), text: yield this.parsoid.toWikitext(), summary: decorateEditSummary(mw.msg(this.parsoid.originalCount > 0 ?
'deputy.ante.content.modify' :
'deputy.ante.content.add'), window.CopiedTemplateEditor.config) })).catch((e, c) => {
throw errorToOO(e, c);
});
Line 11,912 ⟶ 14,532:
"deputy.ante.templateOptions": "Template options",
"deputy.ante.dateAuto": "Pull the date from the provided revision ID (`$1` parameter)",
"deputy.ante.dateAuto.invalid": "Parameter does not appear to be a valid revision ID.",
"deputy.ante.dateAuto.failed": "Could not pull date from revision: $1",
"deputy.ante.dateAuto.missing": "The revision $1 could not be found. Its page may have been deleted.",
Line 11,960 ⟶ 14,581:
"deputy.ante.copied.dateInvalid": "The previous date value, \"$1\", was not a valid date.",
"deputy.ante.copied.diffDeprecate": "The <code>to_diff</code> and <code>to_oldid</code> parameters are preferred in favor of the <code>diff</code> parameter.",
"deputy.ante.copied.diffDeprecate.warnHost": "The URL in this parameter is not the same as the wiki you're currently editing on. Continue?",
"deputy.ante.copied.diffDeprecate.replace": "The current value of '$1', \"$2\", will be replaced with \"$3\". Continue?",
"deputy.ante.copied.diffDeprecate.failed": "Cannot convert `diff` parameter to URL. See your browser console for more details.",
Line 12,026 ⟶ 14,648:
"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 12,063 ⟶ 14,685:
};
 
var deputySharedEnglish = {
/**
"deputy.name": "Deputy",
* Handles resource fetching operations.
"deputy.description": "Copyright cleanup and case processing tool for Wikipedia.",
*/
"deputy.ia": "Infringement Assistant",
class DeputyResources {
"deputy.ia.short": "I. Assistant",
/**
"deputy.ia.acronym": "Deputy: IA",
* Loads a resource from the provided resource root.
"deputy.ante": "Attribution Notice Template Editor",
*
"deputy.ante.short": "Attrib. Template Editor",
* @param path A path relative to the resource root.
"deputy.ante.acronym": "Deputy: ANTE",
* @return A Promise that resolves to the resource's content as a UTF-8 string.
"deputy.cancel": "Cancel",
*/
"deputy.review": "Review",
static loadResource(path) {
"deputy.review.title": "Review a diff of the changes to be made to the page",
return __awaiter(this, void 0, void 0, function* () {
"deputy.save": "Save",
switch (this.root.type) {
"deputy.close": "Close",
case 'url': {
"deputy.positiveDiff": "+{{FORMATNUM:$1}}",
const headers = new Headers();
"deputy.negativeDiff": "-{{FORMATNUM:$1}}",
headers.set('Origin', window.___location.origin);
"deputy.zeroDiff": "0",
return fetch((new URL(path, this.root.url)).href, {
"deputy.brokenDiff": "?",
method: 'GET',
"deputy.brokenDiff.explain": "The internal parent revision ID for this diff points to a non-existent revision. [[phab:T186280]] has more information.",
headers
"deputy.moreInfo": "More information",
}).then((r) => r.text());
"deputy.dismiss": "Dismiss",
}
"deputy.revision.cur": "cur",
case 'wiki': {
"deputy.revision.prev": "prev",
this.assertApi();
"deputy.revision.cur.tooltip": "Difference with latest revision",
return getPageContent(this.root.prefix.replace(/\/$/, '') + '/' + path, {}, this.api);
"deputy.revision.prev.tooltip": "Difference with preceding revision",
}
"deputy.revision.talk": "talk",
}
"deputy.revision.contribs": "contribs",
});
"deputy.revision.bytes": "{{FORMATNUM:$1}} bytes",
}
"deputy.revision.byteChange": "{{FORMATNUM:$1}} bytes after change of this size",
/**
"deputy.revision.tags": "{{PLURAL:$1|Tag|Tags}}:",
* Ensures that `this.api` is a valid ForeignApi.
"deputy.revision.new": "N",
*/
"deputy.revision.new.tooltip": "This edit created a new page.",
static assertApi() {
"deputy.comma-separator": ", ",
if (this.root.type !== 'wiki') {
"deputy.diff": "Review your changes",
return;
"deputy.diff.load": "Loading changes...",
}
"deputy.diff.no-changes": "No difference",
if (!this.api) {
"deputy.diff.error": "An error occurred while trying to get the comparison.",
this.api = new mw.ForeignApi(this.root.wiki.toString(), {
"deputy.loadError.userConfig": "Due to an error, your Deputy configuration has been reset.",
// Force anonymous mode. Deputy doesn't need user data anyway,
"deputy.loadError.wikiConfig": "An error occurred while loading this wiki's Deputy configuration. Please report this to the Deputy maintainers for this wiki."
// so this should be fine.
anonymous: true
});
}
}
}
/**
* The root of all Deputy resources. This should serve static data that Deputy will
* use to load resources such as language files.
*/
DeputyResources.root = {
type: 'url',
url: new URL('https://zoomiebot.toolforge.org/deputy/')
};
 
/**
* Handles internationalization and localization for Deputy and sub-modules.
*/
class DeputyLanguage {
/**
* Loads the language for this Deputy interface.
*
* @param module The module to load a language pack for.
* @param fallback A fallback language pack to load. Since this is an actual
* `Record`, this relies on the language being bundled with the userscript. This ensures
* that a language pack is always available, even if a language file could not be loaded.
*/
static load(module, fallback) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const lang = (_a = window.deputyLang) !== null && _a !== void 0 ? _a : 'en';
// The loaded language resource file. Forced to `null` if using English, since English
// is our fallback language.
const langResource = lang === 'en' ? null :
yield DeputyResources.loadResource(`i18n/${module}/${lang}.json`)
.catch(() => {
// Could not find requested language file.
return null;
});
if (!langResource) {
// Fall back.
for (const key in fallback) {
mw.messages.set(key, fallback[key]);
}
return;
}
try {
const langData = JSON.parse(langResource);
for (const key in langData) {
mw.messages.set(key, langData[key]);
}
}
catch (e) {
console.error(e);
mw.notify(
// No languages to fall back on. Do not translate this string.
'Deputy: Requested language page is not a valid JSON file.', { type: 'error' });
// Fall back.
for (const key in fallback) {
mw.messages.set(key, fallback[key]);
}
}
if (lang !== mw.config.get('wgUserLanguage')) {
yield DeputyLanguage.loadSecondary();
}
});
}
/**
* Loads a specific moment.js locale. It's possible for nothing to be loaded (e.g. if the
* locale is not supported by moment.js), in which case nothing happens and English is
* likely used.
*
* @param locale The locale to load. `window.deputyLang` by default.
*/
static loadMomentLocale(locale = window.deputyLang) {
return __awaiter(this, void 0, void 0, function* () {
if (locale === 'en') {
// Always loaded.
return;
}
if (mw.loader.getState('moment') !== 'ready') {
// moment.js is not yet loaded.
console.warn('Deputy tried loading moment.js locales but moment.js is not yet ready.');
return;
}
if (window.moment.locales().indexOf(locale) !== -1) {
// Already loaded.
return;
}
yield mw.loader.using('moment')
.then(() => true, () => null);
yield mw.loader.getScript(new URL(`resources/lib/moment/locale/${locale}.js`, new URL(mw.util.wikiScript('index'), window.___location.href)).href).then(() => true, () => null);
});
}
/**
* There are times when the user interface language do not match the wiki content
* language. Since Deputy's edit summary and content strings are found in the
* i18n files, however, there are cases where the wrong language would be used.
*
* This solves this problem by manually overriding content-specific i18n keys with
* the correct language. By default, all keys that match `deputy.*.content.**` get
* overridden.
*
* There are no fallbacks for this. If it fails, the user interface language is
* used anyway. In the event that the user interface language is not English,
* this will cause awkward situations. Whether or not something should be done to
* catch this specific edge case will depend on how frequent it happens.
*
* @param locale
* @param match
*/
static loadSecondary(locale = mw.config.get('wgContentLanguage'), match = /^deputy\.(?:[^.]+)?\.content\./g) {
return __awaiter(this, void 0, void 0, function* () {
// The loaded language resource file. Forced to `null` if using English, since English
// is our fallback language.
const langResource = locale === 'en' ? null :
yield DeputyResources.loadResource(`i18n/${module}/${locale}.json`)
.catch(() => {
// Could not find requested language file.
return null;
});
if (!langResource) {
return;
}
try {
const langData = JSON.parse(langResource);
for (const key in langData) {
if (cloneRegex$1(match).test(key)) {
mw.messages.set(key, langData[key]);
}
}
}
catch (e) {
// Silent failure.
console.error('Deputy: Requested language page is not a valid JSON file.', e);
}
});
}
}
 
/**
* Refers to a specific setting on the configuration. Should be initialized with
* a raw (serialized) type and an actual (deserialized) type.
*
* This is used for both client and wiki-wide configuration.
*/
class Setting {
/**
*
* @param options
* @param options.serialize Serialization function. See {@link Setting#serialize}
* @param options.deserialize Deserialization function. See {@link Setting#deserialize}
* @param options.alwaysSave See {@link Setting#alwaysSave}.
* @param options.defaultValue Default value. If not supplied, `undefined` is used.
* @param options.displayOptions See {@link Setting#displayOptions}
* @param options.allowedValues See {@link Setting#allowedValues}
*/
constructor(options) {
var _a, _b;
this.serialize = options.serialize;
this.deserialize = options.deserialize;
this.displayOptions = options.displayOptions;
this.allowedValues = options.allowedValues;
this.value = this.defaultValue = options.defaultValue;
this.alwaysSave = options.alwaysSave;
this.isDisabled = ((_a = options.displayOptions) === null || _a === void 0 ? void 0 : _a.disabled) != null ?
(typeof options.displayOptions.disabled === 'function' ?
options.displayOptions.disabled.bind(this) :
() => options.displayOptions.disabled) : () => false;
this.isHidden = ((_b = options.displayOptions) === null || _b === void 0 ? void 0 : _b.hidden) != null ?
(typeof options.displayOptions.hidden === 'function' ?
options.displayOptions.hidden.bind(this) :
() => options.displayOptions.hidden) : () => false;
}
/**
* @return `true` if `this.value` is not null or undefined.
*/
ok() {
return this.value != null;
}
/**
* @return The current value of this setting.
*/
get() {
return this.value;
}
/**
* Sets the value and performs validation. If the input is an invalid value, and
* `throwOnInvalid` is false, the value will be reset to default.
*
* @param v
* @param throwOnInvalid
*/
set(v, throwOnInvalid = false) {
if (this.locked) {
console.warn('Attempted to modify locked setting.');
return;
}
if (this.allowedValues) {
const keys = Array.isArray(this.allowedValues) ?
this.allowedValues : getObjectValues(this.allowedValues);
if (Array.isArray(v)) {
if (v.some((v1) => keys.indexOf(v1) === -1)) {
if (throwOnInvalid) {
throw new Error('Invalid value');
}
v = this.value;
}
}
else {
if (this.allowedValues && keys.indexOf(v) === -1) {
if (throwOnInvalid) {
throw new Error('Invalid value');
}
v = this.value;
}
}
}
this.value = v;
}
/**
* Resets this setting to its original value.
*/
reset() {
this.set(this.defaultValue);
}
/**
* Parses a given raw value and mutates the setting.
*
* @param raw The raw value to parse.
* @return The new value.
*/
load(raw) {
return (this.value = this.deserialize(raw));
}
/**
* Prevents the value of the setting from being changed. Used for debugging.
*/
lock() {
this.locked = true;
}
/**
* Allows the value of the setting to be changed. Used for debugging.
*/
unlock() {
this.locked = false;
}
}
Setting.basicSerializers = {
serialize: (value) => value,
deserialize: (value) => value
};
 
/**
* Works like `Object.fromEntries`
*
* @param obj The object to get the values of.
* @return The values of the given object as an array
*/
function fromObjectEntries(obj) {
const i = {};
for (const [key, value] of obj) {
i[key] = value;
}
return i;
}
 
/**
* Generates configuration properties for serialized <b>string</b> enums.
*
* Trying to use anything that isn't a string enum here (union enum, numeral enum)
* will likely cause serialization/deserialization failures.
*
* @param _enum
* @param defaultValue
* @return Setting properties.
*/
function generateEnumConfigurationProperties(_enum, defaultValue) {
return {
serialize: (value) => value === defaultValue ? undefined : value,
deserialize: (value) => value,
displayOptions: {
type: 'radio'
},
allowedValues: fromObjectEntries(Array.from(new Set(Object.keys(_enum)).values())
.map((v) => [_enum[v], _enum[v]])),
defaultValue: defaultValue
};
}
var PortletNameView;
(function (PortletNameView) {
PortletNameView["Full"] = "full";
PortletNameView["Short"] = "short";
PortletNameView["Acronym"] = "acronym";
})(PortletNameView || (PortletNameView = {}));
 
var CompletionAction;
(function (CompletionAction) {
CompletionAction["Nothing"] = "nothing";
CompletionAction["Reload"] = "reload";
})(CompletionAction || (CompletionAction = {}));
var TripleCompletionAction;
(function (TripleCompletionAction) {
TripleCompletionAction["Nothing"] = "nothing";
TripleCompletionAction["Reload"] = "reload";
TripleCompletionAction["Redirect"] = "redirect";
})(TripleCompletionAction || (TripleCompletionAction = {}));
 
/**
* A configuration. Defines settings and setting groups.
*/
class ConfigurationBase {
/**
* Creates a new Configuration.
*/
constructor() { }
// eslint-disable-next-line jsdoc/require-returns-check
/**
* @return the configuration from the current wiki.
*/
static load() {
throw new Error('Unimplemented method.');
}
/**
* Deserializes a JSON configuration into this configuration. This WILL overwrite
* past settings.
*
* @param serializedData
*/
deserialize(serializedData) {
var _a;
for (const group in this.all) {
const groupObject = this.all[group];
for (const key in this.all[group]) {
const setting = groupObject[key];
if (((_a = serializedData === null || serializedData === void 0 ? void 0 : serializedData[group]) === null || _a === void 0 ? void 0 : _a[key]) !== undefined) {
setting.set(setting.deserialize ?
// Type-checked upon declaration, just trust it to skip errors.
setting.deserialize(serializedData[group][key]) :
serializedData[group][key]);
}
}
}
}
/**
* @return the serialized version of the configuration. All `undefined` values are stripped
* from output. If a category remains unchanged from defaults, it is skipped. If the entire
* configuration remains unchanged, `null` is returned.
*/
serialize() {
const config = {};
for (const group of Object.keys(this.all)) {
const groupConfig = {};
const groupObject = this.all[group];
for (const key in this.all[group]) {
const setting = groupObject[key];
if (setting.get() === setting.defaultValue && !setting.alwaysSave) {
continue;
}
const serialized = setting.serialize ?
// Type-checked upon declaration, just trust it to skip errors.
setting.serialize(setting.get()) : setting.get();
if (serialized !== undefined) {
groupConfig[key] = serialized;
}
}
if (Object.keys(groupConfig).length > 0) {
config[group] = groupConfig;
}
}
if (Object.keys(config).length > 0) {
return config;
}
else {
return null;
}
}
}
ConfigurationBase.configVersion = 1;
 
/**
* A configuration. Defines settings and setting groups.
*/
class UserConfiguration extends ConfigurationBase {
/**
* Creates a new Configuration.
*
* @param serializedData
*/
constructor(serializedData = {}) {
var _a;
super();
this.core = {
/**
* Numerical code that identifies this config version. Increments for every breaking
* configuration file change.
*/
configVersion: new Setting({
defaultValue: UserConfiguration.configVersion,
displayOptions: { hidden: true },
alwaysSave: true
}),
language: new Setting({
defaultValue: mw.config.get('wgUserLanguage'),
displayOptions: { type: 'select' }
}),
modules: new Setting({
defaultValue: ['cci', 'ante', 'ia'],
displayOptions: { type: 'checkboxes' },
allowedValues: ['cci', 'ante', 'ia']
}),
portletNames: new Setting(generateEnumConfigurationProperties(PortletNameView, PortletNameView.Full)),
seenAnnouncements: new Setting({
defaultValue: [],
displayOptions: { hidden: true }
})
};
this.cci = {
enablePageToolbar: new Setting({
defaultValue: true,
displayOptions: {
type: 'checkbox'
}
}),
showCvLink: new Setting({
defaultValue: true,
displayOptions: {
type: 'checkbox'
}
}),
showUsername: new Setting({
defaultValue: false,
displayOptions: {
type: 'checkbox'
}
}),
autoShowDiff: new Setting({
defaultValue: false,
displayOptions: {
type: 'checkbox'
}
}),
maxRevisionsToAutoShowDiff: new Setting({
defaultValue: 2,
displayOptions: {
type: 'number',
// Force any due to self-reference
disabled: (config) => !config.cci.autoShowDiff.get(),
extraOptions: {
min: 1
}
}
}),
maxSizeToAutoShowDiff: new Setting({
defaultValue: 500,
displayOptions: {
type: 'number',
// Force any due to self-reference
disabled: (config) => !config.cci.autoShowDiff.get(),
extraOptions: {
min: -1
}
}
}),
forceUtc: new Setting({
defaultValue: false,
displayOptions: {
type: 'checkbox'
}
}),
signingBehavior: new Setting(generateEnumConfigurationProperties(ContributionSurveyRowSigningBehavior, ContributionSurveyRowSigningBehavior.Always)),
openOldOnContinue: new Setting({
defaultValue: false,
displayOptions: {
type: 'checkbox'
}
})
};
this.ante = {
enableAutoMerge: new Setting({
defaultValue: false,
displayOptions: {
type: 'checkbox',
disabled: 'unimplemented'
}
}),
onSubmit: new Setting(generateEnumConfigurationProperties(CompletionAction, CompletionAction.Reload))
};
this.ia = {
responses: new Setting(Object.assign(Object.assign({}, Setting.basicSerializers), { defaultValue: null, displayOptions: {
disabled: 'unimplemented',
type: 'unimplemented'
} })),
enablePageToolbar: new Setting({
defaultValue: true,
displayOptions: {
type: 'checkbox',
disabled: 'unimplemented'
}
}),
defaultEntirePage: new Setting({
defaultValue: true,
displayOptions: {
type: 'checkbox'
}
}),
defaultFromUrls: new Setting({
defaultValue: true,
displayOptions: {
type: 'checkbox'
}
}),
onHide: new Setting(generateEnumConfigurationProperties(TripleCompletionAction, TripleCompletionAction.Reload)),
onSubmit: new Setting(generateEnumConfigurationProperties(TripleCompletionAction, TripleCompletionAction.Reload)),
onBatchSubmit: new Setting(generateEnumConfigurationProperties(CompletionAction, CompletionAction.Reload))
};
this.type = 'user';
this.all = { core: this.core, cci: this.cci, ante: this.ante, ia: this.ia };
if (serializedData) {
this.deserialize(serializedData);
}
if (mw.storage.get(`mw-${UserConfiguration.optionKey}-lastVersion`) !== version) ;
mw.storage.set(`mw-${UserConfiguration.optionKey}-lastVersion`, version);
if ((_a = window.deputy) === null || _a === void 0 ? void 0 : _a.comms) {
window.deputy.comms.addEventListener('userConfigUpdate', (e) => {
// Update the configuration based on another tab's message.
this.deserialize(e.data.config);
});
}
}
/**
* @return the configuration from the current wiki.
*/
static load() {
const config = new UserConfiguration();
try {
if (mw.user.options.get(UserConfiguration.optionKey)) {
const decodedOptions = JSON.parse(mw.user.options.get(UserConfiguration.optionKey));
config.deserialize(decodedOptions);
}
}
catch (e) {
console.error(e, mw.user.options.get(UserConfiguration.optionKey));
mw.hook('deputy.i18nDone').add(function notifyConfigFailure() {
mw.notify(mw.msg('deputy.loadError.userConfig'), {
type: 'error'
});
mw.hook('deputy.i18nDone').remove(notifyConfigFailure);
});
config.save();
}
return config;
}
/**
* Saves the configuration.
*/
save() {
return __awaiter(this, void 0, void 0, function* () {
yield MwApi.action.saveOption(UserConfiguration.optionKey, JSON.stringify(this.serialize()));
});
}
}
UserConfiguration.configVersion = 1;
UserConfiguration.optionKey = 'userjs-deputy';
 
var deputySettingsStyles = ".deputy-setting {margin-bottom: 1em;}.deputy-setting > .oo-ui-fieldLayout-align-top .oo-ui-fieldLayout-header .oo-ui-labelElement-label {font-weight: bold;}.dp-mb {margin-bottom: 1em;}.deputy-about {display: flex;}.deputy-about > :first-child {flex: 0;}.deputy-about > :first-child > img {height: 5em;width: auto;}.ltr .deputy-about > :first-child {margin-right: 1em;}.rtl .deputy-about > :first-child {margin-left: 1em;}.deputy-about > :nth-child(2) {flex: 1;}.deputy-about > :nth-child(2) > :first-child > * {display: inline;}.deputy-about > :nth-child(2) > :first-child > :first-child {font-weight: bold;font-size: 2em;}.deputy-about > :nth-child(2) > :first-child > :nth-child(2) {color: gray;vertical-align: bottom;margin-left: 0.4em;}.deputy-about > :nth-child(2) > :not(:first-child) {margin-top: 0.5em;}.ltr .deputy-about + div > :not(:last-child) {margin-right: 0.5em;}.rtl .deputy-about + div > :not(:last-child) {margin-left: 0.5em;}.ltr .deputy-about + div {text-align: right;}.rtl .deputy-about + div {text-align: left;}";
 
/* eslint-disable mediawiki/msg-doc */
let InternalConfigurationGroupTabPanel$1;
/**
* Initializes the process element.
*/
function initConfigurationGroupTabPanel$1() {
InternalConfigurationGroupTabPanel$1 = class ConfigurationGroupTabPanel extends OO.ui.TabPanelLayout {
/**
* @param config Configuration to be passed to the element.
*/
constructor(config) {
super(`configurationGroupPage_${config.group}`);
this.config = config;
this.mode = config.config instanceof UserConfiguration ? 'user' : 'wiki';
if (this.mode === 'wiki') {
this.$element.append(new OO.ui.MessageWidget({
classes: [
'deputy', 'dp-mb'
],
type: 'warning',
label: mw.msg('deputy.settings.dialog.wikiConfigWarning')
}).$element);
}
for (const settingKey of Object.keys(this.settings)) {
const setting = this.settings[settingKey];
if (setting.isHidden(this.config.config)) {
continue;
}
switch (setting.displayOptions.type) {
case 'checkbox':
this.$element.append(this.newCheckboxField(settingKey, setting));
break;
case 'checkboxes':
this.$element.append(this.newCheckboxesField(settingKey, setting));
break;
case 'radio':
this.$element.append(this.newRadioField(settingKey, setting));
break;
case 'text':
this.$element.append(this.newStringField(settingKey, setting, setting.displayOptions.extraOptions));
break;
case 'number':
this.$element.append(this.newNumberField(settingKey, setting, setting.displayOptions.extraOptions));
break;
case 'page':
this.$element.append(this.newPageField(settingKey, setting, setting.displayOptions.extraOptions));
break;
case 'code':
this.$element.append(this.newCodeField(settingKey, setting, setting.displayOptions.extraOptions));
break;
default:
this.$element.append(this.newUnimplementedField(settingKey));
break;
}
}
this.on('change', () => {
console.log(this.config.config);
console.log(this.config.config.serialize());
});
}
/**
* @return The {@Link Setting}s for this group.
*/
get settings() {
return this.config.config.all[this.config.group];
}
/**
* Sets up the tab item
*/
setupTabItem() {
this.tabItem.setLabel(this.getMsg(this.config.group));
return this;
}
/**
* @return the i18n message for this setting tab.
*
* @param messageKey
*/
getMsg(messageKey) {
return mw.msg(`deputy.setting.${this.mode}.${messageKey}`);
}
/**
* Gets the i18n message for a given setting.
*
* @param settingKey
* @param key
* @return A localized string
*/
getSettingMsg(settingKey, key) {
return this.getMsg(`${this.config.group}.${settingKey}.${key}`);
}
/**
* @param settingKey
* @param allowedValues
* @return a tuple array of allowed values that can be used in OOUI `items` parameters.
*/
getAllowedValuesArray(settingKey, allowedValues) {
const items = [];
if (Array.isArray(allowedValues)) {
for (const key of allowedValues) {
const message = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.${key}`);
items.push([key, message.exists() ? message.text() : key]);
}
}
else {
for (const key of Object.keys(allowedValues)) {
const message = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.${key}`);
items.push([key, message.exists() ? message.text() : key]);
}
}
return items;
}
/**
* Creates an unimplemented setting notice.
*
* @param settingKey
* @return An HTMLElement of the given setting's field.
*/
newUnimplementedField(settingKey) {
const desc = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.description`);
return h_1("div", { class: "deputy-setting" },
h_1("b", null, this.getSettingMsg(settingKey, 'name')),
desc.exists() ? h_1("p", { style: { fontSize: '0.925em', color: '#54595d' } }, desc.text()) : '',
h_1("p", null, mw.msg('deputy.settings.dialog.unimplemented')));
}
/**
* Creates a checkbox field.
*
* @param settingKey
* @param setting
* @return An HTMLElement of the given setting's field.
*/
newCheckboxField(settingKey, setting) {
const isDisabled = setting.isDisabled(this.config.config);
const desc = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.description`);
const field = new OO.ui.CheckboxInputWidget({
selected: setting.get(),
disabled: isDisabled !== undefined && isDisabled !== false
});
const layout = new OO.ui.FieldLayout(field, {
align: 'inline',
label: this.getSettingMsg(settingKey, 'name'),
help: typeof isDisabled === 'string' ?
this.getSettingMsg(settingKey, isDisabled) :
desc.exists() ? desc.text() : undefined,
helpInline: true
});
field.on('change', () => {
setting.set(field.isSelected());
this.emit('change');
});
// Attach disabled re-checker
this.on('change', () => {
field.setDisabled(!!setting.isDisabled(this.config.config));
});
return h_1("div", { class: "deputy-setting" }, unwrapWidget(layout));
}
/**
* Creates a new checkbox set field.
*
* @param settingKey
* @param setting
* @return An HTMLElement of the given setting's field.
*/
newCheckboxesField(settingKey, setting) {
const isDisabled = setting.isDisabled(this.config.config);
const desc = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.description`);
const field = new OO.ui.CheckboxMultiselectInputWidget({
value: setting.get(),
disabled: isDisabled !== undefined && isDisabled !== false,
options: this.getAllowedValuesArray(settingKey, setting.allowedValues)
.map(([key, label]) => ({ data: key, label }))
});
const layout = new OO.ui.FieldLayout(field, {
align: 'top',
label: this.getSettingMsg(settingKey, 'name'),
help: typeof isDisabled === 'string' ?
this.getSettingMsg(settingKey, isDisabled) :
desc.exists() ? desc.text() : undefined,
helpInline: true
});
// TODO: @types/oojs-ui limitation
field.on('change', (items) => {
const finalData = Array.isArray(setting.allowedValues) ?
items :
field.getValue().map((v) => setting.allowedValues[v]);
setting.set(finalData);
this.emit('change');
});
// Attach disabled re-checker
this.on('change', () => {
field.setDisabled(!!setting.isDisabled(this.config.config));
});
return h_1("div", { class: "deputy-setting" }, unwrapWidget(layout));
}
/**
* Creates a new radio set field.
*
* @param settingKey
* @param setting
* @return An HTMLElement of the given setting's field.
*/
newRadioField(settingKey, setting) {
var _a;
const isDisabled = setting.isDisabled(this.config.config);
const desc = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.description`);
const field = new OO.ui.RadioSelectWidget({
disabled: isDisabled !== undefined && isDisabled !== false &&
!((_a = setting.displayOptions.readOnly) !== null && _a !== void 0 ? _a : false),
items: this.getAllowedValuesArray(settingKey, setting.allowedValues)
.map(([key, label]) => new OO.ui.RadioOptionWidget({
data: key,
label: label,
selected: setting.get() === key
})),
multiselect: false
});
const layout = new OO.ui.FieldLayout(field, {
align: 'top',
label: this.getSettingMsg(settingKey, 'name'),
help: typeof isDisabled === 'string' ?
this.getSettingMsg(settingKey, isDisabled) :
desc.exists() ? desc.text() : undefined,
helpInline: true
});
// OOUIRadioInputWidget
field.on('select', (items) => {
const finalData = Array.isArray(setting.allowedValues) ?
items.data :
setting.allowedValues[items.data];
setting.set(finalData);
this.emit('change');
});
// Attach disabled re-checker
this.on('change', () => {
field.setDisabled(!!setting.isDisabled(this.config.config));
});
return h_1("div", { class: "deputy-setting" }, unwrapWidget(layout));
}
/**
* Creates a new field that acts like a string field.
*
* @param FieldClass
* @param settingKey
* @param setting
* @param extraFieldOptions
* @return A Deputy setting field
*/
newStringLikeField(FieldClass, settingKey, setting, extraFieldOptions = {}) {
var _a, _b, _c;
const isDisabled = setting.isDisabled(this.config.config);
const desc = mw.message(`deputy.setting.${this.mode}.${this.config.group}.${settingKey}.description`);
const field = new FieldClass(Object.assign({ readOnly: (_a = setting.displayOptions.readOnly) !== null && _a !== void 0 ? _a : false, value: (_c = (_b = setting.serialize) === null || _b === void 0 ? void 0 : _b.call(setting, setting.get())) !== null && _c !== void 0 ? _c : setting.get(), disabled: isDisabled !== undefined && isDisabled !== false }, extraFieldOptions));
const layout = new OO.ui.FieldLayout(field, {
align: 'top',
label: this.getSettingMsg(settingKey, 'name'),
help: typeof isDisabled === 'string' ?
this.getSettingMsg(settingKey, isDisabled) :
desc.exists() ? desc.text() : undefined,
helpInline: true
});
if (FieldClass === OO.ui.NumberInputWidget) {
field.on('change', (value) => {
setting.set(+value);
this.emit('change');
});
}
else {
field.on('change', (value) => {
setting.set(value);
this.emit('change');
});
}
// Attach disabled re-checker
this.on('change', () => {
field.setDisabled(setting.isDisabled(this.config.config));
});
return h_1("div", { class: "deputy-setting" }, unwrapWidget(layout));
}
/**
* Creates a new string setting field.
*
* @param settingKey
* @param setting
* @param extraFieldOptions
* @return An HTMLElement of the given setting's field.
*/
newStringField(settingKey, setting, extraFieldOptions) {
return this.newStringLikeField(OO.ui.TextInputWidget, settingKey, setting, extraFieldOptions);
}
/**
* Creates a new number setting field.
*
* @param settingKey
* @param setting
* @param extraFieldOptions
* @return An HTMLElement of the given setting's field.
*/
newNumberField(settingKey, setting, extraFieldOptions) {
return this.newStringLikeField(OO.ui.NumberInputWidget, settingKey, setting, extraFieldOptions);
}
/**
* Creates a new page title setting field.
*
* @param settingKey
* @param setting
* @param extraFieldOptions
* @return An HTMLElement of the given setting's field.
*/
newPageField(settingKey, setting, extraFieldOptions) {
return this.newStringLikeField(mw.widgets.TitleInputWidget, settingKey, setting, extraFieldOptions);
}
/**
* Creates a new code setting field.
*
* @param settingKey
* @param setting
* @param extraFieldOptions
* @return An HTMLElement of the given setting's field.
*/
newCodeField(settingKey, setting, extraFieldOptions) {
return this.newStringLikeField(OO.ui.MultilineTextInputWidget, settingKey, setting, extraFieldOptions);
}
};
}
/**
* Creates a new ConfigurationGroupTabPanel.
*
* @param config Configuration to be passed to the element.
* @return A ConfigurationGroupTabPanel object
*/
function ConfigurationGroupTabPanel (config) {
if (!InternalConfigurationGroupTabPanel$1) {
initConfigurationGroupTabPanel$1();
}
return new InternalConfigurationGroupTabPanel$1(config);
}
 
var deputySettingsEnglish = {
"deputy.about.version": "v$1 ($2)",
"deputy.about": "About",
"deputy.about.homepage": "Homepage",
"deputy.about.openSource": "Source",
"deputy.about.contact": "Contact",
"deputy.about.credit": "Deputy was made with the help of the English Wikipedia Copyright Cleanup WikiProject and the Wikimedia Foundation.",
"deputy.about.license": "Deputy is licensed under the <a href=\"$1\">Apache License 2.0</a>. The source code for Deputy is available on <a href=\"$2\">GitHub</a>, and is free for everyone to view and suggest changes.",
"deputy.about.thirdParty": "Deputy is bundled with third party libraries to make development easier. All libraries have been vetted for user security and license compatibility. For more information, see the <a href=\"$1\">\"Licensing\"</a> section on Deputy's README.",
"deputy.about.buildInfo": "Deputy v$1 ($2), committed $3.",
"deputy.about.footer": "Made with love, coffee, and the tears of copyright editors.",
"deputy.settings.portlet": "Deputy preferences",
"deputy.settings.portlet.tooltip": "Opens a dialog to modify Deputy preferences",
"deputy.settings.wikiEditIntro.title": "This is a Deputy configuration page",
"deputy.settings.wikiEditIntro.current": "Deputy's active configuration comes from this page. Changing this page will affect the settings of all Deputy users on this wiki. Edit responsibly, and avoid making significant changes without prior discussion.",
"deputy.settings.wikiEditIntro.other": "This is a valid Deputy configuration page, but the configuration is currently being loaded from {{wikilink:$1}}. If this becomes the active configuration page, changing it will affect the settings of all Deputy users on this wiki. Edit responsibly, and avoid making significant changes without prior discussion.",
"deputy.settings.wikiEditIntro.edit.current": "Modify configuration",
"deputy.settings.wikiEditIntro.edit.other": "Modify this configuration",
"deputy.settings.wikiEditIntro.edit.otherCurrent": "Modify the active configuration",
"deputy.settings.wikiEditIntro.edit.protected": "This page's protection settings do not allow you to edit the page.",
"deputy.settings.wikiOutdated": "Outdated configuration",
"deputy.settings.wikiOutdated.help": "Deputy has detected a change in this wiki's configuration for all Deputy users. We've automatically downloaded the changes for you, but you have to reload to apply the changes.",
"deputy.settings.wikiOutdated.reload": "Reload",
"deputy.settings.dialog.title": "Deputy Preferences",
"deputy.settings.dialog.unimplemented": "A way to modify this setting has not yet been implemented. Check back later!",
"deputy.settings.saved": "Preferences saved. Please refresh the page to see changes.",
"deputy.settings.dialog.wikiConfigWarning": "You are currently editing a wiki-wide Deputy configuration page. Changes made to this page may affect the settings of all Deputy users on this wiki. Edit responsibly, and avoid making significant changes without prior discussion.",
"deputy.setting.user.core": "Deputy",
"deputy.setting.user.core.language.name": "Language",
"deputy.setting.user.core.language.description": "Deputy's interface language. English (US) is used by default, and is used as a fallback if no translations are available. If the content of the wiki you work on is in a different language from the interface language, Deputy will need to load additional data to ensure edit summaries, text, etc., saved on-wiki match the wiki's content language. For this reason, we suggest keeping the interface language the same as the wiki's content language.",
"deputy.setting.user.core.modules.name": "Modules",
"deputy.setting.user.core.modules.description": "Choose the enabled Deputy modules. By default, all modules are enabled.\nDisabling specific modules won't make Deputy load faster, but it can remove\nUI features added by Deputy which may act as clutter when unused.",
"deputy.setting.user.core.modules.cci": "Contributor Copyright Investigations",
"deputy.setting.user.core.modules.ante": "{{int:deputy.ante}}",
"deputy.setting.user.core.modules.ia": "{{int:deputy.ia}}",
"deputy.setting.user.core.portletNames.name": "Portlet names",
"deputy.setting.user.core.portletNames.description": "Choose which names appear in the Deputy portlet (toolbox) links.",
"deputy.setting.user.core.portletNames.full": "Full names (e.g. Attribution Notice Template Editor)",
"deputy.setting.user.core.portletNames.short": "Shortened names (e.g. Attrib. Template Editor)",
"deputy.setting.user.core.portletNames.acronym": "Acronyms (e.g. ANTE)",
"deputy.setting.user.cci": "CCI",
"deputy.setting.user.cci.enablePageToolbar.name": "Enable page toolbar",
"deputy.setting.user.cci.enablePageToolbar.description": "Enables the page toolbar, which is used to quickly show tools, analysis options, and related case information on a page that is the subject of a CCI investigation.",
"deputy.setting.user.cci.showCvLink.name": "Show \"cv\" (\"copyvios\") link for revisions",
"deputy.setting.user.cci.showCvLink.description": "Show a \"cv\" link next to \"cur\" and \"prev\" on revision rows. This link will only appear if this wiki is configured to use Earwig's Copyvio Detector.",
"deputy.setting.user.cci.showUsername.name": "Show username",
"deputy.setting.user.cci.showUsername.description": "Show the username of the user who made the edit on revision rows. This may be redundant for cases which only have one editor.",
"deputy.setting.user.cci.autoShowDiff.name": "Automatically show diffs",
"deputy.setting.user.cci.autoShowDiff.description": "Enabling automatic loading of diffs. Configurable with two additional options to avoid loading too much content.",
"deputy.setting.user.cci.maxRevisionsToAutoShowDiff.name": "Maximum revisions to automatically show diff",
"deputy.setting.user.cci.maxRevisionsToAutoShowDiff.description": "The maximum number of revisions for a given page to automatically show the diff for each revision in the main interface.",
"deputy.setting.user.cci.maxSizeToAutoShowDiff.name": "Maximum size to automatically show diff",
"deputy.setting.user.cci.maxSizeToAutoShowDiff.description": "The maximum size of a diff to be automatically shown, if the diff will be automatically shown (see \"Maximum revisions to automatically show diff\"). Prevents extremely large diffs from opening. Set to -1 to show regardless of size.",
"deputy.setting.user.cci.forceUtc.name": "Force UTC time",
"deputy.setting.user.cci.forceUtc.description": "Forces Deputy to use UTC time whenever displaying dates and times, irregardless of your system's timezone or your MediaWiki time settings.",
"deputy.setting.user.cci.signingBehavior.name": "Row signing behavior",
"deputy.setting.user.cci.signingBehavior.description": "Choose how Deputy should behave when signing rows. By default, all rows are always signed with your signature (~~~~). You may configure Deputy to only sign the last row or never sign. You can also configure Deputy to leave a hidden trace behind (<!-- User:Example|2016-05-28T14:32:12Z -->), which helps Deputy (for other users) determine who assessed a row.",
"deputy.setting.user.cci.signingBehavior.always": "Always sign rows",
"deputy.setting.user.cci.signingBehavior.alwaysTrace": "Always leave a trace",
"deputy.setting.user.cci.signingBehavior.alwaysTraceLastOnly": "Always leave a trace, but sign the last row modified",
"deputy.setting.user.cci.signingBehavior.lastOnly": "Only sign the last row modified (prevents assessor recognition)",
"deputy.setting.user.cci.signingBehavior.never": "Never sign rows (prevents assessor recognition)",
"deputy.setting.user.cci.openOldOnContinue.name": "Open old versions on continue",
"deputy.setting.user.cci.openOldOnContinue.description": "If enabled, all previously-open sections of a given case page will also be opened alongside the section where the \"continue CCI session\" link was clicked.",
"deputy.setting.user.ante": "ANTE",
"deputy.setting.user.ante.enableAutoMerge.name": "Merge automatically on run",
"deputy.setting.user.ante.enableAutoMerge.description": "If enabled, templates that can be merged will automatically be merged when the dialog opens.",
"deputy.setting.user.ante.enableAutoMerge.unimplemented": "This feature has not yet been implemented.",
"deputy.setting.user.ante.onSubmit.name": "Action on submit",
"deputy.setting.user.ante.onSubmit.description": "Choose what to do after editing attribution notice templates.",
"deputy.setting.user.ante.onSubmit.nothing": "Do nothing",
"deputy.setting.user.ante.onSubmit.reload": "Reload the page",
"deputy.setting.user.ia": "IA",
"deputy.setting.user.ia.responses.name": "Custom responses",
"deputy.setting.user.ia.responses.description": "A custom set of responses, or overrides for existing responses. If an entry\nwith the same key on both the wiki-wide configuration and the user configuration\nexists, the user configuration will override the wiki-wide configuration. Wiki-wide configuration responses can also be disabled locally. If this setting is empty, no overrides are made.",
"deputy.setting.user.ia.enablePageToolbar.name": "Enable page toolbar",
"deputy.setting.user.ia.enablePageToolbar.description": "If enabled, the page toolbar will be shown when dealing with CP cases. The IA page toolbar works slightly differently from the CCI page toolbar. Namely, it shows a button for responding instead of a status dropdown.",
"deputy.setting.user.ia.enablePageToolbar.unimplemented": "This feature has not yet been implemented.",
"deputy.setting.user.ia.defaultEntirePage.name": "Hide entire page by default",
"deputy.setting.user.ia.defaultEntirePage.description": "If enabled, the Infringement Assistant reporting window will hide the entire page by default.",
"deputy.setting.user.ia.defaultFromUrls.name": "Use URLs by default",
"deputy.setting.user.ia.defaultFromUrls.description": "If enabled, the Infringement Assistant reporting window will use URL inputs by default.",
"deputy.setting.user.ia.onHide.name": "Action on hide",
"deputy.setting.user.ia.onHide.description": "Choose what to do after the \"Hide content only\" button is selected and the relevant content is hidden from the page.",
"deputy.setting.user.ia.onHide.nothing": "Do nothing",
"deputy.setting.user.ia.onHide.reload": "Reload the page",
"deputy.setting.user.ia.onHide.redirect": "Redirect to the noticeboard page",
"deputy.setting.user.ia.onSubmit.name": "Action on submit",
"deputy.setting.user.ia.onSubmit.description": "Choose what to do after the \"Submit\" button is selected, the relevant content is hidden from the page, and the page is reported.",
"deputy.setting.user.ia.onSubmit.nothing": "Do nothing",
"deputy.setting.user.ia.onSubmit.reload": "Reload the page",
"deputy.setting.user.ia.onSubmit.redirect": "Redirect to the noticeboard page",
"deputy.setting.user.ia.onBatchSubmit.name": "Action on batch listing submit",
"deputy.setting.user.ia.onBatchSubmit.description": "When reporting a batch of pages, choose what to do after the \"Report\" button is selected and the pages are reported.",
"deputy.setting.user.ia.onBatchSubmit.nothing": "Do nothing",
"deputy.setting.user.ia.onBatchSubmit.reload": "Reload the noticeboard page",
"deputy.setting.wiki.core": "Core",
"deputy.setting.wiki.core.lastEdited.name": "Configuration last edited",
"deputy.setting.wiki.core.lastEdited.description": "The last time that this configuration was edited, as a timestamp. This is a way to ensure that all users are on the correct wiki-wide configuration version before changes are made. Checks are performed on every page load with Deputy.",
"deputy.setting.wiki.core.dispatchRoot.name": "Deputy Dispatch root URL",
"deputy.setting.wiki.core.dispatchRoot.description": "The URL to a Deputy Dispatch instance that can handle this wiki. Deputy Dispatch is a webserver responsible for centralizing and optimizing data used by Deputy, and can be used to reduce load on wikis. More information can be found at https://github.com/ChlodAlejandro/deputy-dispatch.",
"deputy.setting.wiki.core.changeTag.name": "Change tag",
"deputy.setting.wiki.core.changeTag.description": "Tag to use for all Deputy edits.",
"deputy.setting.wiki.cci": "CCI",
"deputy.setting.wiki.cci.enabled.name": "Enable contributor copyright investigations assistant",
"deputy.setting.wiki.cci.enabled.description": "Enables the CCI workflow assistant. This allows Deputy to replace the contribution survey found on CCI case pages with a graphical interface which works with other tabs to make the CCI workflow easier.",
"deputy.setting.wiki.cci.rootPage.name": "Root page",
"deputy.setting.wiki.cci.rootPage.description": "The main page that holds all subpages containing valid contribution copyright investigation cases.",
"deputy.setting.wiki.cci.collapseTop.name": "Collapsible wikitext (top)",
"deputy.setting.wiki.cci.collapseTop.description": "Placed just below a section heading when closing a contributor survey section. Use \"$1\" to denote user comments and signature. On the English Wikipedia, this is {{Template:collapse top}}. Other wikis may have an equivalent template. This should go hand in hand with \"{{int:deputy.setting.wiki.cci.collapseBottom.name}}\", as they are used as a pair.",
"deputy.setting.wiki.cci.collapseBottom.name": "Collapsible wikitext (bottom)",
"deputy.setting.wiki.cci.collapseBottom.description": "Placed at the end of a section when closing a contributor survey section. On the English Wikipedia, this is {{Template:collapse bottom}}. Other wikis may have an equivalent template.",
"deputy.setting.wiki.cci.earwigRoot.name": "Earwig's Copyvio Detector root URL",
"deputy.setting.wiki.cci.earwigRoot.description": "The URL to an instance of Earwig's Copyvio Detector that can handle this wiki. The official copyvio detector (copyvios.toolforge.org) can only handle Wikimedia wikis — you may change this behavior by specifying a custom instance that can process this wiki here.",
"deputy.setting.wiki.ante": "ANTE",
"deputy.setting.wiki.ante.enabled.name": "Enable the Attribution Notice Template Editor",
"deputy.setting.wiki.ante.enabled.description": "Enables ANTE for all users. ANTE is currently the least-optimized module for localization, and may not work for all wikis.",
"deputy.setting.wiki.ia": "IA",
"deputy.setting.wiki.ia.enabled.name": "Enable the Infringement Assistant",
"deputy.setting.wiki.ia.enabled.description": "Enables IA for all users. IA allows users to easily and graphically report pages with suspected or complicated copyright infringements.",
"deputy.setting.wiki.ia.rootPage.name": "Root page",
"deputy.setting.wiki.ia.rootPage.description": "The root page for Infringement Assistant. This should be the copyright problems noticeboard for this specific wiki. IA will only show quick response links for the root page and its subpages.",
"deputy.setting.wiki.ia.subpageFormat.name": "Subpage format",
"deputy.setting.wiki.ia.subpageFormat.description": "The format to use for subpages of the root page. This is a moment.js format string.",
"deputy.setting.wiki.ia.preload.name": "Preload",
"deputy.setting.wiki.ia.preload.description": "Defines the page content to preload the page with if a given subpage does not exist yet. This should be an existing page on-wiki. Leave blank to avoid using a preload entirely.",
"deputy.setting.wiki.ia.allowPresumptive.name": "Allow presumptive deletions",
"deputy.setting.wiki.ia.allowPresumptive.description": "Allows users to file listings for presumptive deletions. Note that the CCI setting \"Root page\" must be set for this to work, even if the \"CCI\" module is disabled entirely.",
"deputy.setting.wiki.ia.listingWikitext.name": "Listing wikitext",
"deputy.setting.wiki.ia.listingWikitext.description": "Defines the wikitext that will be used when adding listings to a noticeboard page. You may use \"$1\" to denote the page being reported, and \"$2\" for user comments (which shouldn't contain the signature).",
"deputy.setting.wiki.ia.listingWikitextMatch.name": "Regular expression for listings",
"deputy.setting.wiki.ia.listingWikitextMatch.description": "A regular expression that will be used to parse and detect listings on a given noticeboard page. Since its usage is rather technical, this value should be edited by someone with technical knowledge of regular expressions. This regular expression must provide three captured groups: group \"$1\" will catch any bullet point, space, or prefix, \"$2\" will catch the page title ONLY if the given page matches \"{{int:deputy.setting.wiki.ia.listingWikitext.name}}\" or \"{{int:deputy.setting.wiki.ia.batchListingWikitext.name}}\", and \"$3\" will catch the page title ONLY IF the page wasn't caught in \"$2\" (such as in cases where there is only a bare link to the page).",
"deputy.setting.wiki.ia.batchListingWikitext.name": "Batch listing wikitext",
"deputy.setting.wiki.ia.batchListingWikitext.description": "Defines the wikitext that will be used when adding batch listings to a noticeboard page. You may use \"$1\" to denote the page being reported, and \"$2\" for the list of pages (as determined by \"{{int:deputy.setting.wiki.ia.batchListingPageWikitext.name}}\") and \"$3\" for user comments (which doesn't contain the signature).",
"deputy.setting.wiki.ia.batchListingPageWikitext.name": "Batch listing page wikitext",
"deputy.setting.wiki.ia.batchListingPageWikitext.description": "Wikitext to use for every row of text in \"{{int:deputy.setting.wiki.ia.batchListingWikitext.name}}\". No line breaks are automatically added; these must be added into this string.",
"deputy.setting.wiki.ia.hideTemplate.name": "Content hiding wikitext (top)",
"deputy.setting.wiki.ia.hideTemplate.description": "Wikitext to hide offending content with. On the English Wikipedia, this is a usage of {{Template:copyvio}}. Other wikis may have an equivalent template. This should go hand in hand with \"{{int:deputy.setting.wiki.ia.hideTemplateBottom.name}}\", as they are used as a pair.",
"deputy.setting.wiki.ia.hideTemplateBottom.name": "Content hiding wikitext (bottom)",
"deputy.setting.wiki.ia.hideTemplateBottom.description": "Placed at the end of hidden content to hide only part of a page. On the English Wikipedia, this is {{Template:copyvio/bottom}}. Other wikis may have an equivalent template.",
"deputy.setting.wiki.ia.responses.name": "Responses",
"deputy.setting.wiki.ia.responses.description": "Quick responses for copyright problems listings. Used by clerks to resolve specific listings or provide more information about the progress of a given listing."
};
 
let InternalConfigurationGroupTabPanel;
/**
* Initializes the process element.
*/
function initConfigurationGroupTabPanel() {
var _a;
InternalConfigurationGroupTabPanel = (_a = class ConfigurationGroupTabPanel extends OO.ui.TabPanelLayout {
/**
*/
constructor() {
super('configurationGroupPage_About');
this.$element.append(h_1("div", null,
h_1("div", { class: "deputy-about" },
h_1("div", { style: "flex: 0" },
h_1("img", { src: ConfigurationGroupTabPanel.logoUrl, alt: "Deputy logo" })),
h_1("div", { style: "flex: 1" },
h_1("div", null,
h_1("div", null, mw.msg('deputy.name')),
h_1("div", null, mw.msg('deputy.about.version', version, gitAbbrevHash))),
h_1("div", null, mw.msg('deputy.description')))),
h_1("div", null,
h_1("a", { href: "https://w.wiki/7NWR", target: "_blank" }, unwrapWidget(new OO.ui.ButtonWidget({
label: mw.msg('deputy.about.homepage'),
flags: ['progressive']
}))),
h_1("a", { href: "https://github.com/ChlodAlejandro/deputy", target: "_blank" }, unwrapWidget(new OO.ui.ButtonWidget({
label: mw.msg('deputy.about.openSource'),
flags: ['progressive']
}))),
h_1("a", { href: "https://w.wiki/7NWS", target: "_blank" }, unwrapWidget(new OO.ui.ButtonWidget({
label: mw.msg('deputy.about.contact'),
flags: ['progressive']
})))),
h_1("p", { dangerouslySetInnerHTML: mw.msg('deputy.about.credit') }),
h_1("p", { dangerouslySetInnerHTML: mw.msg('deputy.about.license', 'https://www.apache.org/licenses/LICENSE-2.0', 'https://github.com/ChlodAlejandro/deputy') }),
h_1("p", { dangerouslySetInnerHTML: mw.msg('deputy.about.thirdParty', 'https://github.com/ChlodAlejandro/deputy#licensing') }),
h_1("p", { style: { fontSize: '0.9em', color: 'darkgray' }, dangerouslySetInnerHTML: mw.msg('deputy.about.buildInfo', gitVersion, gitBranch, new Date(gitDate).toLocaleString()) }),
h_1("p", { style: { fontSize: '0.9em', color: 'darkgray' }, dangerouslySetInnerHTML: mw.msg('deputy.about.footer') })));
}
/**
* @return The {@Link Setting}s for this group.
*/
get settings() {
return this.config.config.all[this.config.group];
}
/**
* Sets up the tab item
*/
setupTabItem() {
this.tabItem.setLabel(mw.msg('deputy.about'));
return this;
}
},
_a.logoUrl = 'https://upload.wikimedia.org/wikipedia/commons/2/2b/Deputy_logo.svg',
_a);
}
/**
* Creates a new ConfigurationGroupTabPanel.
*
* @return A ConfigurationGroupTabPanel object
*/
function ConfigurationAboutTabPanel () {
if (!InternalConfigurationGroupTabPanel) {
initConfigurationGroupTabPanel();
}
return new InternalConfigurationGroupTabPanel();
}
 
let InternalConfigurationDialog;
/**
* Initializes the process element.
*/
function initConfigurationDialog() {
var _a;
InternalConfigurationDialog = (_a = class ConfigurationDialog extends OO.ui.ProcessDialog {
/**
*
* @param data
*/
constructor(data) {
super();
this.config = data.config;
}
/**
* @return The body height of this dialog.
*/
getBodyHeight() {
return 900;
}
/**
* Initializes the dialog.
*/
initialize() {
super.initialize();
this.layout = new OO.ui.IndexLayout();
this.layout.addTabPanels(this.generateGroupLayouts());
if (this.config instanceof UserConfiguration) {
this.layout.addTabPanels([ConfigurationAboutTabPanel()]);
}
this.$body.append(this.layout.$element);
return this;
}
/**
* Generate TabPanelLayouts for each configuration group.
*
* @return An array of TabPanelLayouts
*/
generateGroupLayouts() {
return Object.keys(this.config.all).map((group) => ConfigurationGroupTabPanel({
config: this.config,
group
}));
}
/**
*
* @param action
* @return An OOUI Process.
*/
getActionProcess(action) {
const process = super.getActionProcess();
if (action === 'save') {
process.next(this.config.save());
process.next(() => {
var _a, _b;
mw.notify(mw.msg('deputy.settings.saved'), {
type: 'success'
});
if (this.config.type === 'user') {
// Override local Deputy option, just in case the user wishes to
// change the configuration again.
mw.user.options.set(UserConfiguration.optionKey, this.config.serialize());
if ((_a = window.deputy) === null || _a === void 0 ? void 0 : _a.comms) {
window.deputy.comms.send({
type: 'userConfigUpdate',
config: this.config.serialize()
});
}
}
else if (this.config.type === 'wiki') {
// We know it is a WikiConfiguration, the instanceof check here
// is just for type safety.
if ((_b = window.deputy) === null || _b === void 0 ? void 0 : _b.comms) {
window.deputy.comms.send({
type: 'wikiConfigUpdate',
config: {
title: this.config.sourcePage.getPrefixedText(),
editable: this.config.editable,
wt: this.config.serialize()
}
});
}
// Reload the page.
window.___location.reload();
}
});
}
process.next(() => {
this.close();
});
return process;
}
},
_a.static = Object.assign(Object.assign({}, OO.ui.ProcessDialog.static), { name: 'configurationDialog', title: mw.msg('deputy.settings.dialog.title'), size: 'large', actions: [
{
flags: ['safe', 'close'],
icon: 'close',
label: mw.msg('deputy.ante.close'),
title: mw.msg('deputy.ante.close'),
invisibleLabel: true,
action: 'close'
},
{
action: 'save',
label: mw.msg('deputy.save'),
flags: ['progressive', 'primary']
}
] }),
_a);
}
/**
* Creates a new ConfigurationDialog.
*
* @param data
* @return A ConfigurationDialog object
*/
function ConfigurationDialogBuilder(data) {
if (!InternalConfigurationDialog) {
initConfigurationDialog();
}
return new InternalConfigurationDialog(data);
}
let attached = false;
/**
* Spawns a new configuration dialog.
*
* @param config
*/
function spawnConfigurationDialog(config) {
mw.loader.using([
'oojs-ui-core', 'oojs-ui-windows', 'oojs-ui-widgets', 'mediawiki.widgets'
], () => {
const dialog = ConfigurationDialogBuilder({ config });
openWindow(dialog);
});
}
/**
* Attaches the "Deputy preferences" portlet link in the toolbox. Ensures that it doesn't
* get attached twice.
*/
function attachConfigurationDialogPortletLink() {
return __awaiter(this, void 0, void 0, function* () {
if (document.querySelector('#p-deputy-config') || attached) {
return;
}
attached = true;
mw.util.addCSS(deputySettingsStyles);
yield DeputyLanguage.load('settings', deputySettingsEnglish);
mw.util.addPortletLink('p-tb', '#', mw.msg('deputy.settings.portlet'), 'deputy-config', mw.msg('deputy.settings.portlet.tooltip')).addEventListener('click', () => {
// Load a fresh version of the configuration - this way we can make
// modifications live to the configuration without actually affecting
// tool usage.
spawnConfigurationDialog(UserConfiguration.load());
});
});
}
 
/**
* @param config The current configuration (actively loaded, not the one being viewed)
* @return An HTML element consisting of an OOUI MessageWidget
*/
function WikiConfigurationEditIntro(config) {
const current = config.onConfigurationPage();
let buttons;
if (current) {
const editCurrent = new OO.ui.ButtonWidget({
flags: ['progressive', 'primary'],
label: mw.msg('deputy.settings.wikiEditIntro.edit.current'),
disabled: !mw.config.get('wgIsProbablyEditable'),
title: mw.config.get('wgIsProbablyEditable') ?
undefined : mw.msg('deputy.settings.wikiEditIntro.edit.protected')
});
editCurrent.on('click', () => {
spawnConfigurationDialog(config);
});
buttons = [editCurrent];
}
else {
const editCurrent = new OO.ui.ButtonWidget({
flags: ['progressive', 'primary'],
label: mw.msg('deputy.settings.wikiEditIntro.edit.otherCurrent'),
disabled: !config.editable,
title: config.editable ?
undefined : mw.msg('deputy.settings.wikiEditIntro.edit.protected')
});
editCurrent.on('click', () => __awaiter(this, void 0, void 0, function* () {
spawnConfigurationDialog(config);
}));
const editOther = new OO.ui.ButtonWidget({
flags: ['progressive'],
label: mw.msg('deputy.settings.wikiEditIntro.edit.other'),
disabled: !mw.config.get('wgIsProbablyEditable'),
title: mw.config.get('wgIsProbablyEditable') ?
undefined : mw.msg('deputy.settings.wikiEditIntro.edit.protected')
});
editOther.on('click', () => __awaiter(this, void 0, void 0, function* () {
spawnConfigurationDialog(yield config.static.load(normalizeTitle()));
}));
buttons = [editCurrent, editOther];
}
const messageBox = DeputyMessageWidget({
classes: [
'deputy', 'dp-mb'
],
type: 'notice',
title: mw.msg('deputy.settings.wikiEditIntro.title'),
message: current ?
mw.msg('deputy.settings.wikiEditIntro.current') :
h_1("span", { dangerouslySetInnerHTML: mw.message('deputy.settings.wikiEditIntro.other', config.sourcePage.getPrefixedText()).parse() }),
actions: buttons
});
const box = unwrapWidget(messageBox);
box.classList.add('deputy', 'deputy-wikiConfig-intro');
return box;
}
 
/* eslint-disable max-len */
/*
* Replacement polyfills for wikis that have no configured templates.
* Used in WikiConfiguration, to permit a seamless OOB experience.
*/
/** `{{collapse top}}` equivalent */
const collapseTop = `
{| class="mw-collapsible mw-collapsed" style="border:1px solid #C0C0C0;width:100%"
! <div style="background:#CCFFCC;">$1</div>
|-
|
`.trimStart();
/** `{{collapse bottom}}` equivalent */
const collapseBottom = `
|}`;
/** `* {{subst:article-cv|1=$1}} $2 ~~~~` equivalent */
const listingWikitext = '* [[$1]] $2 ~~~~';
/**
* Polyfill for the following:
* `; {{anchor|1={{delink|$1}}}} $1
* $2
* $3 ~~~~`
*/
const batchListingWikitext = `*; <span style="display: none;" id="$1"></span> $1
$2
$3`;
/**
* Inserted and chained as part of $2 in `batchListingWikitext`.
* Equivalent of `* {{subst:article-cv|1=$1}}\n`. Newline is intentional.
*/
const batchListingPageWikitext = '* [[$1]]\n';
/**
* `{{subst:copyvio|url=$1|fullpage=$2}}` equivalent
*/
const copyvioTop = `<div style="padding: 8px; border: 4px solid #0298b1;">
<div style="font-size: 1.2rem"><b>{{int:deputy.ia.content.copyvio}}</b></div>
<div>{{int:deputy.ia.content.copyvio.help}}</div>
{{if:$1|<div>{{if:$presumptive|{{int:deputy.ia.content.copyvio.from.pd}} $1|{{int:deputy.ia.content.copyvio.from}} $1}}</div>}}
</div>
<!-- {{int:deputy.ia.content.copyvio.content}} -->
<div class="copyvio" style="display: none">`;
/**
* `{{subst:copyvio/bottom}}` equivalent.
*/
const copyvioBottom = `
</div>`;
 
/**
* @return A MessageWidget for reloading a page with an outdated configuration.
*/
function ConfigurationReloadBanner() {
const reloadButton = new OO.ui.ButtonWidget({
flags: ['progressive', 'primary'],
label: mw.msg('deputy.settings.wikiOutdated.reload')
});
const messageBox = DeputyMessageWidget({
classes: [
'deputy', 'dp-mb', 'dp-wikiConfigUpdateMessage'
],
type: 'notice',
title: mw.msg('deputy.settings.wikiOutdated'),
message: mw.msg('deputy.settings.wikiOutdated.help'),
actions: [reloadButton]
});
reloadButton.on('click', () => __awaiter(this, void 0, void 0, function* () {
window.___location.reload();
}));
const box = unwrapWidget(messageBox);
box.style.fontSize = 'calc(1em * 0.875)';
return box;
}
 
/**
* Wiki-wide configuration. This is applied to all users of the wiki, and has
* the potential to break things for EVERYONE if not set to proper values.
*
* As much as possible, the correct configuration ___location should be protected
* to avoid vandalism or bad-faith changes.
*
* This configuration works if specific settings are set. In other words, some
* features of Deputy are disabled unless Deputy has been configured. This is
* to avoid messing with existing on-wiki processes.
*/
class WikiConfiguration extends ConfigurationBase {
/**
*
* @param sourcePage
* @param serializedData
* @param editable Whether the configuration is editable by the current user or not.
*/
constructor(sourcePage, serializedData, editable) {
var _a;
super();
this.sourcePage = sourcePage;
this.serializedData = serializedData;
this.editable = editable;
// Used to avoid circular dependencies.
this.static = WikiConfiguration;
this.core = {
/**
* Numerical code that identifies this config version. Increments for every breaking
* configuration file change.
*/
configVersion: new Setting({
defaultValue: WikiConfiguration.configVersion,
displayOptions: { hidden: true },
alwaysSave: true
}),
lastEdited: new Setting({
defaultValue: 0,
displayOptions: { hidden: true },
alwaysSave: true
}),
dispatchRoot: new Setting({
serialize: (v) => v.href,
deserialize: (v) => new URL(v),
defaultValue: new URL('https://deputy.toolforge.org/'),
displayOptions: { type: 'text' },
alwaysSave: true
}),
changeTag: new Setting({
defaultValue: null,
displayOptions: { type: 'text' }
})
};
this.cci = {
enabled: new Setting({
defaultValue: false,
displayOptions: { type: 'checkbox' }
}),
rootPage: new Setting({
serialize: (v) => v === null || v === void 0 ? void 0 : v.getPrefixedText(),
deserialize: (v) => new mw.Title(v),
defaultValue: null,
displayOptions: { type: 'page' }
}),
collapseTop: new Setting({
defaultValue: collapseTop,
displayOptions: { type: 'code' }
}),
collapseBottom: new Setting({
defaultValue: collapseBottom,
displayOptions: { type: 'code' }
}),
earwigRoot: new Setting({
serialize: (v) => v.href,
deserialize: (v) => new URL(v),
defaultValue: new URL('https://copyvios.toolforge.org/'),
displayOptions: { type: 'text' },
alwaysSave: true
})
};
this.ante = {
enabled: new Setting({
defaultValue: false,
displayOptions: { type: 'checkbox' }
})
};
this.ia = {
enabled: new Setting({
defaultValue: false,
displayOptions: { type: 'checkbox' }
}),
rootPage: new Setting({
serialize: (v) => v === null || v === void 0 ? void 0 : v.getPrefixedText(),
deserialize: (v) => new mw.Title(v),
defaultValue: null,
displayOptions: { type: 'page' }
}),
subpageFormat: new Setting({
defaultValue: 'YYYY MMMM D',
displayOptions: { type: 'text' }
}),
preload: new Setting({
serialize: (v) => { var _a, _b; return ((_b = (_a = v === null || v === void 0 ? void 0 : v.trim()) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 0 ? null : v.trim(); },
defaultValue: null,
displayOptions: { type: 'page' }
}),
allowPresumptive: new Setting({
defaultValue: true,
displayOptions: { type: 'checkbox' }
}),
listingWikitext: new Setting({
defaultValue: listingWikitext,
displayOptions: { type: 'code' }
}),
/**
* $1 - Title of the batch
* $2 - List of pages (newlines should be added in batchListingPageWikitext).
* $3 - User comment
*/
batchListingWikitext: new Setting({
defaultValue: batchListingWikitext,
displayOptions: { type: 'code' }
}),
/**
* $1 - Page to include
*/
batchListingPageWikitext: new Setting({
defaultValue: batchListingPageWikitext,
displayOptions: { type: 'code' }
}),
/**
* @see {@link CopyrightProblemsListing#articleCvRegex}
*
* This should match both normal and batch listings.
*/
listingWikitextMatch: new Setting({
defaultValue: '(\\*\\s*)?\\[\\[([^\\]]+)\\]\\]',
displayOptions: { type: 'code' }
}),
hideTemplate: new Setting({
defaultValue: copyvioTop,
displayOptions: { type: 'code' }
}),
hideTemplateBottom: new Setting({
defaultValue: copyvioBottom,
displayOptions: { type: 'code' }
}),
responses: new Setting(Object.assign(Object.assign({}, Setting.basicSerializers), { defaultValue: null, displayOptions: { type: 'unimplemented' } }))
};
this.type = 'wiki';
this.all = { core: this.core, cci: this.cci, ante: this.ante, ia: this.ia };
/**
* Set to true when this configuration is outdated based on latest data. Usually adds banners
* to UI interfaces saying a new version of the configuration is available, and that it should
* be used whenever possible.
*
* TODO: This doesn't do what the documentations says yet.
*/
this.outdated = false;
if (serializedData) {
this.deserialize(serializedData);
}
if ((_a = window.deputy) === null || _a === void 0 ? void 0 : _a.comms) {
// Communications is available. Register a listener.
window.deputy.comms.addEventListener('wikiConfigUpdate', (e) => {
this.update(Object.assign({}, e.data.config, {
title: normalizeTitle(e.data.config.title)
}));
});
}
}
/**
* Loads the configuration from a set of possible sources.
*
* @param sourcePage The specific page to load from
* @return A WikiConfiguration object
*/
static load(sourcePage) {
return __awaiter(this, void 0, void 0, function* () {
if (sourcePage) {
// Explicit source given. Do not load from local cache.
return this.loadFromWiki(sourcePage);
}
else {
return this.loadFromLocal();
}
});
}
/**
* Loads the wiki configuration from localStorage and/or MediaWiki
* settings. This allows for faster loads at the expense of a (small)
* chance of outdated configuration.
*
* The localStorage layer allows fast browser-based caching. If a user
* is logging in again on another device, the user configuration
* will automatically be sent to the client, lessening turnaround time.
* If all else fails, the configuration will be loaded from the wiki.
*
* @return A WikiConfiguration object.
*/
static loadFromLocal() {
return __awaiter(this, void 0, void 0, function* () {
let configInfo;
// If `mw.storage.get` returns `false` or `null`, it'll be thrown up.
let rawConfigInfo = mw.storage.get(WikiConfiguration.optionKey);
// Try to grab it from user options, if it exists.
if (!rawConfigInfo) {
rawConfigInfo = mw.user.options.get(WikiConfiguration.optionKey);
}
if (typeof rawConfigInfo === 'string') {
try {
configInfo = JSON.parse(rawConfigInfo);
}
catch (e) {
// Bad local! Switch to non-local.
console.error('Failed to get Deputy wiki configuration', e);
return this.loadFromWiki();
}
}
else {
console.log('No locally-cached Deputy configuration, pulling from wiki.');
return this.loadFromWiki();
}
if (configInfo) {
return new WikiConfiguration(new mw.Title(configInfo.title.title, configInfo.title.namespace), JSON.parse(configInfo.wt), configInfo.editable);
}
else {
return this.loadFromWiki();
}
});
}
/**
* Loads the configuration from the current wiki.
*
* @param sourcePage The specific page to load from
* @return A WikiConfiguration object
*/
static loadFromWiki(sourcePage) {
return __awaiter(this, void 0, void 0, function* () {
const configPage = sourcePage ? Object.assign({ title: sourcePage }, yield (() => __awaiter(this, void 0, void 0, function* () {
const content = yield getPageContent(sourcePage, {
prop: 'revisions|info',
intestactions: 'edit',
fallbacktext: '{}'
});
return {
wt: content,
editable: content.page.actions.edit
};
}))()) : yield this.loadConfigurationWikitext();
try {
// Attempt save of configuration to local options (if not explicitly loaded)
if (sourcePage == null) {
mw.storage.set(WikiConfiguration.optionKey, JSON.stringify(configPage));
}
return new WikiConfiguration(configPage.title, JSON.parse(configPage.wt), configPage.editable);
}
catch (e) {
console.error(e, configPage);
mw.hook('deputy.i18nDone').add(function notifyConfigFailure() {
mw.notify(mw.msg('deputy.loadError.wikiConfig'), {
type: 'error'
});
mw.hook('deputy.i18nDone').remove(notifyConfigFailure);
});
return null;
}
});
}
/**
* Loads the wiki-wide configuration from a set of predefined locations.
* See {@link WikiConfiguration#configLocations} for a full list.
*
* @return The string text of the raw configuration, or `null` if a configuration was not found.
*/
static loadConfigurationWikitext() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield MwApi.action.get({
action: 'query',
prop: 'revisions|info',
rvprop: 'content',
rvslots: 'main',
rvlimit: 1,
intestactions: 'edit',
redirects: true,
titles: WikiConfiguration.configLocations.join('|')
});
const redirects = toRedirectsObject(response.query.redirects, response.query.normalized);
for (const page of WikiConfiguration.configLocations) {
const title = normalizeTitle(redirects[page] || page).getPrefixedText();
const pageInfo = response.query.pages.find((p) => p.title === title);
if (!pageInfo.missing) {
return {
title: normalizeTitle(pageInfo.title),
wt: pageInfo.revisions[0].slots.main.content,
editable: pageInfo.actions.edit
};
}
}
return null;
});
}
/**
* Check if the current page being viewed is a valid configuration page.
*
* @param page
* @return `true` if the current page is a valid configuration page.
*/
static isConfigurationPage(page) {
if (page == null) {
page = new mw.Title(mw.config.get('wgPageName'));
}
return this.configLocations.some((v) => equalTitle(page, normalizeTitle(v)));
}
/**
* Check for local updates, and update the local configuration as needed.
*
* @param sourceConfig A serialized version of the configuration based on a wiki
* page configuration load.
*/
update(sourceConfig) {
return __awaiter(this, void 0, void 0, function* () {
// Asynchronously load from the wiki.
let fromWiki;
if (sourceConfig) {
fromWiki = sourceConfig;
}
else {
// Asynchronously load from the wiki.
fromWiki = yield WikiConfiguration.loadConfigurationWikitext();
if (fromWiki == null) {
// No configuration found on the wiki.
return;
}
}
const liveWikiConfig = JSON.parse(fromWiki.wt);
// Attempt save if on-wiki config found and doesn't match local.
// Doesn't need to be from the same config page, since this usually means a new config
// page was made, and we need to switch to it.
if (this.core.lastEdited.get() < liveWikiConfig.core.lastEdited) {
const onSuccess = () => {
var _a;
// Only mark outdated after saving, so we don't indirectly cause a save operation
// to cancel.
this.outdated = true;
// Attempt to add site notice.
if (document.querySelector('.dp-wikiConfigUpdateMessage') == null) {
(_a = document.getElementById('siteNotice')) === null || _a === void 0 ? void 0 : _a.insertAdjacentElement('afterend', ConfigurationReloadBanner());
}
};
// If updated from a source config (other Deputy tab), do not attempt to save
// to MediaWiki settings. This is most likely already saved by the original tab
// that sent the comms message.
if (!sourceConfig) {
// Use `liveWikiConfig`, since this contains the compressed version and is more
// bandwidth-friendly.
const rawConfigInfo = JSON.stringify({
title: fromWiki.title,
editable: fromWiki.editable,
wt: JSON.stringify(liveWikiConfig)
});
mw.storage.set(WikiConfiguration.optionKey, rawConfigInfo);
yield MwApi.action.saveOption(WikiConfiguration.optionKey, rawConfigInfo).then(() => {
var _a;
if ((_a = window.deputy) === null || _a === void 0 ? void 0 : _a.comms) {
// Broadcast the update to other tabs.
window.deputy.comms.send({
type: 'wikiConfigUpdate',
config: {
title: fromWiki.title.getPrefixedText(),
editable: fromWiki.editable,
wt: liveWikiConfig
}
});
}
onSuccess();
}).catch(() => {
// silently fail
});
}
else {
onSuccess();
}
}
});
}
/**
* Saves the configuration on-wiki. Does not automatically generate overrides.
*/
save() {
return __awaiter(this, void 0, void 0, function* () {
// Update last edited number
this.core.lastEdited.set(Date.now());
yield MwApi.action.postWithEditToken(Object.assign(Object.assign({}, changeTag(yield window.deputy.getWikiConfig())), { action: 'edit', title: this.sourcePage.getPrefixedText(), text: JSON.stringify(this.serialize()) }));
});
}
/**
* Check if the current page being viewed is the active configuration page.
*
* @param page
* @return `true` if the current page is the active configuration page.
*/
onConfigurationPage(page) {
return equalTitle(page !== null && page !== void 0 ? page : mw.config.get('wgPageName'), this.sourcePage);
}
/**
* Actually displays the banner which allows an editor to modify the configuration.
*/
displayEditBanner() {
return __awaiter(this, void 0, void 0, function* () {
mw.loader.using(['oojs', 'oojs-ui'], () => {
if (document.getElementsByClassName('deputy-wikiConfig-intro').length > 0) {
return;
}
document.getElementById('mw-content-text').insertAdjacentElement('afterbegin', WikiConfigurationEditIntro(this));
});
});
}
/**
* Shows the configuration edit intro banner, if applicable on this page.
*
* @return void
*/
prepareEditBanners() {
return __awaiter(this, void 0, void 0, function* () {
if (['view', 'diff'].indexOf(mw.config.get('wgAction')) === -1) {
return;
}
if (document.getElementsByClassName('deputy-wikiConfig-intro').length > 0) {
return;
}
if (this.onConfigurationPage()) {
return this.displayEditBanner();
}
else if (WikiConfiguration.isConfigurationPage()) {
return this.displayEditBanner();
}
});
}
}
WikiConfiguration.configVersion = 1;
WikiConfiguration.optionKey = 'userjs-deputy-wiki';
WikiConfiguration.configLocations = [
'MediaWiki:Deputy-config.json',
// Prioritize interface protected page over Project namespace
'User:Chlod/Scripts/Deputy/configuration.json',
'Project:Deputy/configuration.json'
];
 
/**
Line 13,961 ⟶ 14,731:
*/
class DeputyModule {
/**
*
* @param deputy
*/
constructor(deputy) {
this.deputy = deputy;
}
/**
* @return The responsible window manager for this class.
Line 14,004 ⟶ 14,767:
get wikiConfig() {
return this.deputy ? this.deputy.wikiConfig : this._wikiConfig;
}
/**
*
* @param deputy
*/
constructor(deputy) {
this.deputy = deputy;
}
/**
* Get the module key for this module. Allows modules to be identified with a different
* configuration key.
*
* @return The module key. the module name by default.
*/
getModuleKey() {
return this.getName();
}
/**
Line 14,015 ⟶ 14,794:
yield Promise.all([
DeputyLanguage.load(this.getName(), fallback),
DeputyLanguage.load('shared', deputySharedEnglish),
DeputyLanguage.loadMomentLocale()
]);
Line 14,029 ⟶ 14,809:
return __awaiter(this, void 0, void 0, function* () {
yield this.getWikiConfig();
if (((_a = this.wikiConfig[this.getNamegetModuleKey()]) === null || _a === void 0 ? void 0 : _a.enabled.get()) !== true) {
// Stop loading here.
console.warn(`[Deputy] Preinit for ${this.getName()} cancelled; module is disabled.`);
return false;
}
Line 14,166 ⟶ 14,946:
openEditDialog() {
mw.loader.using(CopiedTemplateEditor.dependencies, () => __awaiter(this, void 0, void 0, function* () {
yield DeputyLanguage.loadMomentLocale();
OO.ui.WindowManager.static.sizes.huge = {
width: 1100
Line 14,185 ⟶ 14,966:
this.windowManager.addWindows([this.dialog]);
}
yield this.windowManager.openWindow(this.dialog).opened;
}));
}
Line 14,220 ⟶ 15,001:
];
 
var deputyStyles = "/*=============================================================================== GLOBAL DEPUTY CLASSES===============================================================================*/* > .deputy.dp-heading {position: absolute;opacity: 0;pointer-events: none;}*:hover > .deputy.dp-heading:not(.dp-heading--active) {opacity: 1;pointer-events: all;}.dp-loadingDots-1, .dp-loadingDots-2, .dp-loadingDots-3 {display: inline-block;margin: 0.1em 0.6em 0.1em 0.1em;width: 0.8em;height: 0.8em;background-color: rgba(0, 0, 0, 50%);animation: dp-loadingDots linear 3s infinite;border-radius: 50%;}@keyframes dp-loadingDots {0% {background-color: rgba(0, 0, 0, 10%);}16% {background-color: rgba(0, 0, 0, 40%);}32% {background-color: rgba(0, 0, 0, 10%);}100% {background-color: rgba(0, 0, 0, 10%);}}.dp-loadingDots-1 {animation-delay: -1s;}.dp-loadingDots-2 {animation-delay: -0.5s;}#mw-content-text.dp-reloading {opacity: 0.2;pointer-events: none;}p.dp-messageWidget-message {margin: 0 0 0.5em 0;}.dp-messageWidget-actions .oo-ui-buttonElement {margin-top: 0;}.oo-ui-image-destructive.oo-ui-icon-checkAll, .oo-ui-image-destructive.mw-ui-icon-checkAll::before {background-image: url(\"data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2220%22 height=%2220%22 viewBox=%220 0 20 20%22%3E%3Ctitle%3E check all %3C/title%3E%3Cpath fill=%22%23d73333%22 d=%22m.29 12.71 1.42-1.42 2.22 2.22 8.3-10.14 1.54 1.26-9.7 11.86zM12 10h5v2h-5zm-3 4h5v2H9zm6-8h5v2h-5z%22/%3E%3C/svg%3E\");}/*=============================================================================== DEPUTY REVIEW DIALOG (DeputyReviewDialog)===============================================================================*/.dp-review-progress {flex: 1;width: 60%;min-width: 300px;}/*=============================================================================== DEPUTY ENTRY POINTS (DeputyCCISessionStartLink, etc.)===============================================================================*/.deputy.dp-sessionStarter {font-size: small;font-weight: normal;margin-left: 0.25em;vertical-align: baseline;line-height: 1em;font-family: sans-serif;}.deputy.dp-sessionStarter::before {content: '\\200B';}.mw-content-ltr .deputy.dp-sessionStarter .dp-sessionStarter-bracket:first-of-type,.mw-content-rtl .deputy.dp-sessionStarter .dp-sessionStarter-bracket:not(:first-of-type) {margin-right: 0.25em;color: #54595d;}.client-js .deputy.dp-sessionStarter .dp-sessionStarter-bracket:first-of-type,.client-js .deputy.dp-sessionStarter .dp-sessionStarter-bracket:not(:first-of-type) {margin-left: 0.25em;color: #54595d}.dp-cs-section-add {position: absolute;top: 0;/* -1.6em derived from MediaWiki list margins. */left: -1.6em;width: calc(100% + 1.6em);background-color: rgba(255, 255, 255, 75%);display: flex;justify-content: center;align-items: center;}.dp-cs-section-add .dp-cs-section-addButton {opacity: 0;transition: opacity 0.2s ease-in-out;}.dp-cs-section-add:hover .dp-cs-section-addButton {opacity: 1;}/*=============================================================================== DEPUTY CONTRIBUTION SURVEY SECTION===============================================================================*/.dp-cs-section-archived .dp-cs-row-content {background-color: rgba(255, 0, 0, 6%);}.dp-cs-session-notice {margin-top: 8px;position: sticky;top: 8px;z-index: 50;}.skin-vector-2022.vector-sticky-header-visible .dp-cs-session-notice {top: calc(3.125rem + 8px);}.dp-cs-section-footer {position: relative;padding: 8px;}.dp-cs-section-danger--separator {flex-basis: 100%;margin: 8px 0;border-bottom: 1px solid #d73333;color: #d73333;font-weight: bold;font-size: 0.7em;text-align: right;text-transform: uppercase;line-height: 0.7em;padding-bottom: 0.2em;}.dp-cs-section-closing {margin: 1em 1.75em;}.dp-cs-section-progress {margin-top: 8px;max-height: 0;transition: max-height 0.2s ease-in-out;display: flex;justify-content: center;align-items: center;overflow: hidden;}.dp-cs-section-progress.active {max-height: 50px;}.dp-cs-section-progress .oo-ui-progressBarWidget {flex: 1}.dp-cs-section-closingCommentsField {margin-top: 8px;}.dp-cs-extraneous {border: 1px solid rgba(0, 159, 255, 40%);background-color: rgba(0, 159, 255, 10%);margin-bottom: 8px;padding: 16px;}.dp-cs-extraneous > dl {margin-left: -1.6em;}.dp-cs-extraneous > :first-child {margin-top: 0 !important;}.dp-cs-extraneous > :last-child {margin-bottom: 0 !important;}.dp-cs-section-archived-warn, .dp-cs-row, .dp-cs-extraneous {margin-bottom: 8px;}.dp-cs-row .dp--loadingDots {display: flex;align-items: center;justify-content: center;padding: 0.4em;}.dp-cs-row-status {max-width: 5.4em;}.dp-cs-row-status .oo-ui-dropdownWidget-handle .oo-ui-labelElement-label {width: 0;opacity: 0;}.dp-cs-row-status .dp-cs-row-status--unknown:not(.oo-ui-optionWidget-selected) {display: none;}.dp-cs-row-head > * {vertical-align: middle;}.dp-cs-row-comments {padding: 16px;background-color: rgba(0, 159, 255, 10%);margin: 4px 0;}.dp-cs-row-comments > b {letter-spacing: 0.1em;font-weight: bold;text-transform: uppercase;color: rgba(0, 0, 0, 0.5);}.dp-cs-row-comments hr {border-color: rgb(0, 31, 51);}body.mediawiki.ltr .dp-cs-row-head > :not(:first-child):not(:last-child),body.mediawiki.ltr .dp-cs-row-head > :not(:first-child):not(:last-child) {margin-right: 16px;}body.mediawiki.rtl .dp-cs-row-head > :not(:first-child):not(:last-child),body.mediawiki.rtl .dp-cs-row-head > :not(:first-child):not(:last-child) {margin-left: 16px;}.dp-cs-row-links {margin-right: 0 !important;}.dp-cs-row-links > :not(:last-child) {margin-right: 8px !important;}.dp-cs-row-title {font-weight: bold;font-size: 1.2em;vertical-align: middle;}.dp-cs-row-details {color: #4a5054;font-weight: bold;}.dp-cs-row-toggle .oo-ui-iconElement-icon {background-size: 1em;}.dp-cs-row-toggle .oo-ui-buttonElement-button {border-radius: 50%;}.dp-cs-row .history-user,.dp-cs-row :not(.newpage) + .mw-changeslist-date {margin-left: 0.4em;margin-right: 0.2em;}.dp-cs-row .newpage {margin-left: 0.4em;}.dp-cs-row-content {padding: 16px;background-color: rgba(0, 0, 0, 6%);margin: 4px 0;}.dp-cs-row-content.dp-cs-row-content-empty {display: none !important;}.dp-cs-row-unfinishedWarning {margin-bottom: 8px;}.dp-cs-section-unfinishedWarning {margin-top: 8px;}.dp-cs-row-closeComments {font-family: monospace, monospace;font-size: small;}.dp-cs-row-closeComments:not(:last-child) {margin-bottom: 8px;}.dp-cs-row-finished .oo-ui-fieldLayout:first-child {margin-top: 0;}.dp-cs-row-finished .oo-ui-fieldLayout {margin-top: 8px;}.dp-cs-row-revisions .mw-tag-markers .mw-tag-marker:not(:first-child),.dp-cs-row-detail:not(:first-child) {margin-left: 0.2em;}.dp-cs-rev-checkbox {margin-right: 4px;}.dp-cs-rev-toggleDiff {vertical-align: baseline;margin-right: 4px;}.dp-cs-rev-diff {background-color: white;position: relative;}.dp-cs-rev-diff--loaded {margin: 4px 0;padding: 8px 14px;}.dp-cs-rev-diff--hidden {display: none;}.dp-cs-rev-toggleDiff > .oo-ui-buttonElement-button {padding: 0;min-height: 1em;background-color: unset !important;}.dp-cs-rev-toggleDiff .oo-ui-indicatorElement-indicator {top: -1px;}/*=============================================================================== DEPUTY PAGE TOOLBAR===============================================================================*/.dp-pageToolbar {position: fixed;bottom: 8px;left: 8px;z-index: 100;padding: 8px;background-color: #fff;border: 1px solid gray;font-size: 0.9rem;display: flex;}.dp-pageToolbar .dp-pageToolbar-main {padding: 8px;display: flex;align-items: center;}.dp-pageToolbar-actions {width: 12px;display: flex;flex-direction: column;font-size: 12px;line-height: 1em;}.dp-pageToolbar-close {cursor: pointer;height: 12px;text-align: center;background-color: rgba(0, 0, 0, 0.25);}.dp-pageToolbar-close:hover {transition: background-color 0.1s ease-in-out;background-color: rgba(0, 0, 0, 0.4);}.dp-pageToolbar-close::before {content: '×';vertical-align: middle;position: relative;right: 1px;}.dp-pageToolbar-collapse {cursor: pointer;flex: 1;background-color: rgba(0, 0, 0, 0.125);text-align: center;writing-mode: vertical-rl;position: relative;}.dp-pageToolbar-collapse:hover {transition: background-color 0.1s ease-in-out;background-color: rgba(0, 0, 0, 0.25);}.dp-pageToolbar-collapse::before {content: '»';position: absolute;vertical-align: middle;width: 12px;left: 0;bottom: 2px;}.dp-pageToolbar-collapsed {cursor: pointer;width: 32px;height: 32px;/* logo-white.svg */background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDgwIDEwODAiIHdpZHRoPSIxMDgwIiBoZWlnaHQ9IjEwODAiPjxkZWZzPjxzdHlsZT4uY2xzLTF7ZmlsbDojMDI5N2IxO308L3N0eWxlPjwvZGVmcz48cGF0aCBjbGFzcz0iY2xzLTEiIGQ9Ik04NzcuNTQsNDM4LjY5YTQzNy41NCw0MzcuNTQsMCwwLDEtODQuMzgsMjU4Ljc4bDI2Ny4wNiwyNjcuMjJhNjcuNTYsNjcuNTYsMCwxLDEtOTUuNTYsOTUuNTRMNjk3LjYsNzkzYTQzNi4yNyw0MzYuMjcsMCwwLDEtMjU4LjgzLDg0LjM2QzE5Ni4zOSw4NzcuMzcsMCw2ODEsMCw0MzguNjlTMTk2LjM5LDAsNDM4Ljc3LDAsODc3LjU0LDE5Ni4zNSw4NzcuNTQsNDM4LjY5Wk00MzguNzcsNzQyLjM5YzE2Ny43LDAsMzAzLjc3LTEzNiwzMDMuNzctMzAzLjdTNjA2LjQ3LDEzNSw0MzguNzcsMTM1LDEzNSwyNzEsMTM1LDQzOC42OSwyNzEuMDcsNzQyLjM5LDQzOC43Nyw3NDIuMzlaIi8+PHBhdGggY2xhc3M9ImNscy0xIiBkPSJNNTI0LjgzLDUxNS4yOGExMDQuODUsMTA0Ljg1LDAsMCwxLTE0OS40MSwwYy00MS41LTQxLjg3LTQxLjUtMTEwLDAtMTUxLjk1YTEwNC45MiwxMDQuOTIsMCwwLDEsMTQ5LjUxLjA4QTUwLjc2LDUwLjc2LDAsMCwwLDU5NywyOTEuOWEyMDYuNDQsMjA2LjQ0LDAsMCwwLTI5My41NSwwYy04MC41Nyw4MS4yNy04MC41NywyMTMuNTMsMCwyOTQuODNBMjA1LjI1LDIwNS4yNSwwLDAsMCw0NTAuMTgsNjQ4aDBBMjA1LjMsMjA1LjMsMCwwLDAsNTk3LDU4Ni43MWE1MC43Nyw1MC43NywwLDAsMC03Mi4xNi03MS40M1oiLz48L3N2Zz4=') no-repeat center;background-size: 24px;}@media only screen and (max-width: 768px) {.dp-pageToolbar {flex-wrap: wrap;bottom: 0;left: 0;border-left: 0;border-bottom: 0;border-right: 0;width: 100%;}}.dp-pt-section {display: inline-block;white-space: nowrap;}.dp-pt-section .oo-ui-popupWidget-popup {/** Avoid preventing line breaks in popups */white-space: initial;}.dp-pt-section + .dp-pt-section {/* TODO: Recheck RTL compatibility */margin-left: 16px;padding-left: 16px;border-left: 1px solid gray;}.dp-pt-section:last-child {/* TODO: Recheck RTL compatibility */margin-right: 8px;}.dp-pt-section-label {font-weight: bold;font-size: 0.6rem;color: #4a5054;text-transform: uppercase;}.dp-pt-section-content .oo-ui-buttonElement:last-child {margin-right: 0;}.dp-pt-caseInfo {font-weight: bold;font-size: 1.3rem;pointer-events: none;}.dp-pt-missingRevision {white-space: normal;}.dp-pageToolbar .dp-cs-row-status {width: 5.4em;}.dp-pt-menu .oo-ui-menuSelectWidget {min-width: 300px;}.dp-pt-menu .oo-ui-menuOptionWidget {padding-top: 8px;padding-bottom: 8px;}";
 
var deputyCoreEnglish = {
Line 14,246 ⟶ 15,027:
"deputy.session.section.close": "Archive section",
"deputy.session.section.closeComments": "Archiving comments",
"deputy.session.section.closeHelpcloseCommentsSign": "YourInclude my signature will automatically be included.",
"deputy.session.section.closeError": "Some revisions remain unassessed. You must mark these revisions as assessed before archiving this section.",
"deputy.session.section.closeError.danger": "Some revisions remain unassessed, but Deputy will allow archiving while danger mode is enabled.",
"deputy.session.section.closeWarn": "You have unsaved changes. Close the section without saving?",
"deputy.session.section.closed": "This section has been archived. You can edit its contents, but you cannot un-archive it.",
"deputy.session.section.stop": "Stop session",
"deputy.session.section.stop.title": "Stop then current session, closing all sections and saving changes for later.",
"deputy.session.section.saved": "Section saved",
"deputy.session.section.failed": "Failed to save section",
Line 14,256 ⟶ 15,040:
"deputy.session.section.conflict.title": "Edit conflict",
"deputy.session.section.conflict.help": "Someone else edited the page before you. Deputy will restart to load the new case content. Your changes will be preserved.",
"deputy.session.section.danger": "Danger mode",
"deputy.session.section.markAllFinished": "Mark all revisions in all sections as finished",
"deputy.session.section.instantArchive": "Archive",
"deputy.session.section.instantArchive.title": "Archive and save this section immediately. Revisions will not be marked as finished.",
"deputy.session.row.status": "Current page status",
"deputy.session.row.status.unfinished": "Unfinished",
Line 14,282 ⟶ 15,070:
"deputy.session.row.checked.talk": "talk",
"deputy.session.row.checked.contribs": "contribs",
"deputy.session.row.pageonly": "This row does not contain any diffs. Please assess the page history manually.",
"deputy.session.revision.assessed": "Mark as assessed",
"deputy.session.revision.diff.toggle": "Toggle comparison (diff) view",
Line 14,299 ⟶ 15,088:
"deputy.session.revision.new.tooltip": "This edit created a new page.",
"deputy.session.revision.missing": "The revision [[Special:Diff/$1|$1]] could not be found. It may have been deleted or suppressed.",
"deputy.session.page.close": "Minimize the toolbar to the sidebar",
"deputy.session.page.collapse": "Collapse the toolbar",
"deputy.session.page.expand": "Expand the toolbar",
"deputy.session.page.open": "Open Deputy toolbar",
"deputy.session.page.open.tooltip": "Open the Deputy page toolbar",
"deputy.session.page.diff.previous": "Navigate to the previous unassessed revision",
"deputy.session.page.diff.next": "Navigate to the next unassessed revision",
Line 14,309 ⟶ 15,103:
"deputy.session.page.caseInfo.assessed": "Assessed?",
"deputy.session.page.caseInfo.next": "Navigate to the next unassessed revision",
"deputy.session.page.pageonly.title": "No revisions",
"deputy.session.page.pageonly.help": "This row does not contain any revisions with it. Please assess the page history manually before making an assessment.",
"deputy.session.page.analysis": "Analysis",
"deputy.session.page.earwigLatest": "Earwig's Copyvio Detector (latest)",
Line 14,316 ⟶ 15,112:
"deputy.session.page.iabot.reason": "Possible copyright violation investigation",
"deputy.session.page.tools": "Tools"
};
 
var deputySharedEnglish = {
"deputy.name": "Deputy",
"deputy.description": "Copyright cleanup and case processing tool for Wikipedia.",
"deputy.ia": "Infringement Assistant",
"deputy.ia.short": "I. Assistant",
"deputy.ia.acronym": "Deputy: IA",
"deputy.ante": "Attribution Notice Template Editor",
"deputy.ante.short": "Attrib. Template Editor",
"deputy.ante.acronym": "Deputy: ANTE",
"deputy.cancel": "Cancel",
"deputy.review": "Review",
"deputy.save": "Save",
"deputy.close": "Close",
"deputy.positiveDiff": "+{{FORMATNUM:$1}}",
"deputy.negativeDiff": "-{{FORMATNUM:$1}}",
"deputy.moreInfo": "More information",
"deputy.dismiss": "Dismiss",
"deputy.comma-separator": ", ",
"deputy.diff": "Review your changes",
"deputy.diff.load": "Loading changes...",
"deputy.diff.no-changes": "No difference",
"deputy.diff.error": "An error occurred while trying to get the comparison.",
"deputy.loadError.userConfig": "Due to an error, your Deputy configuration has been reset.",
"deputy.loadError.wikiConfig": "An error occurred while loading this wiki's Deputy configuration. Please report this to the Deputy maintainers for this wiki."
};
 
Line 14,416 ⟶ 15,186:
"deputy.ia.listing.re.unverified": "Permission unverified as of this tagging; article will need to be deleted if that does not change.",
"deputy.ia.listing.re.viable": "Viable rewrite proposed; rewrite on temp page can be merged into the article.",
"deputy.ia.report.intro": "You are reporting to <b>{{wikilink:[[$1}}]]</b>",
"deputy.ia.report.page": "Currently reporting <b>{{wikilink:[[$1}}]]</b>",
"deputy.ia.report.lead": "Lead section",
"deputy.ia.report.end": "End of page",
Line 14,462 ⟶ 15,232:
*/
class CopyrightProblemsPage {
/**
* Private constructor. Use `get` instead to avoid cache misses.
*
* @param listingPage
* @param revid
*/
constructor(listingPage, revid) {
this.title = listingPage;
this.main = CopyrightProblemsPage.rootPage.getPrefixedText() ===
listingPage.getPrefixedText();
this.revid = revid;
}
/**
* @return See {@link WikiConfiguration#ia}.rootPage.
Line 14,523 ⟶ 15,281:
return page;
}
}
/**
* Private constructor. Use `get` instead to avoid cache misses.
*
* @param listingPage
* @param revid
*/
constructor(listingPage, revid) {
this.title = listingPage;
this.main = CopyrightProblemsPage.rootPage.getPrefixedText() ===
listingPage.getPrefixedText();
this.revid = revid;
}
/**
Line 14,628 ⟶ 15,398:
yield this.tryListingAppend(this.getListingWikitext(page, comments), decorateEditSummary(mw.msg(presumptive ?
'deputy.ia.content.listing.pd' :
'deputy.ia.content.listing', listingPage.getPrefixedText(), page.getPrefixedText()), window.InfringementAssistant.config));
});
}
Line 14,662 ⟶ 15,432:
yield this.tryListingAppend(this.getBatchListingWikitext(page, title, comments), decorateEditSummary(mw.msg(presumptive ?
'deputy.ia.content.batchListing.pd' :
'deputy.ia.content.batchListing', listingPage.getPrefixedText(), title), window.InfringementAssistant.config));
});
}
Line 14,683 ⟶ 15,453:
 
/**
* 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,700 ⟶ 15,470:
* @return the page linked to
*/
function anchorToTitlepagelinkToTitle(el) {
const href = el.getAttribute('href');
const articlePathRegex = new RegExp(mw.util.getUrl('(.*)'));
Line 14,752 ⟶ 15,522:
}
 
/**
* 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,757 ⟶ 15,536:
*/
class CopyrightProblemsListing {
/**
* Creates a new listing object.
*
* @param data Additional data about the page
* @param listingPage The page that this listing is on. This is not necessarily the page that
* the listing's wikitext is on, nor is it necessarily the root page.
* @param i A discriminator used to avoid collisions when a page is listed multiple times.
*/
constructor(data, listingPage, i = 1) {
this.listingPage = listingPage !== null && listingPage !== void 0 ? listingPage : CopyrightProblemsPage.get(data.listingPage);
this.i = Math.max(1, i); // Ensures no value below 1.
this.basic = data.basic;
this.title = data.title;
this.element = data.element;
if (data.basic === false) {
this.anchor = data.anchor;
this.plainlinks = data.plainlinks;
}
}
/**
* Responsible for determining listings on a page. This method allows for full-metadata
Line 14,782 ⟶ 15,542:
* 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,808 ⟶ 15,570:
*/
static getListingHeader(el) {
var _a;
let listingPage = null;
let previousPivot = (
// Target the ol/ul element itself if a list, target the <p> if not a list.
el.parentElement.tagName === 'LI' ? el.parentElement.parentElement : el.parentElement).previousElementSibling;
let heading;
while (previousPivot != null && previousPivot.tagName !== 'H4') {
// Search for a level 4 heading backwards.
while (previousPivot != null &&
// Set the ceiling to be immediately above for efficiency.
((_a = (heading = normalizeWikiHeading(previousPivot, previousPivot.parentElement))) === null || _a === void 0 ? void 0 : _a.level) !== 4) {
previousPivot = previousPivot.previousElementSibling;
}
Line 14,818 ⟶ 15,585:
return false;
}
if// At this point, (previousPivot.querySelector('.mw-headline') !=is null)likely {a MediaWiki level 4 heading.
const h4Anchor = heading.h.querySelector('a');
// At this point, previousPivot is likely a MediaWiki level 4 heading.
if 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,858 ⟶ 15,625:
// 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
// away.
elSiblings.indexOf(plainlinks) - elIndex > 2) {
return false;
}
Line 14,888 ⟶ 15,659:
return {
basic: false,
id,
title,
listingPage,
Line 14,896 ⟶ 15,668:
}
catch (e) {
console.warn("Couldn't parse listing. Might be malformed?", e, el);
return false;
}
}
/**
* A much more loose version of {@link CopyrightProblemsListing#getListing}, which only checks if a given
* which only checks if a given page is a link at the start of a paragraph or `<[uo]l>` list. Metadata is
* `<[uo]l>` list. Metadata is unavailable with this method.
*
* @param el
Line 14,925 ⟶ 15,697:
}
// Attempt to extract page title.
const title = anchorToTitlepagelinkToTitle(el);
if (!title) {
return false;
Line 14,946 ⟶ 15,718:
}
catch (e) {
console.warn("Couldn't parse listing. Might be malformed?", e, el);
return false;
}
Line 14,954 ⟶ 15,726:
* wikitext.
*/
get idanchorId() {
return this.title.getPrefixedDb()id + (this.i > 1 ? `-${this.i}` : '');
}
/**
* Creates a new listing object.
*
* @param data Additional data about the page
* @param listingPage The page that this listing is on. This is not necessarily the page that
* the listing's wikitext is on, nor is it necessarily the root page.
* @param i A discriminator used to avoid collisions when a page is listed multiple times.
*/
constructor(data, listingPage, i = 1) {
this.listingPage = listingPage !== null && listingPage !== void 0 ? listingPage : CopyrightProblemsPage.get(data.listingPage);
this.i = Math.max(1, i); // Ensures no value below 1.
this.basic = data.basic;
this.title = data.title;
this.element = data.element;
if (data.basic === false) {
this.id = data.id;
this.anchor = data.anchor;
this.plainlinks = data.plainlinks;
}
}
/**
Line 14,964 ⟶ 15,756:
* the line on which the listing appears, the `end` denotes the last line
* where there is a comment on that specific listing.
*
* Use in conjunction with `listingPage.getWikitext()` to get the lines in wikitext.
*
* @return See documentation body.
*/
getListingWikitextLines() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const lines = (yield this.listingPage.getWikitext()).split('\n');
Line 14,974 ⟶ 15,769:
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 14,981 ⟶ 15,778:
if (startLine != null) {
if (bulletList ?
!/^(\*[*:]+|:)/g.test(lineText) :
/^[^:*]/.test(lineText)) {
return { start: startLine, end: endLine !== null && endLine !== void 0 ? endLine : startLine };
Line 14,993 ⟶ 15,790:
.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,003 ⟶ 15,799:
skipCounter++;
continue;
}
if (idMalformed && match[2] === match[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 15,009 ⟶ 15,808:
}
}
if// (startLineWe've ===reached lines.lengththe -end 1)of {the document.
// `startLine` is only //ever Lastset lineif only.the IDs match, so we can safely assume
// that if `startLine` returnand {`endLine` start:is startLine,set end:or if `startLine` is the last };line
// in the page, then we've found the listing (and it is the last listing on the
// page, where `endLine` would have been set if it had comments).
if ((startLine != null && endLine != null) ||
(startLine != null && startLine === lines.length - 1)) {
return { start: startLine, end: endLine !== null && endLine !== void 0 ? endLine : startLine };
}
// Couldn't find an ending. Malformed listing?
// It should be nearly impossible to hit this condition.
// Gracefully handle this.
throw new Error("Couldn'Listingt isdetect missinglisting from wikitext or(edit malformedconflict/is listing'it missing?)");
});
}
Line 15,030 ⟶ 15,835:
const range = yield this.getListingWikitextLines();
if (indent) {
// This usually isn't needed. {{CPC}} handles the bullet.
message = (this.element.parentElement.tagName === 'LI' ?
'*:' :
Line 15,049 ⟶ 15,855:
return __awaiter(this, void 0, void 0, function* () {
const newWikitext = yield this.addComment(message, indent);
yield MwApi.action.postWithEditToken(Object.assign(Object.assign({}, changeTag(yield window.InfringementAssistant.getWikiConfig())), { action: 'edit', format: 'json', formatversion: '2', utf8: 'true', title: this.listingPage.title.getPrefixedText(), text: newWikitext, summary: decorateEditSummary(summary !== null && summary !== void 0 ? summary : mw.msg('deputy.ia.content.respond', this.listingPage.title.getPrefixedText(), this.title.getPrefixedText()), window.InfringementAssistant.config) }));
yield this.listingPage.getWikitext(true);
});
}
/**
* Serialize this listing. Used for tests.
*/
serialize() {
return __awaiter(this, void 0, void 0, function* () {
return {
basic: this.basic,
i: this.i,
id: this.id,
title: {
namespace: this.title.getNamespaceId(),
title: this.title.getMainText(),
fragment: this.title.getFragment()
},
listingPage: {
namespace: this.listingPage.title.getNamespaceId(),
title: this.listingPage.title.getMainText(),
fragment: this.listingPage.title.getFragment()
},
lines: yield this.getListingWikitextLines()
};
});
}
Line 15,059 ⟶ 15,888:
*/
class ListingResponsePanel extends EventTarget {
/**
*
* @param originLink
* @param listing
*/
constructor(originLink, listing) {
super();
// TODO: types-mediawiki limitation
this.reloadPreviewThrottled = mw.util.throttle(this.reloadPreview, 500);
this.originLink = originLink;
this.listing = listing;
}
/**
* @return A set of possible copyright problems responses.
Line 15,078 ⟶ 15,895:
}
/**
*
* @param response
* @param locale
Line 15,092 ⟶ 15,908:
response.label :
((_c = (_b = response.label[locale]) !== null && _b !== void 0 ? _b : response.label[locale1]) !== null && _c !== void 0 ? _c : response.label[0]);
}
/**
* @param originLink
* @param listing
*/
constructor(originLink, listing) {
super();
// TODO: types-mediawiki limitation
this.reloadPreviewThrottled = mw.util.throttle(this.reloadPreview, 500);
this.originLink = originLink;
this.listing = listing;
}
/**
Line 15,191 ⟶ 16,018:
}
catch (e) {
console.error(e);
OO.ui.alert(mw.msg('deputy.ia.listing.re.error', e.message));
this.dropdown.setDisabled(false);
Line 15,266 ⟶ 16,093:
}
return this.prefill ?
mw.format(this.prefill.template, this.listing.title.getPrefixedText(), (_c = this.comments) !== null && _c !== void 0 ? _c : '') :
this.comments;
}
Line 15,392 ⟶ 16,219:
initialize() {
super.initialize();
const intro = unwrapJQ(h_1("div", { class: "ia-report-intro" }), dangerouslySetInnerHTML: mw.message('deputy.ia.report.intro', CopyrightProblemsPage.getCurrentListingPage().getPrefixedText()).parseparseDom() });
intro.querySelector('a').setAttribute('target', '_blank');
const page = unwrapJQ(h_1("div", { class: "ia-report-intro" }), dangerouslySetInnerHTML: mw.message('deputy.ia.report.page', this.page.getPrefixedText()).parseparseDom() });
page.querySelector('a').setAttribute('target', '_blank');
this.fieldsetLayout = new OO.ui.FieldsetLayout({
Line 15,728 ⟶ 16,555:
if (this.data.entirePage) {
finalPageContent = copyvioWikitext + '\n' + this.wikitext;
if (wikiConfig.entirePageAppendBottom.get()) {
finalPageContent += '\n' + wikiConfig.hideTemplateBottom.get();
}
}
else {
Line 15,753 ⟶ 16,583:
.cci.rootPage.get().getPrefixedText(),
this.data.presumptiveCase
] : [])), window.InfringementAssistant.config) }));
});
}
Line 15,760 ⟶ 16,590:
*/
postListing() {
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function* () {
const sourceUrls = (_a = this.data.sourceUrls) !== null && _a !== void 0 ? _a : [];
Line 15,777 ⟶ 16,607:
.cci.rootPage.get().getPrefixedText(),
this.data.presumptiveCase
] : [from]), (_b = this.data.notes) !== null && _b !== void 0 ? _b : '')) :
(_b_c = this.data.notes) !== null && _b_c !== void 0 ? _b_c : '';
yield CopyrightProblemsPage.getCurrent()
.postListing(this.page, comments, this.data.presumptive);
Line 16,174 ⟶ 17,004:
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,211 ⟶ 17,043:
}
/**
* Adds a panel containing the "new listing" buttons (single and multiple)
*
* and the panel container (when filing a multiple-page listing) to the proper
* ___location: either at the end of the copyright problems section or replacing
* the redlink to the blank copyright problems page.
*/
addNewListingsPanel() {
document.querySelectorAll('.mw-headline >a, .mw-heading a, a.external, a.redlink').forEach((el) => {
const href = el.getAttribute('href');
const url = new URL(href, window.___location.href);
if (equalTitle(url.searchParams.get('title'), CopyrightProblemsPage.getCurrentListingPage()) ||
url.pathname === mw.util.getUrl(CopyrightProblemsPage.getCurrentListingPage().getPrefixedText())) {
if (el.classList.contains('external') || el.classList.contains('redlink')) {
// Crawl backwards, avoiding common inline elements, to see if this is a standalone
// lineKeep withincrawling up and find the renderedparent of this element that is text.directly
let currentPivot = el // below the parser root or the current section.parentElement;
while ( let currentPivot !== null &&el;
['I',while 'B', 'SPAN', 'EM', 'STRONG'].indexOf(currentPivot.tagName) !== -1)null {&&
currentPivot = !currentPivot.parentElement;classList.contains('mw-parser-output') &&
} ['A', 'I', 'B', 'SPAN', 'EM', 'STRONG']
// By this point, current pivot will be a <div>, <p>, or other.indexOf(currentPivot.tagName) usable!== element.-1) {
if (!el currentPivot = currentPivot.parentElement.classList.contains('mw-headline') &&;
(currentPivot == null ||
currentPivot.children.length > 1)) {
return;
}
else if (el.parentElement.classList.contains('mw-headline')) {
// "Edit source" button of an existing section heading.
let headingBottom = el.parentElement.parentElement.nextElementSibling;
let pos = 'beforebegin';
while (headingBottom != null &&
!/^H[123456]$/.test(headingBottom.tagName)) {
headingBottom = headingBottom.nextElementSibling;
}
if// (headingBottomWe're ==now null)at {the <p> or <div> or whatever.
// Check if it headingBottomonly =has el.parentElement.parentElement.parentElement;one child (the tree that contains this element)
// and if so, posreplace =the 'beforeend';links.
if (currentPivot.children.length > 1) {
return;
}
// Add below today's section header.
mw.loader.using([
'oojs-ui-core',
Line 16,251 ⟶ 17,076:
'mediawiki.widgets.TitlesMultiselectWidget'
], () => {
//swapElements(currentPivot, H4NewCopyrightProblemsListing());
headingBottom.insertAdjacentElement(pos, NewCopyrightProblemsListing());
});
}
else {
// This is in a heading. Let's place it after the section heading.
const heading = normalizeWikiHeading(el);
if (heading.root.classList.contains('dp-ia-upgraded')) {
return;
}
heading.root.classList.add('dp-ia-upgraded');
mw.loader.using([
'oojs-ui-core',
Line 16,262 ⟶ 17,092:
'mediawiki.widgets.TitlesMultiselectWidget'
], () => {
swapElementsheading.root.insertAdjacentElement(el'afterend', NewCopyrightProblemsListing());
});
}
Line 16,270 ⟶ 17,100:
}
 
var iaStyles = ".ia-listing-action {display: inline-block;}body.ltr .ia-listing-action {margin-left: 0.5em;}body.ltr .ia-listing-action--bracket:first-child,body.rtl .ia-listing-action--bracket:first-child {margin-right: 0.2em;}body.rtl .ia-listing-action {margin-right: 0.5em;}body.ltr .ia-listing-action--bracket:last-child,body.rtl .ia-listing-action--bracket:last-child {margin-left: 0.2em;}.ia-listing-action--link[disabled] {color: gray;pointer-events: none;}@keyframes ia-newResponse {from { background-color: #ffe29e }to { background-color: rgba( 0, 0, 0, 0 ); }}.ia-newResponse {animation: ia-newResponse 2s ease-out;}.ia-listing-response, .ia-listing-new {max-width: 50em;}.ia-listing-response {margin-top: 0.4em;margin-bottom: 0.4em;}.mw-content-ltr .ia-listing-response, .mw-content-rtl .mw-content-ltr .ia-listing-response {margin-left: 1.6em;margin-right: 0;}.mw-content-rtl .ia-listing-response, .mw-content-ltr .mw-content-rtl .ia-listing-response {margin-left: 0;margin-right: 1.6em;}.ia-listing-response > div {margin-bottom: 8px;}.ia-listing--preview {box-sizing: border-box;background: #f6f6f6;padding: 0.5em 1em;overflow: hidden;}/** \"Preview\" */.ia-listing--preview::before {content: attr(data-label);color: #808080;display: block;margin-bottom: 0.2em;}.ia-listing-response--submit {text-align: right;}/** * NEW LISTINGS */.ia-listing-newPanel {margin-top: 0.5em;}.ia-listing-new {display: flex;align-items: end;margin-top: 0.5em;padding: 1em;}.ia-listing-new--field {flex: 1;}.ia-listing-new--cancel {margin-left: 0.5em;}.ia-batchListing-new {padding: 1em;max-width: 50em;}.ia-batchListing-new--buttons {display: flex;justify-content: end;margin-top: 12px;}.ia-batchListing-new .ia-listing--preview {margin-top: 12px;}/** * REPORTING DIALOG */.ia-report-intro {font-size: 0.8rem;padding-bottom: 12px;border-bottom: 1px solid gray;margin-bottom: 12px;}.ia-report-intro b {display: block;font-size: 1rem;}.ia-report-submit {padding-top: 12px;display: flex;justify-content: flex-end;}/** * COPYVIO PREVIEWS */.copyvio.deputy-show {display: inherit !important;border: 0.2em solid #f88;padding: 1em;}.dp-hiddenVio {display: flex;flex-direction: row;margin: 1em 0;}.dp-hiddenVio-message {flex: 1;}.dp-hiddenVio-actions {flex: 0;margin-left: 1em;display: flex;flex-direction: column;justify-content: center;}";
 
/**
Line 16,277 ⟶ 17,107:
class HiddenViolationUI {
/**
*
* @param el
*/
Line 16,291 ⟶ 17,120:
attach() {
this.vioElement.insertAdjacentElement('beforebegin', h_1("div", { class: "deputy dp-hiddenVio" },
h_1("div", null{ class: "dp-hiddenVio-message" }, this.renderMessage()),
h_1("div", { class: "dp-hiddenVio-actions" }, this.renderButton())));
this.vioElement.classList.add('deputy-upgraded');
Line 16,354 ⟶ 17,183:
return false;
}
yield Promise.all([
DeputyLanguage.load('shared', deputySharedEnglish),
DeputyLanguage.loadMomentLocale()
]);
mw.hook('ia.preload').fire();
mw.util.addCSS(iaStyles);
Line 16,385 ⟶ 17,210:
// Query parameter-based autostart disable (i.e. don't start if param exists)
if (!/[?&]ia-autostart(=(0|no|false|off)?(&|$)|$)/.test(window.___location.search)) {
returnyield mw.loader.using(InfringementAssistant.dependencies, () => __awaiter(this, void 0, void 0, function* () {
yield this.init();
}));
return true;
}
return true;
Line 16,430 ⟶ 17,256:
}
/**
* Opens the workflow dialog.
*/
openWorkflowDialog() {
return __awaiter(this, void 0, void 0, function* () {
returnyield mw.loader.using(InfringementAssistant.dependencies, () => __awaiter(this, void 0, void 0, function* () {
yield DeputyLanguage.loadMomentLocale();
if (!this.dialog) {
yield DeputyLanguage.loadMomentLocale();
Line 16,443 ⟶ 17,270:
this.windowManager.addWindows([this.dialog]);
}
yield this.windowManager.openWindow(this.dialog).opened;
}));
});
Line 16,472 ⟶ 17,299:
var _a;
const page = normalizeTitle();
if (page.namespacegetNamespaceId() === nsId('special') ||
page.namespacegetNamespaceId() === nsId('media')) {
// Don't save virtual namespaces.
return;
Line 16,500 ⟶ 17,327:
}
Recents.key = 'mw-userjs-recents';
 
/**
* Applies configuration overrides. This takes two objects, A and B.
* A's keys will be respected and will remain unchanged. Object
* values of A that also exist in B will be overwritten with its
* values in B.
*
* @param data
* @param overrides
* @param logger
*/
function applyOverrides(data, overrides, logger) {
if (overrides) {
for (const category of Object.keys(data)) {
if (!overrides[category]) {
continue; // Category does not exist.
}
for (const categoryKey of Object.keys(overrides[category])) {
if (logger) {
logger(`${category}.${categoryKey}`, data[category][categoryKey], overrides[category][categoryKey]);
}
data[category][categoryKey] =
overrides[category][categoryKey];
}
}
for (const category of Object.keys(overrides)) {
if (!data[category]) {
data[category] = overrides[category];
if (logger) {
logger(`${category}`, data[category], overrides[category]);
}
}
}
}
}
 
/**
Line 16,586 ⟶ 17,448:
yield currentValues;
}
}
 
/**
* Unwraps an element into its child elements. This entirely discards
* the parent element.
*
* @param el The element to unwrap.
* @return The unwrapped element.
*/
function unwrapElement (el) {
return Array.from(el.childNodes).map(v => v instanceof HTMLElement ? v :
(v instanceof Text ? v.textContent : undefined)).filter(v => v !== undefined);
}
 
var util = {
applyOverrides: applyOverrides,
blockExit: blockExit$1,
classMix: classMix,
Line 16,594 ⟶ 17,469:
cloneRegex: cloneRegex$1,
copyToClipboard: copyToClipboard,
dangerModeConfirm: dangerModeConfirm,
equalTitle: equalTitle,
error: error,
findNextSiblingElement: findNextSiblingElement,
fromObjectEntries: fromObjectEntries,
generateId: generateId,
getObjectValues: getObjectValues,
last: last,
log: log,
matchAll: matchAll,
moveToStart: moveToStart,
organize: organize,
pickSequence: pickSequence,
removeElement: removeElement,
Line 16,606 ⟶ 17,486:
sleep: sleep,
swapElements: swapElements,
unwrapElement: unwrapElement,
unwrapJQ: unwrapJQ,
unwrapWidget: unwrapWidget,
warn: warn,
yesNo: yesNo
};
 
/**
* Finds a MediaWiki section heading from the current DOM using its title.
*
* @param sectionHeadingName The name of the section to find.
* @param n The `n` of the section. Starts at 1.
* @return The found section heading. `null` if not found.
*/
function findSectionHeading(sectionHeadingName, n = 1) {
let currentN = 1;
const headlines = Array.from(document.querySelectorAll(
// Old style headings
[1, 2, 3, 4, 5, 6].map(v => `h${v} > .mw-headline`).join(',') +
',' +
// New style headings
[1, 2, 3, 4, 5, 6].map(v => `mw-heading > h${v}`).join(',')));
for (const el of headlines) {
if (el instanceof HTMLElement && el.innerText === sectionHeadingName) {
if (currentN >= n) {
return el.parentElement;
}
else {
currentN++;
}
}
}
return null;
}
 
/**
Line 16,626 ⟶ 17,537:
nativeRange.setEnd(rangeLike.endContainer, rangeLike.endOffset);
return nativeRange;
}
 
/**
* From a list of page titles, get which pages exist.
*
* @param pages The pages to search for
* @return An array of pages which exist, ordered by input order.
*/
function getPageExists (pages) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (!Array.isArray(pages)) {
pages = [pages];
}
const pageNames = pages
.map(p => p instanceof mw.Title ? p.getPrefixedText() : p);
const pageRequest = (yield MwApi.action.get({
action: 'query',
titles: pageNames.join('|')
})).query;
const existingPages = [];
if (pageRequest.pages.length > 0) {
const redirects = toRedirectsObject(pageRequest.redirects, pageRequest.normalized);
const pageMap = Object.fromEntries(pageRequest.pages.map((v) => [v.title, !v.missing]));
// Use `pages` to retain client order (assume MW response can be tampered with)
for (const loc of pageNames) {
const actualLocation = (_a = redirects[loc]) !== null && _a !== void 0 ? _a : loc;
if (pageMap[actualLocation]) {
existingPages.push(actualLocation);
}
}
}
return existingPages;
});
}
 
Line 16,643 ⟶ 17,588:
 
var wikiUtil = {
anchorToTitle: anchorToTitle,
decorateEditSummary: decorateEditSummary,
delink: delink,
errorToOO: errorToOO,
findSectionHeading: findSectionHeading,
getApiErrorText: getApiErrorText,
getNativeRange: getNativeRange,
getPageContent: getPageContent,
getPageExists: getPageExists,
getPageTitle: getPageTitle,
getRevisionContent: getRevisionContent,
getRevisionDiffURL: getRevisionDiffURL,
getRevisionURL: getRevisionURL,
getSectionElements: getSectionElements,
getSectionHTML: getSectionHTML,
getSectionId: getSectionId,
guessAuthor: guessAuthor,
isWikiHeading: isWikiHeading,
msgEval: msgEval,
normalizeTitle: normalizeTitle,
normalizeWikiHeading: normalizeWikiHeading,
nsId: nsId,
openWindow: openWindow,
pagelinkToTitle: pagelinkToTitle,
parseDiffUrl: parseDiffUrl,
performHacks: performHacks,
purge: purge,
renderWikitext: renderWikitext,
sectionHeadingId: sectionHeadingId,
sectionHeadingN: sectionHeadingN,
sectionHeadingName: sectionHeadingName,
toRedirectsObject: toRedirectsObject
};
Line 16,772 ⟶ 17,722:
*/
class Deputy {
/**
* @return An OOUI window manager
*/
get windowManager() {
if (!this._windowManager) {
this._windowManager = new OO.ui.WindowManager();
document.body.appendChild(unwrapWidget(this._windowManager));
}
return this._windowManager;
}
/**
* Initialize Deputy. This static function attaches Deputy to the `window.deputy`
* object and initializes that instance.
*/
static init() {
return __awaiter(this, void 0, void 0, function* () {
Deputy.instance = new Deputy();
window.deputy = Deputy.instance;
return window.deputy.init();
});
}
/**
* Private constructor. To access Deputy, use `window.deputy` or Deputy.instance.
*/
constructor() {
this.DeputyDispatch = DeputyDispatchDispatch;
this.DeputyStorage = DeputyStorage;
this.DeputySession = DeputySession;
this.DeputyPreferences = DeputyPreferences;
this.DeputyCommunications = DeputyCommunications;
this.DeputyCase = DeputyCase;
Line 16,811 ⟶ 17,781:
this.ia = new InfringementAssistant(this);
/* ignored */
}
/**
* @return An OOUI window manager
*/
get windowManager() {
if (!this._windowManager) {
this._windowManager = new OO.ui.WindowManager();
document.body.appendChild(unwrapWidget(this._windowManager));
}
return this._windowManager;
}
/**
* Initialize Deputy. This static function attaches Deputy to the `window.deputy`
* object and initializes that instance.
*/
static init() {
return __awaiter(this, void 0, void 0, function* () {
Deputy.instance = new Deputy();
window.deputy = Deputy.instance;
return window.deputy.init();
});
}
/**
Line 16,861 ⟶ 17,810:
yield this.storage.init();
// Initialize the Deputy API interface
this.dispatch = new DeputyDispatch()Dispatch.i;
// Initialize the Deputy preferences instance
this.prefs = new DeputyPreferences();
// Initialize communications
this.comms = new DeputyCommunications();
Line 16,880 ⟶ 17,827:
}
yield this.wikiConfig.prepareEditBanners();
console.log('Loaded!');
mw.hook('deputy.load').fire(this);
// Perform post-load tasks.