MediaWiki:NewBlog.js

From Brickipedia, the LEGO Wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/****************************************************/
/* PageMakerPro.				*/
/* Written by: Shining-Armor.			*/
/* Adapted by ToaMeiko and NovaHawk for Brickipedia */
/* https://en.brickimedia.org			*/
/*						*/
/* Derived from adaptations by			*/
/* Star Warden for the				*/
/* Dragon Mania Legends Wiki			*/
/* dragon-mania-legends-wiki.mobga.me		*/
/* License: GPL v2.				*/
/****************************************************/

( function ( $, mw, window ) {

	/***************************************************/
	/* i18n: Please contribute translations here only! */
	/***************************************************/

	var i18n = {
	   'en': {
			errorMsgNotLoggedIn: 'Please $1log in$2 or join Brickipedia by $3registering a user account$4 to create blogs!',
			formEnterTitle: 'Please enter the title of your blog:',
			formPlaceholder: 'Blog title',
			formTitle: 'Create a new blog',
			formTitleText: 'Create new blog - $1',
			formStart: 'Create',
			formPage: 'Special:BlankPage/newblog',
		},
		'fi': {
			errorMsgNotLoggedIn: '$1Kirjaudu sisään$2 tai liity Brickipediaan $3rekisteröimällä käyttäjätunnus$4 luodaksesi blogeja!',
			formEnterTitle: 'Anna blogisi otsikko:',
			formPlaceholder: 'Blogin otsikko',
			formTitle: 'Luo uusi blogi',
			formTitleText: 'Luo uusi blogi - $1',
			formStart: 'Luo'
		}
	};

	/****************************************************/
	/* End of i18n. Please don't change anything below. */
	/****************************************************/

	/* Variables for use in the script */
	var server = mw.config.get( 'wgServer' );
	var lang = mw.config.get( 'wgUserLanguage' );
	if ( i18n[lang] === undefined ) {
		lang = 'en';
	}
	var page = mw.config.get( 'wgPageName' );
	var user = mw.config.get( 'wgUserName' );
	var monobookHTML = '<fieldset id="page-create-fieldset" style="width: 70%;"><br /><label>' + i18n[lang].formEnterTitle + '</label><br /><br /><input type="text" id="NewPageTitle" style="width: 80%;" placeholder="' + i18n[lang].formPlaceholder + '"/><br /><br /><button id="create-button" style="float: right;">' + i18n[lang].formStart + '</button></fieldset>';

	if ( page != i18n[lang].formPage ) {
		$( '#p-tb ul' ).append( '<li><a href="' + server + '/wiki/' + i18n[lang].formPage + '">' + i18n[lang].formTitle + '</a></li>' );
	} else {
		makePage();
	}

	function makePage() {
		var isRegistered = ( user !== null );

		// Change the page <title> as well as the <h1> elements' values to what we want
		$( 'title' ).text( i18n[lang].formTitleText.replace( /\$1/, mw.config.get( 'wgSiteName' ) ) );
		$( '#firstHeading' ).html( i18n[lang].formTitle );

		// Show an error message to anons and prompt them to log in or sign up.
		if ( !isRegistered ) {
			$( '#bodyContent' ).html(
				i18n[lang].errorMsgNotLoggedIn
					// @todo FIXME: the URL construction isn't great here. It'll work for Brickipedia, though.
					.replace( /\$1/, '<a href="' + mw.config.get( 'wgArticlePath' ).replace( /\$1/, 'Special:UserLogin' ) + '">' )
					.replace( /\$2/, '</a>' )
					.replace( /\$3/, '<a href="' + mw.config.get( 'wgArticlePath' ).replace( /\$1/, 'Special:CreateAccount' ) + '">' )
					.replace( /\$4/, '</a>' )
			);
			return;
		}

		$( '#bodyContent' ).html( monobookHTML );
		$( '#create-button' ).click( function () {
			redirectWindow();
		} );
	}

	function redirectWindow() {
		var target = $( '#NewPageTitle' ).val();
		var link = server + '/wiki/User_blog:' + user + '/';

		link += target + '?action=edit';
		link += '&preload=MediaWiki:Createplate-Blog';

		link += '&summary=New blog created.';
		window.location = link;
	}
}( this.jQuery, this.mediaWiki, this ) );

mw.loader.addStyleTag( 'fieldset#page-create-fieldset input[type=radio]:not(:first-of-type){margin-left: 1em;}' );