MediaWiki  1.23.2
MediaWikiPageLinkRenderer.php
Go to the documentation of this file.
1 <?php
31 
35  protected $formatter;
36 
40  protected $baseUrl;
41 
53  public function __construct( TitleFormatter $formatter, $baseUrl = null ) {
54  if ( $baseUrl === null ) {
55  $baseUrl = $GLOBALS['wgArticlePath'];
56  }
57 
58  $this->formatter = $formatter;
59  $this->baseUrl = $baseUrl;
60  }
61 
70  public function getPageUrl( TitleValue $page, $params = array() ) {
71  //TODO: move the code from Linker::linkUrl here!
72  //The below is just a rough estimation!
73 
74  $name = $this->formatter->getPrefixedText( $page );
75  $name = str_replace( ' ', '_', $name );
76  $name = wfUrlencode( $name );
77 
78  $url = $this->baseUrl . $name;
79 
80  if ( $params ) {
81  $separator = ( strpos( $url, '?' ) ) ? '&' : '?';
82  $url .= $separator . wfArrayToCgi( $params );
83  }
84 
85  $fragment = $page->getFragment();
86  if ( $fragment !== '' ) {
87  $url = $url . '#' . wfUrlencode( $fragment );
88  }
89 
90  return $url;
91  }
92 
101  public function renderHtmlLink( TitleValue $page, $text = null ) {
102  if ( $text === null ) {
103  $text = $this->formatter->getFullText( $page );
104  }
105 
106  // TODO: move the logic implemented by Linker here,
107  // using $this->formatter and $this->baseUrl, and
108  // re-implement Linker to use a HtmlPageLinkRenderer.
109  $title = Title::newFromTitleValue( $page );
110  $link = Linker::link( $title, htmlspecialchars( $text ) );
111  return $link;
112  }
113 
122  public function renderWikitextLink( TitleValue $page, $text = null ) {
123  if ( $text === null ) {
124  $text = $this->formatter->getFullText( $page );
125  }
126 
127  $name = $this->formatter->getFullText( $page );
128 
129  return '[[:' . $name . '|' . wfEscapeWikiText( $text ) . ']]';
130  }
131 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:330
MediaWikiPageLinkRenderer\renderHtmlLink
renderHtmlLink(TitleValue $page, $text=null)
Returns an HTML link to the given page, using the given surface text.
Definition: MediaWikiPageLinkRenderer.php:99
$params
$params
Definition: styleTest.css.php:40
$link
set to $title object and return false for a match for latest after cache objects are set use the ContentHandler facility to handle CSS and JavaScript for highlighting & $link
Definition: hooks.txt:2149
Linker\link
static link( $target, $html=null, $customAttribs=array(), $query=array(), $options=array())
This function returns an HTML link to the given target.
Definition: Linker.php:192
PageLinkRenderer
Represents a link rendering service for MediaWiki.
Definition: PageLinkRenderer.php:33
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
Title\newFromTitleValue
static newFromTitleValue(TitleValue $titleValue)
Create a new Title from a TitleValue.
Definition: Title.php:169
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
TitleValue\getFragment
getFragment()
Definition: TitleValue.php:103
MediaWikiPageLinkRenderer\renderWikitextLink
renderWikitextLink(TitleValue $page, $text=null)
Returns a wikitext link to the given page, using the given surface text.
Definition: MediaWikiPageLinkRenderer.php:120
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:2077
MediaWikiPageLinkRenderer\__construct
__construct(TitleFormatter $formatter, $baseUrl=null)
Definition: MediaWikiPageLinkRenderer.php:51
TitleFormatter
A title formatter service for MediaWiki.
Definition: TitleFormatter.php:33
MediaWikiPageLinkRenderer\$formatter
TitleFormatter $formatter
Definition: MediaWikiPageLinkRenderer.php:34
MediaWikiPageLinkRenderer\getPageUrl
getPageUrl(TitleValue $page, $params=array())
Returns the (partial) URL for the given page (including any section identifier).
Definition: MediaWikiPageLinkRenderer.php:68
MediaWikiPageLinkRenderer
A service for generating links from page titles.
Definition: MediaWikiPageLinkRenderer.php:30
$GLOBALS
$GLOBALS['IP']
Definition: ComposerHookHandler.php:6
MediaWikiPageLinkRenderer\$baseUrl
string $baseUrl
Definition: MediaWikiPageLinkRenderer.php:38
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:36
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes two arrays as input, and returns a CGI-style string, e.g.
Definition: GlobalFunctions.php:367