User:TheSandDoctor/scripts/test2.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:TheSandDoctor/scripts/test2. |
// 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.");
}
}
} );