MediaWiki:Gadget-BugStatusUpdate.js
Jump to navigation
Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Clear the cache in Tools → Preferences
For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
* Bug Status Update Gadget
*
* Authors:
* - Written by Rob Moen (robm).
* - Ported to Phabricator by Matthew Flaschen (Mattflaschen (WMF))
*
* Description:
* - Finds and updates bug status templates on a page.
* - Makes 1 JSONP request to phabricator-bug-status API (maintained by Matthew Flaschen)
* - (which passes the request to Phabricator's Conduit API)
*
* Original source: [[mw:User:Robmoen/bugStatusUpdate.js]]
*
*/
const target = 'https://phabricator-bug-status.toolforge.org/queryTasks';
$(() => {
"use strict";
let ids = [];
// Get the Phabricator task id numbers on the page
$('.mw-trackedTemplate').each(() => {
let taskID = $(this).data("phabTask");
if (taskID !== null) {
ids.push(taskID);
}
});
// Do not query if no ids were found
if (!ids.length) {
return;
}
// Make jsonp request
$.ajax({
url: target,
dataType: 'jsonp',
timeout: 5000, // Give up if Tool Labs is being slow today
statusCode: {
500: () => { /* Toolforge has failed, nothing to do here */ }
},
data: $.param({ids: JSON.stringify(ids)}),
})
.done(data => {
let phid, taskInfo;
// Loop over the tasks the server returned data for.
for (phid in data) {
taskInfo = data[phid];
// Loop over all instances of the template with this ID.
$(".phab-T" + taskInfo.id).each(() => {
$(this).find(".tracked-linktext").text(taskInfo.title);
let $status = $(this).find('.tracked-closure');
if ($status.length === 0) {
$status = $('<span></span>')
.addClass('tracked-closure');
$(this).append($status);
}
// If a manual status gives the wrong class, remove it.
if (taskInfo.status !== "resolved" && taskInfo.status !== "fixed") {
$status.removeClass("tracked-resolved");
}
// Update the status element
$status
.addClass("phab-status-" + taskInfo.status)
.text(taskInfo.statusName);
});
}
});
});