Extension:NumerAlpha

From MediaWiki.org

Jump to: navigation, search

           

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
NumerAlpha

Release status: experimental

Implementation  Tag
Description incremential tag (numbers, roman and alphabet)
Author(s)  Thierry G. Veilleux (KronoxtTalk)
Last Version  0.1 (15:31, 9 May 2009 (UTC))
MediaWiki  1.13+ didn't check other
License not specified
Download see below

check usage (experimental)

Contents

[edit] Description

This is an incremental tag... it counts how many tag you insert in the page source. You can reset the count at any moment or begin to a specified number. You have three form :

  • a zero(s) padded number. (you can configure in the source code the length of your zero padded number. (0 = no zero padding)
  • Roman numeral (i, ii, iii, iv, etc.)
  • alphabetic (a,b,...,z,aa,ab,...,zz,...)

tags:

  • <in />
  • <ir />
  • <ia />

[edit] License

License not specified... you can use it, modify it, distribute it, etc.

[edit] Status

experimental

[edit] Why this extension?

First, it was for Semantic_Forms to add a table numbered when you use the multiple option... But you can use it in templates, using the {{tag: }} magic word... and can be really useful.

You can reset it using the parameter reset, and restart the count with the parameter begin example:

<ir />
<ir />
<ir />
<ir />
<ir />
<ir />
<ir />
<ir />
<ir />
<ir />

<ir reset=1 />
<ir />
<ir />
<ir />
<ir />
<ir />

<ia />
<ia />
<ia />

<ir begin=10 />
<ir />
<ir />
<ir />

That will be render like

i ii iii iv v vi vii viii ix


i ii iii iv v


a b c

x xi xii xiii

So it's easy to list the alphabet:

<ia reset=1 /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia /><ia />

abcdefghijklmnopqrstuvwxyz

[edit] installation

You can install it by

  • copying the following php code:
  • save it with the NumerAlpha.php filename.
  • copy it into your extensions directory
  • and add the inclusion in your [localsettings.php] file. → require_once("$IP/extensions/NumerAlpha.php");
<?php
//NumerAlpha or Numeral Alpha extension!!
//KroNoxt extension kronoxt[at]izeta.org 
//free to use modify or anything if you want to give me credits you're free to do so.
//when you want to reset... you put the reset parameter to "1" //when you want to begin to a specified number, put this number in the begin parameter
 $wgExtensionCredits['parserhook'][] = array(
	'name' => 'NumerAlpha',
	'author' => 'KroNoxt',
	'description' => 'Incremental tag with zero padded number, roman and alpha numbers',
	'url' => 'http://www.mediawiki.org/wiki/Extension:NumerAlpha'
);
 
 
$wgExtNumerAlpha = new ExtNumerAlpha();
$wgExtensionFunctions[] = array( &$wgExtNumerAlpha, 'setup' );
class ExtNumerAlpha
{
  const VERSION = '0.1';
  private static $NumerACnt = 0; 
  private static $NumerACnt2 = 0; //this is for roman character... 
  private static $NumerACnt3 = 0; //this for abc incremential... 
  public function setup() 
  {	
    global $wgParser;
$wgParser->setHook( 'ir', array( &$this, 'RomanRender' ) );
$wgParser->setHook( 'in', array( &$this, 'NumeralRender' ) );
$wgParser->setHook( 'ia', array( &$this, 'AlphaRender' ) );
}        //-->register these tags in the core <ir /> <in /><ia />
 
 
 function NumeralRender($text,$argv,&$parser){
 	if (isset($argv['reset']) && $argv['reset'] = "yes" OR isset($argv['reset']) && $argv['reset'] = "1") {self::$NumerACnt = 0;}
 	if (isset($argv['begin']) && $argv['begin'] != "") {self::$NumerACnt = $argv['begin'];}
 	$num = self::$NumerACnt++;;
 	$num = intval($num);
 	$length = 2;   ////////////////////YOU CAN CHANGE THE LENGHT for the zeros padding here.
	$output = str_pad($num,$length,"0",STR_PAD_LEFT);
	return  htmlspecialchars($output);
 	}
 
function RomanRender($text,$argv,&$parser){
 	if (isset($argv['reset']) && $argv['reset'] = "yes" OR isset($argv['reset']) && $argv['reset'] = "1") {self::$NumerACnt2 = 0;}
 	if (isset($argv['begin']) && $argv['begin'] != "") {self::$NumerACnt2 = $argv['begin'];}
 	$num = self::$NumerACnt2++;
 	$n = intval($num);
     $result = '';
     $equival = array(
     'm' => 1000, 
     'cm' => 900, 
     'd' => 500, 
     'cd' => 400,
     'c' => 100, 
     'xc' => 90, 
     'l' => 50, 
     'xl' => 40,
     'x' => 10, 
     'ix' => 9, 
     'v' => 5, 
     'iv' => 4, 
     'i' => 1
     );
      foreach ($equival as $roma => $val) 
     {
         $concordances = intval($n / $val);
          $result .= str_repeat($roma, $concordances);
 		 $n = $n % $val;
     }
 
 	$output = $result;
	return  htmlspecialchars($output);
 	}
 
function AlphaRender($text,$argv,&$parser){
 	if (isset($argv['reset']) && $argv['reset'] = "yes" OR isset($argv['reset']) && $argv['reset'] = "1") {self::$NumerACnt3 = 0;}
 	if (isset($argv['begin']) && $argv['begin'] != "") {self::$NumerACnt3 = $argv['begin'];}
 	$num = self::$NumerACnt3++;
 	$num = intval($num);
 	$alpha = "";  
  while($num >= 1) {   
    $num = $num - 1;
    $alpha = chr(($num % 26)+97).$alpha; //we use the ascii table. //I don't remember where I pick this idea... but  it's not from me... well I coded it... 
    $num = $num / 26; }
 
 	$output = $alpha;
	return  htmlspecialchars($output);
 	}
 
 
 
}