User:CBM/ratemath.js

//

// Script to assess articles for WPMATH // Rewritten by User:This, that and the other - November 2011

mw.loader.using(['ext.gadget.Twinkle'], function {   /**        CONFIGURATION        ratemathWatchRatedMathPages (boolean)        If, when applying rating template to page, watch it        Default true        */    if( typeof( ratemathWatchRatedMathPages ) === 'undefined' ) {        ratemathWatchRatedMathPages = true;    }    function ratemath {        if( (mw.config.get('wgNamespaceNumber') !== 0 && mw.config.get('wgNamespaceNumber') !== 1) || !mw.config.get('wgCurRevisionId') ) {           return;        }

mw.util.addPortletLink( 'p-cactions', "javascript:ratemath.callback",                        "Rate math", "tw-rate", "Rate article for WikiProject Mathematics", "");

}   window.ratemath = ratemath; $(document).ready(ratemath); ratemath.callback = function ratemathCallback { var Window = new SimpleWindow( 600, 250 ); Window.setTitle( "Rate mathematics article" ); var form = new QuickForm( ratemath.callback.evaluate ); form.append( {               type: 'select',                name: 'quality',                label: 'Quality: ',                list: [                    { label: 'Stub class', value: 'Stub' },                    { label: 'Start class', value: 'Start' },                    { label: 'C class', value: 'C' },                    { label: 'B class', value: 'B' },                    { label: 'B+ class', value: 'Bplus' },                    { label: 'Good article', value: 'GA' },                    { label: 'A class', value: 'A' },                    { label: 'Featured article', value: 'FA' },                    { label: 'List', value: 'List' },                    { label: 'Featured list', value: 'FL' }                ]            } ); form.append( {               type: 'select',                name: 'priority',                label: 'Priority: ',                list: [                    { label: 'Low', value: 'Low' },                    { label: 'Mid', value: 'Mid' },                    { label: 'High', value: 'High' },                    { label: 'Top', value: 'Top' },                ]            } ); form.append( {               type: 'select',                name: 'field',                label: 'Field: ',                list: [                    { label: 'Analysis', value: 'analysis' },                    { label: 'Algebra', value: 'algebra' },                    { label: 'Applied mathematics', value: 'applied' },                    { label: 'Basic topics (elementary material and common facts)', value: 'basics' },                    { label: 'Discrete mathematics', value: 'discrete' },                    { label: 'Foundations (logic and set theory)', value: 'foundations' },                    { label: 'General', value: 'general' },                    { label: 'Geometry', value: 'geometry' },                    { label: 'History', value: 'history' },                    { label: 'Mathematical Physics', value: 'mathematical physics' },                    { label: 'Mathematicians', value: 'mathematicians' }, { label: 'Number theory', value: 'number theory' }, { label: 'Probability and statistics', value: 'probability and statistics' }, { label: 'Topology', value: 'topology' } ]              } );        form.append( { type:'submit' } );        var result = form.render;        Window.setContent( result );        Window.display;    };

ratemath.callbacks = { main: function( pageobj ) { var text = pageobj.getPageText; var statelem = pageobj.getStatusElement; var params = pageobj.getCallbackParameters;

if( text.search(/\{\{\s*[mM]ath(s)?[ _]?rating/) != -1 ) { Status.info('Info', 'Removing previous rating templates'); text = text.replace(/\{\{\s*[mM]aths?[ _]?rating([a-zA-Z |= \n])*\}\}\n*/g, ''); if( text.search(/\{\{\s*[mM]ath(s)?[ _]?rating/) != -1 ) { statelem.error('Failed to remove previous templates, aborting'); return; }           }                pageobj.setPageText("\n" + text); pageobj.setWatchlist(ratemathWatchRatedMathPages); pageobj.setEditSummary("Rating article for WikiProject Mathematics. Quality: " + params.quality +                " / Priority: " + params.priority + " / Field: " + params.field + " (script assisted)"); pageobj.save; }   };

ratemath.callback.evaluate = function ratemathCallbackEvaluate(e) { var form = e.target; var quality = form.quality.value; var priority = form.priority.value; var field = form.field.value;

mw.config.set('wgPageName', mw.config.get('wgPageName').replace(/_/g, ' ')); // for queen/king/whatever and country!

var pagename = mw.config.get('wgPageName'); if (mw.config.get('wgNamespaceNumber') === 0) { pagename = 'Talk:' + mw.config.get('wgPageName'); }

Status.init( form ); SimpleWindow.setButtonsEnabled(false);

Wikipedia.actionCompleted.redirect = pagename; Wikipedia.actionCompleted.notice = "Tagging complete, reloading talk page in some seconds";

var wikipedia_page = new Wikipedia.page(pagename, 'Tagging talk page'); wikipedia_page.setCallbackParameters({ quality: quality, priority: priority, field: field }); wikipedia_page.setFollowRedirect(false); wikipedia_page.load(ratemath.callbacks.main); }; });

//