Extension:AutoLink

What can this extension do?
When a new page is created, or an existing page is saved, Some of the specific words in the page content will automatically become links to other pages. Such Extension was very much required for my application so i thought of placing it here so that others if interested can use it.

Usage
Once this extension is installed, Just edit a page,add some content to it and save the page. The words in the page content which are present in the page AutoLinkPages will become links to respective page. So AutoLinkPages acts as a dictionary for the Auto Link words.

Installation

 * Create a page with name AutoLinkPages.This page will contain : separated pagenames which have to be auto linked.For Example AutoLinkPages.
 * Just copy the extension directy from AutoLink.
 * Save it as AutoLink.php in extensions directory.

Changes to LocalSettings.php
Include this extension in LocalSettings.php as follows:- require_once("$IP/extensions/AutoLink.php");

Code
 "AutoLink (version-1.0)",    'author' => 'Sanjeev Sanjeev' );

$wgHooks['ArticleSave'][] = 'wfAddAutoLinks';

function wfAddAutoLinks(&$article,&$user,&$text) {       $content = $text; $pages = array; #This should not work for the Page AutoLinkPages. if($article->mTitle->mTextform != 'AutoLinkPages') {               $pages = getPages; foreach($pages as $p) {                       #Replace the already present auto links, to prevent linking again. $content = str_replace("".$p."",$p,$content); if(strpos($content,$p)) {                               $content = str_replace($p,"".$p."",$content); }               }                $text = $content; }       return true; }
 * 1) Event Handler for ArticleSave Event.

function getPages {       $title = Title::newFromURL('AutoLinkPages'); $article = new Article($title); $pagenames = $article->getContent; $pages = explode(':',$pagenames); return $pages; } ?>
 * 1) Function to return page names from AutoLinkPages as an array

Contact
In case of any issues please get in touch with me. Sanjeev Thanks!!!