Extension:GalleryTable

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
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
Check usage and version matrix.

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

Installation[edit]

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[edit]

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

Code[edit]

<?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;
 }
 ?>