JargonExtension

From S23Wiki

Contents

[edit] About

This is a Mediawiki extension that inserts JargonFile definitions on wiki pages.

[edit] Usage

The simplest way to do so is to insert <jargon /> in a page, that will use the current page title as lookup term.

Alternatively you can use <jargon>something</jargon>.

Pages using it are also automatically included in Category:Jargon.

[edit] ToDo

You can help here by going to a page that already uses it (--> Category:Jargon), clicking the red "Next" or "Prev" links and then simply inserting <jargon /> (and nothing else) into the new page.

[ ] Include all JargonFile terms as wiki pages (All)

[edit] Source

[edit] Install

To install copy into ./extensions/JargonExtension.php and then include("extensions/JargonExtension.php"); in LocalSettings.php as usual with Mediawiki extensions.

The extension uses the Debian package jargon. apt-get install jargon. (Also see vh).


<?php
# JargonFile terms on Mediawiki pages
# On inserting <jargon>something</jargon> in a wiki page,
# execute "jargon something" on the shell and return the formatted output
# mutante/s23 - 10/2007

$wgExtensionCredits['other'][] = array(
'name' => 'JargonFile extension',
'author' => 'mutante',
'version' => '10/2007',
'url' => 'http://s23.org/wiki/JargonExtension',
'description' => 'displays the [[JargonFile]] entry for a term on a wiki page.'
);

$wgExtensionFunctions[] = "wfJargonExtension";

function wfJargonExtension() {
        global $wgParser;
        $wgParser->setHook( "jargon", "getJargon" );
}

function getJargon( $input, $args, &$parser ) {
        global $wgParser;
        global $wgTitle;

        # Get the definition of a term from the JargonFile

        # if no input term is set get the current page title and use that
        if ($input=="") {
                $mytitle=$wgTitle->mTextform;
                $term=$mytitle;
        } else {
                # if there is input use that
                $term = $input;
        }

        # avoid evil stuff from user and at the same time make terms with whitespace work
        $term = escapeshellarg($term);

        # execute, we dont want the info messages from errout
        $jargon=`jargon 2>/dev/null $term`;

        # Get next link
        $next=explode("Next: ",$jargon);
        $next=explode(",",$next[1]);
        $next=$next[0];
        # Get previous link
        $prev=explode("Prev: ",$jargon);
        $prev=explode(",",$prev[1]);
        $prev=$prev[0];

        # remove header line
        $jargon=explode("=",$jargon);
        $jargon=$jargon[2];

        # add wiki links
        $jargon=str_replace("{","[[",$jargon);
        $jargon=str_replace("}","]]",$jargon);

        # remove ` and stuff
        $jargon=str_replace("'","''",$jargon);
        $jargon=str_replace("`","''",$jargon);

        # build output
        $output="<table><tr><td>[[Image:Glider.png|30px]]</td><td>";
        $output.="This is the [[Jargon File]] entry for '''$term''' - Next: [[".$next."]], Prev: [[".$prev."]]</td></tr>";
        $output.="<tr><td colspan=\"2\"><pre>".$jargon."</pre></td></tr><tr><td colspan=\"2\" style=\"font-size:0.8em\">* (''text is auto-included via [[JargonExtension]] by [[User:Mutante|mutante]] using [[jargon]] with VERSION 4.0.0, 24 JUL 1996 - JargonFile by [[Eric_Raymond|Eric S. Raymond]] is in the [[public domain]])</td></tr></table>\n[[Category:Jargon]]''";


        # trim,parse and return it
        $output=trim($output);
        $parsed_output = $parser->recursiveTagParse( $output );
        return $parsed_output;

}

?>
Personal tools