More function and variable documentation
[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 * @static
15 * @param $parser Parser_LinkHooks
16 * @return bool
17 */
18 static function register( $parser ) {
19 $parser->setLinkHook( NS_CATEGORY, array( __CLASS__, 'categoryLinkHook' ) );
20 return true;
21 }
22
23 /**
24 * @static
25 * @param $parser Parser
26 * @param $holders LinkHolderArray
27 * @param $markers LinkMarkerReplacer
28 * @param Title $title
29 * @param $titleText
30 * @param null $displayText
31 * @param bool $leadingColon
32 * @return bool
33 */
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
42 return false;
43 }
44 return $holders->makeHolder( $title, isset($displayText) ? $displayText : $titleText, '', '', '' );
45 }
46
47 /**
48 * @static
49 * @param $parser Parser
50 * @param $holders LinkHolderArray
51 * @param $markers LinkMarkerReplacer
52 * @param Title $title
53 * @param $titleText
54 * @param null $sortText
55 * @param bool $leadingColon
56 * @return bool|string
57 */
58 static function categoryLinkHook( $parser, $holders, $markers,
59 Title $title, $titleText, &$sortText = null, &$leadingColon = false ) {
60 global $wgContLang;
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
69 return false;
70 }
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 );
76 return '';
77 }
78
79 }