User:Tog000/common.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.using(['jquery.ui'], function {   $(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'        ); });   // This function will not be in global scope by default because it is loaded through    // a ResourceLoader callback, so we attach it to the window object.    window.quickRC = 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.getUrl( v.title ), }, v.title) );                               }                                myTitleExists[v.title]=1;                } ) ; renderQuickRCDialog; }        );    }    function renderQuickRCDialog {      var $dialog = $('  ')        .html('Welcome, '+mw.user.getName+'! The following pages have been recently modified: '+myPages.join(" ")+"")        .dialog({ autoOpen: true, title: 'Hello there!', width: '70%' });   } });