wiki.techinc.nl/includes/parser/ParserOutputLinkTypes.php
C. Scott Ananian 004cb43c56 ParserOutput: Introduce ParserOutput::getLinkList()
This deprecates a number of methods which returned arrays by reference and
exposed internal representation details of the ParserOutput.  It also
regularizes the return values to return consistent LinkTarget values,
working around the wide variety of different internal storage formats
used for links.

In the future, once these methods which expose the internal representation
are removed, we can simplify our internal storage as well.  But for the
moment we add the new getter without changing the internal representation.

Note that by returning TitleValue objects this new interface also provides
a means to fix the issue identified in T204792 where interwiki and namespace
prefixes were getting confused.  A TitleValue properly distinguishes between
these -- although the callers will still have to be careful to use it as
a TitleValue and not attempt to reparse it.

These methods also correctly handle fragments, which are present for the
language link type but stripped for the other linkt types.

Bug: T204792
Change-Id: I48a2077b9645124f83082afd953d6bf7a861270b
2024-10-18 13:24:10 -04:00

103 lines
2.5 KiB
PHP

<?php
/**
* Registry of flags used with ParserOutput::{getLinkList,appendLink}()
* within MediaWiki core.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @since 1.43
*
* @file
* @ingroup Parser
*/
namespace MediaWiki\Parser;
/**
* Registry of flags used with ParserOutput::{getLinkList,appendLink}()
* within MediaWiki core.
*
* All link types used should be defined in this class.
*
* @package MediaWiki\Parser
*/
class ParserOutputLinkTypes {
/**
* @var string Category links
* @see ParserOutput::addCategory
* @see ParserOutput::getCategoryMap
* @see ParserOutput::getCategoryNames
*/
public const CATEGORY = 'category';
/**
* @var string Interwiki links
* @see ParserOutput::addInterwikiLink
* @see ParserOutput::getInterwikiLinks
*/
public const INTERWIKI = 'interwiki';
/**
* @var string Language links
* @see ParserOutput::addLanguageLink
* @see ParserOutput::getLanguageLinks
*/
public const LANGUAGE = 'language';
/**
* @var string Local links
* @see ParserOutput::addLink
* @see ParserOutput::getLinks
*/
public const LOCAL = 'local';
/**
* @var string Links to media
* @see ParserOutput::addImage
* @see ParserOutput::getImages
* @see ParserOutput::getFileSearchOptions
*/
public const MEDIA = 'media';
/**
* @var string Links to special pages
* @see ParserOutput::addLink
* @see ParserOutput::getLinksSpecial
*/
public const SPECIAL = 'special';
/**
* @var string Links to templates
* @see ParserOutput::addTemplate
* @see ParserOutput::getTemplates
* @see ParserOutput::getTemplateIds
*/
public const TEMPLATE = 'template';
public static function cases(): array {
return [
self::CATEGORY,
self::INTERWIKI,
self::LANGUAGE,
self::LOCAL,
self::MEDIA,
self::SPECIAL,
self::TEMPLATE,
];
}
}