Extension:GalleryTable

From Linux Web Expert

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
MediaWiki extensions manual
GalleryTable
Release status: unmaintained
Implementation Tag
Description Displays a table-gallery
Author(s) RUNA (Runa_cgtalk)
Latest version 0.1 (March 2010)
MediaWiki tested on 1.10.2, 1.15.1
License GPL
Download See the section labeled code below
Quarterly downloads Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin').
Public wikis using Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin').

Displays a table, divided by the specified number of columns. Table Cells are separated by a newline. The contents of the cell - wikitext.

Installation

To install this extension

  • Create file in your /extension directory: GalleryTable.php (see #Code section)
  • Add the following to LocalSettings.php :
require_once("$IP/extensions/GalleryTable.php");

Syntax

<gal cols="column number (default = 3)">
gallery cell 1
gallery cell 2
gallery cell 3
...
gallery cell n
</gal>

Code

<?php
 //Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980
if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
	$wgHooks['ParserFirstCallInit'][] = 'wfGalleryTable';
} else { // Otherwise do things the old fashioned way
	$wgExtensionFunctions[] = 'wfGalleryTable';
}

 function wfGalleryTable() {
         global $wgParser;
         $wgParser->setHook( "gal", "GalleryTable" );
         return true;
 }
 
 function GalleryTable( $input, $argv, $parser, $frame ) {
      global $wgScriptPath;
      $cols = 3;
      if (isset($argv['cols'])) {$cols = $argv['cols'];}
      $cwidth = floor(100/$cols);

      $output = "<table>";
      $tdcontent = explode(chr(10), $input);
      $count = count($tdcontent);
      for ($i=1; $i<$count-1; $i++) {      
      	if ($i % $cols == 1) {$output .= chr(10)."<tr>";}		
      	$content = $parser->recursiveTagParse($tdcontent[$i]);
      	$output .= "<td width=\"".$cwidth."%\">".$content."</td>";
      	if ($i % $cols == 0) {$output .= "</tr>";}
      }
      if (($count-2) % $cols > 0) {      	
      $output .= "<td colspan=\"".($cols - (($count-2) % $cols))."\">&nbsp;</td></tr>";      }
      $output .= "</table>";
      return $output;
 }
 ?>