3 * Link functions provided by MediaWiki core; experimental
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Various core link functions, registered in Parser::firstCallInit()
28 class CoreLinkFunctions
{
30 * @param $parser Parser_LinkHooks
33 static function register( $parser ) {
34 $parser->setLinkHook( NS_CATEGORY
, array( __CLASS__
, 'categoryLinkHook' ) );
39 * @param $parser Parser
40 * @param $holders LinkHolderArray
41 * @param $markers LinkMarkerReplacer
44 * @param null $displayText
45 * @param bool $leadingColon
48 static function defaultLinkHook( $parser, $holders, $markers,
49 Title
$title, $titleText, &$displayText = null, &$leadingColon = false ) {
50 if( isset( $displayText ) && $markers->findMarker( $displayText ) ) {
51 # There are links inside of the displayText
52 # For backwards compatibility the deepest links are dominant so this
53 # link should not be handled
54 $displayText = $markers->expand( $displayText );
55 # Return false so that this link is reverted back to WikiText
58 return $holders->makeHolder( $title, isset( $displayText ) ?
$displayText : $titleText, array(), '', '' );
62 * @param $parser Parser
63 * @param $holders LinkHolderArray
64 * @param $markers LinkMarkerReplacer
67 * @param null $sortText
68 * @param bool $leadingColon
71 static function categoryLinkHook( $parser, $holders, $markers,
72 Title
$title, $titleText, &$sortText = null, &$leadingColon = false ) {
74 # When a category link starts with a : treat it as a normal link
75 if( $leadingColon ) return true;
76 if( isset( $sortText ) && $markers->findMarker( $sortText ) ) {
77 # There are links inside of the sortText
78 # For backwards compatibility the deepest links are dominant so this
79 # link should not be handled
80 $sortText = $markers->expand( $sortText );
81 # Return false so that this link is reverted back to WikiText
84 if( !isset( $sortText ) ) $sortText = $parser->getDefaultSort();
85 $sortText = Sanitizer
::decodeCharReferences( $sortText );
86 $sortText = str_replace( "\n", '', $sortText );
87 $sortText = $wgContLang->convertCategoryKey( $sortText );
88 $parser->mOutput
->addCategory( $title->getDBkey(), $sortText );