MediaWiki:Tutorial-QuickRC.js

/*

Tutorial script: QuickRC ("Quick Recent Changes")

A tutorial user script which adds a link to the toolbox to show a pop-up dialog with up to 25 recent edits.

Demonstrates: - Use of the API - Use of jQuery - Use of ResourceLoader default modules

(Be bold and improve it!)

-- 2011-11-03 Erik Moeller, public domain



// Import the jQuery dialog plugin mw.loader.load('jquery.ui.dialog');

$(document).ready(function {   // Add a link to the toolbox    mw.util.addPortletLink( 'p-tb', 'javascript:quickRC', 'Quick changelog', 't-prettylinkwidget', 'Show a quick overview of changes', '',     '#t-print' ); });

function quickRC { myPages = new Array; myTitleExists = new Array; // Fetch recent changes from the API jQuery.getJSON(       mw.util.wikiScript( 'api' ), {            'format': 'json',            'action': 'query',            'list': 'recentchanges',            'rclimit' : 25        }, function( data ) {            $.each ( data.query.recentchanges, function ( k , v ) { // Build a unique array of links, use mw.util helper to format them if(!myTitleExists[v.title]) { myPages.push(                                  mw.html.element( 'a', { href: mw.util.wikiGetlink( v.title ), }, v.title)                                ); }                           myTitleExists[v.title]=1; } ) ;           renderQuickRCDialog;		}     ); } function renderQuickRCDialog {

var $dialog = $(' ') .html('Welcome, '+mw.user.name+'! The following pages have been recently modified: '+myPages.join(" ")+"") .dialog({      autoOpen: true,       title: 'Hello there!',       width: '70%'    });

}