Jump to content

User:TheSandDoctor/scripts/test2.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Make sure the utilities module is loaded (will only load if not already)
//
mw.loader.using( ['mediawiki.util','ext.visualEditor.desktopArticleTarget.init'], function () {

    // Wait for the page to be parsed
    $(document).ready( function () { 

   //see below "Portlets" subsection
        var link = mw.util.addPortletLink( 'p-cactions', '#', 'MedChecker', 'ca-medchecker', 'Prototype of script requested by Doc James for helping med students learn Wikipedia.'); 
        $( link ).click( function ( event ) {
            event.preventDefault();
            doQwikify();

        } );
    } );
    function template( template ) {
		var first_char = template.substr( 0, 1 );
		var template_re_string = "(?:[Tt]emplate:)?\\s*[" + first_char.toUpperCase() + first_char.toLowerCase() + ']' + RegExp.escape( template.substr( 1 ), true );
		var links_re = new RegExp( "\\{\\{" + template_re_string );
		var allTemplates = Morebits.array.uniq(Morebits.string.splitWeightedByKeys( this.text, '{{', '}}', [ '{{{', '}}}' ] ));
		for( var i = 0; i < allTemplates.length; ++i ) {
			if( links_re.test( allTemplates[i] ) ) {
				this
				//this.text = this.text.replace( allTemplates[i], '', 'g' );
			}
		}
	}
    function doQwikify() {
    //	document.editform.wpTextbox1.value = "{" + "{wikify}}\n\n" + document.editform.wpTextbox1.value;
    //	document.editform.submit();
  //  	var reg = /\.ezproxy\./;
    	var str = document.editform.wpTextbox1.value;
    	if (str.match(/\.ezproxy\./g)) {
    		mw.notify( 'Internal URL found. Not good!' ); // Send a plaintext notification
    	}
    	else {
    		mw.notify( 'Internal URL not found. Good!' );
    	}
    	// regex for matching all caps (how it works is basically match anything ''but'' lowercase letters')
    	//TODO: Needs fixing
    	if (str.match(/=+(?:[A-Z]\w* )*(?:[A-Z][\w.]+)=+/g)) {
    		mw.notify( "Section headings shouldn't be in all caps. Generally only the first word in a heading gets a cap unless the other words are proper names.");
    	}
    	// punctuation vs citation check (cite before punct? Notify that house style is punct before cite)
    	if (str.match(/<ref>(.+)<\/ref>[.,\/#!$%\^&?\*;:{}=\-_`~()]+/g)){
    		mw.notify("The house style is refs go immediately after the punctuation.");
    	}
}
} );