Skip to content

Instantly share code, notes, and snippets.

@abarth500
Created December 15, 2011 03:21
Show Gist options
  • Save abarth500/1479684 to your computer and use it in GitHub Desktop.
Save abarth500/1479684 to your computer and use it in GitHub Desktop.
Gist Extension for MediaWiki
<?php
# GitHubGist MediaWiki extension v.1
# Author: Shohei Yokoyama (Shizuoka Univ. Japan)
#
#-Install
# 1. Save this code as $MediaWikiRoot/extensions/Gist.php
# 2. Append "require_once "$IP/extensions/Gist.php";" to LocalSetting.php
#
#-Usage
# Tag :
# <gist><script src="https://gist.github.com/1476815.js"> </script></gist>
# Tag :
# <gist>1477057</gist> and <gist>1477057 </gist>
$wgExtensionFunctions[] = 'wfGist';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'Gist',
'description' => 'Import Gist entry.',
'author' => 'Shohei Yokoyama',
'url' => 'http://shohei.yokoyama.ac/'
);
function wfGist() {
global $wgParser;
$wgParser->setHook('gist', 'wfGist_func');
}
function wfGist_func($input,$arg,&$parser) {
if(preg_match("/^[0-9]+ ?/",$input)){
return '<script src="https://gist.github.com/'.trim($input).'.js"> </script>';
}else{
$script = new SimpleXMLElement($input);
if(preg_match("/^https\:\/\/gist\.github\.com\/[0-9]+\.js(\?file\=.*)?$/",$script["src"])){
return '<script src="'.$script["src"].'"> </script>';
}else{
return "<b>ERROR: Gist url(".$script["src"].") is invalid.</b>";
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment