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