Well, “anything” is loosely termed. I run about 6 different MediaWiki sites for the NMC, and I have to remind myself alot that the software is a huge black box (it works super) and I am pretty sure the things I have done tap maybe 8% of what it is capable of doing.

One of the limits is the kind of content you can put in the editing pane. Sure you can add additional tags you want to allow, but even a security lazy bum like me is not interesting in allowing any person to add <script> tags in there. Danger, Danger, MediaWiki Robinson!

So in prepping some new things for the wiki that we have reset for the 2009 NMC Horizon Project— we don’t delete the old stuff or hide them in edits; each year I migrate content to its own namespace, e.g. http://horizon.nmc.org/wiki/Horizon2007:Main_Page and http://horizon.nmc.org/wiki/Horizon2008:Main_Page. I’d like to know if I can have different Sidebars for these, but that’s another tinkering.

I was thinking a nice feature would be to add the Google Custom Search Engine I toyed with last year- a CSE is an incredible free tool where you can make your own search site, that rather than searching all 12 trillion Google pages, confines the search to a set of web sites that you pick. That is an amazing tool! Where is yours?

It was easy peasy to put it on the NMC web site, as the page I made is completely custom PHP- it’s not even drupal, just mocked the style of the main site, and to add a drupal block with the form that pushes searches there as a block on the right sidebar at http://horizon.nmc.org/:

But getting that functionality inside MediaWiki? Hmmmm. There is embed code provided with the GoogleCSE, but it is merely (well not so merely) a Javascript tag linked to a remote source file, and you cannot just slap JavaScript into your wiki text.

Then a light bulb went off- I bet it could be done by writing a custom MediaWiki Extension- I had done some mods of an RSS embedding extension almost 2 years ago (and still use it extensively!). You just need to know the syntax and have it spit out web content.

Of course I consulted an oracle and at first fell into the mire that is MediaWiki “documentation” – this was really helpful:

… When {{#funcname …}} is implemented as a parser function, it passes its template parameters to a PHP function instead of the usual template article. This function returns a string of wiki text that replaces the parameterized template. Parser functions are used to handle wiki text generation that involves logic that is too complex or confusing to write using normal template writing techniques….

But dipping back into the well, I found an easy example to understand at Glenn’s Junk Chest.

So to start the explanation, first here is the working version: http://horizon.nmc.org/wiki/Horizon_Google_CSE.

What you need besides your own Google CSE, is the code it provides where you can get embed stuff. I even got fancy and made mine so you can pass it a few tags.

Basically, I defined my own markup tags:

and pass it parameters so I could possible use the extension with a different CSE or do some mini customization. I could have done it really easy by no parameters and just spit out the code, but I was optimistic.

I could walk you through the code, but am hopeful I documented just about all the steps. Download the php code It is posted as googleCSE.php.txt- simply remove the .txt entension and upload to your MediaWiki extensions directory.

The all you need to do is to add a line at the bottom area of your LocalSettings.php file:

and toss some <gsce>…</gsce>… tags into your wikitext.

This is a crude off the cuff demo, but it is sending off a few ricochets of ideas (so much I skipped the project I intended to do this afternoon) — this essentially means you could write extensions to put any kind of content into your wiki pages, and not necessarily let anyone put any code in the editor…

what do you want in your wiki?

The post "How to Put Anything in Your MediaWiki Pages" was originally pushed out of the bottom of a purple jar of Play-Doh at CogDogBlog (http://cogdogblog.com/2008/09/anything-in-your-mediawiki-pages/) on September 10, 2008.


Leave a Comment

All fields are required. Your email address will not be published.