Browse Source

Backlink summary API logic.

develop
Ben Kurtovic 9 years ago
parent
commit
7999add4bc
1 changed files with 48 additions and 12 deletions
  1. +48
    -12
      tfdclerk.js

+ 48
- 12
tfdclerk.js View File

@@ -76,15 +76,17 @@ TFD = function(id, head) {
TFDClerk.api_get = function(tfd, params, done, fail, always) { TFDClerk.api_get = function(tfd, params, done, fail, always) {
TFDClerk._api.get(params) TFDClerk._api.get(params)
.done(function(data) { .done(function(data) {
if (done !== undefined)
if (done)
done.call(tfd, data); done.call(tfd, data);
}) })
.fail(function(error) { .fail(function(error) {
if (done !== undefined)
if (fail)
fail.call(tfd, error); fail.call(tfd, error);
else
tfd._error("API query failure", error);
}) })
.always(function() { .always(function() {
if (always !== undefined)
if (always)
always.call(tfd); always.call(tfd);
}); });
}; };
@@ -207,9 +209,7 @@ TFD.prototype._with_content = function(callback) {
callback.call(this, content); callback.call(this, content);
for (var i in this._wikitext_callbacks) for (var i in this._wikitext_callbacks)
this._wikitext_callbacks[i].call(this, content); this._wikitext_callbacks[i].call(this, content);
}, function(error) {
this._error("API query failure", error);
}, function() {
}, null, function() {
this._wikitext_callbacks = []; this._wikitext_callbacks = [];
}); });
}; };
@@ -339,6 +339,9 @@ TFD.prototype._build_close_results = function() {
else else
var choices = ["Delete", "Keep", "Redirect", "No consensus"]; var choices = ["Delete", "Keep", "Redirect", "No consensus"];


// TODO: block submit until one is selected; possibly disable individual
// action options based on what is picked

var elems = $("<div/>"); var elems = $("<div/>");
$("<label/>").append($("<input/>", { $("<label/>").append($("<input/>", {
name: "result-speedy", name: "result-speedy",
@@ -372,21 +375,56 @@ TFD.prototype._build_close_results = function() {
return elems; return elems;
}; };


TFD.prototype._on_backlink_summary = function(tlinfo, ntrans, nmlinks) {
TFD.prototype._on_backlink_summary = function(page, tlinfo, ntrans, nlinks) {
tlinfo.empty().append($("<li/>").append($("<a/>", { tlinfo.empty().append($("<li/>").append($("<a/>", {
href: "/foobar", // TODO: actual URL here href: "/foobar", // TODO: actual URL here
title: "Transclusions of " + page, title: "Transclusions of " + page,
text: ntrans + " transclusions" text: ntrans + " transclusions"
}))); })));


if (nmlinks > 0)
if (nlinks != 0)
tlinfo.append($("<li/>").append($("<a/>", { tlinfo.append($("<li/>").append($("<a/>", {
href: "/foobar", // TODO: actual URL here href: "/foobar", // TODO: actual URL here
title: "Mainspace links to " + page, title: "Mainspace links to " + page,
text: nmlinks + " mainspace links"
text: nlinks + " mainspace links"
}))); })));
}; };


TFD.prototype._load_backlink_summary = function(page, tlinfo) {
var limit = TFDClerk._sysop ? 5000 : 500;
TFDClerk.api_get(this, {
action: "query",
list: "embeddedin|backlinks",
eititle: page,
eilimit: limit,
bltitle: page,
blnamespace: "0|10",
bllimit: limit,
blredirect: ""
}, function(data) {
if (data["continue"] && data["continue"].eicontinue)
var ntrans = limit + "+";
else
var ntrans = data.query.embeddedin.length;

if (data["continue"] && data["continue"].blcontinue)
var nlinks = limit + "+";
else
var nlinks = data.query.backlinks.reduce(function(acc, pg) {
var c = 0;
if (pg.ns == 0)
c++;
if (pg.redirlinks)
c += pg.redirlinks.filter(function(rl) {
return rl.ns == 0;
}).length;
return acc + c;
}, 0);

this._on_backlink_summary(page, tlinfo, ntrans, nlinks);
});
}

TFD.prototype._build_close_action_entry = function(page) { TFD.prototype._build_close_action_entry = function(page) {
var redlink = this.head.nextUntil("h4").filter("ul").first() var redlink = this.head.nextUntil("h4").filter("ul").first()
.find("a").filter(function() { return $(this).text() == page; }) .find("a").filter(function() { return $(this).text() == page; })
@@ -394,7 +432,7 @@ TFD.prototype._build_close_action_entry = function(page) {


var tlinfo = $("<ul/>", {style: "display: inline;"}) var tlinfo = $("<ul/>", {style: "display: inline;"})
.append(this._build_loading_node("li", "Fetching transclusions")); .append(this._build_loading_node("li", "Fetching transclusions"));
// TODO: callback to fetch backlink data and call _on_backlink_summary
this._load_backlink_summary(page, tlinfo);


return $("<li/>").append($("<a/>", { return $("<li/>").append($("<a/>", {
href: mw.util.getUrl(page), href: mw.util.getUrl(page),
@@ -482,8 +520,6 @@ TFD.prototype._on_date_change = function() {
})); }));
if (date == (new Date().toLogDateFormat())) if (date == (new Date().toLogDateFormat()))
info.append($("<span/>", {text: " (today)"})); info.append($("<span/>", {text: " (today)"}));
}, function(error) {
this._error("API query failure", error);
}); });
}; };




Loading…
Cancel
Save