Topic on Extension talk:Maps

Add Maps icon to WikiEditor toolbar

4
Felix Englisch (talkcontribs)

If you are using the Maps extension in combination with Extension:WikiEditor, you might want to make it easier for your users to insert a map. It is quite easy to add an icon to the toolbar which automatically inserts the code snippet required for embedding. Simply add the following to you LocalSettings.php:

$wgUseSiteJs = true;


Then, open the page "MediaWiki:Common.js" on your wiki and insert the following:

var customizeToolbar = function () {
  $('#wpTextbox1').wikiEditor('addToToolbar', {
      section: 'advanced',
      group: 'insert',
      tools: {
        "Map": {
          label: 'Insert map',
          type: 'button',
          icon: '//upload.wikimedia.org/wikipedia/commons/b/b4/OOjs_UI_icon_map-ltr.svg',
          action: {
            type: 'encapsulate',
            options: {
              pre: '{{#display_map:',
              peri: "Example street 1, Berlin~'''Heading'''~Short description; optional: 2nd marker",
              post: '|fullscreen=on}}'
            }
          }
        }
      }
    });
};
    
    /* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
    if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
    mw.loader.using( 'user.options' ).then( function () {
    if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
      $.when(
        mw.loader.using( 'ext.wikiEditor' ), $.ready
      ).then( customizeToolbar );
    }
  } );
}


Of course, you can change the default parameters of the map and also the icon. Just visit https://commons.wikimedia.org/wiki/Main_Page and look for a better one. And for more information about editing the toolbar, see Extension:WikiEditor/Toolbar customization.

Have fun!

Jeroen De Dauw (talkcontribs)
OurOakland (talkcontribs)

@Jeroen De Dauw -- any update on adding this to the Maps extension? It seems very useful to add directly to the Maps extension.

I tried the directions above on my new wiki, but when I try to save the Javascript, I get "Internal Server Error". I can make other changes to the file, so it doesn't seem to be a permissions thing.

Jeroen De Dauw (talkcontribs)

No work was done on this AFAIK

Reply to "Add Maps icon to WikiEditor toolbar"