MediaWiki  REL1_19
CoreLinkFunctions.php
Go to the documentation of this file.
00001 <?php
00012 class CoreLinkFunctions {
00017         static function register( $parser ) {
00018                 $parser->setLinkHook( NS_CATEGORY, array( __CLASS__, 'categoryLinkHook' ) );
00019                 return true;
00020         }
00021 
00032         static function defaultLinkHook( $parser, $holders, $markers,
00033                         Title $title, $titleText, &$displayText = null, &$leadingColon = false ) {
00034                 if( isset($displayText) && $markers->findMarker( $displayText ) ) {
00035                         # There are links inside of the displayText
00036                         # For backwards compatibility the deepest links are dominant so this
00037                         # link should not be handled
00038                         $displayText = $markers->expand($displayText);
00039                         # Return false so that this link is reverted back to WikiText
00040                         return false;
00041                 }
00042                 return $holders->makeHolder( $title, isset($displayText) ? $displayText : $titleText, array(), '', '' );
00043         }
00044 
00055         static function categoryLinkHook( $parser, $holders, $markers,
00056                         Title $title, $titleText, &$sortText = null, &$leadingColon = false ) {
00057                 global $wgContLang;
00058                 # When a category link starts with a : treat it as a normal link
00059                 if( $leadingColon ) return true;
00060                 if( isset($sortText) && $markers->findMarker( $sortText ) ) {
00061                         # There are links inside of the sortText
00062                         # For backwards compatibility the deepest links are dominant so this
00063                         # link should not be handled
00064                         $sortText = $markers->expand($sortText);
00065                         # Return false so that this link is reverted back to WikiText
00066                         return false;
00067                 }
00068                 if( !isset($sortText) ) $sortText = $parser->getDefaultSort();
00069                 $sortText = Sanitizer::decodeCharReferences( $sortText );
00070                 $sortText = str_replace( "\n", '', $sortText );
00071                 $sortText = $wgContLang->convertCategoryKey( $sortText );
00072                 $parser->mOutput->addCategory( $title->getDBkey(), $sortText );
00073                 return '';
00074         }
00075 
00076 }