Benutzer:Se4598/js/BugStatus.js
Zur Navigation springen
Zur Suche springen
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
- Opera: Strg+F5
/*
* Bug Status Update Gadget
* Author: Rob Moen (robm)
* Description:
* Finds and updates bug status templates and links on a page.
* Makes 1 JSONP request to Bugzilla JSON RPC api.
*
* Source: [[mw:User:Robmoen/bugStatusUpdate.js]] in version [https://www.mediawiki.org/w/index.php?title=User:Robmoen/bugStatusUpdate.js&oldid=535722]
*
* modified by [[:w:de:User:Se4598]]
*/
// <nowiki>
(function($, mw) {
var config = {};
config.addNewStatus = true;
config.addStatusBZlinks = true;
config.color = {
"RESOLVED" : "green",
"VERIFIED" : "green",
"FIXED" : "green",
"DUPLICATE" : "orange",
"WONTFIX" : "red",
"INVALID" : "red",
"CRITICAL" : "red",
};
config.template = {};
config.template.style = {
'font-weight' : 'bold',
'font-size' : '1.5em',
'text-transform' : 'uppercase'
};
config.lang = {};
config.lang['en'] = {
"UNCONFIRMED" : "UNCONFIRMED",
"NEW" : "NEW",
"ASSIGNED" : "ASSIGNED",
"PATCH_TO_REVIEW" : "PATCH TO REVIEW",
"REOPENED" : "REOPENED",
"RESOLVED" : "RESOLVED", //should be one of the following sub-cases
"FIXED" : "RESOLVED FIXED",
"INVALID" : "RESOLVED INVALID",
"WONTFIX" : "RESOLVED WONTFIX",
"LATER" : "RESOLVED LATER", //not used?
"DUPLICATE" : "RESOLVED DUPLICATE",
"WORKSFORME" : "RESOLVED WORKSFORME",
"VERIFIED" : "VERIFIED", //should have the same sub-cases as resolved?
"CLOSED" : "CLOSED", //not used?
};
config.lang['de'] = {
"UNCONFIRMED" : "Unbestätigt",
"NEW" : "Neu",
"ASSIGNED" : "Zugewiesen",
"PATCH_TO_REVIEW" : "Patch anhängig",
"REOPENED" : "Wiedereröffnet",
"RESOLVED" : "Erledigt",
"FIXED" : "Gelöst",
"INVALID" : "Ungültig",
"WONTFIX" : "Wird nicht behoben",
"LATER" : "Wird später behoben",
"DUPLICATE" : "Duplikat",
"WORKSFORME" : "Scheint zu funktionieren",
"VERIFIED" : "Verifiziert Erledigt",
"CLOSED" : "Geschlossen",
};
var mylang = mw.config.get('wgContentLanguage');
if ( typeof (config.lang[mylang]) != 'object') {
mylang = 'en';
}
var target = 'https://bugzilla.wikimedia.org/jsonrpc.cgi';
//ugly way to compose the request parameters. though, bugzilla is happy with it
var getParams = function(ids) {
return 'method=Bug.get&id=158¶ms=[{ "ids": [' + ids.join(',') + '],"include_fields":["last_change_time","status","resolution", "id"]}]';
};
var main = function() {
//future: maybe wait for user-js
//merge user-config with default
//TODO user / fliegelflagel
$.extend(true, config, {}/* user-config-obj */, {} /* fliegelflagel-config */ );
var ids = [];
//get the bug id numbers on the page
$('.mw-trackedTemplate').each(function() {
var title = $(this).find('a[title^="bugzilla:"]').attr('title');
ids.push(title.split(':')[1]);
});
if (config.addStatusBZlinks) {
$('a[title^="bugzilla:"]').each(function(index) {
var title = $(this).attr('title');
ids.push(title.split(':')[1]);
});
}
//make all values unique; bz returns a bug twice if id passed twice
var ids_unique = ids.filter(function(itm, i, arr) {
// filter empty entrys by [[bugzilla:]] and filter duplicates
return (itm.length !== 0) && (i == arr.indexOf(itm) )
;
});
if (ids_unique.length === 0) {
return;
}
//make jsonp
$.ajax({
url : target,
dataType : 'jsonp',
data : getParams(ids_unique),
success : function(data) {
var status, status_text, status_color;
if (data.error) {
// ex.: Bug #xxx does not exist or invalid link: [[bugzilla:bug 1]]
// if error then data.result == null
// TODO could be improved
alert(data.error.message || 'Bugzilla returned an API-error');
return;
} else if (data.result && data.result.bugs) {
for (var b in data.result.bugs) {
if(!data.result.bugs.hasOwnProperty(b)){
continue;
}
status = data.result.bugs[b].status;
if (status == 'RESOLVED' || status == "VERIFIED") {
if (data.result.bugs[b].resolution) {
status = data.result.bugs[b].resolution;
} else {// bugzilla apparently or only sometimes doesn't return resolution for fixed ones?
//status = 'FIXED';
}
}
status_text = config.lang[mylang][status] || status;
status_color = config.color[status] || '#333333';
var $items;
$items = $('.mw-trackedTemplate').find('a[title="bugzilla:' + data.result.bugs[b].id + '"]');
$items.each(function(index, elem) {// for each template-link
var $item = $(elem);
//find child, if exists
var $status = $item.parent().nextAll('p').last().children('span');
//create the status element if it does not exist or we should append new one
if ($status.length === 0 || config.addNewStatus) {
$item.parent().parent().append($('<p />').append($('<span />').css(config.template.style).text('Status')));
}
//refresh $status-element
$status = $item.parent().nextAll('p').last().children('span');
//udpate the status element
$status.css('color', status_color).text(status_text);
$status = null;
$item = null;
});
//END each
$items = null;
if (config.addStatusBZlinks) {
//find all bz-links that are not in the template
//TODO maybe also user-defined excludes?
$items = $('a[title="bugzilla:' + data.result.bugs[b].id + '"]:not(.mw-trackedTemplate a)');
$items.each(function(index, elem) {// for each bz-link
var $item = $(elem);
var $status = $('<span />').css('color', status_color).text(status_text);
$item.append($('<span />').addClass('se4598-bugStatus').append(' (').append($status).append(')'));
$status = null;
$item = null;
});
//END each
$items = null;
} //END if config.addStatusBZlinks
} //END for data.result.bugs
}
//END if data.result.bugs
} //END success
});
//END ajax
};
//END main
$(document).ready(main);
})(jQuery, mediaWiki);
// </nowiki>