User:Addshore/friendlywelcome-custom.js

// //-- FR welcome start --

// If FriendlyConfig aint exist. if( typeof( FriendlyConfig ) == 'undefined' ) { FriendlyConfig = {}; } /** FriendlyConfig.summaryAd ( string ) If ad should be added or not to summary, default Friendly */ if( typeof( FriendlyConfig.summaryAd ) == 'undefined' ) { FriendlyConfig.summaryAd = " using Friendly"; } /** FriendlyConfig.topWelcomes ( boolean ) */ if( typeof( FriendlyConfig.topWelcomes ) == 'undefined' ) { FriendlyConfig.topWelcomes = false; } /** FriendlyConfig.watchWelcomes ( boolean ) */ if( typeof( FriendlyConfig.watchWelcomes ) == 'undefined' ) { FriendlyConfig.watchWelcomes = true; } /** FriendlyConfig.insertHeadings ( boolean ) */ if( typeof( FriendlyConfig.insertHeadings ) == 'undefined' ) { FriendlyConfig.insertHeadings = true; } /** FriendlyConfig.welcomeHeading ( string ) */ if( typeof( FriendlyConfig.welcomeHeading ) == 'undefined' ) { FriendlyConfig.welcomeHeading = "== Welcome =="; } /** FriendlyConfig.insertUsername ( boolean ) */ if( typeof( FriendlyConfig.insertUsername ) == 'undefined' ) { FriendlyConfig.insertUsername = true; } /** FriendlyConfig.insertSignature ( boolean ) */ if( typeof( FriendlyConfig.insertSignature ) == 'undefined' ) { FriendlyConfig.insertSignature = true; } /** FriendlyConfig.markWelcomesAsMinor ( boolean ) */ if( typeof( FriendlyConfig.markWelcomesAsMinor ) == 'undefined' ) { FriendlyConfig.markWelcomesAsMinor = true; } /** FriendlyConfig.quickWelcomeMode ( String ) */ if( typeof( FriendlyConfig.quickWelcomeMode ) == 'undefined' ) { FriendlyConfig.quickWelcomeMode = "auto"; } /** FriendlyConfig.quickWelcomeTemplate ( String ) */ if( typeof( FriendlyConfig.quickWelcomeTemplate ) == 'undefined' ) { FriendlyConfig.quickWelcomeTemplate = "Welcome"; } /** FriendlyConfig.maskTemplateInSummary ( boolean ) */ if( typeof( FriendlyConfig.maskTemplateInSummary ) == 'undefined' ) { FriendlyConfig.maskTemplateInSummary = true; } $( function {		if( QueryString.exists( 'friendlywelcome' ) ) {			if( QueryString.get( 'friendlywelcome' == 'auto' ) ) {				friendlywelcome.auto;			} else {				friendlywelcome.semiauto;			}		} else {			friendlywelcome.normal;		}	} ); friendlywelcome = { auto: function { if( QueryString.get( 'action' ) != 'edit' ) { // userpage not empty, aborting auto-welcome return; }		return friendlywelcome.welcome; },	semiauto: function { friendlywelcome.callback( wgTitle.split( '/' )[0].replace( /\"/, "\\\"") ); },	normal: function { if( QueryString.exists( 'diff' ) ) { // all nodes with "New user account" var oSet1 = '//div[@id="mw-diff-otitle2"]'; var nSet1 = '//div[@id="mw-diff-ntitle2"]'; // all nodes with empty talk page var oSet2 = '//div[@id="mw-diff-otitle2"][contains(a[2][@class="new"], "Talk")]'; var nSet2 = '//div[@id="mw-diff-ntitle2"][contains(a[2][@class="new"], "Talk")]'; // intersection of set1 and set2 is new user accounts with empty talk pages var oXPath = '(' + oSet1 + ')[count(.|' + oSet2 + ')=count(' + oSet2 + ')]'; var nXPath = '(' + nSet1 + ')[count(.|' + nSet2 + ')=count(' + nSet2 + ')]'; var oList = document.evaluate( oXPath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ); var nList = document.evaluate( nXPath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null ); var spanTag = function( color, content ) { var span = document.createElement( 'span' ); span.style.color = color; span.appendChild( document.createTextNode( content ) ); return span; }			var welcomeNode = document.createElement('strong'); var welcomeLink = document.createElement('a'); welcomeLink.appendChild( spanTag( 'Black', '[' ) ); welcomeLink.appendChild( spanTag( 'Goldenrod', 'welcome' ) ); welcomeLink.appendChild( spanTag( 'Black', ']' ) ); welcomeNode.appendChild(welcomeLink); for(var i = 0; i < oList.snapshotLength; ++i ) { var current = oList.snapshotItem(i); var href = document.evaluate( 'a[2]/@href', current, null, XPathResult.STRING_TYPE, null ).stringValue; var tmpNode = welcomeNode.cloneNode( true ); tmpNode.firstChild.setAttribute( 'href', href + '&' + QueryString.create( { 'friendlywelcome': 'norm' } )						+ '&' + QueryString.create( { 'vanarticle': wgPageName.replace(/_/g, ' ') } ) ); current.appendChild( document.createTextNode( ' ' ) ); current.appendChild( tmpNode ); }			for(var i = 0; i < nList.snapshotLength; ++i ) { var current = nList.snapshotItem(i); var href = document.evaluate( 'a[2]/@href', current, null, XPathResult.STRING_TYPE, null ).stringValue; var tmpNode = welcomeNode.cloneNode( true ); tmpNode.firstChild.setAttribute( 'href', href + '&' + QueryString.create( { 'friendlywelcome': 'norm' } )						+ '&' + QueryString.create( { 'vanarticle': wgPageName.replace(/_/g, ' ') } ) ); current.appendChild( document.createTextNode( ' ' ) ); current.appendChild( tmpNode ); }		}		if( wgNamespaceNumber == 3 ) { var username = wgTitle.split( '/' )[0].replace( /\"/, "\\\""); // only first part before any slashes mw.util.addPortletLink( 'p-cactions', "javascript:friendlywelcome.callback(\"" + username + "\")", "welcome", "friendly-welcome", "Welcome user", ""); }	} } friendlywelcome.welcome = function welcomeUser { Status.init( document.getElementById('bodyContent') ); var params = { value: FriendlyConfig.quickWelcomeTemplate, article: QueryString.exists( 'vanarticle' ) ? QueryString.get( 'vanarticle' ) : '', mode: 'auto' };	var query = { 'title': wgPageName, 'action': 'submit' };	Wikipedia.actionCompleted.redirect = wgPageName; Wikipedia.actionCompleted.notice = "Welcoming complete, reloading talk page in some seconds"; var wikipedia_wiki = new Wikipedia.wiki( 'User talk page modification', query, friendlywelcome.callbacks.main ); wikipedia_wiki.params = params; wikipedia_wiki.get; } friendlywelcome.callback = function friendlywelcomeCallback( uid ) { if( uid == wgUserName ){ alert( 'You don\'t need to welcome yourself, do you?' ); return; }	var Window = new SimpleWindow( 600, 400 ); Window.setTitle( "Choose a welcome template" ); var form = new QuickForm( friendlywelcome.callback.evaluate, 'change' ); form.append( {			type: 'input',			name: 'article',			label: 'Linked article (if supported by template)',			value:( QueryString.exists( 'vanarticle' ) ? QueryString.get( 'vanarticle' ) : '' ),			tooltip: 'An article might be linked to the welcome if the template supports it. Leave empty for no artice to be linked. Templates that support a linked article are marked with an asterisk.  Ignored for templates that do not support a linked article.',			event: function( event ) {				event.stopPropagation;			}		}	); form.append( { type:'header', label:'Simple templates' } ); form.append( { type: 'radio', name: 'simple', list: friendlywelcome.standardList } ); form.append( { type:'header', label:'Welcoming committee templates' } ); form.append( { type: 'radio', name: 'welcomingCommittee', list: friendlywelcome.welcomingCommitteeList } ); form.append( { type:'header', label:'Potential problem user templates' } ); form.append( { type: 'radio', name: 'problem', list: friendlywelcome.problemList } ); form.append( { type:'header', label:'Anonymous user templates' } ); form.append( { type: 'radio', name: 'anonymous', list: friendlywelcome.anonymousList } ); var result = form.render; Window.setContent( result ); Window.display; } friendlywelcome.standardList = [ {		label: ': my user welcome*', value: 'User:Addshore/welcome' }, {		label: ': my user welcome*', value: 'User:Addshore/welcomeg' }, {		label: ': my anon welcome*', value: 'User:Addshore/welcome-anon' }, {		label: ': my acc welcome*', value: 'User:Addshore/welcome-acc' }, {		label: ': standard welcome*', value: 'Welcome' }, { 		label: ': short welcome', value: 'Welcomeshort', tooltip: 'Includes section heading.' }, { 		label: ': simple welcome', value: 'WelcomeSimple', tooltip: 'Won\'t overwhelm new users. Includes section heading.' }, {		label: ': very short and simple welcome', value: 'Welcom', tooltip: 'Shortest welcome template available. Includes section heading and signature.' }, {		label: ': includes a plate of cookies', value: 'Welcome-personal', tooltip: 'A personal welcome with an introduction from you and a plate of cookies. Includes section heading and signature.' }, { 		label: ': welcome with menu of links', value: 'WelcomeMenu', tooltip: 'Contains a welcome message and many useful links broken up into different sections. Includes signature.' }, { 		label: ': similar to ', value: 'Welcomeg', tooltip: 'Contains a welcome message and many useful links broken up into different sections. Includes signature.' }, { 		label: ': same as but with a section heading', value: 'Welcomeh', tooltip: 'Contains a section heading, a welcome message and many useful links broken up into different sections. Includes section heading and signature.' } ] friendlywelcome.welcomingCommitteeList = [ { 		label: ': similar to, but automatically identifies anonymous and registered users*', value: 'Wel', tooltip: 'This template checks whether the username contains any letters. If there are any, will be shown. If there are none, will be shown.' }, { 		label: ': standard template, similar to with additional options', value: 'W-basic', tooltip: 'This template is similar to but supports many different options. Includes a signature.' }, { 		label: ': extroverted message with bold advice', value: 'W-shout', tooltip: 'This template is similar to but spports many different options. Includes a signature.' }, { 		label: ': concise; won\'t overwhelm', value: 'W-short', tooltip: 'This template is similar to but supports many different options. Includes a signature.' }, { 		label: ': shortest greeting, links to Welcoming committee\'s greetings page', value: 'W-link', tooltip: 'This template is similar to but supports many different options. Includes a signature.' }, { 		label: ': graphical menu format to ease transition from the graphic-heavy web', value: 'W-graphical', tooltip: 'This template is similar to but has fewer links. Supports many different options. Includes a signature.' }, { 		label: ': graphical; designed to fit the size of the user\'s screen', value: 'W-screen', tooltip: 'This template is a nice graphical welcome with many different options. Includes a signature.' } ] friendlywelcome.problemList = [ { 		label: ': welcome with information about copyrights, npov, the sandbox, and vandalism', value: 'Welcomelaws' }, { 		label: ': for someone whose initial efforts appear to be vandalism*', value: 'Welcomevandal', tooltip: 'Includes a section heading.' }, { 		label: ': for someone whose initial efforts do not adhere to the neutral point of view policy*', value: 'Welcomenpov' }, { 		label: ': welcome with additional discussion of anti-spamming polices*', value: 'Welcomespam' }, { 		label: ': for someone whose initial efforts are uncited*', value: 'Welcomeunsourced' } ] friendlywelcome.anonymousList = [ {		label: ': for anonymous users; encourages getting a username*', value: 'Welcome-anon' }, {		label: ': similar to but with hints and tips*', value: 'Welcomeanon2', tooltip: 'Includes section heading.' }, {		label: ': similar to but with a border and section heading', value: 'Welc-anon', tooltip: 'Includes section heading.' }, {		label: ': for anonymous users to urge them to create an account', value: 'welcomeunclesam' }, {		label: ': for anonymous users who have vandalized a page*', value: 'Welcome-anon-vandal', tooltip: 'Includes a section heading and signature.' } ] // Set to true if template already has heading friendlywelcome.headingHash = { 'User:Addshore/welcome': true, 'User:Addshore/welcomeg': true, 'User:Addshore/welcome-anon': true, 'User:Addshore/welcome-acc': true, 'Welcome': false, 'Welcomeshort': true, 'WelcomeSimple': true, 'Welcom': true, 'Welcome-personal': true, 'WelcomeMenu': false, 'Welcomeg': false, 'Welcomeh': true, 'Wel': true, 'W-basic': false, 'W-shout': false, 'W-short': false, 'W-link': false, 'W-graphical': false, 'W-screen': false, 'Welcomelaws': false, 'Welcomevandal': true, 'Welcomenpov': false, 'Welcomespam': false, 'Welcomeunsourced': false, 'Welcome-anon': false, 'Welcomeanon2': true, 'Welc-anon': true, 'Welcomeunclesam': false, 'Welcome-anon-vandal': true } // Set to true if template already has signature friendlywelcome.signatureHash = { 'User:Addshore/welcome': false, 'User:Addshore/welcomeg': true, 'User:Addshore/welcome-anon': false, 'User:Addshore/welcome-acc': false, 'Welcome': false, 'Welcomeshort': false, 'WelcomeSimple': false, 'Welcom': true, 'Welcome-personal': false, 'WelcomeMenu': true, 'Welcomeg': true, 'Welcomeh': true, 'Wel': false, 'W-basic': true, 'W-shout': true, 'W-short': true, 'W-link': true, 'W-graphical': true, 'W-screen': true, 'Welcomelaws': false, 'Welcomevandal': true, 'Welcomenpov': false, 'Welcomespam': false, 'Welcomeunsourced': false, 'Welcome-anon': false, 'Welcomeanon2': false, 'Welc-anon': false, 'Welcomeunclesam': false, 'Welcome-anon-vandal': true } /* Set to true if template supports article * name from art template parameter */ friendlywelcome.artHash = { 'User:Addshore/welcome': false, 'User:Addshore/welcomeg': false, 'User:Addshore/welcome-anon': false, 'User:Addshore/welcome-acc': false, 'Welcome': true, 'Welcomeshort': false, 'WelcomeSimple': false, 'Welcom': false, 'Welcome-personal': false, 'WelcomeMenu': false, 'Welcomeg': false, 'Welcomeh': false, 'Wel': true, 'W-basic': false, 'W-shout': false, 'W-short': false, 'W-link': false, 'W-graphical': false, 'W-screen': false, 'Welcomelaws': false, 'Welcomevandal': false, 'Welcomenpov': false, 'Welcomespam': false, 'Welcomeunsourced': false, 'Welcome-anon': true, 'Welcomeanon2': true, 'Welc-anon': false, 'Welcomeunclesam': false, 'Welcome-anon-vandal': false } /* Set to true if template supports article * name from vanarticle url parameter */ friendlywelcome.vandalHash = { 'User:Addshore/welcome': false, 'User:Addshore/welcomeg': false, 'User:Addshore/welcome-anon': false, 'User:Addshore/welcome-acc': false, 'Welcome': false, 'Welcomeshort': false, 'WelcomeSimple': false, 'Welcom': false, 'Welcome-personal': false, 'WelcomeMenu': false, 'Welcomeg': false, 'Welcomeh': false, 'Wel': false, 'W-basic': false, 'W-shout': false, 'W-short': false, 'W-link': false, 'W-graphical': false, 'W-screen': false, 'Welcomelaws': false, 'Welcomevandal': true, 'Welcomenpov': true, 'Welcomespam': true, 'Welcomeunsourced': true, 'Welcome-anon': false, 'Welcomeanon2': false, 'Welc-anon': false, 'Welcomeunclesam': false, 'Welcome-anon-vandal': true } friendlywelcome.callbacks = { main: function( self ) { var form = self.responseXML.getElementById( 'editform' ); // abort if mode is auto and form is not empty if( form.wpTextbox1.value != '\n' && self.params.mode == 'auto' ) { Status.info( 'Warning', 'User talk page not empty; aborting automatic welcome' ); Wikipedia.actionCompleted.event; return; }		var text = ''; Status.info( 'Info', 'Will add the welcome template to the '				+ ( FriendlyConfig.topWelcomes ? 'top' : 'bottom' )				+ ' of the user\'s talk page.' ); if( !FriendlyConfig.topWelcomes ) { text += form.wpTextbox1.value + '\n\n'; }		if( !friendlywelcome.headingHash[ self.params.value ] && FriendlyConfig.insertHeadings ) { Status.info( 'Info', 'Will create a new heading for the welcome' ); text += FriendlyConfig.welcomeHeading + "\n"; }		Status.info( 'Info', 'Will substitute the welcome template' ); text += '\{\{subst:' + self.params.value; if( friendlywelcome.artHash[ self.params.value ] ) { if( FriendlyConfig.insertUsername ) { Status.info( 'Info', 'Will add your username to the template' ); text += '|' + wgUserName; }			if( self.params.article != '' ) { Status.info( 'Info', 'Will add article link to the template' ); text += '|art=' + self.params.article; }		} else if( friendlywelcome.vandalHash[ self.params.value ] ) { if( self.params.article != '' ) { Status.info( 'Info', 'Will add vandalized article link to the template' ); }			text += '|' + self.params.article; if( FriendlyConfig.insertUsername ) { Status.info( 'Info', 'Will add your username to the template' ); text += '|' + wgUserName; }		} else if( FriendlyConfig.insertUsername ) { Status.info( 'Info', 'Will add your username to the template' ); text += '|' + wgUserName; } 		text += '\}\}'; if( !friendlywelcome.signatureHash[ self.params.value ] && FriendlyConfig.insertSignature ) { Status.info( 'Info', 'Will add your signature after the welcome' ); text += ' \n\~\~\~\~'; }		if( FriendlyConfig.topWelcomes ) { text += '\n\n' + form.wpTextbox1.value; }		var postData = { 'wpMinoredit': FriendlyConfig.markWelcomesAsMinor ? 1 : undefined, 'wpWatchthis': form.wpWatchthis.checked ? 1 : (FriendlyConfig.watchWelcomes ? 1 : undefined), 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': 'Added ' + ( FriendlyConfig.maskTemplateInSummary ? 'welcome' : ( '\{\{' + self.params.value + '\}\}' ) ) + ' template to user talk page.' + FriendlyConfig.summaryAd, 'wpTextbox1': text };		self.post( postData ); } } friendlywelcome.callback.evaluate = function friendlywelcomeCallbackEvaluate(e) { // Ignore if a change to the text field triggered this event if( e.target.name == 'article' ) { return; }	var params = { value: e.target.value, article: e.target.form.article.value, mode: 'manual' };	Status.init( e.target.form ); var query = { 'title': wgPageName, 'action': 'submit' };	Wikipedia.actionCompleted.redirect = wgPageName; Wikipedia.actionCompleted.notice = "Welcoming complete, reloading talk page in some seconds"; var wikipedia_wiki = new Wikipedia.wiki( 'User talk page modification', query, friendlywelcome.callbacks.main ); wikipedia_wiki.params = params; wikipedia_wiki.get; } //-- FR welcome end -- //