3 * Link functions provided by MediaWiki core; experimental
9 * Various core link functions, registered in Parser::firstCallInit()
12 class CoreLinkFunctions
{
14 * @param $parser Parser_LinkHooks
17 static function register( $parser ) {
18 $parser->setLinkHook( NS_CATEGORY
, array( __CLASS__
, 'categoryLinkHook' ) );
23 * @param $parser Parser
24 * @param $holders LinkHolderArray
25 * @param $markers LinkMarkerReplacer
28 * @param null $displayText
29 * @param bool $leadingColon
32 static function defaultLinkHook( $parser, $holders, $markers,
33 Title
$title, $titleText, &$displayText = null, &$leadingColon = false ) {
34 if( isset($displayText) && $markers->findMarker( $displayText ) ) {
35 # There are links inside of the displayText
36 # For backwards compatibility the deepest links are dominant so this
37 # link should not be handled
38 $displayText = $markers->expand($displayText);
39 # Return false so that this link is reverted back to WikiText
42 return $holders->makeHolder( $title, isset($displayText) ?
$displayText : $titleText, array(), '', '' );
46 * @param $parser Parser
47 * @param $holders LinkHolderArray
48 * @param $markers LinkMarkerReplacer
51 * @param null $sortText
52 * @param bool $leadingColon
55 static function categoryLinkHook( $parser, $holders, $markers,
56 Title
$title, $titleText, &$sortText = null, &$leadingColon = false ) {
58 # When a category link starts with a : treat it as a normal link
59 if( $leadingColon ) return true;
60 if( isset($sortText) && $markers->findMarker( $sortText ) ) {
61 # There are links inside of the sortText
62 # For backwards compatibility the deepest links are dominant so this
63 # link should not be handled
64 $sortText = $markers->expand($sortText);
65 # Return false so that this link is reverted back to WikiText
68 if( !isset($sortText) ) $sortText = $parser->getDefaultSort();
69 $sortText = Sanitizer
::decodeCharReferences( $sortText );
70 $sortText = str_replace( "\n", '', $sortText );
71 $sortText = $wgContLang->convertCategoryKey( $sortText );
72 $parser->mOutput
->addCategory( $title->getDBkey(), $sortText );