MediaWiki REL1_27
MediaWikiPageLinkRenderer.php
Go to the documentation of this file.
1<?php
25
36 protected $formatter;
37
41 protected $baseUrl;
42
54 public function __construct( TitleFormatter $formatter, $baseUrl = null ) {
55 if ( $baseUrl === null ) {
56 $baseUrl = $GLOBALS['wgArticlePath'];
57 }
58
59 $this->formatter = $formatter;
60 $this->baseUrl = $baseUrl;
61 }
62
71 public function getPageUrl( LinkTarget $page, $params = [] ) {
72 // TODO: move the code from Linker::linkUrl here!
73 // The below is just a rough estimation!
74
75 $name = $this->formatter->getPrefixedText( $page );
76 $name = str_replace( ' ', '_', $name );
78
79 $url = $this->baseUrl . $name;
80
81 if ( $params ) {
82 $separator = ( strpos( $url, '?' ) ) ? '&' : '?';
83 $url .= $separator . wfArrayToCgi( $params );
84 }
85
86 $fragment = $page->getFragment();
87 if ( $fragment !== '' ) {
88 $url = $url . '#' . wfUrlencode( $fragment );
89 }
90
91 return $url;
92 }
93
102 public function renderHtmlLink( LinkTarget $linkTarget, $text = null ) {
103 if ( $text === null ) {
104 $text = $this->formatter->getFullText( $linkTarget );
105 }
106
107 // TODO: move the logic implemented by Linker here,
108 // using $this->formatter and $this->baseUrl, and
109 // re-implement Linker to use a HtmlPageLinkRenderer.
110
111 $title = Title::newFromLinkTarget( $linkTarget );
112 $link = Linker::link( $title, htmlspecialchars( $text ) );
113
114 return $link;
115 }
116
125 public function renderWikitextLink( LinkTarget $page, $text = null ) {
126 if ( $text === null ) {
127 $text = $this->formatter->getFullText( $page );
128 }
129
130 $name = $this->formatter->getFullText( $page );
131
132 return '[[:' . $name . '|' . wfEscapeWikiText( $text ) . ']]';
133 }
134}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$GLOBALS['IP']
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
static link( $target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition Linker.php:195
A service for generating links from page titles.
__construct(TitleFormatter $formatter, $baseUrl=null)
renderWikitextLink(LinkTarget $page, $text=null)
Returns a wikitext link to the given page, using the given surface text.
renderHtmlLink(LinkTarget $linkTarget, $text=null)
Returns an HTML link to the given page, using the given surface text.
getPageUrl(LinkTarget $page, $params=[])
Returns the (partial) URL for the given page (including any section identifier).
static newFromLinkTarget(LinkTarget $linkTarget)
Create a new Title from a LinkTarget.
Definition Title.php:251
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition hooks.txt:2379
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:944
the value to return A Title object or null for latest to be modified or replaced by the hook handler or if authentication is not possible after cache objects are set for highlighting & $link
Definition hooks.txt:2692
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:314
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Represents a link rendering service for MediaWiki.
A title formatter service for MediaWiki.
$params