From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- includes/title/MediaWikiPageLinkRenderer.php | 131 +++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 includes/title/MediaWikiPageLinkRenderer.php (limited to 'includes/title/MediaWikiPageLinkRenderer.php') diff --git a/includes/title/MediaWikiPageLinkRenderer.php b/includes/title/MediaWikiPageLinkRenderer.php new file mode 100644 index 00000000..f46cb5e3 --- /dev/null +++ b/includes/title/MediaWikiPageLinkRenderer.php @@ -0,0 +1,131 @@ +formatter = $formatter; + $this->baseUrl = $baseUrl; + } + + /** + * Returns the (partial) URL for the given page (including any section identifier). + * + * @param TitleValue $page The link's target + * @param array $params Any additional URL parameters. + * + * @return string + */ + public function getPageUrl( TitleValue $page, $params = array() ) { + //TODO: move the code from Linker::linkUrl here! + //The below is just a rough estimation! + + $name = $this->formatter->getPrefixedText( $page ); + $name = str_replace( ' ', '_', $name ); + $name = wfUrlencode( $name ); + + $url = $this->baseUrl . $name; + + if ( $params ) { + $separator = ( strpos( $url, '?' ) ) ? '&' : '?'; + $url .= $separator . wfArrayToCgi( $params ); + } + + $fragment = $page->getFragment(); + if ( $fragment !== '' ) { + $url = $url . '#' . wfUrlencode( $fragment ); + } + + return $url; + } + + /** + * Returns an HTML link to the given page, using the given surface text. + * + * @param TitleValue $page The link's target + * @param string $text The link's surface text (will be derived from $page if not given). + * + * @return string + */ + public function renderHtmlLink( TitleValue $page, $text = null ) { + if ( $text === null ) { + $text = $this->formatter->getFullText( $page ); + } + + // TODO: move the logic implemented by Linker here, + // using $this->formatter and $this->baseUrl, and + // re-implement Linker to use a HtmlPageLinkRenderer. + $title = Title::newFromTitleValue( $page ); + $link = Linker::link( $title, htmlspecialchars( $text ) ); + + return $link; + } + + /** + * Returns a wikitext link to the given page, using the given surface text. + * + * @param TitleValue $page The link's target + * @param string $text The link's surface text (will be derived from $page if not given). + * + * @return string + */ + public function renderWikitextLink( TitleValue $page, $text = null ) { + if ( $text === null ) { + $text = $this->formatter->getFullText( $page ); + } + + $name = $this->formatter->getFullText( $page ); + + return '[[:' . $name . '|' . wfEscapeWikiText( $text ) . ']]'; + } +} -- cgit v1.2.2