mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-15 11:59:42 +00:00
3a19bb8b0c
Clear up a bunch of phpcs ignores by documenting many methods. Also remove Scribunto_LuaError::setLineMap(), which has apparently never been used since it was added in Ia51f439e. Change-Id: I763bcdbc7edbbb8e4600495a03acca3439fc0ec9
90 lines
2 KiB
PHP
90 lines
2 KiB
PHP
<?php
|
|
|
|
class Scribunto_LuaUriLibrary extends Scribunto_LuaLibraryBase {
|
|
public function register() {
|
|
$lib = [
|
|
'anchorEncode' => [ $this, 'anchorEncode' ],
|
|
'localUrl' => [ $this, 'localUrl' ],
|
|
'fullUrl' => [ $this, 'fullUrl' ],
|
|
'canonicalUrl' => [ $this, 'canonicalUrl' ],
|
|
];
|
|
|
|
return $this->getEngine()->registerInterface( 'mw.uri.lua', $lib, [
|
|
'defaultUrl' => $this->getTitle()->getFullUrl(),
|
|
] );
|
|
}
|
|
|
|
/**
|
|
* Handler for anchorEncode
|
|
* @internal
|
|
* @param string $s
|
|
* @return string[]
|
|
*/
|
|
public function anchorEncode( $s ) {
|
|
return [ CoreParserFunctions::anchorencode(
|
|
$this->getParser(), $s
|
|
) ];
|
|
}
|
|
|
|
/**
|
|
* Get a URL (helper for handlers)
|
|
* @param string $func Title class method to call
|
|
* @param string $page Page title
|
|
* @param array $query Query string
|
|
* @return string[]|null[]
|
|
*/
|
|
private function getUrl( $func, $page, $query ) {
|
|
$title = Title::newFromText( $page );
|
|
if ( !$title ) {
|
|
$title = Title::newFromURL( urldecode( $page ) );
|
|
}
|
|
if ( $title ) {
|
|
# Convert NS_MEDIA -> NS_FILE
|
|
if ( $title->getNamespace() == NS_MEDIA ) {
|
|
$title = Title::makeTitle( NS_FILE, $title->getDBkey() );
|
|
}
|
|
if ( $query !== null ) {
|
|
$text = $title->$func( $query );
|
|
} else {
|
|
$text = $title->$func();
|
|
}
|
|
return [ $text ];
|
|
} else {
|
|
return [ null ];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handler for localUrl
|
|
* @internal
|
|
* @param string $page
|
|
* @param array $query
|
|
* @return string[]|null[]
|
|
*/
|
|
public function localUrl( $page, $query ) {
|
|
return $this->getUrl( 'getLocalURL', $page, $query );
|
|
}
|
|
|
|
/**
|
|
* Handler for fullUrl
|
|
* @internal
|
|
* @param string $page
|
|
* @param array $query
|
|
* @return string[]|null[]
|
|
*/
|
|
public function fullUrl( $page, $query ) {
|
|
return $this->getUrl( 'getFullURL', $page, $query );
|
|
}
|
|
|
|
/**
|
|
* Handler for canonicalUrl
|
|
* @internal
|
|
* @param string $page
|
|
* @param array $query
|
|
* @return string[]|null[]
|
|
*/
|
|
public function canonicalUrl( $page, $query ) {
|
|
return $this->getUrl( 'getCanonicalURL', $page, $query );
|
|
}
|
|
}
|