User:Thisisborin9/nba.js

// // If NbaConfig aint exist. if( typeof( NbaConfig ) == 'undefined' ) { NbaConfig = {}; } /** NbaConfig.summaryAd ( string ) If ad should be added or not to summary, default NBA Project Tagger */ if( typeof( NbaConfig.summaryAd ) == 'undefined' ) { NbaConfig.summaryAd = " using NBA Project Tagger"; } /** NbaConfig.groupByDefault ( boolean ) */ if( typeof( NbaConfig.groupByDefault ) == 'undefined' ) { NbaConfig.groupByDefault = true; } /** NbaConfig.watchTaggedPages ( boolean ) */ if( typeof( NbaConfig.watchTaggedPages ) == 'undefined' ) { NbaConfig.watchTaggedPages = true; } /** NbaConfig.markTaggedPagesAsMinor ( boolean ) */ if( typeof( NbaConfig.markTaggedPagesAsMinor ) == 'undefined' ) { NbaConfig.markTaggedPagesAsMinor = true; } function nbatag { if( QueryString.exists( 'redirect' ) && QueryString.get( 'redirect' ) == 'no' ) { isRedirect = true; mw.util.addPortletLink( 'p-cactions', "javascript:nbatag.callback", "assessment", "nba-tag", "Inserts assessment", ""); } else if( wgNamespaceNumber != 0 || wgCurRevisionId == false ) { return; } else { mw.util.addPortletLink( 'p-cactions', "javascript:nbatag.callback", "assessment", "nba-tag", "Inserts assessment", ""); } } $(nbatag); nbatag.callback = function nbatagCallback( uid ) { var Window = new SimpleWindow( 600, 400 ); if( !isRedirect ) { Window.setTitle( "NBA Project tagging" ); } else { Window.setTitle( "NBA Project tagging" ); }	var form = new QuickForm( nbatag.callback.evaluate ); if( !isRedirect ) { form.append( {				type: 'checkbox',				list: [					{						label: 'Group into one if possible',						value: 'group',						name: 'group',					}				]			}		); form.append( { type:'submit' } ); form.append( { type:'header', label:'Start-Class' } ); form.append( { type:'checkbox', name: 'start', list: nbatag.startList } ); form.append( { type:'header', label:'B-Class' } ); form.append( { type:'checkbox', name: 'b', list: nbatag.bList } ); form.append( { type:'header', label:'GA-Class' } ); form.append( { type:'checkbox', name: 'ga', list: nbatag.gaList } ); } else { form.append( { type:'submit' } ); form.append( { type:'header', label:'A-Class' } ); form.append( { type:'checkbox', name: 'a', list: nbatag.aList } ); form.append( { type:'header', label:'FA-Class' } ); form.append( { type:'checkbox', name: 'fa', list: nbatag.faList } ); form.append( { type:'header', label:'FL-Class' } ); form.append( { type:'checkbox', name: 'fl', list: nbatag.flList } ); }	form.append( { type:'submit' } ); var result = form.render; Window.setContent( result ); Window.display; } isRedirect = false; nbatag.startList = [ {		label: ': Low importance', value: 'startlow' }, {		label: ': Med importance', value: 'startmed' }, {		label: ': High importance', value: 'starthigh' }, {		label: ': Top importance', value: 'starttop' } ]; nbatag.bList = [ {		label: ': Low importance', value: 'blow' }, {		label: ': Med importance', value: 'bmed' }, {		label: ': High importance', value: 'bhigh' }, {		label: ': Top importance', value: 'btop' } ]; nbatag.gaList = [ {		label: ': Low importance', value: 'galow' }, {		label: ': Med importance', value: 'gamed' }, {		label: ': High importance', value: 'gahigh' }, {		label: ': Top importance', value: 'gatop' } ]; nbatag.aList = [ {		label: ': Low importance', value: 'alow' }, {		label: ': Med importance', value: 'amed' }, {		label: ': High importance', value: 'ahigh' }, {		label: ': Top importance', value: 'atop' } ]; nbatag.faList = [ {		label: ': Low importance', value: 'falow' }, {		label: ': Med importance', value: 'famed' }, {		label: ': High importance', value: 'fahigh' }, {		label: ': Top importance', value: 'fatop' } ]; nbatag.flList = [ {		label: ': Low importance', value: 'fllow' }, {		label: ': Med importance', value: 'flmed' }, {		label: ': High importance', value: 'flhigh' }, {		label: ': Top importance', value: 'fltop' } ]; friendlytag.callback.change_current = function friendlytagCallbackChangeCurrent(e) { if( e.target.checked ) { var currentSelect = new QuickForm.element( { type:'select', name:'currentList' } ); for( var i in friendlytag.currentList ) { currentSelect.append( { type:'option',	label:friendlytag.currentList[i].label, value:friendlytag.currentList[i].value } ); }		e.target.parentNode.removeChild( e.target.nextSibling ); e.target.parentNode.appendChild( currentSelect.render.firstChild ); } else { e.target.parentNode.removeChild( e.target.parentNode.lastChild ); var currentLabel = document.createElement( "label" ); e.target.parentNode.appendChild( currentLabel ); currentLabel.innerHTML = friendlytag.noticeList[0].label; } } friendlytag.callback.change_future = function friendlytagCallbackChangeFuture(e) { if( e.target.checked ) { var futureSelect = new QuickForm.element( { type:'select', name:'futureList' } ); for( var i in friendlytag.futureList ) { futureSelect.append( { type:'option',	label:friendlytag.futureList[i].label, value:friendlytag.futureList[i].value } ); }		e.target.parentNode.removeChild( e.target.nextSibling ); e.target.parentNode.appendChild( futureSelect.render.firstChild ); } else { e.target.parentNode.removeChild( e.target.parentNode.lastChild ); var futureLabel = document.createElement( "label" ); e.target.parentNode.appendChild( futureLabel ); futureLabel.innerHTML = friendlytag.noticeList[1].label; } } friendlytag.callbacks = { main: function( self ) { var form = self.responseXML.getElementById( 'editform' ); var tagRe, text = '', summaryText = 'Added'; var tags = new Array, groupableTags = new Array; if( !isRedirect ) { // Check for preexisting tags and separate tags into groupable and non-groupable arrays Status.info( 'Info', 'Checking for preexisting tags on the article' ); for( var i = 0; i < self.params.tags.length; i++ ) { tagRe = new RegExp( '(\{\{' + self.params.tags[i] + '(\||\}\}))', 'im' ); if( !tagRe.exec( form.wpTextbox1.value ) ) { if( friendlytag.groupHash[ self.params.tags[i] ] ) { groupableTags = groupableTags.concat( self.params.tags[i] ); } else { tags = tags.concat( self.params.tags[i] ); }				} else { Status.info( 'Info', 'Found on the article already...excluding' ); }			}			if( self.params.group && groupableTags.length > 3 ) { Status.info( 'Info', 'Grouping supported tags into ' ); groupableTags.sort; text += '\n'; } else { tags = tags.concat( groupableTags ); }		} else { // Check for preexisting tags Status.info( 'Info', 'Checking for preexisting tags on the redirect' ); for( var i = 0; i < self.params.tags.length; i++ ) { tagRe = new RegExp( '(\{\{' + self.params.tags[i] + '(\||\}\}))', 'im' ); if( !tagRe.exec( form.wpTextbox1.value ) ) { tags = tags.concat( self.params.tags[i] ); } else { Status.info( 'Info', 'Found on the redirect already...excluding' ); }			}		}		tags.sort; for( var i = 0; i < tags.length; i++ ) { if( tags[i] != 'uncategorized' ) { if( tags[i] == 'current' ) { text += '{{' + self.params.currentSubcategory; } else if( tags[i] == 'future' ) { text += '{{' + self.params.futureSubcategory; } else { text += ( isRedirect ? '\n' : '' ) + '{{' + tags[i]; }				if( tags[i] == 'notability' && self.params.notabilitySubcategory != 'none' ) { text += '|' + self.params.notabilitySubcategory; }				text += isRedirect ? '}}' : '|date= }}\n'; } else { form.wpTextbox1.value += '\n\n'; }			if( i == (tags.length - 1) && ( i > 0 || groupableTags.length > 3 ) ) { summaryText += ' and'; } else if ( i < (tags.length - 1) && ( i != 0 || groupableTags.length > 3 ) ) { summaryText += ','; }			summaryText += ' '; }		if( !isRedirect ) { text += form.wpTextbox1.value; } else { text = form.wpTextbox1.value + text; }		summaryText += ' tag' + ' page ' + ' with ' + ' NBA ' + ' Project ' + ' assessment ' + NbaConfig.summaryAd; var postData = { 'wpMinoredit': NbaConfig.markTaggedPagesAsMinor ? 1 : undefined, 'wpWatchthis': form.wpWatchthis.checked ? 1 : (NbaConfig.watchTaggedPages ? 1 : undefined), 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': summaryText, 'wpTextbox1': text };		self.post( postData ); } } nbatag.callback.evaluate = function friendlytagCallbackEvaluate(e) { var form = e.target; var tags = isRedirect ? ( getChecked( form.administrative ).concat( getChecked( form.alternative ) ).concat( getChecked( form.spelling ) ) ) : ( getChecked( form.notice ).concat( getChecked( form.problem ) ).concat( getChecked( form.maintenance ) ) ); if( tags.length == 0 ) { alert( 'You must select at least one tag!' ); return; }	Status.init( form ); var query = { 'title': wgPageName, 'action': 'submit' };	Wikipedia.actionCompleted.redirect = wgPageName; Wikipedia.actionCompleted.notice = "Tagging complete, reloading article in some seconds"; var wikipedia_wiki = new Wikipedia.wiki( 'Article modification', query, friendlytag.callbacks.main ); wikipedia_wiki.params = params; wikipedia_wiki.get; } //