_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

MediaWiki:Gadget-BugStatusUpdate.js

In this article we will be addressing the topic of MediaWiki:Gadget-BugStatusUpdate.js, which has aroused great interest in today's society due to its relevance and impact in various areas. MediaWiki:Gadget-BugStatusUpdate.js is a topic that has generated controversy and debate, as well as aroused the interest of experts and specialists in the field. Along these lines, we will explore different aspects related to MediaWiki:Gadget-BugStatusUpdate.js, examining its origins, evolution, implications and possible solutions. There is no doubt that MediaWiki:Gadget-BugStatusUpdate.js represents a topic of great importance in the current context, so it is essential to deepen its understanding and analysis.
/*
 * 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)
 * Source: ]
 */

( function( $ ){
	var	ids = ,
		target = 'https://tools.wmflabs.org/phabricator-bug-status/queryTasks';

	var getParams = function( ids ) {
		return $.param( { ids: JSON.stringify( ids ) } );
	};

	// Get the Phabricator task id numbers on the page
	// The template should provide a data attribute, for simplicity and probably better performance.  There
	// should also be a class, so it could quickly be found.  E.g.
	// data-phabricator-task="123" class="trakfab ..." ...
	// This could then be selected easily, and the number could be accessed with .data( 'phabricatorTask' )
	$( '.mw-trackedTemplate' ).find( 'a' ).each( function() {
		var titleMatch = $( this ).attr( 'title' ).match( /phabricator:T(\d*)/ );
		if ( titleMatch !== null ) {
			ids.push( parseInt( titleMatch, 10 ) );
		}
	});
		
	// Do not query if no ids were found
	if ( !ids.length ) {
		return;
	}

	// Make jsonp
	$.ajax( {
		url: target,
		dataType: 'jsonp',
		timeout: 5000, // Give up if Tool Labs is being slow today
		statusCode: { 500: function () { /* Tool Labs has failed, nothing to do here */ } },
		data: getParams( ids ),
		success: function ( data ) {

			var		color = {
						"resolved": "green"
					},
					phid, taskInfo, taskNumber, selector,
					trackedTemplate, $taskLink, $title, $item,
					$status;

			for( phid in data ) {
				taskInfo = data;
				taskNumber = taskInfo.id;
				// Find the right task to update
				selector = '.mw-trackedTemplate a';
				$taskLink = $( selector );
				$title = $taskLink.find( '.trakfab-T' + taskNumber );
				if ( $title ) {
					$title.text( taskInfo.title );
				}

				$item = $taskLink.closest( '.mw-trackedTemplate' );
				if( $item ) {
					// Find child, if exists
					// This is very fragile; this needs a class.
					$status = $( '.tracked-closure' );

					// Create the status element if it does not exist
					if( $status.length === 0 ) {
						$status = $( '<span></span>' )
							.addClass('tracked-closure');
						$item.append( '<br>', $status );
					}

					// Update the status element
					// This matches Template:Tracked itself, where only resolved has a color
					// defined for Phabricator (everything else is black).
					$status
						.text( taskInfo.statusName )
						.css( 'color', color || 'black' );
				}
			}
		}
	} );
})( jQuery );