CoreLinkFunctions.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Various core link functions, registered in Parser::firstCallInit()
  4. * @ingroup Parser
  5. */
  6. class CoreLinkFunctions {
  7. static function register( $parser ) {
  8. $parser->setLinkHook( NS_CATEGORY, array( __CLASS__, 'categoryLinkHook' ) );
  9. return true;
  10. }
  11. static function defaultLinkHook( $parser, $holders, $markers,
  12. Title $title, $titleText, &$displayText = null, &$leadingColon = false ) {
  13. if( isset($displayText) && $markers->findMarker( $displayText ) ) {
  14. # There are links inside of the displayText
  15. # For backwards compatibility the deepest links are dominant so this
  16. # link should not be handled
  17. $displayText = $markers->expand($displayText);
  18. # Return false so that this link is reverted back to WikiText
  19. return false;
  20. }
  21. return $holders->makeHolder( $title, isset($displayText) ? $displayText : $titleText, '', '', '' );
  22. }
  23. static function categoryLinkHook( $parser, $holders, $markers,
  24. Title $title, $titleText, &$sortText = null, &$leadingColon = false ) {
  25. global $wgContLang;
  26. # When a category link starts with a : treat it as a normal link
  27. if( $leadingColon ) return true;
  28. if( isset($sortText) && $markers->findMarker( $sortText ) ) {
  29. # There are links inside of the sortText
  30. # For backwards compatibility the deepest links are dominant so this
  31. # link should not be handled
  32. $sortText = $markers->expand($sortText);
  33. # Return false so that this link is reverted back to WikiText
  34. return false;
  35. }
  36. if( !isset($sortText) ) $sortText = $parser->getDefaultSort();
  37. $sortText = Sanitizer::decodeCharReferences( $sortText );
  38. $sortText = str_replace( "\n", '', $sortText );
  39. $sortText = $wgContLang->convertCategoryKey( $sortText );
  40. $parser->mOutput->addCategory( $title->getDBkey(), $sortText );
  41. return '';
  42. }
  43. }