Extension:LinkHint
From MediaWiki.org
This extension requires patches to core MediaWiki code . Extensions implemented using patches may be disabled by or interfere with upgrades and security patches. If a suitable alternative without a patch is available, we recommend you use that extension instead.
|
LinkHint Release status: beta |
|
|---|---|
| Implementation | User interface |
| Description | LinkHint gives you a simple preview of the inner links on a page |
| Author(s) | Nadav Wexler (Blop Talk) |
| Version | 0.9 (07-27-2007) |
| Download | no link |
LinkHint gives you a Hint on inner links - a tooltip of the first sentence of the value appears when you hover the link.
Contents |
[edit] Usage
No special usage - just install and hover over inner links.
[edit] Installation
- Patch your includes/Linker.php. The patch is here.
- Make file called extensions/linkhint.php and copy the code into it.
- Change your LocalSettings.php:
require_once("$IP/extensions/linkhint.php");
Enjoy! :)
[edit] Code
[edit] extensions/linkhint.php
<?php /* * LinkHint MediaWiki extention * Created by Nadav Wexler (nadavwexler [at] yahoo.com) * Original idea by Noam Galili * * @author Nadav Wexler * @author Noam Galili */ if ( !defined( 'MEDIAWIKI' ) ) { die( 'This file is a MediaWiki extension, it is not a valid entry point' ); } global $wgHooks; global $wgExtensionCredits; $wgExtensionCredits['parserhook'][] = array( 'name' => 'LinkHint', 'author' => 'Nadav Wexler (nadavwexler [at] yahoo.com) - Original idea by Noam Galili', 'version' => '0.9', 'url' => 'http://www.mediawiki.org/wiki/Extension:LinkHint', 'description' => 'Shows the first line of a link as its tooltip.', ); $wgHooks['ParserAfterTidy'][] = 'fnLinkHint'; // Callback Function used on the main function function fnGetLinkLine($matches) { $title = Title::newFromText($matches[1]); if ($title) { $wordArticle = new Article( $title ); $wordArticle->getContent(); if( $wordArticle->mContentLoaded ) { $res = $wordArticle->mContent . '.'; // Take only the first sentence $res = substr($res, 0, strpos($res, '.')); // Tidy a bit $res = str_replace(array('[',']'),'',$res); $res = preg_replace("/\s+/"," ",$res); return 'class="innerlink" title="' . htmlspecialchars($res) . '"'; } } return $matches[0]; } // Main Callback function - finds and replace the links function fnLinkHint( &$parser, &$text) { global $action; // Access the global "action" variable // Only do the replacement if the action is not edit or history if( $action !== 'edit' && $action !== 'history' && $action !== 'delete' && $action !== 'watch' ) { $text = preg_replace_callback ('|class="innerlink"\s+title="(.*?)"|', 'fnGetLinkLine', $text); } }

