Extension:WikiPagesTag
|
WikiPagesTag Release status: beta |
|||
|---|---|---|---|
| Implementation | Tag | ||
| Description | Allows to have a list enclosed in <WikiPages> </WikiPages> tag that auto links to internal links weather or not is exists. | ||
| Author(s) | Rajinder Uppal (owngeekTalk) | ||
| Last version | 1.0 | ||
| License | Freeware just give me credit if you use it. | ||
| Download | No link | ||
|
|||
|
|||
|
|||
|
Check usage (experimental) |
|||
Contents |
[edit] What can this extension do?
This extension was made because there was no way other than using auto-link to create internal links to documents or articles using a tag. But auto-link is very intensive one resources etc. Also I wanted the ability to have a list of words separated by a carriage return and have those words automatically link to internal pages whether or not those pages exist.
So if you had a list of words like:
billy bob
jane austin
mike duck
super man
And you want to create internal links for those documents, you would have to place [[ and ]] around those words. If there is a lot of words, that is a lot of manual editing. This will allow you to auto link all of those words without manually adding the brackets.
[edit] Usage
<WikiPages> list list list </WikiPages>
Will do the equivalent of:
[[list]] [[list]] [[list]] [[list]]
Thanks and if you have questions email me at owngeek@gmail.com
[edit] Download instructions
Please cut and paste the code found below. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds $IP/extensions/WikiPages.php LocalSettings.php.
[edit] Installation
To install this extension, add the following to LocalSettings.php:
#add configuration parameters here
#setup user rights here
require_once("$IP/extensions/WikiPages.php");
[edit] Configuration parameters
Just put everything in <WikiPages> tags.
[edit] User rights
Feel free to use it as you like, just give me credit :)
[edit] Code
[edit] Version 0.1
<?php #This is the first version 0.1. It parses everything in between the <WikiPages> </WikiPages> tags as a list and autolinks the list to internal documents. # #For Example: #In a page add the <WikiPages> tag like this: # #<WikiPages> #list thing #another thing #some thing #</WikiPages> # # Will do the equivelant of: #[[list thing]] #[[another thing]] #[[some thing]] # Without having to add the brackets around each word manually. # if (!defined('MEDIAWIKI')) die(); $wgExtensionCredits['validextensionclass'][] = array( 'name' => 'WikiPagesTag', 'author' =>'Rajinder Uppal', 'url' => 'owngeek@gmail.com', 'description' => 'This Extension allows you to automatically add [[ ]] around a list of words in a wiki to auto link them.' ); //Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980 if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { $wgHooks['ParserFirstCallInit'][] = 'wfWikiPages'; } else { // Otherwise do things the old fashioned way $wgExtensionFunctions[] = 'wfWikiPages'; } function wfWikiPages( $data ) { global $wgParser; $wgParser->setHook( 'WikiPages', 'wfWikiPagesTagParser' ); return true; } function wfWikiPagesTagParser( $data,$args,&$parser ) { global $wgParser; return $parser->recursiveTagParse( "[[" . implode( "]]<br /> \n[[", array_map( 'wfWikiPagesString', explode( "\n", trim( $data ) ) ) ) . "]]<br />\n"); } function wfWikiPagesString( $text ) { return strtr( wfWikiPagesDisplay( $text ), array( "\\" => "\\\\", "\"" => "\\\"", "'" => "\\'", "\r\n" => "\\n", "\r" => "\\n", "\n" => "\\n", ) ); } function wfWikiPagesDisplay( $text ) { static $invisibles = array( ' ', ' ' ); static $visibles = array( '&nbsp;', '&#160;' ); return Sanitizer::decodeCharReferences( str_replace( $invisibles, $visibles, $text ) ); } ?>
[edit] Version 0.2
<?php #This is the first version. It parses everything in between the <WikiPages> </WikiPages> tags as a list and autolinks the list to internal documents. # #For Example: #In a page add the <WikiPages> tag like this: # #<WikiPages> #list thing #another thing #some thing #</WikiPages> # # Will do the equivelant of: #[[list thing]] #[[another thing]] #[[some thing]] # Without having to add the brackets around each word manually. ############## # #Version 0.2. This adds the <li> tag around each list item processed so you can use CSS to make it have bullets etc. # #So it will add the equivelant of: # #<li>[[list thing]]</li> #<li>[[another thing]]</li> #<li>[[some thing]]</li> # if (!defined('MEDIAWIKI')) die(); $wgExtensionCredits['validextensionclass'][] = array( 'name' => 'WikiPagesTag', 'author' =>'Rajinder Uppal', 'url' => 'owngeek@gmail.com', 'description' => 'This Extension allows you to automatically add [[ ]] around a list of words in a wiki to auto link them.' ); //Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980 if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { $wgHooks['ParserFirstCallInit'][] = 'wfWikiPages'; } else { // Otherwise do things the old fashioned way $wgExtensionFunctions[] = 'wfWikiPages'; } function wfWikiPages( $data ) { global $wgParser; $wgParser->setHook( 'WikiPages', 'wfWikiPagesTagParser' ); return true; } function wfWikiPagesTagParser( $data,$args,&$parser ) { global $wgParser; return $parser->recursiveTagParse( '<li>' . "[[" . implode( "]]<br /></li>\n<li>[[", array_map( 'wfWikiPagesString', explode( "\n", trim( $data ) ) ) ) . "]]</li><br />"); } function wfWikiPagesString( $text ) { return strtr( wfWikiPagesDisplay( $text ), array( "\\" => "\\\\", "\"" => "\\\"", "'" => "\\'", "\r\n" => "\\n", "\r" => "\\n", "\n" => "\\n", ) ); } function wfWikiPagesDisplay( $text ) { static $invisibles = array( ' ', ' ' ); static $visibles = array( '&nbsp;', '&#160;' ); return Sanitizer::decodeCharReferences( str_replace( $invisibles, $visibles, $text ) ); } ?>
[edit] Version 1.0
This is the version 1.0 It includes the ability to add css styling to the output. Also you can specify if you want the UL or LI per line.
<?php if (!defined('MEDIAWIKI')) die(); $wgExtensionCredits['validextensionclass'][] = array( 'name' => 'WikiPagesTag', 'author' =>'Rajinder Uppal', 'url' => 'owngeek@gmail.com', 'description' => 'This Extension allows you to automatically add [[ ]] around alist of words in a wiki to auto link them.' ); //Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980 if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { $wgHooks['ParserFirstCallInit'][] = 'wfWikiPages'; } else { // Otherwise do things the old fashioned way $wgExtensionFunctions[] = 'wfWikiPages'; } function wfWikiPages( $data ) { global $wgParser; $wgParser->setHook( 'WikiPages', 'wfWikiPagesTagParser' ); return true; } function wfWikiPagesTagParser( $data,$args,&$parser) { global $wgParser; // Declare Variables $cols = 4; // Check arguments are passed. if (array_key_exists('cols', $argv)) {$cols = trim($argv['type']);} if (array_key_exists('class', $argv)) {$class = trim($argv['type']);} $table = "<table class=\"$class\" style=\"text-align: center;\">'; $tr_field='<tr>'; $td_field='<td>'; // $before_list_line_insert='<ul><li>[['; // $after_list_lineInsert=']] </li></ul>'; $before_list_line_insert='[['; $after_list_lineInsert=']]'; $output= $table; # return $parser->recursiveTagParse( "[[" . implode( "]]<br /> \n[[", # array_map( 'wfWikiPagesString', # explode( "\n", trim( $data ) ) ) ) . "]]<br />\n"); $index=1; $array = array_map( 'wfWikiPagesString',explode( "\n", trim( $data ))); $output .= $tr_field; for ( $x=0; $x < 4; $x++ ) { $output .= $td_field; for ($y=$x; $y < count($array); $y+=4) { $val = $before_list_line_insert . $array[$y] . $after_list_lineInsert; $output .= $val; } $output .= "</td>"; } $output .= "</tr></table>"; return $parser->recursiveTagParse( $output); } function wfWikiPagesString( $text ) { return strtr( wfWikiPagesDisplay( $text ), array( "\\" => "\\\\", "\"" => "\\\"", "'" => "'", "\r\n" => "\\n", "\r" => "\\n", "\n" => "\\n", ) ); } function wfWikiPagesDisplay( $text ) { static $invisibles = array( ' ', ' ' ); static $visibles = array( '&nbsp;', '&#160;' ); return Sanitizer::decodeCharReferences( str_replace( $invisibles, $visibles, $text ) ); } ?>
