Skip to content

Instantly share code, notes, and snippets.

@musinsky musinsky/GistHub.php
Created Apr 12, 2012

Embed
What would you like to do?
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>';
}
?>

GistHub is MediaWiki extension. It is a simple fork of this GitHub extension

Installation

  1. Download this GistHub.php file and place it in $IP/extensions/GistHub/GistHub.php
  2. Add the following to LocalSettings.php <syntaxhighlight lang="php">require_once("$IP/extensions/GistHub/GistHub.php");</syntaxhighlight>

Usage

  • <gisthub gist="2370651"/> import file (or all files) from gist
  • <gisthub gist="2370651" file="GistHub.wiki"/> import only one specif GistHub.wiki file
  • Use ''''/'''' at the end of line is important
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.