Extension:WikiPagesTag

From mediawiki.org
MediaWiki extensions manual
WikiPagesTag
Release status: unmaintained
Implementation Tag
Description Allows to have a list enclosed in <WikiPages> </WikiPages> tag that auto links to internal links whether or not is exists.
Author(s) Rajinder Uppal (owngeektalk)
Latest version 1.0 (2010-01-27)
MediaWiki
Database changes No
License Freeware just give me credit if you use it.
Download No link
  • <WikiPages> </WikiPages>

What can this extension do?[edit]

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.

Usage[edit]

<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

Download instructions[edit]

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.

Installation[edit]

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

#add configuration parameters here
#setup user rights here
require_once("$IP/extensions/WikiPages.php");

Code[edit]

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' => 'https://www.mediawiki.org/wiki/Extension:WikiPagesTag',
       'description' => '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;

// 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(     '&nbsp;',     '&#160;' );
        static $visibles   = array( '&amp;nbsp;', '&amp;#160;' );
        return Sanitizer::decodeCharReferences(
                        str_replace( $invisibles, $visibles, $text ) );
}