User:Sedali/global.js

importArticle({   type: 'script',    articles: [        'u:dev:NullEditButton/code.js',        'u:dev:MediaWiki:MultipleFileDelete/code.js',        'u:dev:MediaWiki:AjaxDelete/code.js',        'u:dev:QuickDiff/code.js',        'u:dev:QuickIW/code.js',        'u:dev:MediaWiki:PurgeButton/code.js',        'u:dev:MediaWiki:NewPagesUser.js',        'u:dev:QuickCreateUserPage/code.js'        ] });

importScriptURI('http://pastebin.com/raw/AGusXuNv');

var qtUserPageTemplate = ''; var qtEnableUserPageOverwrite = true;

/** Quick user page creation **/ var grUserPageText = ''; var grUserTalkPageText = ''; ( function( $ ) {	// Don't load twice...	if ( typeof window.grCreateUserPage !== 'undefined' ) {		return false;	}	window.grCreateUserPage = {		version: '0.2',		/* Initialize the script */		init: function {			var $qcLink = $( ' ' ).attr( 'id', 'quick-cup' ).html( $( '' ).attr( 'title', grCreateUserPage.langMsg( 'button-tooltip' ) ) .attr( 'style', 'cursor: pointer' ).attr( 'data-upage', 'User:' + wgUserName ).text( grCreateUserPage.langMsg( 'button-link-text' ) ) .click( grCreateUserPage.checkIfUserPageExists ) );			$( '#AccountNavigation' ).find( 'li > ul.subnav' ).prepend( $qcLink );			if( window.grUserTalkPageText ) {				var $qctLink = $( ' ' ).html( $( '' ).attr( 'title', grCreateUserPage.langMsg( 'buttontalk-tooltip' ) ) .attr( 'style', 'cursor: pointer' ).attr( 'data-upage', 'User talk:' + wgUserName ).text( grCreateUserPage.langMsg( 'buttontalk-link-text' ) ) .click( grCreateUserPage.checkIfUserPageExists ) );				$( '#AccountNavigation' ).find( 'li > ul.subnav > #quick-cup' ).after( $qctLink );			}		},		/* i18n config */		langConfig: {			userLang: false,			//English			en: {				'button-link-text': 'Create user page',				'button-tooltip': 'Create your user page on this wiki automagically',				'buttontalk-link-text': 'Create user talk page',				'buttontalk-tooltip': 'Create your user talk page on this wiki automagically',				'cup-reason': 'Creating user page',				'cup-success-text': 'Successfully created page!',				'cup-error-notemplate': 'Please specify a page template in your global.js.',				'cup-error-exists': 'Page already exists!'			}		},		/* i18n function */		langMsg: function ( name ) {			if ( grCreateUserPage.langConfig.userLang && wgUserLanguage in grCreateUserPage.langConfig && name in grCreateUserPage.langConfig[wgUserLanguage] ) { return grCreateUserPage.langConfig[wgUserLanguage][name]; }			if ( wgContentLanguage in grCreateUserPage.langConfig && name in grCreateUserPage.langConfig[wgContentLanguage] ) { return grCreateUserPage.langConfig[wgContentLanguage][name]; }			return grCreateUserPage.langConfig.en[name]; },		/* See if our user page exists on this wiki, if not, create it! */		checkIfUserPageExists: function { var editPageName = $( this ).attr( 'data-upage' ); // Exit if user hasn't specified a template if( editPageName.indexOf( 'User:' ) === 0 && !window.grUserPageText ) { $( 'div.WikiaPageContentWrapper' ).prepend( ' ' + grCreateUserPage.langMsg( 'cup-error-notemplate' ) + ' ' ); return false; }			var	checkingUrl = wgServer + wgScriptPath + '/api.php?action=query&prop=revisions&meta=siteinfo&titles=' + encodeURIComponent( editPageName ) + '&format=json', editContent = ( editPageName.indexOf( 'User talk:' ) === 0 ) ? grUserTalkPageText : grUserPageText; $.getJSON( checkingUrl, function ( data ) {				for ( var p in data.query.pages ) {					break;				}				if( p !== '-1' ) {					$( 'div.WikiaPageContentWrapper' ).prepend( '  ' + grCreateUserPage.langMsg( 'cup-error-exists' ) + ' ' );					return false;				}				grCreateUserPage.getEditToken( editPageName, editContent );			} ); },		getEditToken: function ( editPageName, editContent ) { var	editTokenUrl = wgServer + wgScriptPath + '/api.php?action=query&prop=info|revisions&intoken=edit&titles=Main%20Page&format=json', editSummary = grCreateUserPage.langMsg( 'cup-reason' ); $.getJSON( editTokenUrl, function ( data ) {				for ( var p in data.query.pages ) {					break;				}				var editToken = data.query.pages[p].edittoken;				grCreateUserPage.makeAPIEdit( editPageName, editSummary, editContent, editToken );			} ); },		makeAPIEdit: function ( editPageName, editSummary, editContent, editToken ) { $.ajax( {				url: wgScriptPath + '/api.php?',				data: 'action=edit&title=' + encodeURIComponent( editPageName ) + '&summary=' + encodeURIComponent( editSummary )					+ '&text=' + encodeURIComponent( editContent ) + '&format=json&token=' + encodeURIComponent( editToken ),				dataType: 'json',				type: 'POST',				success: function( data ) {					if ( data.edit.result === "Success" ) {						var editId = data.edit.newrevid;						$( 'div.WikiaPageContentWrapper' ).prepend( '  ' + grCreateUserPage.langMsg( 'cup-success-text' ) + ' ' );					} else {						alert( 'Error: Unknown result from API.' );					}				},				error: function( xhr ) {					alert( 'Error: Edit failed.' );				}			} ); }	};	$(document).ready( grCreateUserPage.init ); } )( jQuery );