Jump to content

User:Polygnotus/Scripts/WikiEditorButtons.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <nowiki>
// WikiEditor Custom Buttons Configuration
// Add this to your User:YourUserName/common.js page

// Check if we're editing a page
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
	// Add a hook handler
	mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
		
		// Add a new section for custom templates
		$textarea.wikiEditor( 'addToToolbar', {
			sections: {
				customtemplates: {
					type: 'toolbar',
					label: 'Templates'
				}
			}
		} );
		
		// Add a group for user warning templates
		$textarea.wikiEditor( 'addToToolbar', {
			section: 'customtemplates',
			groups: {
				userwarnings: {
					label: 'User Warnings'
				}
			}
		} );
		
		// Welcome button
		$textarea.wikiEditor( 'addToToolbar', {
			section: 'customtemplates',
			group: 'userwarnings',
			tools: {
				'welcome': {
					label: 'Welcome',
					type: 'button',
					oouiIcon: 'hand',
					action: {
						type: 'encapsulate',
						options: {
							pre: '{{' + 'subst:User:Polygnotus/Templates/welcome}} ~~' + '~~\n'
						}
					}
				}
			}
		} );
		
		// External Link In Body button
		$textarea.wikiEditor( 'addToToolbar', {
			section: 'customtemplates',
			group: 'userwarnings',
			tools: {
				'externallink': {
					label: 'External Link In Body',
					type: 'button',
					oouiIcon: 'linkExternal',
					action: {
						type: 'encapsulate',
						options: {
							pre: '{{' + 'subst:User:Polygnotus/Templates/exlink}} ~~' + '~~\n'
						}
					}
				}
			}
		} );
		
		// Vandalism Warning Level 1
		$textarea.wikiEditor( 'addToToolbar', {
			section: 'customtemplates',
			group: 'userwarnings',
			tools: {
				'vand1': {
					label: 'Vandalism Warning Level 1',
					type: 'button',
					icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/Eo_circle_green_number-1.svg/22px-Eo_circle_green_number-1.svg.png',
					action: {
						type: 'encapsulate',
						options: {
							pre: '{{' + 'subst:uw-vand1}} ~~' + '~~\n'
						}
					}
				}
			}
		} );
		
		// Vandalism Warning Level 2
		$textarea.wikiEditor( 'addToToolbar', {
			section: 'customtemplates',
			group: 'userwarnings',
			tools: {
				'vand2': {
					label: 'Vandalism Warning Level 2',
					type: 'button',
					icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Eo_circle_yellow_number-2.svg/22px-Eo_circle_yellow_number-2.svg.png',
					action: {
						type: 'encapsulate',
						options: {
							pre: '{{' + 'subst:uw-vand2}} ~~' + '~~\n'
						}
					}
				}
			}
		} );
		
		// Vandalism Warning Level 3
		$textarea.wikiEditor( 'addToToolbar', {
			section: 'customtemplates',
			group: 'userwarnings',
			tools: {
				'vand3': {
					label: 'Vandalism Warning Level 3',
					type: 'button',
					icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Eo_circle_orange_number-3.svg/22px-Eo_circle_orange_number-3.svg.png',
					action: {
						type: 'encapsulate',
						options: {
							pre: '{{' + 'subst:uw-vand3}} ~~' + '~~\n'
						}
					}
				}
			}
		} );
		
		// Vandalism Warning Level 4
		$textarea.wikiEditor( 'addToToolbar', {
			section: 'customtemplates',
			group: 'userwarnings',
			tools: {
				'vand4': {
					label: 'Vandalism Warning Level 4',
					type: 'button',
					icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/9f/Eo_circle_red_white_number-4.svg/22px-Eo_circle_red_white_number-4.svg.png',
					action: {
						type: 'encapsulate',
						options: {
							pre: '{{' + 'subst:uw-vand4}} ~~' + '~~\n'
						}
					}
				}
			}
		} );
		
	} );
}
// </nowiki>