User:CBM/ratemath.js

In the article titled User:CBM/ratemath.js, we will delve into an exciting topic that addresses relevant aspects of interest to a wide audience. This article aims to offer a detailed and in-depth look at User:CBM/ratemath.js, exploring its origins, evolution, ramifications and possible future implications. Along these lines, we will examine different perspectives, expert opinions and relevant data that will help us better understand the topic at hand. Without a doubt, User:CBM/ratemath.js is a fascinating topic that deserves our attention and detailed analysis, so this article will become a valuable source of information for anyone interested in the topic.
// <nowiki>

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

mw.loader.using(, 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*ath(s)??rating/) != -1 ) {
                Status.info('Info', 'Removing previous rating templates');        
                text = text.replace(/\{\{\s*aths??rating()*\}\}\n*/g,  '');  
                if( text.search(/\{\{\s*ath(s)??rating/) != -1 ) {
                    statelem.error('Failed to remove previous templates, aborting');        
                    return;
                }
            }    
            
            pageobj.setPageText("{{maths rating|class=" + params.quality +
                 "|priority=" + params.priority + "|field=" + params.field + "|math-nested=no}}\n" + text);
            pageobj.setWatchlist(ratemathWatchRatedMathPages);
            pageobj.setEditSummary("Rating article for ]. 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);
    };
});

// </nowiki>