]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/parser/CoreLinkFunctions.php
MediaWiki 1.14.0-scripts
[autoinstalls/mediawiki.git] / includes / parser / CoreLinkFunctions.php
1 <?php
2
3 /**
4  * Various core link functions, registered in Parser::firstCallInit()
5  * @ingroup Parser
6  */
7 class CoreLinkFunctions {
8         static function register( $parser ) {
9                 $parser->setLinkHook( NS_CATEGORY, array( __CLASS__, 'categoryLinkHook' ) );
10                 return true;
11         }
12
13         static function defaultLinkHook( $parser, $holders, $markers,
14                         Title $title, $titleText, &$displayText = null, &$leadingColon = false ) {
15                 if( isset($displayText) && $markers->findMarker( $displayText ) ) {
16                         # There are links inside of the displayText
17                         # For backwards compatibility the deepest links are dominant so this
18                         # link should not be handled
19                         $displayText = $markers->expand($displayText);
20                         # Return false so that this link is reverted back to WikiText
21                         return false;
22                 }
23                 return $holders->makeHolder( $title, isset($displayText) ? $displayText : $titleText, '', '', '' );
24         }
25         
26         static function categoryLinkHook( $parser, $holders, $markers,
27                         Title $title, $titleText, &$sortText = null, &$leadingColon = false ) {
28                 global $wgContLang;
29                 # When a category link starts with a : treat it as a normal link
30                 if( $leadingColon ) return true;
31                 if( isset($sortText) && $markers->findMarker( $sortText ) ) {
32                         # There are links inside of the sortText
33                         # For backwards compatibility the deepest links are dominant so this
34                         # link should not be handled
35                         $sortText = $markers->expand($sortText);
36                         # Return false so that this link is reverted back to WikiText
37                         return false;
38                 }
39                 if( !isset($sortText) ) $sortText = $parser->getDefaultSort();
40                 $sortText = Sanitizer::decodeCharReferences( $sortText );
41                 $sortText = str_replace( "\n", '', $sortText );
42                 $sortText = $wgContLang->convertCategoryKey( $sortText );
43                 $parser->mOutput->addCategory( $title->getDBkey(), $sortText );
44                 return '';
45         }
46         
47 }