مستخدم:Gerges/Gadget-CatMaker.js
يمكن توفير توثيق لسكربت المستخدم هذا في الصفحة : مستخدم:Gerges/Gadget-CatMaker. |
ملاحظة: بعد الحفظ، قد يلزمك إفراغ الكاش لرؤية التغييرات.
"use strict";
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
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(undefined); }); }; }
$(function () {
$.when(mw.loader.using('mediawiki.util'), $.ready).then(function () {
mw.util.addPortletLink('p-tb', '/wiki/وب:منتص', 'منشئ التصانيف الجديد', 'ca-catmaker', 'الانتقال إلى منشئ التصانيف الجديد');
});
if (mw.config.get('wgArticleId') == 9558529 && mw.config.get('wgAction') == "view") {
var pageIsExist = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(title, language) {
var selectedLanguage, api, params, data;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
selectedLanguage = language;
api = new mw.ForeignApi("https://".concat(selectedLanguage, ".wikipedia.org/w/api.php"));
params = {
action: 'query',
titles: title.replace(/ /g, '_'),
// Replace spaces with underscores
format: 'json',
prop: 'pageprops'
};
_context.next = 6;
return api.post(params);
case 6:
data = _context.sent;
return _context.abrupt("return", typeof data.query.pages["-1"] != "undefined" ? false : true);
case 10:
_context.prev = 10;
_context.t0 = _context["catch"](0);
console.error("Error:", _context.t0);
return _context.abrupt("return", false);
case 14:
case "end":
return _context.stop();
}
}, _callee, null, [[0, 10]]);
}));
return function pageIsExist(_x, _x2) {
return _ref.apply(this, arguments);
};
}();
var createCat = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(secondCat, content) {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
new mw.Api().create(secondCat, {
summary: 'إنشاء تصنيف باستخدام [[وب:منتص|منشئ التصانيف الجديد]]'
}, content).done(function () {
addToLogs("تم إنشاء التصنيف بنجاح!");
}).fail(function () {
addToLogs("حدث خطأ أثناء عملية إنشاء التصنيف. حاول مرة أخرى.");
});
_context2.next = 8;
break;
case 4:
_context2.prev = 4;
_context2.t0 = _context2["catch"](0);
console.error("Error:", _context2.t0);
return _context2.abrupt("return", false);
case 8:
case "end":
return _context2.stop();
}
}, _callee2, null, [[0, 4]]);
}));
return function createCat(_x3, _x4) {
return _ref2.apply(this, arguments);
};
}();
var addCat = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(secondCat, title) {
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
_context3.prev = 0;
new mw.Api().edit(title, function () {
return {
appendtext: "\n[[" + secondCat.replace(/_/g, " ") + "]]",
summary: "إضافة " + "[[" + secondCat.replace(/_/g, " ") + "]] بواسطة [[وب:منتص]]",
minor: true
};
});
addToLogs("تم إضافة التصنيف إلى صفحة " + title);
_context3.next = 9;
break;
case 5:
_context3.prev = 5;
_context3.t0 = _context3["catch"](0);
console.error("Error:", _context3.t0);
return _context3.abrupt("return", false);
case 9:
case "end":
return _context3.stop();
}
}, _callee3, null, [[0, 5]]);
}));
return function addCat(_x5, _x6) {
return _ref3.apply(this, arguments);
};
}();
var getSubCats = /*#__PURE__*/function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(firstCat, secondCat, language, namespace) {
var counter, selectedLanguage, api, params, data, i, isExist;
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
addToLogs("محاولة إضافة وصلة للتصنيف الجديد لـ 3 مقالات/تصانيف على الأكثر");
counter = 0;
_context4.prev = 2;
selectedLanguage = language;
api = new mw.ForeignApi("https://".concat(selectedLanguage, ".wikipedia.org/w/api.php"));
params = {
cmtitle: firstCat.replace(/ /g, '_'),
// Replace spaces with underscores
action: "query",
list: "categorymembers",
cmnamespace: namespace,
cmlimit: "500"
};
_context4.next = 8;
return api.post(params);
case 8:
data = _context4.sent;
if (!(_typeof(data.query.categorymembers.length) != 0)) {
_context4.next = 23;
break;
}
i = 0;
case 11:
if (!(i < data.query.categorymembers.length && counter <= 3)) {
_context4.next = 23;
break;
}
_context4.t0 = getSiteLink;
_context4.next = 15;
return getWikidataItem(data.query.categorymembers[i].title, selectedLanguage);
case 15:
_context4.t1 = _context4.sent;
_context4.next = 18;
return (0, _context4.t0)(_context4.t1);
case 18:
isExist = _context4.sent;
if (isExist != "") {
addToLogs("إضافة وصلة للتصنيف في صفحة " + isExist);
addCat(secondCat, isExist);
counter++;
}
case 20:
i++;
_context4.next = 11;
break;
case 23:
_context4.next = 29;
break;
case 25:
_context4.prev = 25;
_context4.t2 = _context4["catch"](2);
console.error("Error:", _context4.t2);
return _context4.abrupt("return", false);
case 29:
case "end":
return _context4.stop();
}
}, _callee4, null, [[2, 25]]);
}));
return function getSubCats(_x7, _x8, _x9, _x10) {
return _ref4.apply(this, arguments);
};
}();
var setArSitelink = /*#__PURE__*/function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(secondCat, wikidataItem) {
var api;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
_context5.prev = 0;
api = new mw.ForeignApi("https://www.wikidata.org/w/api.php");
_context5.next = 4;
return api.get({
action: 'query',
meta: 'tokens'
}).done(function (data) {
api.post({
action: "wbsetsitelink",
id: wikidataItem,
linksite: "arwiki",
token: data.query.tokens.csrftoken,
linktitle: secondCat.replace(/_/g, ' ')
});
addToLogs("تم إضافة وصلة التصنيف العربي إلى عنصر ويكي بيانات");
});
case 4:
_context5.next = 10;
break;
case 6:
_context5.prev = 6;
_context5.t0 = _context5["catch"](0);
console.error("Error:", _context5.t0);
return _context5.abrupt("return", false);
case 10:
case "end":
return _context5.stop();
}
}, _callee5, null, [[0, 6]]);
}));
return function setArSitelink(_x11, _x12) {
return _ref5.apply(this, arguments);
};
}();
var setArLabel = /*#__PURE__*/function () {
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(secondCat, wikidataItem) {
var api;
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
_context6.prev = 0;
api = new mw.ForeignApi("https://www.wikidata.org/w/api.php");
_context6.next = 4;
return api.get({
action: 'query',
meta: 'tokens'
}).done(function (data) {
api.post({
action: "wbsetlabel",
id: wikidataItem,
language: "ar",
token: data.query.tokens.csrftoken,
value: secondCat.replace(/_/g, ' ')
});
addToLogs("تم إضافة تسمية إلى عنصر ويكي بيانات الجديد");
});
case 4:
_context6.next = 10;
break;
case 6:
_context6.prev = 6;
_context6.t0 = _context6["catch"](0);
console.error("Error:", _context6.t0);
return _context6.abrupt("return", false);
case 10:
case "end":
return _context6.stop();
}
}, _callee6, null, [[0, 6]]);
}));
return function setArLabel(_x13, _x14) {
return _ref6.apply(this, arguments);
};
}();
var setArDescription = /*#__PURE__*/function () {
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(secondCat, wikidataItem) {
var api;
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
_context7.prev = 0;
api = new mw.ForeignApi("https://www.wikidata.org/w/api.php");
_context7.next = 4;
return api.get({
action: 'query',
meta: 'tokens'
}).done(function (data) {
api.post({
action: "wbsetdescription",
id: wikidataItem,
language: "ar",
token: data.query.tokens.csrftoken,
value: 'تصنيف ويكيميديا'
});
addToLogs("تم إضافة وصف إلى عنصر ويكي بيانات الجديد");
});
case 4:
_context7.next = 10;
break;
case 6:
_context7.prev = 6;
_context7.t0 = _context7["catch"](0);
console.error("Error:", _context7.t0);
return _context7.abrupt("return", false);
case 10:
case "end":
return _context7.stop();
}
}, _callee7, null, [[0, 6]]);
}));
return function setArDescription(_x15, _x16) {
return _ref7.apply(this, arguments);
};
}();
var getSiteLink = /*#__PURE__*/function () {
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(wikidataItem) {
var siteLink, api, params, data;
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
case 0:
siteLink = "";
_context8.prev = 1;
api = new mw.ForeignApi("https://www.wikidata.org/w/api.php");
params = {
action: 'wbgetentities',
ids: wikidataItem,
sites: 'arwiki',
// Specify "arwiki" for Arabic Wikipedia
format: 'json'
};
_context8.next = 6;
return api.post(params);
case 6:
data = _context8.sent;
if (typeof data.entities[wikidataItem].sitelinks.arwiki == "undefined") {
siteLink = "";
} else {
siteLink = data.entities[wikidataItem].sitelinks.arwiki.title;
}
return _context8.abrupt("return", siteLink);
case 11:
_context8.prev = 11;
_context8.t0 = _context8["catch"](1);
console.error("Error:", _context8.t0);
return _context8.abrupt("return", false);
case 15:
case "end":
return _context8.stop();
}
}, _callee8, null, [[1, 11]]);
}));
return function getSiteLink(_x17) {
return _ref8.apply(this, arguments);
};
}();
var getWikidataItem = /*#__PURE__*/function () {
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(title, language) {
var wikidataItem, api, params, data;
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
while (1) switch (_context9.prev = _context9.next) {
case 0:
wikidataItem = "";
_context9.prev = 1;
api = new mw.ForeignApi("https://".concat(language, ".wikipedia.org/w/api.php"));
params = {
action: 'query',
titles: title,
// Replace spaces with underscores
format: 'json',
prop: 'pageprops',
formatversion: "2"
};
_context9.next = 6;
return api.post(params);
case 6:
data = _context9.sent;
if (data.query.pages[0].pageprops.wikibase_item == "undefined") {
wikidataItem = "";
} else {
wikidataItem = data.query.pages[0].pageprops.wikibase_item;
}
return _context9.abrupt("return", wikidataItem);
case 11:
_context9.prev = 11;
_context9.t0 = _context9["catch"](1);
console.error("Error:", _context9.t0);
return _context9.abrupt("return", false);
case 15:
case "end":
return _context9.stop();
}
}, _callee9, null, [[1, 11]]);
}));
return function getWikidataItem(_x18, _x19) {
return _ref9.apply(this, arguments);
};
}(); //فحص إذا كان صندوق النص الأجنبي فارغا
var step1A = /*#__PURE__*/function () {
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(firstCat, secondCat, language) {
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
case 0:
addToLogs("يجري الآن فحص المدخلات...");
if (firstCat == "") {
addToLogs("هل تم تحديد قيمة للتصنيف الأجنبي؟. ❌");
addToLogs("⏸ انتهاء ⏸");
} else if (firstCat != "") {
addToLogs("هل تم تحديد قيمة للتصنيف الأجنبي؟. ✅");
step1B(firstCat, secondCat, language);
}
case 2:
case "end":
return _context10.stop();
}
}, _callee10);
}));
return function step1A(_x20, _x21, _x22) {
return _ref10.apply(this, arguments);
};
}(); //فحص إذا كان صندوق النص العربي فارغا
var step1B = /*#__PURE__*/function () {
var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(firstCat, secondCat, language) {
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
case 0:
if (secondCat == "") {
addToLogs("هل تم تحديد قيمة للتصنيف العربي. ❌");
addToLogs("⏸ انتهاء ⏸");
} else if (secondCat != "") {
addToLogs("هل تم تحديد قيمة للتصنيف العربي. ✅");
step2A(firstCat, secondCat, language);
}
case 1:
case "end":
return _context11.stop();
}
}, _callee11);
}));
return function step1B(_x23, _x24, _x25) {
return _ref11.apply(this, arguments);
};
}(); //فحص إذا كان كان التصنيف الأجنبي هو عنوان لتصنيف
var step2A = /*#__PURE__*/function () {
var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(firstCat, secondCat, language) {
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
while (1) switch (_context12.prev = _context12.next) {
case 0:
addToLogs("يجري الآن فحص المدخلات...");
if (!firstCat.toLowerCase().startsWith("category:") && !firstCat.toLowerCase().startsWith("catégorie:")) {
addToLogs("هل عنوان التصنيف الأجنبي صحيح؟. ❌");
addToLogs("⏸ انتهاء ⏸");
} else {
addToLogs("هل عنوان التصنيف الأجنبي صحيح؟. ✅");
step2B(firstCat, secondCat, language);
}
case 2:
case "end":
return _context12.stop();
}
}, _callee12);
}));
return function step2A(_x26, _x27, _x28) {
return _ref12.apply(this, arguments);
};
}(); //فحص إذا كان التصنيف العربي هو عنوان لتصنيف
var step2B = /*#__PURE__*/function () {
var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(firstCat, secondCat, language) {
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
while (1) switch (_context13.prev = _context13.next) {
case 0:
if (!secondCat.startsWith("تصنيف:")) {
addToLogs("هل عنوان التصنيف العربي صحيح؟. ❌");
addToLogs("⏸ انتهاء ⏸");
} else {
addToLogs("هل عنوان التصنيف العربي صحيح؟. ✅");
step3A(firstCat, secondCat, language);
}
case 1:
case "end":
return _context13.stop();
}
}, _callee13);
}));
return function step2B(_x29, _x30, _x31) {
return _ref13.apply(this, arguments);
};
}(); //فحص إذا كان التصنيف الأجنبي موجود
var step3A = /*#__PURE__*/function () {
var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(firstCat, secondCat, language) {
var pageExists;
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
while (1) switch (_context14.prev = _context14.next) {
case 0:
_context14.next = 2;
return pageIsExist(firstCat, language);
case 2:
pageExists = _context14.sent;
if (pageExists) {
step3B(firstCat, secondCat, language);
} else {
addToLogs("لا يمكن إكمال العملية؛ لأن التصنيف الأجنبي غير موجود بنفس العنوان في ويكيبيديا " + $("#languageList>select").find(":selected").text());
addToLogs("⏸ انتهاء ⏸");
}
case 4:
case "end":
return _context14.stop();
}
}, _callee14);
}));
return function step3A(_x32, _x33, _x34) {
return _ref14.apply(this, arguments);
};
}(); //فحص إذا كان التصنيف العربي غير موجود
var step3B = /*#__PURE__*/function () {
var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(firstCat, secondCat, language) {
var pageExists1;
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
while (1) switch (_context15.prev = _context15.next) {
case 0:
_context15.next = 2;
return pageIsExist(secondCat, "ar");
case 2:
pageExists1 = _context15.sent;
if (pageExists1) {
addToLogs("لا يمكن إكمال العملية؛ لأن التصنيف العربي موجود فعلًا في ويكيبيديا العريبة بنفس الاسم");
addToLogs("⏸ انتهاء ⏸");
} else {
addToLogs("عنوان التصنيف العربي غير موجود في ويكيبيديا العربية✅.");
step4(firstCat.replace(/ /g, '_'), secondCat, language);
}
case 4:
case "end":
return _context15.stop();
}
}, _callee15);
}));
return function step3B(_x35, _x36, _x37) {
return _ref15.apply(this, arguments);
};
}(); //جلب قيمة عنصر ويكي بيانات للتصنيف الأجنبي
var step4 = /*#__PURE__*/function () {
var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(firstCat, secondCat, language) {
var wikidataItem;
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
while (1) switch (_context16.prev = _context16.next) {
case 0:
addToLogs("يتم جلب قيمة عنصر ويكي بيانات للتصنيف: " + firstCat);
_context16.next = 3;
return getWikidataItem(firstCat, language);
case 3:
wikidataItem = _context16.sent;
if (wikidataItem == "") {
addToLogs("لا يمكن الاستمرار في العملية؛ لأن التصنيف الأجنبي ليس له عنصر ويكي بيانات.");
addToLogs("⏸ انتهاء ⏸");
} else {
addToLogs(wikidataItem);
step5(firstCat, secondCat, language, wikidataItem);
}
case 5:
case "end":
return _context16.stop();
}
}, _callee16);
}));
return function step4(_x38, _x39, _x40) {
return _ref16.apply(this, arguments);
};
}(); //تحقق من أن عنصر ويكي بيانات غير موصول بتصنيف في ويكيبيديا العربية
var step5 = /*#__PURE__*/function () {
var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(firstCat, secondCat, language, wikidataItem) {
var siteLink;
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
while (1) switch (_context17.prev = _context17.next) {
case 0:
_context17.prev = 0;
_context17.next = 3;
return getSiteLink(wikidataItem);
case 3:
siteLink = _context17.sent;
addToLogs("التحقق إذا كان التصنيف الإنجليزي موصول بتصنيف في ويكيبيديا العربية");
if (siteLink == "") {
addToLogs("التصنيف غير موصول");
step6(firstCat, secondCat, language, wikidataItem);
} else {
addToLogs("عذرًا. لا يمكن الاستمرار؛ لأن التصنيف الإنجليزي مرتبط بتصنيف في ويكيبيديا العربية");
addToLogs("⏸ انتهاء ⏸");
}
_context17.next = 12;
break;
case 8:
_context17.prev = 8;
_context17.t0 = _context17["catch"](0);
console.error("Error:", _context17.t0);
return _context17.abrupt("return", false);
case 12:
case "end":
return _context17.stop();
}
}, _callee17, null, [[0, 8]]);
}));
return function step5(_x41, _x42, _x43, _x44) {
return _ref17.apply(this, arguments);
};
}(); //التحقق من أن التصنيف له أي وصلة في المشاريع الشقيقة
var step6 = /*#__PURE__*/function () {
var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(firstCat, secondCat, language, wikidataItem) {
var hasSisterLink, api, params, data;
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
while (1) switch (_context18.prev = _context18.next) {
case 0:
hasSisterLink = false;
_context18.prev = 1;
api = new mw.ForeignApi("https://www.wikidata.org/w/api.php");
params = {
action: 'wbgetentities',
ids: wikidataItem,
sites: 'arwiki',
// Specify "arwiki" for Arabic Wikipedia
format: 'json'
};
_context18.next = 6;
return api.post(params);
case 6:
data = _context18.sent;
addToLogs("التحقق إذا كان التصنيف الإنجليزي موصول بمشاريع شقيقة");
if (typeof data.entities[wikidataItem].sitelinks.commonswiki != "undefined") {
addToLogs("موجود في كومنز: " + data.entities[wikidataItem].sitelinks.commonswiki.title);
hasSisterLink = true;
}
if (typeof data.entities[wikidataItem].sitelinks.arwikisource != "undefined") {
addToLogs("موجود في ويكي مصدر: " + data.entities[wikidataItem].sitelinks.arwikisource.title);
hasSisterLink = true;
}
if (typeof data.entities[wikidataItem].sitelinks.arwikibooks != "undefined") {
addToLogs("موجود في ويكي الكتب: " + data.entities[wikidataItem].sitelinks.arwikibooks.title);
hasSisterLink = true;
}
if (typeof data.entities[wikidataItem].sitelinks.arwikinews != "undefined") {
addToLogs("موجود في ويكي الأخبار: " + data.entities[wikidataItem].sitelinks.arwikinews.title);
hasSisterLink = true;
}
if (typeof data.entities[wikidataItem].sitelinks.arwikivoyage != "undefined") {
addToLogs("موجود في ويكي الرحلات: " + data.entities[wikidataItem].sitelinks.arwikivoyage.title);
hasSisterLink = true;
}
if (typeof data.entities[wikidataItem].sitelinks.arwikiversity != "undefined") {
addToLogs("موجود في ويكي الجامعة: " + data.entities[wikidataItem].sitelinks.arwikiversity.title);
hasSisterLink = true;
}
if (typeof data.entities[wikidataItem].sitelinks.arwikitionary != "undefined") {
addToLogs("موجود في ويكياموس: " + data.entities[wikidataItem].sitelinks.arwikitionary.title);
hasSisterLink = true;
}
if (typeof data.entities[wikidataItem].sitelinks.arwikiquote != "undefined") {
addToLogs("موجود في ويكي اقتباس: " + data.entities[wikidataItem].sitelinks.arwikiquote.title);
hasSisterLink = true;
}
step7(firstCat, secondCat, language, wikidataItem, hasSisterLink);
_context18.next = 23;
break;
case 19:
_context18.prev = 19;
_context18.t0 = _context18["catch"](1);
console.error("Error:", _context18.t0);
return _context18.abrupt("return", false);
case 23:
case "end":
return _context18.stop();
}
}, _callee18, null, [[1, 19]]);
}));
return function step6(_x45, _x46, _x47, _x48) {
return _ref18.apply(this, arguments);
};
}(); //التحقق من أن التصنيف له مقالة رئيسية
var step7 = /*#__PURE__*/function () {
var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(firstCat, secondCat, language, wikidataItem, hasSisterLink) {
var mainTopic, api, params, data;
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
while (1) switch (_context19.prev = _context19.next) {
case 0:
mainTopic = "";
_context19.prev = 1;
api = new mw.ForeignApi("https://www.wikidata.org/w/api.php");
params = {
action: 'wbgetentities',
ids: wikidataItem,
props: 'claims',
// Request claims for the item
claim: 'P301',
// Specifically request claim for property "P301"
format: 'json'
};
_context19.next = 6;
return api.post(params);
case 6:
data = _context19.sent;
addToLogs("التحقق إذا كان التصنيف الأجنبي له مقالة رئيسية");
if (typeof data.entities[wikidataItem].claims["P301"] == "undefined") {
addToLogs("لا توجد مقالة رئيسية");
step8(firstCat, secondCat, language, wikidataItem, hasSisterLink, "");
} else {
addToLogs("يوجد مقالة رئيسية");
mainTopic = 1;
step8(firstCat, secondCat, language, wikidataItem, hasSisterLink, mainTopic);
}
_context19.next = 15;
break;
case 11:
_context19.prev = 11;
_context19.t0 = _context19["catch"](1);
console.error("Error:", _context19.t0);
return _context19.abrupt("return", false);
case 15:
case "end":
return _context19.stop();
}
}, _callee19, null, [[1, 11]]);
}));
return function step7(_x49, _x50, _x51, _x52, _x53) {
return _ref19.apply(this, arguments);
};
}(); //التحقق من أن التصنيف يحتوي على أي بوابة
var step8 = /*#__PURE__*/function () {
var _ref20 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(firstCat, secondCat, language, wikidataItem, hasSisterLink, mainTopic) {
var portals, selectedLanguage, api, params, data, i, isExist;
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
while (1) switch (_context20.prev = _context20.next) {
case 0:
addToLogs("فحص إذا كان التصنيف الأجنبي يحتوي على أي بوابات");
portals = "{{شريط بوابات";
_context20.prev = 2;
selectedLanguage = language;
api = new mw.ForeignApi("https://".concat(selectedLanguage, ".wikipedia.org/w/api.php"));
params = {
"action": "query",
"prop": "links",
"titles": firstCat.replace(/ /g, '_'),
"plnamespace": "100",
"formatversion": "2"
};
_context20.next = 8;
return api.post(params);
case 8:
data = _context20.sent;
if (!(typeof data.query.pages[0].links != "undefined")) {
_context20.next = 23;
break;
}
i = 0;
case 11:
if (!(i < data.query.pages[0].links.length)) {
_context20.next = 23;
break;
}
_context20.t0 = getSiteLink;
_context20.next = 15;
return getWikidataItem(data.query.pages[0].links[i].title, selectedLanguage);
case 15:
_context20.t1 = _context20.sent;
_context20.next = 18;
return (0, _context20.t0)(_context20.t1);
case 18:
isExist = _context20.sent;
if (isExist != "") {
addToLogs("إضافة " + isExist);
portals = portals + "|" + isExist.replace("بوابة:", "");
}
case 20:
i++;
_context20.next = 11;
break;
case 23:
if (portals == "{{شريط بوابات") {
portals = "";
} else {
portals = portals + "}}";
}
step9(firstCat, secondCat, language, wikidataItem, hasSisterLink, mainTopic, portals);
_context20.next = 31;
break;
case 27:
_context20.prev = 27;
_context20.t2 = _context20["catch"](2);
console.error("Error:", _context20.t2);
return _context20.abrupt("return", false);
case 31:
case "end":
return _context20.stop();
}
}, _callee20, null, [[2, 27]]);
}));
return function step8(_x54, _x55, _x56, _x57, _x58, _x59) {
return _ref20.apply(this, arguments);
};
}(); //جلب التصانيف الموجودة في ويكيبيديا العربية
var step9 = /*#__PURE__*/function () {
var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(firstCat, secondCat, language, wikidataItem, hasSisterLink, mainTopic, portals) {
var content, selectedLanguage, api, params, data, i, isExist;
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
while (1) switch (_context21.prev = _context21.next) {
case 0:
content = "";
if (hasSisterLink) {
content = content + "{{روابط شقيقة}}\n";
}
if (mainTopic == "1") {
content = content + "{{مقالة تصنيف}}\n";
}
content = content + portals + "\n\n";
addToLogs("تجهيز النص النهائي");
_context21.prev = 5;
selectedLanguage = language;
api = new mw.ForeignApi("https://".concat(selectedLanguage, ".wikipedia.org/w/api.php"));
params = {
"action": "query",
"prop": "categories",
"titles": firstCat.replace(/_/g, ' '),
"clshow": "!hidden",
cllimit: "500",
"formatversion": "2"
};
_context21.next = 11;
return api.post(params);
case 11:
data = _context21.sent;
addToLogs("إضافة تصانيف داخل التصنيف العربي");
if (!(typeof data.query.pages[0].categories != "undefined")) {
_context21.next = 27;
break;
}
i = 0;
case 15:
if (!(i < data.query.pages[0].categories.length)) {
_context21.next = 27;
break;
}
_context21.t0 = getSiteLink;
_context21.next = 19;
return getWikidataItem(data.query.pages[0].categories[i].title, selectedLanguage);
case 19:
_context21.t1 = _context21.sent;
_context21.next = 22;
return (0, _context21.t0)(_context21.t1);
case 22:
isExist = _context21.sent;
if (isExist != "") {
addToLogs(isExist);
content = content + "[[" + isExist + "]]\n";
}
case 24:
i++;
_context21.next = 15;
break;
case 27:
addToLogs("النص النهائي هو: \n\n");
addToLogs(content);
step10(firstCat, secondCat, language, content, wikidataItem);
_context21.next = 36;
break;
case 32:
_context21.prev = 32;
_context21.t2 = _context21["catch"](5);
console.error("Error:", _context21.t2);
return _context21.abrupt("return", false);
case 36:
case "end":
return _context21.stop();
}
}, _callee21, null, [[5, 32]]);
}));
return function step9(_x60, _x61, _x62, _x63, _x64, _x65, _x66) {
return _ref21.apply(this, arguments);
};
}();
var step10 = /*#__PURE__*/function () {
var _ref22 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(firstCat, secondCat, language, content, wikidataItem) {
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
while (1) switch (_context22.prev = _context22.next) {
case 0:
_context22.next = 2;
return createCat(secondCat, content);
case 2:
_context22.next = 4;
return new Promise(function (r) {
return setTimeout(r, 2000);
});
case 4:
_context22.next = 6;
return setArSitelink(secondCat, wikidataItem);
case 6:
_context22.next = 8;
return setArDescription(secondCat, wikidataItem);
case 8:
_context22.next = 10;
return setArLabel(secondCat, wikidataItem);
case 10:
_context22.next = 12;
return getSubCats(firstCat, secondCat, language, 0);
case 12:
_context22.next = 14;
return getSubCats(firstCat, secondCat, language, 14);
case 14:
addToLogs("⏸ انتهاء ⏸");
case 15:
case "end":
return _context22.stop();
}
}, _callee22);
}));
return function step10(_x67, _x68, _x69, _x70, _x71) {
return _ref22.apply(this, arguments);
};
}();
var addToLogs = function addToLogs(newLog) {
$('#logsInput>textarea').val(function (i, text) {
return text + newLog + "\n";
});
$('#logsInput>textarea').scrollTop($('#logsInput>textarea')[0].scrollHeight - $('#logsInput>textarea').height());
};
mw.loader.using('oojs-ui-core').done(function () {
$(function () {
logsInputLabel = new OO.ui.FieldsetLayout({
label: 'سجل العمليات'
});
var logsInput = new OO.ui.MultilineTextInputWidget({
value: 'هنا ستظهر جميع المعلومات عن تسلسل العمليات التي تحدث خلال عملية إنشاء التصنيف',
disabled: true,
id: "logsInput"
});
firstCatInputLabel = new OO.ui.FieldsetLayout({
label: 'اسم التصنيف الأجنبي'
});
var firstCatInput = new OO.ui.TextInputWidget({
placeholder: 'مثال (Category:Payment networks)',
id: "firstCatInput"
});
secondCatInputLabel = new OO.ui.FieldsetLayout({
label: 'اسم التصنيف العربي'
});
var secondCatInput = new OO.ui.TextInputWidget({
placeholder: 'مثال (تصنيف:شبكات دفع)',
id: "secondCatInput"
});
languageListLabel = new OO.ui.FieldsetLayout({
label: 'اختر اللغة التي تريد استيراد التصنيف منها'
});
var languageList = new OO.ui.DropdownInputWidget({
options: [{
data: 'en',
label: 'الإنجليزية'
}, {
data: 'fr',
label: 'الفرنسية'
}],
id: "languageList"
});
var saveButton = new OO.ui.ButtonWidget({
//disabled:true
});
saveButton.setIcon('checkAll').setLabel('إنشاء!').setFlags('progressive');
saveButton.on('click', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
while (1) switch (_context23.prev = _context23.next) {
case 0:
$("#logsInput>textarea").val("");
step1A($("#firstCatInput>input").val(), $("#secondCatInput>input").val(), $("#languageList>select").find(":selected").attr("value"));
case 2:
case "end":
return _context23.stop();
}
}, _callee23);
})));
$('#mw-content-text').append(languageListLabel.$element, languageList.$element, "<div style = 'max-width: 50em;border-top: 3px dashed #bbb;margin:20px 0px;'></div>", firstCatInputLabel.$element, firstCatInput.$element, "<div style = 'max-width: 50em;border-top: 3px dashed #bbb;margin:20px 0px;'></div>", secondCatInputLabel.$element, secondCatInput.$element, "<div style = 'max-width: 50em;border-top: 3px dashed #bbb;margin:20px 0px;'></div>", logsInputLabel.$element, logsInput.$element, "<div style = 'max-width: 50em;border-top: 3px dashed #bbb;margin:20px 0px;'></div>", saveButton.$element);
$("#logsInput>textarea").css("min-height", "150px");
$("#logsInput>textarea").css("overflow", "scroll");
$("#logsInput>textarea").css("max-height", "150px");
});
});
}
});