MediaWiki
REL1_20
|
00001 <?php 00028 class CoreLinkFunctions { 00033 static function register( $parser ) { 00034 $parser->setLinkHook( NS_CATEGORY, array( __CLASS__, 'categoryLinkHook' ) ); 00035 return true; 00036 } 00037 00048 static function defaultLinkHook( $parser, $holders, $markers, 00049 Title $title, $titleText, &$displayText = null, &$leadingColon = false ) { 00050 if( isset($displayText) && $markers->findMarker( $displayText ) ) { 00051 # There are links inside of the displayText 00052 # For backwards compatibility the deepest links are dominant so this 00053 # link should not be handled 00054 $displayText = $markers->expand($displayText); 00055 # Return false so that this link is reverted back to WikiText 00056 return false; 00057 } 00058 return $holders->makeHolder( $title, isset($displayText) ? $displayText : $titleText, array(), '', '' ); 00059 } 00060 00071 static function categoryLinkHook( $parser, $holders, $markers, 00072 Title $title, $titleText, &$sortText = null, &$leadingColon = false ) { 00073 global $wgContLang; 00074 # When a category link starts with a : treat it as a normal link 00075 if( $leadingColon ) return true; 00076 if( isset($sortText) && $markers->findMarker( $sortText ) ) { 00077 # There are links inside of the sortText 00078 # For backwards compatibility the deepest links are dominant so this 00079 # link should not be handled 00080 $sortText = $markers->expand($sortText); 00081 # Return false so that this link is reverted back to WikiText 00082 return false; 00083 } 00084 if( !isset($sortText) ) $sortText = $parser->getDefaultSort(); 00085 $sortText = Sanitizer::decodeCharReferences( $sortText ); 00086 $sortText = str_replace( "\n", '', $sortText ); 00087 $sortText = $wgContLang->convertCategoryKey( $sortText ); 00088 $parser->mOutput->addCategory( $title->getDBkey(), $sortText ); 00089 return ''; 00090 } 00091 00092 }