Index: trunk/extensions/redircite/redircite.php |
— | — | @@ -0,0 +1,73 @@ |
| 2 | +<?php
|
| 3 | +/**
|
| 4 | + * This program is free software; you can redistribute it and/or modify
|
| 5 | + * it under the terms of the GNU General Public License as published by
|
| 6 | + * the Free Software Foundation; either version 2 of the License, or
|
| 7 | + * (at your option) any later version.
|
| 8 | + *
|
| 9 | + * @author Roan Kattouw <roan.kattouw@home.nl>
|
| 10 | + * @copyright Copyright (C) 2007 Roan Kattouw
|
| 11 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
|
| 12 | + *
|
| 13 | + * An extension that allows for abbreviated inline citations.
|
| 14 | + * Idea by Joe Beaudoin Jr. from The Great Machine wiki <http://tgm.firstones.com/>
|
| 15 | + * Code by Roan Kattouw (AKA Catrope) <roan.kattouw@home.nl>
|
| 16 | + * For information on how to install and use this extension, see the README file.
|
| 17 | + *
|
| 18 | + */
|
| 19 | +
|
| 20 | +$wgExtensionFunctions[] = 'redircite_setup';
|
| 21 | +$wgExtensionCredits['other'][] = array(
|
| 22 | + 'name' => 'redircite',
|
| 23 | + 'author' => 'Roan Kattouw',
|
| 24 | + 'description' => 'Allows for abbreviated inline citations',
|
| 25 | + 'version' => '1.0',
|
| 26 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:Redircite'
|
| 27 | +);
|
| 28 | +
|
| 29 | +function redircite_setup()
|
| 30 | +{
|
| 31 | + global $wgParser, $wgHooks;
|
| 32 | + $wgParser->setHook('redircite', 'redircite_render');
|
| 33 | + $wgHooks['ParserAfterTidy'][] = 'redircite_afterTidy';
|
| 34 | +}
|
| 35 | +
|
| 36 | +$markerList = array();
|
| 37 | +function redircite_render($input, $args, $parser)
|
| 38 | +{
|
| 39 | + // Generate HTML code and add it to the $markerList array
|
| 40 | + // Add "xx-redircite-marker-NUMBER-redircite-xx" to the output,
|
| 41 | + // which will be translated to the HTML stored in $markerList by
|
| 42 | + // redircite_afterTidy()
|
| 43 | + global $markerList;
|
| 44 | + $lparse = clone $parser;
|
| 45 | + $link1 = $lparse->parse("[[$input]]", $parser->mTitle, $parser->mOptions, false, false);
|
| 46 | + $link1text = $link1->getText();
|
| 47 | + $title1 = Title::newFromText($input);
|
| 48 | + if(!$title1) // Page doesn't exist
|
| 49 | + // Just output a normal (red) link
|
| 50 | + return $link1text;
|
| 51 | + $articleObj = new Article($title1);
|
| 52 | + $title2 = Title::newFromRedirect($articleObj->fetchContent());
|
| 53 | + if(!$title2) // Page is not a redirect
|
| 54 | + // Just output a normal link
|
| 55 | + return $link1text;
|
| 56 | +
|
| 57 | + $link2 = $lparse->parse("[[{$title2->getPrefixedText()}|$input]]", $parser->mTitle, $parser->mOptions, false, false);
|
| 58 | + $link2text = $link2->getText();
|
| 59 | +
|
| 60 | + $marker = "xx-redircite-marker-" . count($markerList) . "-redircite-xx";
|
| 61 | + $markerList[] = "<span onmouseout='this.firstChild.innerHTML = \"$input\";' onmouseover='this.firstChild.innerHTML = \"{$title2->getPrefixedText()}\";'>$link2text</span>";
|
| 62 | + return $marker;
|
| 63 | +}
|
| 64 | +
|
| 65 | +function redircite_afterTidy(&$parser, &$text)
|
| 66 | +{
|
| 67 | + // Translate the markers added by redircite_render() to the HTML
|
| 68 | + // associated with them through $markerList
|
| 69 | + global $markerList;
|
| 70 | + foreach($markerList as $i => $output)
|
| 71 | + $text = preg_replace("/xx-redircite-marker-$i-redircite-xx/", $output, $text);
|
| 72 | + return true;
|
| 73 | +}
|
| 74 | +?>
|
Index: trunk/extensions/redircite/CHANGELOG |
Index: trunk/extensions/redircite/README |
— | — | @@ -0,0 +1,46 @@ |
| 2 | +REDIRCITE EXTENSION README
|
| 3 | +
|
| 4 | +TABLE OF CONTENTS
|
| 5 | +1. Introduction
|
| 6 | +2. Where to get redircite
|
| 7 | +3. Installation
|
| 8 | +4. Examples
|
| 9 | +5. Contact
|
| 10 | +6. Credits
|
| 11 | +
|
| 12 | +
|
| 13 | +1. INTRODUCTION
|
| 14 | +This extension implements links to redirects that expand to the redirect's target when the mouse is moved over them.
|
| 15 | +
|
| 16 | +2. WHERE TO GET REDIRCITE
|
| 17 | +The current version of redircite can be downloaded from the MediaWiki SVN repository at http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/redircite
|
| 18 | +Simply click the redircite.php file, then click download. The latest version of this README can be downloaded in a similar way.
|
| 19 | +
|
| 20 | +3. INSTALLATION
|
| 21 | +Download redircite.php (see section 2), create a directory named "redircite" (without quotes) in /path/to/your/wiki/extensions, then move redircite.php to the /path/to/your/wiki/extensions/redircite/ directory.
|
| 22 | +
|
| 23 | +Open LocalSettings.php and add the following line just before the line with ?> on it:
|
| 24 | +
|
| 25 | +require_once("$IP/extensions/redircite/redircite.php");
|
| 26 | +
|
| 27 | +4. EXAMPLES
|
| 28 | +Say you have a page called "S1E01" which is a redirect to "Midnight on the Firing Line". If you type
|
| 29 | +
|
| 30 | +<redircite>S1E01</redircite>
|
| 31 | +
|
| 32 | +it will show as
|
| 33 | +
|
| 34 | +S1E01
|
| 35 | +
|
| 36 | +and if you move the mouse over it, it will expand to
|
| 37 | +
|
| 38 | +Midnight on the Firing Line
|
| 39 | +
|
| 40 | +Of course the text is also linked to the Midnight on the Firing Line article.
|
| 41 | +
|
| 42 | +
|
| 43 | +5. CONTACT
|
| 44 | +Redircite is currently maintained by Roan Kattouw. If you have any questions, complaints, feature requests, found a bug, or any other reason to contact the maintainer, please send your e-mails to roan.kattouw@home.nl and mention "redircite" in the subject.
|
| 45 | +
|
| 46 | +6. CREDITS
|
| 47 | +Joe Beaudoin Jr. from The Great Machine wiki <http://tgm.firstones.com/> came up with the idea, Roan Kattouw wrote the code.
|