Extension:DiggButton

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
DiggButton

Release status: stable

Implementation Tag
Description Creates a DiggButton button.
Author(s) Piotr Zuk (zukoTalk)
Last version 1.0.0 (2011-08-11)
MediaWiki 1.16
License GNU public License
Download MediawikiExtDiggButton.zip

or
this page

Example C++Book reference
Hooks used
ParserFirstCallInit

Check usage (experimental)

Contents

[edit] What can this extension do?

Allows you to very simply include DiggButton button in four customized versions.

[edit] Usage

With the tag <diggbutton></diggbutton>

  • Version 1: <diggbutton style="1"></diggbutton> (wide version)

Diggbutton1.png

  • Version 2: <diggbutton style="2"></diggbutton> (medium version)

Diggbutton2.png

  • Version 3: <diggbutton style="3"></diggbutton> (compact version)

Diggbutton3.png

  • Version 4: <diggbutton style="3"></diggbutton> (icon version)

Diggbutton4.png

Default version = 3

[edit] Download instructions

You can download the php file from MediawikiExtDiggButton_zip or copy and paste the code below to the file: $IP/extensions/DiggButton/DiggButton.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

[edit] Installation

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/DiggButton/DiggButton.php");

[edit] Code

<?php
/* Wiki DiggButton MediaWiki extension
** Installation Instructions: http://www.mediawiki.org/wiki/Extension:DiggButton
*/
 
$wgExtensionFunctions[] = "diggbuttonExtension";
 
function diggbuttonExtension() {
   global $wgParser;
   global $versions_diggbutton;
 
   $wgParser->setHook( "diggbutton", "renderDiggButton" );
 
   $versions_diggbutton = array();
   $scri = '<script type="text/javascript">(function() {'.
                'var s = document.createElement(\'SCRIPT\'), s1 = document.getElementsByTagName(\'SCRIPT\')[0];'.
                's.type = \'text/javascript\';'.
                's.async = true;'.
                's.src = \'http://widgets.digg.com/buttons.js\';'.
                's1.parentNode.insertBefore(s, s1);'.
                '})();'.
                '</script>';
 
   $versions_diggbutton[1] = $scri.'<a class="DiggThisButton DiggWide"></a>';
   $versions_diggbutton[2] = $scri.'<a class="DiggThisButton DiggMedium"></a>';
   $versions_diggbutton[3] = $scri.'<a class="DiggThisButton DiggCompact"></a>';
   $versions_diggbutton[4] = $scri.'<a class="DiggThisButton DiggIcon"></a>';
}
 
function renderDiggButton( $input, $argv )
{
   global $versions_diggbutton;   
   $style= @$argv['style'];
 
   if (is_numeric($style)) {
           $version = $style;
           if (!$versions_diggbutton[$version]) {
                   $version = 3;              
           }
   } else {              
           $version = 3;
   }
 
   $form=$versions_diggbutton[$version];
 
   $output = $form;
   return $output;
}
 
$wgExtensionCredits['parserhook'][] = array(
      'name' => 'Wiki DiggButton',
      'version' => '1.0.0',
      'author' => 'Piotr Zuk',
      'url' => 'http://www.mediawiki.org/wiki/Extension:DiggButton',
      'description' => 'Mediawiki DiggButton Extension'
);
Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox