3 * Link functions provided by MediaWiki core; experimental
9 * Various core link functions, registered in Parser::firstCallInit()
12 class CoreLinkFunctions
{
15 * @param $parser Parser_LinkHooks
18 static function register( $parser ) {
19 $parser->setLinkHook( NS_CATEGORY
, array( __CLASS__
, 'categoryLinkHook' ) );
25 * @param $parser Parser
26 * @param $holders LinkHolderArray
27 * @param $markers LinkMarkerReplacer
30 * @param null $displayText
31 * @param bool $leadingColon
34 static function defaultLinkHook( $parser, $holders, $markers,
35 Title
$title, $titleText, &$displayText = null, &$leadingColon = false ) {
36 if( isset($displayText) && $markers->findMarker( $displayText ) ) {
37 # There are links inside of the displayText
38 # For backwards compatibility the deepest links are dominant so this
39 # link should not be handled
40 $displayText = $markers->expand($displayText);
41 # Return false so that this link is reverted back to WikiText
44 return $holders->makeHolder( $title, isset($displayText) ?
$displayText : $titleText, array(), '', '' );
49 * @param $parser Parser
50 * @param $holders LinkHolderArray
51 * @param $markers LinkMarkerReplacer
54 * @param null $sortText
55 * @param bool $leadingColon
58 static function categoryLinkHook( $parser, $holders, $markers,
59 Title
$title, $titleText, &$sortText = null, &$leadingColon = false ) {
61 # When a category link starts with a : treat it as a normal link
62 if( $leadingColon ) return true;
63 if( isset($sortText) && $markers->findMarker( $sortText ) ) {
64 # There are links inside of the sortText
65 # For backwards compatibility the deepest links are dominant so this
66 # link should not be handled
67 $sortText = $markers->expand($sortText);
68 # Return false so that this link is reverted back to WikiText
71 if( !isset($sortText) ) $sortText = $parser->getDefaultSort();
72 $sortText = Sanitizer
::decodeCharReferences( $sortText );
73 $sortText = str_replace( "\n", '', $sortText );
74 $sortText = $wgContLang->convertCategoryKey( $sortText );
75 $parser->mOutput
->addCategory( $title->getDBkey(), $sortText );