MediaWiki master
MessageProvider.php
Go to the documentation of this file.
1<?php
2
4
11use Wikimedia\Parsoid\Core\LinkTarget;
12
19 public function __construct(
20 private MessageCache $cache,
21 private Language $contLang,
22 private SlotRoleRegistry $slotRoleRegistry,
23 private ContentHandlerFactory $contentHandlerFactory,
24 ) {
25 }
26
27 public function get( PageReference $title ): ?ShadowPage {
28 [ $name, $lang ] = $this->cache->figureMessage(
29 $this->contLang->lcfirst( $title->getDBkey() )
30 );
31
32 $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
33 if ( !$message->exists() ) {
34 return null;
35 }
36 $text = $message->plain();
37 $model = $this->slotRoleRegistry
38 ->getRoleHandler( SlotRecord::MAIN )
39 ->getDefaultModel( $title );
40 $content = $this->contentHandlerFactory->getContentHandler( $model )
41 ->unserializeContent( $text );
42
43 return new MessagePage( $this->getParseHelper(), $content, $title );
44 }
45
46 public function existsForLink( PageReference|LinkTarget $link ): bool {
47 [ $name, $lang ] = $this->cache->figureMessage(
48 $this->contLang->lcfirst( $link->getDBkey() )
49 );
50
51 return wfMessage( $name )->inLanguage( $lang )->useDatabase( false )->exists();
52 }
53
54}
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Base class for language-specific code.
Definition Language.php:65
Cache messages that are defined by MediaWiki-namespace pages or by hooks.
Value object representing a content slot associated with a page revision.
A registry service for SlotRoleHandlers, used to define which slot roles are available on which page.
Shadow page for nonexistent pages in the NS_MEDIAWIKI namespace.
The provider for NS_MEDIAWIKI.
__construct(private MessageCache $cache, private Language $contLang, private SlotRoleRegistry $slotRoleRegistry, private ContentHandlerFactory $contentHandlerFactory,)
existsForLink(PageReference|LinkTarget $link)
Interface for objects (potentially) representing a page that can be viewable and linked to on a wiki.
The interface for shadow pages.