// mediawiki-1.37.0\includes\parser\CoreParserFunctions.php
public static function localurl( $parser, $s = '', $arg = null ) {
return self::urlFunction( 'getLocalURL', $s, $arg );
}
// mediawiki-1.37.0\includes\parser\CoreParserFunctions.php
public static function urlFunction( $func, $s = '', $arg = null ) {
$title = Title::newFromText( $s );
# Due to order of execution of a lot of bits, the values might be encoded
# before arriving here; if that's true, then the title can't be created
# and the variable will fail. If we can't get a decent title from the first
# attempt, url-decode and try for a second.
if ( $title === null ) {
$title = Title::newFromURL( urldecode( $s ) );
}
if ( $title !== null ) {
# Convert NS_MEDIA -> NS_FILE
if ( $title->inNamespace( NS_MEDIA ) ) {
$title = Title::makeTitle( NS_FILE, $title->getDBkey() );
}
if ( $arg !== null ) {
$text = $title->$func( $arg );
} else {
$text = $title->$func();
}
return $text;
} else {
return [ 'found' => false ];
}
}
/** mediawiki-1.37.0\includes\Title.php
* Get a URL with no fragment or server name (relative URL) from a Title object.
* If this page is generated with action=render, however,
* $wgServer is prepended to make an absolute URL.
*
* @see self::getFullURL to always get an absolute URL.
* @see self::getLinkURL to always get a URL that's the simplest URL that will be
* valid to link, locally, to the current Title.
* @see self::newFromText to produce a Title object.
*
* @param string|array $query An optional query string,
* not used for interwiki links. Can be specified as an associative array as well,
* e.g., [ 'action' => 'edit' ] (keys and values will be URL-escaped).
* Some query patterns will trigger various shorturl path replacements.
* @param string|string[]|bool $query2 An optional secondary query array. This one MUST
* be an array. If a string is passed it will be interpreted as a deprecated
* variant argument and urlencoded into a variant= argument.
* This second query argument will be added to the $query
* The second parameter is deprecated since 1.19. Pass it as a key,value
* pair in the first parameter array instead.
*
* @return string
*/
public function getLocalURL( $query = '', $query2 = false ) {
global $wgArticlePath, $wgScript, $wgServer, $wgRequest, $wgMainPageIsDomainRoot;
$query = self::fixUrlQueryArgs( $query, $query2 );
$interwiki = self::getInterwikiLookup()->fetch( $this->mInterwiki );
if ( $interwiki ) {
$namespace = $this->getNsText();
if ( $namespace != '' ) {
# Can this actually happen? Interwikis shouldn't be parsed.
# Yes! It can in interwiki transclusion. But... it probably shouldn't.
$namespace .= ':';
}
$url = $interwiki->getURL( $namespace . $this->mDbkeyform );
$url = wfAppendQuery( $url, $query );
} else {
$dbkey = wfUrlencode( $this->getPrefixedDBkey() );
if ( $query == '' ) {
if ( $wgMainPageIsDomainRoot && $this->isMainPage() ) {
$url = '/';
} else {
$url = str_replace( '$1', $dbkey, $wgArticlePath );
}
Hooks::runner()->onGetLocalURL__Article( $this, $url );
} else {
global $wgVariantArticlePath, $wgActionPaths;
$url = false;
$matches = [];
$articlePaths = PathRouter::getActionPaths( $wgActionPaths, $wgArticlePath );
if ( $articlePaths
&& preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
) {
$action = urldecode( $matches[2] );
if ( isset( $articlePaths[$action] ) ) {
$query = $matches[1];
if ( isset( $matches[4] ) ) {
$query .= $matches[4];
}
$url = str_replace( '$1', $dbkey, $articlePaths[$action] );
if ( $query != '' ) {
$url = wfAppendQuery( $url, $query );
}
}
}
if ( $url === false
&& $wgVariantArticlePath
&& preg_match( '/^variant=([^&]*)$/', $query, $matches )
&& $this->getPageLanguage()->equals(
MediaWikiServices::getInstance()->getContentLanguage() )
&& $this->getPageLanguageConverter()->hasVariants()
) {
$variant = urldecode( $matches[1] );
if ( $this->getPageLanguageConverter()->hasVariant( $variant ) ) {
// Only do the variant replacement if the given variant is a valid
// variant for the page's language.
$url = str_replace( '$2', urlencode( $variant ), $wgVariantArticlePath );
$url = str_replace( '$1', $dbkey, $url );
}
}
if ( $url === false ) {
if ( $query == '-' ) {
$query = '';
}
$url = "{$wgScript}?title={$dbkey}&{$query}";
}
}
Hooks::runner()->onGetLocalURL__Internal( $this, $url, $query );
// @todo FIXME: This causes breakage in various places when we
// actually expected a local URL and end up with dupe prefixes.
if ( $wgRequest->getRawVal( 'action' ) == 'render' ) {
LoggerFactory::getInstance( 'T263581' )
->debug(
"Title::getLocalURL called from render action",
[
'title' => $this->getPrefixedDBkey(),
'exception' => new Exception()
]
);
$url = $wgServer . $url;
}
}
Hooks::runner()->onGetLocalURL( $this, $url, $query );
return $url;
}