MediaWiki represents page titles in several complementary types, from the mutable, feature-richDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/wikimedia/mediawiki/llms.txt
Use this file to discover all available pages before exploring further.
Title class to lightweight immutable value objects and narrow identity interfaces. Understanding when to use each avoids unnecessary coupling to global state.
Type overview
Title
Mutable class implementing both
LinkTarget and PageIdentity. Fetches data from the database and uses global state. Use in presentation code and legacy entry points; prefer lighter types in services.TitleValue
Immutable value object implementing
LinkTarget. No global state, no DB access. Holds namespace, DB key, fragment, and interwiki prefix. Preferred for data transfer between services.PageReference
Minimal interface:
getNamespace(), getDBkey(), getWikiId(). Used as the most general parameter type for services that only need to identify a page.PageIdentity
Extends
PageReference with getId(). Represents a page that may or may not exist. Title implements this interface.TitleValue is the preferred type for internal data transfer. It is immutable, causes no side effects, and does not depend on global state. Prefer TitleValue (or PageReference / PageIdentity) over Title in service constructors and method signatures.Title class
Title (namespace MediaWiki\Title) is the traditional representation of a page title. It implements LinkTarget, PageIdentity, and Stringable.
Creating Title objects
Key Title methods
Title validation rules
Titles parsed byTitle::newFromText() or TitleParser::parseTitle() must pass the following rules (see docs/Title.md):
- Maximum 255 bytes in UTF-8 (512 bytes for
NS_SPECIAL). - No illegal characters matching
$wgLegalTitleCharsnegation. - No percent-encoded sequences (
%XX). - No XML/HTML character references (
&). - No leading/trailing whitespace after normalization.
- Spaces and underscores are interchangeable.
- First letter is uppercased when
$wgCapitalLinksis enabled.
TitleValue
TitleValue (namespace MediaWiki\Title, since 1.23) is an immutable value object implementing LinkTarget. It stores namespace, DB key, fragment, and interwiki prefix.
TitleFormatter service
TitleFormatter (MediaWiki\Title\TitleFormatter, since 1.23, @since 1.28 in MediaWikiServices) converts title objects into display strings. Obtain it from the DI container:
Methods
TitleFormatter::getText() and getPrefixedText() accept both LinkTarget and PageReference objects.
TitleParser service
TitleParser (MediaWiki\Title\TitleParser, since 1.23) parses text strings into TitleValue objects with full normalization and validation.
Methods
parseTitle() applies:
- HTML entity decoding and Unicode normalization.
- Namespace and interwiki prefix detection.
- Fragment extraction (
#). - Whitespace/underscore normalization.
- Length validation (255 / 512 byte limits).
- Capital-letter normalization when
$wgCapitalLinksis enabled.
LinkRenderer service
LinkRenderer (MediaWiki\Linker\LinkRenderer, since 1.28) generates HTML anchor elements for wiki pages. Obtain via MediaWikiServices:
LinkRendererFactory:
Methods
makeLink() performs a database lookup to determine page existence if the title is not in LinkCache. Use makeKnownLink() when you know the page exists, or makePreloadedLink() when you want a blue-link style without any DB overhead.Page identity interfaces
MediaWiki defines a hierarchy of interfaces for identifying pages:| Interface | Key methods | When to use |
|---|---|---|
PageReference | getNamespace(), getDBkey(), getWikiId() | Parameter types in services that only need to identify a page |
PageIdentity | + getId(), canExist(), exists() | When you also need the page ID or existence flag |
ExistingPageIdentity | (marker — getId() returns a positive integer) | When the page is guaranteed to exist |
ProperPageIdentity | (marker — excludes special pages and interwiki) | Content pages that can be stored in the database |
Namespace constants
MediaWiki defines integer constants for the built-in namespaces inincludes/Defines.php:
| Constant | Value | Description |
|---|---|---|
NS_MAIN | 0 | Main (article) namespace |
NS_TALK | 1 | Talk namespace |
NS_USER | 2 | User namespace |
NS_USER_TALK | 3 | User talk namespace |
NS_PROJECT | 4 | Project namespace (e.g. Wikipedia:) |
NS_PROJECT_TALK | 5 | Project talk namespace |
NS_FILE | 6 | File namespace |
NS_FILE_TALK | 7 | File talk namespace |
NS_MEDIAWIKI | 8 | MediaWiki (interface messages) |
NS_MEDIAWIKI_TALK | 9 | MediaWiki talk namespace |
NS_TEMPLATE | 10 | Template namespace |
NS_TEMPLATE_TALK | 11 | Template talk namespace |
NS_HELP | 12 | Help namespace |
NS_HELP_TALK | 13 | Help talk namespace |
NS_CATEGORY | 14 | Category namespace |
NS_CATEGORY_TALK | 15 | Category talk namespace |
NS_SPECIAL | -1 | Special pages (not stored in DB) |
NS_MEDIA | -2 | Media namespace (for file links) |
NamespaceInfo:
