MediaWiki:Gadget-blog.js

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.
console.info( 'Gadget loaded: https://samwilson.id.au/MediaWiki:Gadget-blog.js' );

// Purge the Welcome page if we've just saved a {{post}}.
mw.hook( 'postEdit' ).add( function () {
	if ( document.querySelector( '.tpl-post' ) !== null ) {
		( new mw.Api() ).post( { action: 'purge', titles: 'Welcome|Blog' } );
	}
} );

mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
	$textarea.wikiEditor( 'addToToolbar', {
		section: 'main',
		group: 'format',
		tools: {
			code: {
				label: 'Code',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/3/30/Tt_icon.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{code|",
						post: "}}"
					}
				}
			},
			quotation: {
				label: 'Quotation',
				type: 'button',
				icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/d8/VisualEditor_-_Icon_-_Block-quote.svg/24px-VisualEditor_-_Icon_-_Block-quote.svg.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{quotation|",
						post: "}}"
					}
				}
			}
		}
	} );
} );