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.
 1 /****************************************************/
 2 /* PageMakerPro.				*/
 3 /* Written by: Shining-Armor.			*/
 4 /* Adapted by ToaMeiko and NovaHawk for Brickipedia */
 5 /* https://en.brickimedia.org			*/
 6 /*						*/
 7 /* Derived from adaptations by			*/
 8 /* Star Warden for the				*/
 9 /* Dragon Mania Legends Wiki			*/
10 /* dragon-mania-legends-wiki.mobga.me		*/
11 /* License: GPL v2.				*/
12 /****************************************************/
13 
14 ( function ( $, mw, window ) {
15 
16 	/***************************************************/
17 	/* i18n: Please contribute translations here only! */
18 	/***************************************************/
19 
20 	var i18n = {
21 	   'en': {
22 			errorMsgNotLoggedIn: 'Please $1log in$2 or join Brickipedia by $3registering a user account$4 to create blogs!',
23 			formEnterTitle: 'Please enter the title of your blog:',
24 			formPlaceholder: 'Blog title',
25 			formTitle: 'Create a new blog',
26 			formTitleText: 'Create new blog - $1',
27 			formStart: 'Create',
28 			formPage: 'Special:BlankPage/newblog',
29 		},
30 		'fi': {
31 			errorMsgNotLoggedIn: '$1Kirjaudu sisään$2 tai liity Brickipediaan $3rekisteröimällä käyttäjätunnus$4 luodaksesi blogeja!',
32 			formEnterTitle: 'Anna blogisi otsikko:',
33 			formPlaceholder: 'Blogin otsikko',
34 			formTitle: 'Luo uusi blogi',
35 			formTitleText: 'Luo uusi blogi - $1',
36 			formStart: 'Luo'
37 		}
38 	};
39 
40 	/****************************************************/
41 	/* End of i18n. Please don't change anything below. */
42 	/****************************************************/
43 
44 	/* Variables for use in the script */
45 	var server = mw.config.get( 'wgServer' );
46 	var lang = mw.config.get( 'wgUserLanguage' );
47 	if ( i18n[lang] === undefined ) {
48 		lang = 'en';
49 	}
50 	var page = mw.config.get( 'wgPageName' );
51 	var user = mw.config.get( 'wgUserName' );
52 	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>';
53 
54 	if ( page != i18n[lang].formPage ) {
55 		$( '#p-tb ul' ).append( '<li><a href="' + server + '/wiki/' + i18n[lang].formPage + '">' + i18n[lang].formTitle + '</a></li>' );
56 	} else {
57 		makePage();
58 	}
59 
60 	function makePage() {
61 		var isRegistered = ( user !== null );
62 
63 		// Change the page <title> as well as the <h1> elements' values to what we want
64 		$( 'title' ).text( i18n[lang].formTitleText.replace( /\$1/, mw.config.get( 'wgSiteName' ) ) );
65 		$( '#firstHeading' ).html( i18n[lang].formTitle );
66 
67 		// Show an error message to anons and prompt them to log in or sign up.
68 		if ( !isRegistered ) {
69 			$( '#bodyContent' ).html(
70 				i18n[lang].errorMsgNotLoggedIn
71 					// @todo FIXME: the URL construction isn't great here. It'll work for Brickipedia, though.
72 					.replace( /\$1/, '<a href="' + mw.config.get( 'wgArticlePath' ).replace( /\$1/, 'Special:UserLogin' ) + '">' )
73 					.replace( /\$2/, '</a>' )
74 					.replace( /\$3/, '<a href="' + mw.config.get( 'wgArticlePath' ).replace( /\$1/, 'Special:CreateAccount' ) + '">' )
75 					.replace( /\$4/, '</a>' )
76 			);
77 			return;
78 		}
79 
80 		$( '#bodyContent' ).html( monobookHTML );
81 		$( '#create-button' ).click( function () {
82 			redirectWindow();
83 		} );
84 	}
85 
86 	function redirectWindow() {
87 		var target = $( '#NewPageTitle' ).val();
88 		var link = server + '/wiki/User_blog:' + user + '/';
89 
90 		link += target + '?action=edit';
91 		link += '&preload=MediaWiki:Createplate-Blog';
92 
93 		link += '&summary=New blog created.';
94 		window.location = link;
95 	}
96 }( this.jQuery, this.mediaWiki, this ) );
97 
98 mw.loader.addStyleTag( 'fieldset#page-create-fieldset input[type=radio]:not(:first-of-type){margin-left: 1em;}' );