musinsky
4/12/2012 - 8:09 PM

Gist (GistHub) extension for MediaWiki

Gist (GistHub) extension for MediaWiki

<?php
if( !defined( 'MEDIAWIKI' ) ) {
  echo( "This file is part of an extension to the MediaWiki software and cannot be used standalone.\n" );
  die( 1 );
}

$wgExtensionCredits['other'][] = array(
                                       'name' =>        'GistHub',
                                       'author' =>      'Adam Meyer, Jan Musinsky',
                                       'description' => 'Import file(s) from [https://gist.github.com/ github:gist]',
                                       'url' =>         'https://gist.github.com/2370651'
                                       );

if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
  $wgHooks['ParserFirstCallInit'][] = 'efGistHub';
} else {
  $wgExtensionFunctions[] = 'efGistHub';
}

function efGistHub() {
  global $wgParser;
  $wgParser->setHook( 'gisthub', 'efGistHubRender' );
  return true;
}

function efGistHubRender( $input, $args, $parser ) {
  $attr = array();
  // This time, make a list of attributes and their values,
  // and dump them, along with the user input
  foreach( $args as $name => $value ) {
    if ( $name == 'gist' ) {
      $num = $value;
    }
    if ( $name == 'file' ) {
      $fname = $value;
    }
  }

  return '<script src="https://gist.github.com/'.$num.'.js?file='.$fname.'"></script>';
}
?>
[https://gist.github.com/2370651 GistHub] is MediaWiki extension. It is a simple fork of this [http://www.mediawiki.org/wiki/Extension:GitHub GitHub] extension

== Installation ==
# Download this [https://raw.github.com/gist/2370651/GistHub.php GistHub.php] file and place it in <code>$IP/extensions/GistHub/GistHub.php</code>
# Add the following to [http://www.mediawiki.org/wiki/Manual:LocalSettings.php LocalSettings.php] <syntaxhighlight lang="php">require_once("$IP/extensions/GistHub/GistHub.php");</syntaxhighlight>

== Usage ==
* <code><nowiki><gisthub gist="2370651"/></nowiki></code> import file (or all files) from gist
* <code><nowiki><gisthub gist="2370651" file="GistHub.wiki"/></nowiki></code> import only one specif <code>GistHub.wiki</code> file
* Use '<code>'''/'''</code>' at the end of line is important