MediaWiki:Common.js/edit.js

/*global mw */ /*jshint strict: false, browser: true, jquery: true */ /** * Extra toolbar options *  *  Description: Adds extra buttons to the editing toolbar. *  *  Maintainers: User:Quasar (derived from https://en.wikipedia.org/wiki/MediaWiki:Common.js/edit.js) */ // function addExtraButtons { var TOOL_ONEDIT = 0x01; var TOOL_ONUPLOAD = 0x02; var TOOL_ONCENTRAL = 0x04; var TOOL_ONBOTH = (TOOL_ONEDIT | TOOL_ONUPLOAD); var tools = [ // Generic editing tasks {     imageId: 'mw-editbutton-signature', speedTip: 'Your signature with timestamp', tagOpen: '--~', tagClose: '\n', sampleText: '', onUpload: TOOL_ONCENTRAL },  {      imageId: 'button-add-category', imageFile: '//doomwiki.org/w/images/1/11/Button_category.png', speedTip: 'Add a category', tagOpen: '[[Category:',     tagClose: ']]', sampleText: 'categoryname', onUpload: TOOL_ONBOTH },  {      imageId: 'button-code-tag', imageFile: '//doomwiki.org/w/images/2/23/Button_code.png', speedTip: 'Insert inline code', tagOpen: '', sampleText: 'code', onUpload: TOOL_ONBOTH },  {      imageId: 'button-timeline-link', imageFile: '//doomwiki.org/w/images/4/40/Button_timeline.png', speedTip: 'Create a Timeline link', tagOpen: '', sampleText: 'year', onUpload: TOOL_ONBOTH },  {      imageId: 'button-link-wikipedia', imageFile: '//doomwiki.org/w/images/8/8a/Button_wikipedia_link.png', speedTip: 'Link to an article on Wikipedia', tagOpen: '', sampleText: 'article|linktext', onUpload: TOOL_ONBOTH },  // Image and video buttons {     imageId: 'button-image-right', imageFile: '//doomwiki.org/w/images/2/29/Button_image_right.png', speedTip: 'Insert a right-aligned thumbnail', tagOpen: ,     tagClose: , sampleText: 'Example.png', onUpload: TOOL_ONEDIT },  {      imageId: 'button-gallery', imageFile: '//doomwiki.org/w/images/c/cc/Button_gallery_silk.png', speedTip: 'Insert a picture gallery', tagOpen: '\n', sampleText: 'Example.png|Caption1', onUpload: TOOL_ONEDIT },  {      imageId: 'button-movie', imageFile: '//doomwiki.org/w/images/c/c1/Button_movie.png', speedTip: 'Embed a YouTube video', tagOpen: '', sampleText: 'videoid', onUpload: TOOL_ONEDIT },  {      imageId: 'button-fileinfo', imageFile: '//doomwiki.org/w/images/b/b5/Button_fileinfo.png', speedTip: 'Insert FileInfo template', tagOpen: '', sampleText: '', onUpload: TOOL_ONUPLOAD },  // Table buttons {     imageId: 'button-pretty-table', imageFile: '//doomwiki.org/w/images/0/04/Button_array.png', speedTip: 'Insert a pretty table', tagOpen: '{| \n|-\n|', tagClose: '\n|}', sampleText: '', onUpload: TOOL_ONBOTH },  {      imageId: 'button-pretty-sortable', imageFile: '//doomwiki.org/w/images/b/b5/Button_tablesort.png', speedTip: 'Insert a sortable table', tagOpen: '{| \n|-\n|', tagClose: '\n|}', sampleText: '', onUpload: TOOL_ONBOTH },  // Citations and references {     imageId: 'button-insert-reflink', imageFile: '//doomwiki.org/w/images/2/2b/Button_ref_inscription.png', speedTip: 'Insert a generic reference', tagOpen: ' ', sampleText: 'footnote', onUpload: TOOL_ONEDIT },  {      imageId: 'button-cite-web', imageFile: '//doomwiki.org/w/images/9/91/Button_cite_web.png', speedTip: 'Insert a webpage reference', tagOpen: '', sampleText: '', onUpload: TOOL_ONEDIT },  {      imageId: 'button-insert-references', imageFile: '//doomwiki.org/w/images/9/9a/Button_references.png', speedTip: 'Create a References section', tagOpen: '==References==\n ', tagClose: '\n', sampleText: '', onUpload: TOOL_ONEDIT },  // Archiving {     imageId: 'button-archive-link', imageFile: '//doomwiki.org/w/images/5/53/Button_brokenlink.png', speedTip: 'Archive a broken link', tagOpen: '', sampleText: 'original link', onUpload: TOOL_ONEDIT },  {      imageId: 'button-archive-citeweb', imageFile: '//doomwiki.org/w/images/3/32/Button_brokencite.png', speedTip: 'Archive a broken web citation', tagOpen: '', sampleText: '', onUpload: TOOL_ONEDIT },  // Magic words and stuff {     imageId: 'button-redirect', imageFile: '//doomwiki.org/w/images/c/c8/Button_redirect.png', speedTip: 'Redirect this article to another', tagOpen: '#REDIRECT ',     tagClose: '', sampleText: 'pagename', onUpload: TOOL_ONEDIT }  ];

var toolbar, toolFlags; if(mw.config.get('wgCanonicalSpecialPageName') === 'Upload') { toolFlags = TOOL_ONUPLOAD; toolbar = mw.libs.uploadToolbar; } else { toolFlags = TOOL_ONEDIT; if(wgPageName === 'Doom_Wiki:Central_Processing') // add signature button to CP       toolFlags |= TOOL_ONCENTRAL; toolbar = mw.toolbar; }  for(var i = 0; i < tools.length; i++) { if((tools[i].onUpload & toolFlags) !== 0) toolbar.addButton(tools[i]); } }

mw.loader.using('user.options', function {   // This can be the string "0" if the user disabled the preference (52542)   if(mw.user.options.get('usebetatoolbar') != 1 && mw.user.options.get('showtoolbar') == 1) {      var deps;      if(mw.config.get('wgCanonicalSpecialPageName') === 'Upload')         deps = [ 'mediawiki.toolbar', 'ext.gadget.UploadToolbar' ];      else         deps = [ 'mediawiki.toolbar' ];      $.when( mw.loader.using(deps), $.ready ).then(addExtraButtons);  } }); //