মিডিয়াউইকি:Gadget-BugStatusUpdate.js

উইকিসংকলন থেকে
টীকা: সংরক্ষণ করার পর, পরিবর্তনসমূহ তৎক্ষণাৎ নাও দেখাতে পারে। আপনার ব্রাউজারের ক্যাশ কিভাবে এড়াবেন তা জানতে এখানে ক্লিক করুন।
  • ফায়ারফক্স / সাফারি: Shift ধরে রাখা অবস্থায়পুনঃলোড করুন-এ ক্লিক করুন, অথবা Ctrl-F5 বা Ctrl-R (ম্যাক-এ ⌘-R) চাপুন
  • গুগল ক্রোম: Ctrl-Shift-R (ম্যাক-এ ⌘-Shift-R) চাপুন
  • ইন্টারনেট এক্সপ্লোরার: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 চাপুন
  • অপেরা: মেনু → ব্যবস্থাপনাসমূহ-এ যান (ম্যাকে অপেরা → পছন্দসমূহ) এবং এরপর গোপনীয়তা ও সুরক্ষা → ব্রাউজিং-এর তথ্য পরিষ্কার করুন → ক্যাশে করা ছবি ও ফাইলগুলি

অন্যান্য ব্রাউজার সম্পর্কে বিশদ নির্দেশাবলীর জন্য, উইকিপিডিয়া:আপনার ক্যাশে বাইপাস করুন দেখুন।

/*
 * Bug Status Update Gadget
 *
 * Authors:
 * Written by Rob Moen (robm).
 * Ported to Phabricator by w:User:Mattflaschen (WMF)
 * on 2/10/2015
 *
 * 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: [[mw:User:Robmoen/bugStatusUpdate.js]]
 */

( 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 a[title^="phabricator:T"]' ).each( function() {
		var titleMatch = $( this ).attr( 'title' ).match( /phabricator:T(\d*)/ );
		if ( titleMatch !== null ) {
			ids.push( parseInt( titleMatch[1], 10 ) );
		}
	});

	// Do not query if no ids were found
	if ( !ids.length ) {
		return;
	}

	// Make jsonp
	$.ajax( {
		url: target,
		dataType: 'jsonp',
		data: getParams( ids ),
		success: function ( data ) {

			var color = {
				"resolved": "green"
			},
			statusProps = {
				'font-weight': 'bold',
				'text-transform': 'uppercase'
			},
			phid, taskInfo, taskNumber, selector,
			trackedTemplate, $taskLink, $title, $item,
			$status;

			for( phid in data ) {
				taskInfo = data[phid];
				taskNumber = taskInfo.id;
				// Find the right task to update
				selector = '.mw-trackedTemplate a[title^="phabricator:T' +  taskNumber + '"]';
				$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 = $item.children( 'span' );

					// Create the status element if it does not exist
					if( $status.length === 0 ) {
						$status = $( '<span></span>' )
							.css( statusProps );
						$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[taskInfo.status] || 'black' );
				}
			}
		}
	} );
})( jQuery );