Extension:LinkHint

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
LinkHint

Release status: unknown

Implementation User interface
Description LinkHint gives you a simple preview of the inner links on a page
Author(s) Nadav Wexler (BlopTalk)
Last version 0.9 (07-27-2007)
License No license specified
Download No link

Check usage (experimental)

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

  1. Patch your includes/Linker.php. The patch is here.
  2. Make file called extensions/linkhint.php and copy the code into it.
  3. 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);
        }
}
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox