Friday, October 17, 2008

Google Analytics

How to add Google Analytics script into MediaWiki engine? Or how I've wrote my first MediaWiki extension. The first idea was to patch skins and add analytics script before </body> tag. Of course, it isn't nice to patch all skins and keep these files coherent in future. Next idea was to patch Skin::bottomScripts() or Skin::outputPage(). Finally, I've decided to write extension which use one of standard hooks to add additional JavaScript code in result page generated by MediaWiki.

Finally:
MediaWiki extension to add Google Analytics script in each wiki page.

Check product home page.

Create file /extensions/AvbGoogleAnalytics/AvbGoogleAnalytics.php

This is extension body written on PHP.

<?php

if( !defined( 'MEDIAWIKI' ) ) die( -1 );

// Add hook on SkinAfterBottomScripts.
$wgHooks['SkinAfterBottomScripts'][] = 'onSkinAfterBottomScripts_AddAvbGoogleAnalyticsScript';


// returns Google Analytics tracker script
function getAvbGoogleAnalyticsScript($analytics_id)
{
$s = "\n<!-- avb: AvbGoogleAnalytics -->\n"
. "<script type=\"text/javascript\">\n"
. "var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\n"
. "document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\n"
. "</script>\n"
. "<script type=\"text/javascript\">\n"
. "var pageTracker = _gat._getTracker(\"" . $analytics_id . "\");\n"
. "pageTracker._trackPageview();\n"
. "</script>\n"
. "<h6>avb:2</h6>\n";

return $s;
}

// Event 'SkinAfterBottomScripts': At the end of Skin::bottomScripts()
// $skin: Skin object
// &$text: bottomScripts Text
// Append to $text to add additional text/scripts after the stock bottom scripts.
// Documentation: \mediawiki-1.13.0\docs\hooks.txt
function onSkinAfterBottomScripts_AddAvbGoogleAnalyticsScript($skin, &$text)
{

// Change "YOUR-ANALYTICS-ID" to your actual analytics id
// (analytics id is string like "UA-1223032-7")
$text .= getAvbGoogleAnalyticsScript("YOUR-ANALYTICS-ID");
return true;
}

?>

And the final step - add the line below at the end of your LocalSettings.php

require_once("extensions/AvbGoogleAnalytics/AvbGoogleAnalytics.php");


Full article is here.

Monday, September 29, 2008

Logo

Logo has been changed to
Instruction $wgLogo = "/skins/common/images/avbwiki.png" was added into LocalSettings.php

Saturday, September 20, 2008

Dynamic Page List

Today I'm looking for plug-in for generating article list for main page (for example, list of new articles or list of new edits). It seems DynamicPageList extension will be helpful in this situation. In fact, DynamicPageList or (also known as DPL) is base for number of other plug-ins (for example, Wgraph, TreeAndMenu, Calendar).

DPL manual is here.

As recommended here, I'll install DynamicPageList itself and Call and Inputbox. There are no cross references in DPL extensions in Semeb_extensions.zip!

Step 1
Invoke DPL from your LocalSettings.php with

require_once("extensions/DynamicPageList/DynamicPageList2.php");


Step 2: skipped
There is a special feature in DPL which needs another extension: If you use page inclusion and want to use images as link symbols for the original source you must install the LinkedImage extension. For details see there.

Step 3: skipped
In some special cases (when DPL queries refer to uncategorized pages) DPL needs a special database view in the MySQL database. You should run the database statement which creates that view if you want to use DPL statements which refer to uncategorized pages. Many installations work well without that and you can postpone this step until you really need it. If DPL cannot execute a DPL statement without that view it will issue a corresponding warning. More...

Thursday, September 18, 2008

MediaWiki skins

Below a list of sites with non-traditional MediaWiki skins and non-traditional MediaWiki usage (for example, as CMS for commercial site).

Site with well designed skins:
  1. The best one: http://www.aquawiki.ru/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0
  2. http://www.sunandshadows.com/wiki/index.php?title=Main_Page
  3. http://wikiknitting.com/wiki/Main_Page
  4. http://www.theplenty.net/wiki/index.php/Main_Page
  5. http://www.wowace.com/wiki/Main_Page
  6. http://pynchonwiki.com/
  7. http://www.scion-tech.org/wiki/Main_Page
  8. http://www.wikihow.com/Main-Page
  9. http://xbmc.org/wiki/?title=Main_Page
  10. http://en.wiredtape.com/wiki/Main_Page
  11. http://middleton-stjohns.com/wiki/Main_Page
  12. https://wiki.mozilla.org/Main_Page
  13. http://www.openwetware.org/wiki/Main_Page
  14. http://www.theplenty.net/wiki/index.php/Main_Page
  15. http://www.organicdesign.co.nz/
  16. http://www.mono-project.com/Main_Page
  17. http://www.wikithesia.com/index.php?title=Main_Page
  18. http://www.tyska.net/
  19. http://www.starcadia.sasoriza.us/wiki/Portal:Main
  20. http://24.wikia.com/wiki/Main_Page
  21. http://www.ukgameshows.com/page/index.php?title=Main_Page
  22. http://www.werelate.org/wiki/Main_Page
  23. http://krass.com/wiki/Main_Page
  24. http://www.hayinteriors.com.au/
  25. http://strategywiki.org/wiki/Main_Page
  26. http://www.aidklinik.de/
  27. http://www.wikipathways.org/index.php/WikiPathways
  28. http://www.smartlogicsolutions.com/wiki/Main_Page
  29. http://smallbusiness.com/wiki/Main_Page
  30. http://wiki.openid.net//Main_Page
  31. http://oberwiki.net/Main_Page
  32. http://www.newstartministries.org/MediaWiki/index.php/Main_Page
  33. http://wiki.limewire.org/index.php?title=Main_Page
  34. http://www.hurghada-apartment.com/Media%20Wiki%20Script/index.php?title=Home
  35. http://dishiwiki.com/index.php/Main_Page
  36. http://thediypal.com/index.php?title=Main_page
  37. http://www.wikihow.com/Main-Page

Site with interesting main page (with minor skin changes):
  1. http://www.xbox360gaming.com/wiki/index.php?title=Main_Page
  2. http://developer.valvesoftware.com/wiki/Main_Page
  3. http://wirelessafrica.meraka.org.za/wiki/index.php/Wireless_Africa_Home_Page
  4. http://wiki.wazaabi.org/index.php?title=Main_Page
  5. http://vim.wikia.com/wiki/Main_Page
  6. http://www.videoville.org/wiki/Main_Page
  7. http://www.mailquizzer.com/index.php?title=Main_Page
  8. http://wiki.case.edu/Main_Page
  9. http://www.aboutus.org/

Interesting main page layout:
  1. http://www.unmaintained-free-software.org/wiki/Main_Page
  2. http://www.sklogwiki.org/SklogWiki/index.php/Main_Page
  3. http://www.scramble.nl/wiki/index.php?title=Main_Page
  4. http://www.mono-project.com/Main_Page
  5. http://wiki.guildwars.com/wiki/Main_Page
  6. http://www.hifi-wiki.com/index.php/Main_Page
  7. http://www.machinelearning.ru/wiki/index.php?title=%C3%90%C2%97%C3%90%C2%B0%C3%90%C2%B3%C3%90%C2%BB%C3%90%C2%B0%C3%90%C2%B2%C3%90%C2%BD%C3%90%C2%B0%C3%91%C2%8F_%C3%91%C2%81%C3%91%C2%82%C3%91%C2%80%C3%90%C2%B0%C3%90%C2%BD%C3%90%C2%B8%C3%91%C2%86%C3%90%C2%B0
  8. http://wiki.lamak.ru/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0

There are only design ideas... If somebody know where to get cool free template, please notify me via comments to this post.

Wednesday, September 17, 2008

Disable edit for unregistred users

Disable edit/create page without registration.

Add into LocalSettings.php

$wgGroupPermissions['*']['edit'] = false;

// Not necessary to disable this explicity: it requires the edit right
$wgGroupPermissions['*']['createpage'] = false;
$wgGroupPermissions['*']['createtalk'] = false;

http://www.mediawiki.org/wiki/Manual:User_rights

Change the Math button

Change the Math button in editor (standard Edit Toolbar) to produce <tex> and </tex> tags, instead of <math> and </math>

<math> tag support is like small hack, so I prefer to give users <tex> tag and save <math> tag for compatibility with Wikipedia standards.

Find into WIKI_HOME/includes/EditPage.php
array(
'image' => $wgLang->getImageFile('button-math'),
'id' => 'mw-editbutton-math',
'open' => "<math>",
'close' => "</math>",
'sample' => wfMsg('math_sample'),
'tip' => wfMsg('math_tip'),
'key' => 'C'
),


and replace it with
array(
'image' => $wgLang->getImageFile('button-math'),
'id' => 'mw-editbutton-math',
'open' => "<tex<",
'close' => "</tex>",
'sample' => wfMsg('math_sample'),
'tip' => wfMsg('math_tip'),
'key' => 'C'
),


See also http://www.mediawiki.org/wiki/Mimetex_alternative

It's possible to change MediaWiki system messges like math_sample or math_tip. List of messages is here http://WIKI_HOST/index.php5/Special:AllMessages
To change messages see files in WIKI_HOME/languages/messages (find files for your language).

Adding math tag support

Adding <math> tag support (without Latex installing).
The basic recipe is here: http://www.mediawiki.org/wiki/LaTeX_on_a_shared_host

  1. Find WIKI_HOME/includes/Math.php
  2. Backup it!
  3. Find public static function renderMath($tex, $params=array())
  4. Change function body to

public static function renderMath( $tex, $params=array() ) {
return '<img class="tex" src="/cgi-bin/mimetex.cgi?' . rawurlencode($tex) . '" alt="TeX: ' . rawurlencode($tex) . '">';
}


src="/cgi-bin/mimetex.cgi... because I've added mimetex.cgi into my cgi-bin directory. See also http://avbwiki.blogspot.com/2008/09/enable-tex.html