MediaWiki:Gadget-RCPatrol.js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
/*! <nowiki>
Unminify code: https://github.com/Xi-Plus/RCPatrol
*/
(function() {
"use strict";
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), true).forEach(function(key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _regeneratorRuntime() {
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
_regeneratorRuntime = function() {
return exports;
};
var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = typeof Symbol == "function" ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
function define(obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
}), obj[key];
}
try {
define({}, "");
} catch (err) {
define = function(obj, key, value) {
return obj[key] = value;
};
}
function wrap(innerFn, outerFn, self, tryLocsList) {
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []);
return generator._invoke = function(innerFn2, self2, context2) {
var state = "suspendedStart";
return function(method, arg) {
if (state === "executing")
throw new Error("Generator is already running");
if (state === "completed") {
if (method === "throw")
throw arg;
return doneResult();
}
for (context2.method = method, context2.arg = arg; ; ) {
var delegate = context2.delegate;
if (delegate) {
var delegateResult = maybeInvokeDelegate(delegate, context2);
if (delegateResult) {
if (delegateResult === ContinueSentinel)
continue;
return delegateResult;
}
}
if (context2.method === "next")
context2.sent = context2._sent = context2.arg;
else if (context2.method === "throw") {
if (state === "suspendedStart")
throw state = "completed", context2.arg;
context2.dispatchException(context2.arg);
} else
context2.method === "return" && context2.abrupt("return", context2.arg);
state = "executing";
var record = tryCatch(innerFn2, self2, context2);
if (record.type === "normal") {
if (state = context2.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel)
continue;
return {
value: record.arg,
done: context2.done
};
}
record.type === "throw" && (state = "completed", context2.method = "throw", context2.arg = record.arg);
}
};
}(innerFn, self, context), generator;
}
function tryCatch(fn, obj, arg) {
try {
return {
type: "normal",
arg: fn.call(obj, arg)
};
} catch (err) {
return {
type: "throw",
arg: err
};
}
}
exports.wrap = wrap;
var ContinueSentinel = {};
function Generator() {
}
function GeneratorFunction() {
}
function GeneratorFunctionPrototype() {
}
var IteratorPrototype = {};
define(IteratorPrototype, iteratorSymbol, function() {
return this;
});
var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([])));
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
function defineIteratorMethods(prototype) {
["next", "throw", "return"].forEach(function(method) {
define(prototype, method, function(arg) {
return this._invoke(method, arg);
});
});
}
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {
var record = tryCatch(generator[method], generator, arg);
if (record.type !== "throw") {
var result = record.arg, value = result.value;
return value && typeof value == "object" && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function(value2) {
invoke("next", value2, resolve, reject);
}, function(err) {
invoke("throw", err, resolve, reject);
}) : PromiseImpl.resolve(value).then(function(unwrapped) {
result.value = unwrapped, resolve(result);
}, function(error) {
return invoke("throw", error, resolve, reject);
});
}
reject(record.arg);
}
var previousPromise;
this._invoke = function(method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function(resolve, reject) {
invoke(method, arg, resolve, reject);
});
}
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
};
}
function maybeInvokeDelegate(delegate, context) {
var method = delegate.iterator[context.method];
if (method === void 0) {
if (context.delegate = null, context.method === "throw") {
if (delegate.iterator.return && (context.method = "return", context.arg = void 0, maybeInvokeDelegate(delegate, context), context.method === "throw"))
return ContinueSentinel;
context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
}
return ContinueSentinel;
}
var record = tryCatch(method, delegate.iterator, context.arg);
if (record.type === "throw")
return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
var info = record.arg;
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, context.method !== "return" && (context.method = "next", context.arg = void 0), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
}
function pushTryEntry(locs) {
var entry = {
tryLoc: locs[0]
};
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
}
function resetTryEntry(entry) {
var record = entry.completion || {};
record.type = "normal", delete record.arg, entry.completion = record;
}
function Context(tryLocsList) {
this.tryEntries = [{
tryLoc: "root"
}], tryLocsList.forEach(pushTryEntry, this), this.reset(true);
}
function values(iterable) {
if (iterable) {
var iteratorMethod = iterable[iteratorSymbol];
if (iteratorMethod)
return iteratorMethod.call(iterable);
if (typeof iterable.next == "function")
return iterable;
if (!isNaN(iterable.length)) {
var i = -1, next = function next2() {
for (; ++i < iterable.length; )
if (hasOwn.call(iterable, i))
return next2.value = iterable[i], next2.done = false, next2;
return next2.value = void 0, next2.done = true, next2;
};
return next.next = next;
}
}
return {
next: doneResult
};
}
function doneResult() {
return {
value: void 0,
done: true
};
}
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function(genFun) {
var ctor = typeof genFun == "function" && genFun.constructor;
return !!ctor && (ctor === GeneratorFunction || (ctor.displayName || ctor.name) === "GeneratorFunction");
}, exports.mark = function(genFun) {
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
}, exports.awrap = function(arg) {
return {
__await: arg
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function() {
return this;
}), exports.AsyncIterator = AsyncIterator, exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
PromiseImpl === void 0 && (PromiseImpl = Promise);
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function(result) {
return result.done ? result.value : iter.next();
});
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function() {
return this;
}), define(Gp, "toString", function() {
return "[object Generator]";
}), exports.keys = function(object) {
var keys = [];
for (var key in object)
keys.push(key);
return keys.reverse(), function next() {
for (; keys.length; ) {
var key2 = keys.pop();
if (key2 in object)
return next.value = key2, next.done = false, next;
}
return next.done = true, next;
};
}, exports.values = values, Context.prototype = {
constructor: Context,
reset: function(skipTempReset) {
if (this.prev = 0, this.next = 0, this.sent = this._sent = void 0, this.done = false, this.delegate = null, this.method = "next", this.arg = void 0, this.tryEntries.forEach(resetTryEntry), !skipTempReset)
for (var name in this)
name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = void 0);
},
stop: function() {
this.done = true;
var rootRecord = this.tryEntries[0].completion;
if (rootRecord.type === "throw")
throw rootRecord.arg;
return this.rval;
},
dispatchException: function(exception) {
if (this.done)
throw exception;
var context = this;
function handle(loc, caught) {
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = void 0), !!caught;
}
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i], record = entry.completion;
if (entry.tryLoc === "root")
return handle("end");
if (entry.tryLoc <= this.prev) {
var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc");
if (hasCatch && hasFinally) {
if (this.prev < entry.catchLoc)
return handle(entry.catchLoc, true);
if (this.prev < entry.finallyLoc)
return handle(entry.finallyLoc);
} else if (hasCatch) {
if (this.prev < entry.catchLoc)
return handle(entry.catchLoc, true);
} else {
if (!hasFinally)
throw new Error("try statement without catch or finally");
if (this.prev < entry.finallyLoc)
return handle(entry.finallyLoc);
}
}
}
},
abrupt: function(type, arg) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
var finallyEntry = entry;
break;
}
}
finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
var record = finallyEntry ? finallyEntry.completion : {};
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
},
complete: function(record, afterLoc) {
if (record.type === "throw")
throw record.arg;
return record.type === "break" || record.type === "continue" ? this.next = record.arg : record.type === "return" ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : record.type === "normal" && afterLoc && (this.next = afterLoc), ContinueSentinel;
},
finish: function(finallyLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.finallyLoc === finallyLoc)
return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
}
},
catch: function(tryLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc === tryLoc) {
var record = entry.completion;
if (record.type === "throw") {
var thrown = record.arg;
resetTryEntry(entry);
}
return thrown;
}
}
throw new Error("illegal catch attempt");
},
delegateYield: function(iterable, resultName, nextLoc) {
return this.delegate = {
iterator: values(iterable),
resultName: resultName,
nextLoc: nextLoc
}, this.method === "next" && (this.arg = void 0), ContinueSentinel;
}
}, exports;
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(void 0);
});
};
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o)
return;
if (typeof o === "string")
return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor)
n = o.constructor.name;
if (n === "Map" || n === "Set")
return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length)
len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++)
arr2[i] = arr[i];
return arr2;
}
function _createForOfIteratorHelper(o, allowArrayLike) {
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
if (!it) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it)
o = it;
var i = 0;
var F = function() {
};
return {
s: F,
n: function() {
if (i >= o.length)
return {
done: true
};
return {
done: false,
value: o[i++]
};
},
e: function(e) {
throw e;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var normalCompletion = true, didErr = false, err;
return {
s: function() {
it = it.call(o);
},
n: function() {
var step = it.next();
normalCompletion = step.done;
return step;
},
e: function(e) {
didErr = true;
err = e;
},
f: function() {
try {
if (!normalCompletion && it.return != null)
it.return();
} finally {
if (didErr)
throw err;
}
}
};
}
var hansLocale = {
"gadget-rcp-hist-basic-auto": "已自动巡查",
"gadget-rcp-hist-basic-user": "已由[[User:$1|$1]]巡查",
"gadget-rcp-hist-pending-difflink": "<b>[[Special:Diff/$1/$2|等候巡查]]</b>",
"gadget-rcp-hist-basic": "已巡查修订",
"gadget-rcp-hist-pending": "待巡查修订",
"gadget-rcp-diff2stable": "查看所有待巡查变更",
"gadget-rcp-patrol": "巡查",
"gadget-rcp-patrol-multi": "标记$1笔修订为已巡查",
"gadget-rcp-patrol-multi-confirm": "您确定要将$1笔修订都标记为已巡查吗?",
"gadget-rcp-patrol-notify": "修订版本$1已标记为已巡查。"
};
var hantLocale = {
"gadget-rcp-hist-basic-auto": "已自動巡查",
"gadget-rcp-hist-basic-user": "已由[[User:$1|$1]]巡查",
"gadget-rcp-hist-pending-difflink": "<b>[[Special:Diff/$1/$2|等候巡查]]</b>",
"gadget-rcp-hist-basic": "已巡查修訂",
"gadget-rcp-hist-pending": "待巡查修訂",
"gadget-rcp-diff2stable": "檢視所有待巡查變更",
"gadget-rcp-patrol": "巡查",
"gadget-rcp-patrol-multi": "標記$1筆修訂為已巡查",
"gadget-rcp-patrol-multi-confirm": "您確定要將$1筆修訂都標記為已巡查嗎?",
"gadget-rcp-patrol-notify": "修訂版本$1已標記為已巡查。"
};
$.i18n({
locale: mw.config.get("wgUserLanguage")
});
$.i18n().load({
"zh-hans": hansLocale,
"zh-hant": hantLocale
});
function msg(key) {
var _mw;
if (!mw.messages.exists(key)) {
mw.messages.set(key, $.i18n(key));
}
for (var _len = arguments.length, parameters = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
parameters[_key - 1] = arguments[_key];
}
return (_mw = mw).message.apply(_mw, [key].concat(parameters)).text();
}
function parsedmsg(key) {
var _mw2;
if (!mw.messages.exists(key)) {
mw.messages.set(key, $.i18n(key));
}
for (var _len2 = arguments.length, parameters = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
parameters[_key2 - 1] = arguments[_key2];
}
return (_mw2 = mw).message.apply(_mw2, [key].concat(parameters)).parse();
}
var api = new mw.Api();
var hasPatrol = mw.config.get("wgUserGroups").includes("patroller") || mw.config.get("wgUserGroups").includes("sysop");
var rcpOptions = {
multiPatrol: false,
multiPatrolConfirm: true,
patrolInRC: false
};
var last_patrolled_revid = 0;
var last_rc_revid = 0;
var recentchanges = null;
var autopatrollers = [];
var patrol_logs = null;
function getAutopatrollers() {
return _getAutopatrollers.apply(this, arguments);
}
function _getAutopatrollers() {
_getAutopatrollers = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee() {
var query, data, _iterator2, _step2, user;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!(autopatrollers.length > 0)) {
_context.next = 2;
break;
}
return _context.abrupt("return");
case 2:
query = {
"action": "query",
"format": "json",
"list": "allusers",
"aurights": "autopatrol",
"aulimit": "max"
};
case 3:
_context.next = 6;
return api.get(query);
case 6:
data = _context.sent;
_iterator2 = _createForOfIteratorHelper(data.query.allusers);
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done; ) {
user = _step2.value;
autopatrollers.push(user.name);
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
if (!data["continue"]) {
_context.next = 13;
break;
}
query = _objectSpread2(_objectSpread2({}, query), data["continue"]);
_context.next = 14;
break;
case 13:
return _context.abrupt("break", 16);
case 14:
_context.next = 3;
break;
case 16:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return _getAutopatrollers.apply(this, arguments);
}
function getPatrolLogs() {
return _getPatrolLogs.apply(this, arguments);
}
function _getPatrolLogs() {
_getPatrolLogs = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee2() {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
if (!patrol_logs) {
_context2.next = 2;
break;
}
return _context2.abrupt("return");
case 2:
_context2.next = 4;
return api.get({
"action": "query",
"format": "json",
"list": "logevents",
"leprop": "user|details",
"leaction": "patrol/patrol",
"letitle": mw.config.get("wgPageName"),
"lelimit": "max"
}).then(function(data) {
patrol_logs = data.query.logevents;
});
case 4:
patrol_logs.forEach(function(log) {
last_patrolled_revid = Math.max(last_patrolled_revid, log.params.curid);
});
case 5:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
return _getPatrolLogs.apply(this, arguments);
}
function getPatrolRecords() {
return _getPatrolRecords.apply(this, arguments);
}
function _getPatrolRecords() {
_getPatrolRecords = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee3() {
var query;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
if (!recentchanges) {
_context3.next = 2;
break;
}
return _context3.abrupt("return");
case 2:
query = {
"action": "query",
"format": "json",
"list": "recentchanges",
"rctype": "edit|new",
"rcprop": "ids",
"rclimit": "max",
"rctitle": mw.config.get("wgPageName")
};
if (hasPatrol) {
query.rcprop += "|patrolled";
} else {
query.rcprop += "|user";
}
_context3.next = 6;
return api.get(query).then(function(data) {
recentchanges = data.query.recentchanges;
});
case 6:
if (hasPatrol) {
_context3.next = 11;
break;
}
_context3.next = 9;
return getAutopatrollers();
case 9:
_context3.next = 11;
return getPatrolLogs();
case 11:
if (recentchanges.length === 0) {
last_patrolled_revid = mw.config.get("wgCurRevisionId");
last_rc_revid = mw.config.get("wgCurRevisionId");
} else {
last_patrolled_revid = Math.max(last_patrolled_revid, recentchanges[recentchanges.length - 1].old_revid);
last_rc_revid = recentchanges[recentchanges.length - 1].old_revid;
if (hasPatrol) {
recentchanges.forEach(function(recentchange) {
if (recentchange.patrolled !== void 0) {
last_patrolled_revid = Math.max(last_patrolled_revid, recentchange.revid);
return;
}
});
} else {
recentchanges.forEach(function(recentchange) {
if (autopatrollers.includes(recentchange.user)) {
last_patrolled_revid = Math.max(last_patrolled_revid, recentchange.revid);
return;
}
});
}
}
case 12:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
return _getPatrolRecords.apply(this, arguments);
}
function markHistByRC() {
recentchanges.forEach(function(recentchange) {
var $contribution_row = $(".mw-contributions-list li[data-mw-revid=" + recentchange.revid + "]");
if (recentchange.autopatrolled !== void 0) {
$contribution_row.addClass("gadget-rcp-autopatrolled");
$("<span>").text("[" + msg("gadget-rcp-hist-basic-auto") + "]").addClass("gadget-rcp-hist-basic-auto").appendTo($contribution_row);
} else if (recentchange.patrolled !== void 0) {
$contribution_row.addClass("gadget-rcp-patrolled");
} else {
$contribution_row.addClass("gadget-rcp-unpatrolled");
if (recentchange.revid > last_patrolled_revid) {
$contribution_row.addClass("gadget-rcp-pending");
if (last_patrolled_revid > 0) {
$("<span>").html("[" + parsedmsg("gadget-rcp-hist-pending-difflink", last_patrolled_revid, recentchange.revid) + "]").addClass("gadget-rcp-hist-difflink").appendTo($contribution_row);
}
}
}
});
}
function markHistByPatrolLog() {
return _markHistByPatrolLog.apply(this, arguments);
}
function _markHistByPatrolLog() {
_markHistByPatrolLog = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee4() {
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return getPatrolLogs();
case 2:
patrol_logs.forEach(function(log) {
var $contribution_row = $(".mw-contributions-list li[data-mw-revid=" + log.params.curid + "]");
$("<span>").html("[" + parsedmsg("gadget-rcp-hist-basic-user", log.user) + "]").addClass("gadget-rcp-hist-basic-user").appendTo($contribution_row);
$contribution_row.addClass("gadget-rcp-patrolled");
});
case 3:
case "end":
return _context4.stop();
}
}
}, _callee4);
}));
return _markHistByPatrolLog.apply(this, arguments);
}
function markHistByAutopatrollers() {
return _markHistByAutopatrollers.apply(this, arguments);
}
function _markHistByAutopatrollers() {
_markHistByAutopatrollers = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee5() {
var _iterator3, _step3, contribution_row, revid, username;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return getAutopatrollers();
case 2:
_iterator3 = _createForOfIteratorHelper($(".mw-contributions-list li"));
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done; ) {
contribution_row = _step3.value;
revid = $(contribution_row).data("mw-revid");
username = $(contribution_row).find(".history-user a bdi").text();
if (autopatrollers.includes(username) && (!hasPatrol || revid <= last_rc_revid)) {
$(contribution_row).addClass("gadget-rcp-autopatrolled");
$("<span>").text("[" + msg("gadget-rcp-hist-basic-auto") + "]").addClass("gadget-rcp-hist-basic-auto").appendTo(contribution_row);
}
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
case 4:
case "end":
return _context5.stop();
}
}
}, _callee5);
}));
return _markHistByAutopatrollers.apply(this, arguments);
}
function markHistWithoutRC() {
var _iterator = _createForOfIteratorHelper($(".mw-contributions-list li")), _step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done; ) {
var contribution_row = _step.value;
var revid = $(contribution_row).data("mw-revid");
if (revid > last_patrolled_revid) {
$(contribution_row).addClass("gadget-rcp-pending");
if (last_patrolled_revid > 0) {
$("<span>").html("[" + parsedmsg("gadget-rcp-hist-pending-difflink", last_patrolled_revid, revid) + "]").addClass("gadget-rcp-hist-difflink").appendTo($(contribution_row));
}
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
function markDiffPatrolStatus() {
var $diffHeaderItems = $("<div>").attr("id", "gadget-rcp-diff-headeritems").insertBefore("#mw-content-text table.diff");
var $diffToStable = $("<div>").addClass("gadget-rcp-diff-to-stable").appendTo($diffHeaderItems);
$diffToStable.css({
"text-align": "center"
});
if (last_patrolled_revid > 0 && mw.config.get("wgCurRevisionId") != last_patrolled_revid && (mw.config.get("wgDiffOldId") != last_patrolled_revid || mw.config.get("wgDiffNewId") != mw.config.get("wgCurRevisionId"))) {
$diffToStable.append(document.createTextNode("("));
$diffToStable.append($("<a>").attr("href", mw.util.getUrl(null, {
oldid: last_patrolled_revid,
diff: "cur"
})).text(msg("gadget-rcp-diff2stable")));
$diffToStable.append(document.createTextNode(")"));
}
var $ratingsTable = $("<table>").addClass("gadget-rcp-diff-ratings").appendTo($diffHeaderItems);
var $oldWrapper = $("<td>").addClass("gadget-rcp-diff-old");
$oldWrapper.css({
"text-align": "center",
"width": "50%"
});
var $newWrapper = $("<td>").addClass("gadget-rcp-diff-new");
$newWrapper.css({
"text-align": "center",
"width": "50%"
});
$ratingsTable.append($("<tbody>").append($("<tr>").append($oldWrapper).append($newWrapper)));
var $oldMark = $("<span>").attr("id", "gadget-rcp-diff-old-status").appendTo($oldWrapper);
if (mw.config.get("wgDiffOldId") <= last_patrolled_revid) {
$oldMark.addClass("gadget-rcp-diff-patrolled");
$oldMark.text("[" + msg("gadget-rcp-hist-basic") + "]");
} else {
$oldMark.addClass("gadget-rcp-diff-pending");
$oldMark.text("[" + msg("gadget-rcp-hist-pending") + "]");
}
var $newMark = $("<span>").attr("id", "gadget-rcp-diff-new-status").appendTo($newWrapper);
if (mw.config.get("wgDiffNewId") <= last_patrolled_revid) {
$newMark.addClass("gadget-rcp-diff-patrolled");
$newMark.text("[" + msg("gadget-rcp-hist-basic") + "]");
} else {
$newMark.addClass("gadget-rcp-diff-pending");
$newMark.text("[" + msg("gadget-rcp-hist-pending") + "]");
}
if (hasPatrol && rcpOptions.multiPatrol && $(".diff-multi").length > 0) {
var revidsToPatrol = [];
recentchanges.forEach(function(recentchange) {
if (recentchange.revid <= mw.config.get("wgDiffOldId")) {
return;
}
if (recentchange.revid <= mw.config.get("wgDiffNewId") && recentchange.patrolled === void 0) {
revidsToPatrol.push(recentchange.revid);
}
});
if (revidsToPatrol.length > 0) {
var $diffMulti = $(".diff-multi").first();
var $mutilPatrol = $("<span>").addClass("gadget-rcp-multi-patrol").appendTo($diffMulti);
var $mutilPatrolLink = $("<a>").attr("href", "#").text(msg("gadget-rcp-patrol-multi", revidsToPatrol.length));
$mutilPatrolLink.on("click", function(e) {
e.preventDefault();
if (rcpOptions.multiPatrolConfirm && !confirm(msg("gadget-rcp-patrol-multi-confirm", revidsToPatrol.length))) {
return;
}
$(".patrollink").remove();
$mutilPatrol.remove();
revidsToPatrol.forEach(function(revid) {
api.postWithToken("patrol", {
action: "patrol",
revid: revid
}).done(function() {
mw.notify(msg("gadget-rcp-patrol-notify", revid));
});
});
});
$mutilPatrol.append(document.createTextNode("["));
$mutilPatrol.append($mutilPatrolLink);
$mutilPatrol.append(document.createTextNode("]"));
}
}
}
function addPatrolLinksInRC() {
$(".mw-changeslist-reviewstatus-unpatrolled").each(function(key, change) {
var revid = $(change).data("mw-revid");
var $rcPatrol = $("<span>").addClass("gadget-rcp-rc-patrol").appendTo(change);
var $rcPatrolLink = $("<a>").attr("href", "#").text(msg("gadget-rcp-patrol"));
$rcPatrolLink.on("click", function(e) {
e.preventDefault();
$rcPatrol.remove();
$(change).find(".unpatrolled").remove();
api.postWithToken("patrol", {
action: "patrol",
revid: revid
}).done(function() {
mw.notify(msg("gadget-rcp-patrol-notify", revid));
});
});
$rcPatrol.append(document.createTextNode("["));
$rcPatrol.append($rcPatrolLink);
$rcPatrol.append(document.createTextNode("]"));
});
}
function main() {
return _main.apply(this, arguments);
}
function _main() {
_main = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee6() {
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
rcpOptions = _objectSpread2(_objectSpread2({}, rcpOptions), window.RCPatrolOptions);
if (!(mw.config.get("wgAction") === "history")) {
_context6.next = 7;
break;
}
_context6.next = 4;
return getPatrolRecords();
case 4:
if (hasPatrol) {
markHistByRC();
} else {
markHistWithoutRC();
}
markHistByAutopatrollers();
markHistByPatrolLog();
case 7:
if (!(mw.config.get("wgDiffNewId") && mw.config.get("wgDiffOldId"))) {
_context6.next = 11;
break;
}
_context6.next = 10;
return getPatrolRecords();
case 10:
mw.hook("wikipage.diff").add(markDiffPatrolStatus);
case 11:
if (hasPatrol && ["Recentchanges", "Recentchangeslinked", "Watchlist"].includes(mw.config.get("wgCanonicalSpecialPageName")) && rcpOptions.patrolInRC) {
mw.hook("wikipage.content").add(function(item) {
if (item.is("div")) {
addPatrolLinksInRC();
}
});
}
case 12:
case "end":
return _context6.stop();
}
}
}, _callee6);
}));
return _main.apply(this, arguments);
}
main();
})();
/*! </nowiki> */