MediaWiki REL1_34
UriLibrary.php
Go to the documentation of this file.
1<?php
2
4 public function register() {
5 $lib = [
6 'anchorEncode' => [ $this, 'anchorEncode' ],
7 'localUrl' => [ $this, 'localUrl' ],
8 'fullUrl' => [ $this, 'fullUrl' ],
9 'canonicalUrl' => [ $this, 'canonicalUrl' ],
10 ];
11
12 return $this->getEngine()->registerInterface( 'mw.uri.lua', $lib, [
13 'defaultUrl' => $this->getTitle()->getFullUrl(),
14 ] );
15 }
16
23 public function anchorEncode( $s ) {
25 $this->getParser(), $s
26 ) ];
27 }
28
29 private function getUrl( $func, $page, $query ) {
30 $title = Title::newFromText( $page );
31 if ( !$title ) {
32 $title = Title::newFromURL( urldecode( $page ) );
33 }
34 if ( $title ) {
35 # Convert NS_MEDIA -> NS_FILE
36 if ( $title->getNamespace() == NS_MEDIA ) {
37 $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
38 }
39 if ( $query !== null ) {
40 $text = $title->$func( $query );
41 } else {
42 $text = $title->$func();
43 }
44 return [ $text ];
45 } else {
46 return [ null ];
47 }
48 }
49
57 public function localUrl( $page, $query ) {
58 return $this->getUrl( 'getLocalURL', $page, $query );
59 }
60
68 public function fullUrl( $page, $query ) {
69 return $this->getUrl( 'getFullURL', $page, $query );
70 }
71
79 public function canonicalUrl( $page, $query ) {
80 return $this->getUrl( 'getCanonicalURL', $page, $query );
81 }
82}
static anchorencode( $parser, $text)
This class provides some basic services that Lua libraries will probably need.
getEngine()
Get the engine.
getParser()
Get the parser.
getTitle()
Get the title.
canonicalUrl( $page, $query)
Handler for canonicalUrl.
anchorEncode( $s)
Handler for anchorEncode.
localUrl( $page, $query)
Handler for localUrl.
fullUrl( $page, $query)
Handler for fullUrl.
getUrl( $func, $page, $query)
const NS_FILE
Definition Defines.php:75
const NS_MEDIA
Definition Defines.php:57