00001 <?php 00002 00007 class CoreLinkFunctions { 00008 static function register( $parser ) { 00009 $parser->setLinkHook( NS_CATEGORY, array( __CLASS__, 'categoryLinkHook' ) ); 00010 return true; 00011 } 00012 00013 static function defaultLinkHook( $parser, $holders, $markers, 00014 Title $title, $titleText, &$displayText = null, &$leadingColon = false ) { 00015 if( isset($displayText) && $markers->findMarker( $displayText ) ) { 00016 # There are links inside of the displayText 00017 # For backwards compatibility the deepest links are dominant so this 00018 # link should not be handled 00019 $displayText = $markers->expand($displayText); 00020 # Return false so that this link is reverted back to WikiText 00021 return false; 00022 } 00023 return $holders->makeHolder( $title, isset($displayText) ? $displayText : $titleText, '', '', '' ); 00024 } 00025 00026 static function categoryLinkHook( $parser, $holders, $markers, 00027 Title $title, $titleText, &$sortText = null, &$leadingColon = false ) { 00028 global $wgContLang; 00029 # When a category link starts with a : treat it as a normal link 00030 if( $leadingColon ) return true; 00031 if( isset($sortText) && $markers->findMarker( $sortText ) ) { 00032 # There are links inside of the sortText 00033 # For backwards compatibility the deepest links are dominant so this 00034 # link should not be handled 00035 $sortText = $markers->expand($sortText); 00036 # Return false so that this link is reverted back to WikiText 00037 return false; 00038 } 00039 if( !isset($sortText) ) $sortText = $parser->getDefaultSort(); 00040 $sortText = Sanitizer::decodeCharReferences( $sortText ); 00041 $sortText = str_replace( "\n", '', $sortText ); 00042 $sortText = $wgContLang->convertCategoryKey( $sortText ); 00043 $parser->mOutput->addCategory( $title->getDBkey(), $sortText ); 00044 return ''; 00045 } 00046 00047 }