Extension:Gist

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Gist

Release status: beta

Implementation Tag
Description add github gists into your articles easily
Author(s) Shohei Yokoyama
Last version 1 (2011-12-15)
MediaWiki 1.16 (tested)
License MIT
Download http://shohei.yokoyama.ac/Software/MediaWiki_Extension/Gist/en
Example <gist>1479684</gist>

Check usage (experimental)

This extension makes it possible to easily add github gists into your articles easily.

Contents

[edit] Usage

  • Enbed code (all)
<gist><script src="https://gist.github.com/1479684.js"> </script></gist>
  • Enbed code (file)
<gist><script src="https://gist.github.com/1479684.js?file=Gist.php"></script></gist>
  • Gist#
<gist>1479684 </gist>
Note: You do not need to care about whitespaces.

[edit] Download instructions

Please cut and paste the code found below and place it in $IP/extensions/Gist/Gist.php.

Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

[edit] Installation

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/Gist/Gist.php");

[edit] Code

<?php
# GitHubGist MediaWiki extension v.1
#    Author: Shohei Yokoyama (Shizuoka Univ. Japan)
# 
#-Install
# 1. Save this code as $MediaWikiRoot/extensions/Gist/Gist.php
# 2. Append "require_once "$IP/extensions/Gist/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>";
                }
        }
 
}
Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox