mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-25 16:58:35 +00:00
aa4d72e3ff
The following continue to be ignored: * Generic.Arrays.DisallowLongArraySyntax.Found, because I'm not sure Scribunto is ready to abandon old version support in master. * MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures, because it's overly strict for its purpose. Squiz.Classes.ValidClassName.NotCamelCaps isn't ignored globally, we just ignore it explicitly every place it's needed. Change-Id: I307668da6ef7b3e23da19b1fd1e08914239b99b3
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
// @codingStandardsIgnoreLine Squiz.Classes.ValidClassName.NotCamelCaps
|
|
class Scribunto_LuaUriLibrary extends Scribunto_LuaLibraryBase {
|
|
function register() {
|
|
$lib = array(
|
|
'anchorEncode' => array( $this, 'anchorEncode' ),
|
|
'localUrl' => array( $this, 'localUrl' ),
|
|
'fullUrl' => array( $this, 'fullUrl' ),
|
|
'canonicalUrl' => array( $this, 'canonicalUrl' ),
|
|
);
|
|
|
|
return $this->getEngine()->registerInterface( 'mw.uri.lua', $lib, array(
|
|
'defaultUrl' => $this->getTitle()->getFullUrl(),
|
|
) );
|
|
}
|
|
|
|
public function anchorEncode( $s ) {
|
|
return array( CoreParserFunctions::anchorencode(
|
|
$this->getParser(), $s
|
|
) );
|
|
}
|
|
|
|
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 array( $text );
|
|
} else {
|
|
return array( null );
|
|
}
|
|
}
|
|
|
|
public function localUrl( $page, $query ) {
|
|
return $this->getUrl( 'getLocalURL', $page, $query );
|
|
}
|
|
|
|
public function fullUrl( $page, $query ) {
|
|
return $this->getUrl( 'getFullURL', $page, $query );
|
|
}
|
|
|
|
public function canonicalUrl( $page, $query ) {
|
|
return $this->getUrl( 'getCanonicalURL', $page, $query );
|
|
}
|
|
}
|