Title::moveToInternal doesn't return anything, but it does throw an exception
[lhc/web/wiklou.git] / includes / parser / CoreLinkFunctions.php
1 <?php
2 /**
3 * Link functions provided by MediaWiki core; experimental
4 *
5 * @file
6 */
7
8 /**
9 * Various core link functions, registered in Parser::firstCallInit()
10 * @ingroup Parser
11 */
12 class CoreLinkFunctions {
13 /**
14 * @param $parser Parser_LinkHooks
15 * @return bool
16 */
17 static function register( $parser ) {
18 $parser->setLinkHook( NS_CATEGORY, array( __CLASS__, 'categoryLinkHook' ) );
19 return true;
20 }
21
22 /**
23 * @param $parser Parser
24 * @param $holders LinkHolderArray
25 * @param $markers LinkMarkerReplacer
26 * @param Title $title
27 * @param $titleText
28 * @param null $displayText
29 * @param bool $leadingColon
30 * @return bool
31 */
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
40 return false;
41 }
42 return $holders->makeHolder( $title, isset($displayText) ? $displayText : $titleText, array(), '', '' );
43 }
44
45 /**
46 * @param $parser Parser
47 * @param $holders LinkHolderArray
48 * @param $markers LinkMarkerReplacer
49 * @param Title $title
50 * @param $titleText
51 * @param null $sortText
52 * @param bool $leadingColon
53 * @return bool|string
54 */
55 static function categoryLinkHook( $parser, $holders, $markers,
56 Title $title, $titleText, &$sortText = null, &$leadingColon = false ) {
57 global $wgContLang;
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
66 return false;
67 }
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 );
73 return '';
74 }
75
76 }