Extension talk:AutoLink

Help 04-Jan-2008
Hi Sanjeev

Great program thanks!! Is there anyway of making it work with larger pages? We're using it in anger on our website http://www.kidneycancerresource.com/wiki and quite a few of our pages go well over the 25K mark and what we've found is that it tries to save and then just comes up with a blank page. When you refresh the saved page it goes back to the original and you lose the changes.

I guess it has something to do with the maximum Text size?

Thanks

Andy

help
I have made AutoLink.php in extensions directory, added require_once("$IP/extensions/AutoLink.php"); to LocalSettings.php, and made an AutoLinkPages (http://zimwiki.com/index.php?title=AutoLinkPages). What am I doing wrong?


 * you have to separathe the namepages with ':' ... example: Page1:Page2:Page3

Finally
I've been wanting an extension like this forever, but had no idea how to do it. Thanks for tackling this, can't wait to try and implement it on my wiki.--24.250.230.243 01:44, 15 June 2007 (UTC)

Big Bug (Resolved)
If for example you have the word "animal" in your wordlist AutoLinkPages and you have an images called animal.jpg in your curently edited artikel you get animal.jpg as a result. That ist bad in the "image-" Tag. I think with categories it is the same problem. Anyone here, who can change the code? 89.52.133.99 15:55, 2 July 2007 (UTC)
 * Thankyou very much for drawing my attention to this point.I have just started working with wikis,so as soon as i was done with this extension i put it here.But i'll definitely re-work on this extension keeping all your suggestions in mind.Please wait for some time so that i can make it perfect and then submit.--Sanjeev 08:41, 3 July 2007 (UTC)
 * Sadly to say - it isn't resolved.89.52.189.171 21:22, 9 July 2007 (UTC)
 * Is it too difficult to make this little change? If yes - this tool is not helpfull for me - I am sorry.89.52.164.171 23:47, 10 July 2007 (UTC)
 * In Next two dayz i'll do that.--Sanjeev 08:28, 16 July 2007 (UTC)

one bug, one "feature"
I edited the script so that if you have "animal" in the dictionary page, it will create a link to it from either "animal" or "Animal". Also, there was a bug in the code that did not autolink text if it appeared in position 0 in the content string. It had to do with the return value of the strpos function. You have to use "!== false" to evaluate properly. Anyway -- that was kind of eliminated when I switched to using preg_replace and preg_match. Feel free to roll back if it's not appropriate. I'm currently using the script as I've edited it on my own server. I was planning to address the issue with replacing words that appear inside of square brackets.

Thanks for the idea and for putting the original code together. --Flanagana 19:48, 3 July 2007 (UTC)
 * Hi Flanagana.
 * As,I said i was re-working on this extension,even i was planning to use preg_match/replace functions.And regarding !==false condition, this bug can also be removed if instead of strpos, strstr is used.But nywayz as you said preg_match if used then no need to worry about !==false condition.So the changes made by you to the code contribute towards it's perfection.Thankyou very much for that.Please try to find out if any other problem lies in that,so that we can work together on it. :)
 * Your changes to code and suggestions encourage me to think out of the box and to develop and contribute more extensions for our people.Thanks once again.--Sanjeev 04:50, 4 July 2007 (UTC)

Put all articles automatically into the article "AutoLinkPages" (resolved)
I want to have all my article put automaticaly into AutoLinkPages. Is it possible when opening the article "AutoLinkPages" to be asked "Do you want to have all your articles put into this page?" and when I answer "yes" the script will put all of them automatically into thte page?? 89.52.189.233 10:23, 6 July 2007 (UTC)
 * Hi!!!
 * Yes,it is very much possible to put all the Articles in AutoLink Page.
 * But when i wrote this extension, my requirement was for selective words in a page content.
 * I will definitely work on this to allow, putting all the Articles in that page
 * automatically,but can you please give some more details about your requirement.
 * For example,one case is that from now onwards any page/article you create will have an auto
 * entry in AutoLink page..,or else all the existing article names have to be added to
 * AutoLinkPage.So, Please give me some more details and time to prepare that.
 * Thankyou very much --Sanjeev 06:18, 9 July 2007 (UTC)


 * It's a good idea from you to allow the alternatives: give the user the possibillity ...
 * 1. ... to put single words into AutoLinkPages (as you did before)
 * 2. ... to abandon the AutoLinkPages and automatically use all the article-names
 * Thanks for your work
 * 89.52.189.171 21:16, 9 July 2007 (UTC)

Samuel Gelineau resolved wish 2. 89.52.154.165 09:38, 29 July 2007 (UTC)

Content is wiped out
Hi, I've tried this extension on my wiki, and I always get the content wiped out. I've just started trying editing it myself. If anybody has had the same issue, please suggest a solution. Thanks.--Cartoro 09:16, 11 July 2007 (UTC)
 * Hi Cartoro.

Please do not use the extension now as it's under re-work.Very soon i'll be replacing the code with one which will work perfectly.Sorry for inconvenience.--Sanjeev 13:16, 11 July 2007 (UTC)

Woohoo! Thanks Cartoro for making this point and thanks to Sanjeev for letting us know what is happening. I had thought it was something I was doing when I had the same problem as nobody else mentioned it. I look forward to the new version.

New Version of This Extension
Hi frenzz!!!
 * The code for this extension is updated latest(version1.2) and take cares of the above specified "animal.jpg" problem.Before you use this extension let me make you aware of something.This extension is re-worked to remove the bug like animal.jpg,but i won't say that a bug, coz it depends on once requirements.So this extension may satisfy certain requirements and others not, so all of you feel free to take the code and customize it as per your requirements.This Extension can be made more specific to include other conditions also,so please keep on adding more functionality to it.Ideas are appreciated and will definitely be taken care of.Now about including all Article names in AutoLinkPages,i tried that but it harms the performance badly as my wiki app has many articles.So i thought, not to include it.Please let me know if any issues.Thanks a lot. --Sanjeev 11:31, 16 July 2007 (UTC)

New issue
Sanjeev: I've only used this a little bit more, but I've hit the problem that the matching does not take place when the word is near other punctuation. For example if the word is "animal" then the sentence "This is an animal!" won't link properly, where "This is an animal !" will link... Anyway -- thanks for your efforts on making this better... I'm swamped with other tasks but if I get around to resolving any of these issues, I'll post my updated code. --70.21.34.164 02:26, 18 July 2007 (UTC)

Problems with pictures
"dogs" is put into AutoLinkPage. The following then is changed from:

thumb|500px|animals

into:

Bild:[[dogs and cats.gif|thumb|500px|animals]]


 * It is assumed that name of the images won't be having spaces between them.
 * For example if 'dogs and cat.gif' is 'dogs_and_cat.gif', extension will work and 'dogs' will not be linked.Thanks!!!!Sanjeev


 * You are right - it is no good idea to have spaces in filenames. But we have lots of spaces in names of pictures in our wiki. Nearly impossible to rename them all.
 * Suggestion: Wy not just stop replacing between " " ... and ... " " and also between " [" ... and ...  "] "? 89.52.168.70 11:24, 27 July 2007 (UTC)

New version
Hi, I (not the original Author) wrote a new version which didn't rely on an AutoLinkPage word list. I also rewrote the substitution code so it wouldn't depend on spaces (see "New issue" above), and added an easy-to-edit list of "exception blocks" within which words should not be substituted. There's a regression though: the so-called "animal" problem will probably reoccur.


 * Thank you very much for the further development of the extension.
 * Would it be possible to have both versions in one script? Maybe with a parameter for "wordlist" or "all pages"? Or if there is no article "AutoLinkPages" take all artikels.


 * Otherwise we'll get a third/forth/... version in a few months. 89.52.191.150 19:53, 28 July 2007 (UTC)

Two wishes: Don't touch the hyperlinks I wrote by hand myself. E.g.: There is an article "Animals" but no article "Animalfarm". Now animalfarm would result in "animalfarm" but it shouldn't be touched. 89.52.154.165 10:28, 29 July 2007 (UTC)
 * wiki links are already exception blocks, so the extension won't touch your hand-made hyperlinks. Besides, there's no way the regular expression /animalfarm/ will match the text  "animal]]farm" , so I'm deeply convinced that this already works as expected. Gelisam
 * Thanks for this great extension. My problem: the extension handel german-umlaut like an end of a word. for example: if there is an article named "F" and i write an "für" in my text the extension replace "F|für" . try to fix it, but my php-knowlegth is not deep enough. may its because wiki write umlaut in latin-Kollation. for example: "Ã¼" instate of "ü". 85.232.26.207 16:06, 9 October 2007 (UTC)

Don't hyperlink the articlename itself more than once. E.g.: If the article is called "Animal" then mark only the first "Animal" otherwise there are a lot of bold "Animals". 10:28, 29 July 2007 (UTC)
 * I've just noticed; and I've just fixed it. Although I don't mark the first self-loop either. Gelisam

Added only a little to the "Gelineau"-version and now it is workin fine - thank you very much.89.52.176.161 16:52, 30 July 2007 (UTC)

Bracket bug
If you have an article "PHP" and you write an hyperlink in an other article  Only an example  then .php? gets  |php]?parameter=3 Only an example] . I tried to put  [ ]  into the mapIgnoringBlocks and got further errors. -89.52.168.59 16:08, 5 August 2007 (UTC)


 * I have asked here for an answer. -89.52.137.94 07:00, 21 August 2007 (UTC)

Etiquette violation?
I just posted a new version of this extension, and then I realized I might have committed some MediaWiki etiqutte violation. If so, I apologize and urge you to feel free to pull down my code. I probably should have contacted the author before posting a mod on the same page. --Vjg 16:50, 24 August 2007 (UTC)


 * I just installed the version written by you that prefers longer names. After having tried it a short while I come across my first question. Is there any way to define an exclusion list of certain words that shall not automatically be converted to links? I found that words such as help and contact normally tend to create "strange" link targets given the context of the article being modified.


 * OK - changed the function called getPages to exclude pages listed in a special article. In my version it looks like below.

In addition I added an if-statement in the function wfAddAutoLinks to exclude the exclusion page from being autoLinked. This seems to work quite well.

However, I also have the umlaut-problem referred to above where umlaut-letters seem to trigger word-ending. Fatboy45 14:41, 5 December 2007 (UTC)

nowiki bug
I discovered a bug in both versions that work with all pages. At first I thought I'd introduced it in my version, but I've confirmed it is present in the code I used as the basis of my change. I don't know if it is also present in the code that used the AutoLinkPage.

If you have a page with the text: Page &lt;nowiki&gt; reference Main Page is in a nowiki &lt;/nowiki&gt; block. the text that actually gets saved is: Page &lt;nowiki&gt; reference &lt;/nowiki&gt; Main Page is in a nowiki &lt;/nowiki&gt; block. Note the extra terminating &lt;/nowiki&gt; that was inserted immediately before the first nested wiki link tag. The nowiki block isn't being handled quite right. If I resolve the issue, I'll post changes, but it's low on my priority list. --Vjg 15:03, 27 August 2007 (UTC)


 * Please put it higher in your priority list ;-) 89.52.160.92 18:34, 17 September 2007 (UTC)

Delimiter warning (if not bug)
Be cautious with the use of the delimiter pair array. For instance, the categorytree tag won't be recognized if you have parameters set in the opening tag. Dropping the trailing &gt; on the opening tag will make it work again, but you need to consider this behavior for any delimiter pair you introduce. --Vjg 17:21, 27 August 2007 (UTC)

Help translating
Hello, I want to help translate something (because you wrote it). My only question now is how to do that. (I can speak German, French and Italian) Could you give me a hint? --Iiiiiichdenk 16:23, 1 September 2007 (UTC)

Conflict with other extensions
I added a tag to the function wfAddAutoLinks (in autolink.php), because autolink got in trouble with the extension dirlist. "&lt;nowiki&gt;", "&lt;/nowiki&gt;", "&lt;dirlist","&lt;/dirlist&gt;" Now it works fine. This should also work with other extensions which are manipulating the sourccode during site-saving/editing.--217.5.220.106 09:26, 10 September 2007 (UTC)

Autolink to Categories?
Is it possible to use this script to autolink a page and include it in a category? I really don't know anything about scripting, but if there were a way to do this and someone told me where exactly to change the script, that would be so rad. Thanks. Dwharrington 18:31, 14 November 2007 (UTC)

SVN access
Why this extension is not included in the SVN?

Another amended version
I have mashed up the two code sets, taking bits from each.

I took the performance optimised code from the third code extract. However, I found that including every page was not desirable, so I used the autolinkpages approach (i.e. getpages) from the first extract.

I have also included a fix with the page matching regex. This was done because I had pages with brackets in them which weren't being matched. Neilkt 22:56, 19 December 2007 (UTC)

Neilkt 12:49, 8 January 2008 (UTC) Update to fix a bug with the sorting and limit autolinking to the MAIN namespace (the prior version caused problems in the Mediawiki and Special namespaces). Mediawiki:Sidebar is formatted unusually and this extension previously was not able to parse it correctly.

",	                       "", "",	                        "", "",	                        "[", "]",	                        "",	                        " ", " "	                ),	                $text	        );	}        return true; } function mapIgnoringBlocks($delimiters, $text, $pattern, $replacement) {        if (count($delimiters) == 0) {                return preg_replace($pattern, $replacement, $text);        }        $block_start = array_shift($delimiters);        $block_end = array_shift($delimiters);        $result = "";        $post_headers = explode($block_start, $text);        $first_inter_block = array_shift($post_headers);        $result = $result . mapIgnoringBlocks($delimiters, $first_inter_block, $pattern, $replacement);        foreach($post_headers as $post_header) {                $block_and_inter_block = explode($block_end, $post_header, 2);                $block = array_shift($block_and_inter_block); $result = $result. $block_start. $block. $block_end; $inter_block = array_shift($block_and_inter_block); $result = $result. mapIgnoringBlocks($delimiters, $inter_block, $pattern, $replacement); }       return $result; } function autoLinkWords($delimiters, $text) { global $autolink__current_page; $tmp = ""; $patternMap = array; foreach(getPages as $page) {       	if ($page != $autolink__current_page) {	       	$pattern = preg_replace('/_/', '[_ ]', preg_quote($page, '/')); if (strpos($page,"(")+strpos($page,")") > 0) {							$pattern = '/\b((?<!\[)(?<!\/\/)' . $pattern . '(?!\]))/'; }						else {							$pattern = '/\b((?<!\[)(?<!\/\/)' . $pattern . '(?!\]))\b/i'; }         	$patternMap[$pattern] = '\1'; }       }        foreach($patternMap as $pattern=>$replacement) { $text = mapIgnoringBlocks($delimiters, $text, $pattern, $replacement); }

return $tmp.$text; } function getPages {       $title = Title::newFromURL('AutoLinkPages'); $article = new Article($title); $pagenames = $article->getContent; $pages = explode(':',$pagenames); uasort($pages,"Ascii_sort"); //Longest page titles first return $pages; }
 * 1) Function to return page names from AutoLinkPages as an array

function Ascii_sort($val_1, $val_2) {	// initialize the return value to zero $retVal = 0;

// compare lengths $firstVal = strlen($val_1); $secondVal = strlen($val_2);

if($firstVal > $secondVal) {		$retVal = -1; }	else if($firstVal < $secondVal) {		$retVal = 1; }	return $retVal; }
 * Hi Neilkt, what where the problems with linking in user defined namespaces? I like the idea very much of having links in all namespaces, not only in my main namespace. Ben --84.186.215.218 08:40, 18 January 2008 (UTC)