Manual talk:Custom edit buttons

From mediawiki.org
Latest comment: 5 years ago by Krinkle in topic Getting a bit complicated, doesn't it?

Placing username and timestamps (by ~)[edit]

Hi, I want to place templates with this button. One of them needs username (3x ~) and timestamp (5x ~) as attributes, but I cannot add them to Common.js because they alway get replaced when I save. Is there any way to do this?

if (mwCustomEditButtons) {
 
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://images.wikia.com/central/images/7/74/Button_comment.png",
     "speedTip": "Insert comment",
     "tagOpen": "{\{NKS|name|timestamp}}\n",   <------------ here is the problem, ~ should be there instead
     "tagClose": "\n{\{NKE}}",
     "sampleText": "comment"}
  }

--87.176.88.157 14:34, 27 November 2009 (UTC)Reply


Is this supposed to be an extension? --AnonDiss 05:18, 7 March 2008 (UTC)Reply

I agree, it looks like it should be made into an extension, currently you have to modify the codebase which is not good practise. --Zven 19:01, 20 March 2008 (UTC)Reply

It looks like the slashes used for escaping newlines and apostrophes are out of whack. It was easy enough to fix the extra slashes for he apostrophes, but I'm not sure how to properly escape the newlines needed for the gallery and table. Can someone figure it out? --66.142.154.217 09:50, 20 March 2008 (UTC)Reply

Figured it out, to escape a newline you need to use " instead of an apostrophe. I updated the article to reflect this and removed the buttons that are in mediawiki by default, to remove confusion and potential future problems --66.142.154.217 10:10, 20 March 2008 (UTC)Reply
Using "\n" makes a like break in "open" but it doesn't work in "close". Please help.

Example:

				'open'	=>	"<s>\n",
				'close'	=>	'\n</s>',

will result in:

<s>
Text\n</s>

insteaf of

<s>
Text
</s>

--Yakushi.kabuto 10:35, 7 April 2008 (UTC)Reply

\n doesn't work with single quotes, only with double quotes, so use "\n". --Catrope 12:15, 8 April 2008 (UTC)Reply
If you break the line into multiple strings that are concatenated you can avoid a lot of the conversion problems. (Also, you can escape double quotes with \")
IE "\n{" + "{PAGENAME}" + "}\n{" + "{TemplateX|Var1=\"alpha\"}" + "}\n",
Extra splits of the string cause no harm. Split it wherever you think there might be a problem. All my other JS function on the same page die when there is a problem. -_- ~JSarvis


will not work[edit]

I can not get Custom edit buttons to work I am using 1.6

I have MediaWiki:Common.js or do I place it in monobook.js?

if (mwCustomEditButtons) {
 
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "http://imsaw.com/mediawiki/images/7/74/Button_comment.png",
"speedTip": "Comment visible only for editors",
"tagOpen": "<!-- ",
"tagClose": " -->",
"sampleText": "Insert comment here"}
}

--60.231.4.249 14:27, 22 May 2008 (UTC)Reply

Is this page outdated ?[edit]

The FAQ states a different code and the one provided here didn't work for me on MediaWiki 1.15.1 (neither in Common.js, nor in the user/skin.js).
The code from the FAQ works, but only in Common.js. Is there another way, to have custom buttons, or should it be working anyway? -- Sidcom 23:10, 22 February 2010 (UTC)Reply

This code is right. It work for me on v15.--Juan de Vojníkov 15:06, 7 May 2010 (UTC)Reply

Please do not hotlink images...[edit]

Is this phrase still relevant? Once we can mirror images from Commons.--Juan de Vojníkov 15:02, 7 May 2010 (UTC)Reply

Creating custom edit buttons with popup windows for further input[edit]

Hi im trying to build a mediawiki extension which requires AJAX calls during editing a page. All I need is to add a new edit button on the edit page which displays a javascript popup editor which in turn makes the appropriate calls.

I need to know if it is feasible in Mediawiki, to inject javascrpt code into edit buttons.

Any kind of information or leads are welcome!

--Pradeep122 13:59, 20 June 2010 (UTC)Reply

Download edit buttons with browser[edit]

I found the easiest way to download all images from commons:Mediawiki edit toolbar is to use your browser's "Save page as" function. This will download all images from that website into a subfolder on your PC. hth --Nakohdo 16:02, 21 January 2011 (UTC)Reply

Edit existing Edit Buttons[edit]

Is it possible to edit the existing edit buttons or can I only add further buttons to the existing non-editable buttons?

E.g. I would like the existing Image-Button to give <gallery></gallery>. 94.217.51.49 11:17, 21 July 2011 (UTC)Reply

See http://old.nabble.com/editing-the-edition-buttons-tt29797811.html for some pointers. --Nakohdo 12:42, 21 July 2011 (UTC)Reply
Perfect! Thank you very much! (/wiki/includes/EditPage.php$toolarray) 94.217.51.49 10:17, 27 July 2011 (UTC)Reply

Needing a condition when using deprecated style in monobook.js[edit]

In the deprecated section, I think that it needs some text or example that shows that you still need to add a condition for the newer addButton style to work. At English Wikisource, it was still necessary to wrap in if (mwCustomEditButtons) {...}; though I am not sure whether that is just a local or WMF issue alone.

if (mwCustomEditButtons) {
  mw.toolbar.addButton({
     coding...})
};

billinghurst sDrewth 23:58, 13 May 2013 (UTC)Reply

Use of "mwCustomEditButtons" is deprecated. Use mw.toolbar instead.[edit]

Yes, there are still many around. Krinkle or Helder.wiki, is this page the best resource to explain conversion of good old mwCustomEditButtons to mw.toolbar? Krinkle or Hoo, can you please run mwgrep and post somewhere a list of MediaWiki pages containing mwCustomEditButtons (so that I can warn them)? --Nemo 08:08, 1 June 2014 (UTC)Reply

There is also an example at w:en:User talk:MarkS/Extra edit buttons#Alternative way to add buttons. Helder.wiki 20:00, 1 June 2014 (UTC)

Adding JavaScript options[edit]

Added a section on the various ways that JavaScript delivering edit button functionality could be implemented. Mainly targeted extension developers as addition to JavaScript API's for MediaWiki seems to be an area where we can improve the documentation. Any thoughts on whether to move to a separate page and just reference here?

Iowajason (talk) 02:00, 20 March 2015 (UTC)Reply

Yeah, some of the documentation here is in pretty bad shape. Since this manual page is in general more focused on people with a bit more expertise I think that it may stay here. Thank you for contributing. Cheers --[[kgh]] (talk) 09:26, 20 March 2015 (UTC)Reply

Where is the page?[edit]

I was just wondering where's the page that is responsible for showing this toolbar? Épine (talk) 20:34, 24 August 2017 (UTC)Reply

Extension:WikiEditor/Toolbar customization (linked at the end of the page) --Ciencia Al Poder (talk) 09:07, 25 August 2017 (UTC)Reply

@Ciencia Al Poder: I mean the MediaWiki/Module page that shows the general toolbar every wiki has. Épine (talk) 12:31, 26 August 2017 (UTC)Reply

Getting a bit complicated, doesn't it?[edit]

So, nowadays the proper code to add a button looks like this:

(update: as stated in following messages, the code below is obsolete. The current code is at Manual:Custom edit buttons#Classic edit toolbar.)

if ( ['edit', 'submit'].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
    mw.loader.using( 'mediawiki.action.edit', function () {
        $( function ( $ ) {
            if ( mw.toolbar ) {
                mw.toolbar.addButton( /* actual code... */ );
            }
        } );
    } );
}

And this is only for the old-style toolbar...

Od1n (talk) 10:22, 4 October 2017 (UTC)Reply

Thanks for posting this.. They should put this in the main page, since the simple 'mw.toolbar.addButton' no longer works. -- Ivo — Preceding unsigned comment added by 156.83.1.28 (talkcontribs) 12:11, 22 November 2017‎
@Od1n: Thanks. I have updated the page with a current recommendation, please use that instead. The code posted by Od1n is not supported and may be slower and/or not work in some scenarios. --Krinkle (talk) 19:26, 2 April 2018 (UTC)Reply
Sorry, but that all sounds a bit incomprehensible to me, "mediawiki.toolbar" emit already a deprecated warning (since April [1] due your own phab:T30856) without any proper documentation for replacement, just use jQuery instead. This all on an absolute core function. User: Perhelion 08:12, 26 August 2018 (UTC)Reply
The replacement is to use Extension:WikiEditor (2010) instead. For as long as the classic editor (2006) exists, is deployed on WMF sites, and you are using it there, mw.toolbar will be the only officially supported way to customise it. Deprecation does not mean lack of support. The documentation is correct. --Krinkle (talk) 16:32, 22 September 2018 (UTC)Reply