This is only relevant when processing page views or when constructing
Title urls with an 'action' query. Pretty important stuff, and worth
optimising for if we had to choose, but we can defer it in this case
without slowing it down, which is better for everything else.
It also means we don't mutate configuration (beyond setting whole values
as dynamic defaults), which seems desirable, and makes the overall behaviour
easier to test. Handling absence of 'view' should be PathRouter's
responsibility, not Setup.
Bug: T189966
Change-Id: I9c1eea2dcea74be0e283eb2b175268315ced1793
+
+ /**
+ * @internal For use by Title and WebRequest only.
+ * @param array $actionPaths
+ * @param string $articlePath
+ * @return string[]|false
+ */
+ public static function getActionPaths( array $actionPaths, $articlePath ) {
+ if ( !$actionPaths ) {
+ return false;
+ }
+ // Processing of urls for this feature requires that 'view' is set.
+ // By default, set it to the pretty article path.
+ if ( !isset( $actionPaths['view'] ) ) {
+ $actionPaths['view'] = $articlePath;
+ }
+ return $actionPaths;
+ }
-if ( !empty( $wgActionPaths ) && !isset( $wgActionPaths['view'] ) ) {
- // 'view' is assumed the default action path everywhere in the code
- // but is rarely filled in $wgActionPaths
- $wgActionPaths['view'] = $wgArticlePath;
-}
-
if ( $wgResourceBasePath === null ) {
$wgResourceBasePath = $wgScriptPath;
}
if ( $wgResourceBasePath === null ) {
$wgResourceBasePath = $wgScriptPath;
}
$url = false;
$matches = [];
$url = false;
$matches = [];
- if ( !empty( $wgActionPaths )
+ $articlePaths = PathRouter::getActionPaths( $wgActionPaths, $wgArticlePath );
+
+ if ( $articlePaths
&& preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
) {
$action = urldecode( $matches[2] );
&& preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches )
) {
$action = urldecode( $matches[2] );
- if ( isset( $wgActionPaths[$action] ) ) {
+ if ( isset( $articlePaths[$action] ) ) {
$query = $matches[1];
if ( isset( $matches[4] ) ) {
$query .= $matches[4];
}
$query = $matches[1];
if ( isset( $matches[4] ) ) {
$query .= $matches[4];
}
- $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
+ $url = str_replace( '$1', $dbkey, $articlePaths[$action] );
if ( $query != '' ) {
$url = wfAppendQuery( $url, $query );
}
if ( $query != '' ) {
$url = wfAppendQuery( $url, $query );
}
- if ( $wgActionPaths ) {
- $router->add( $wgActionPaths, [ 'action' => '$key' ] );
+ $articlePaths = PathRouter::getActionPaths( $wgActionPaths, $wgArticlePath );
+ if ( $articlePaths ) {
+ $router->add( $articlePaths, [ 'action' => '$key' ] );
}
global $wgVariantArticlePath;
}
global $wgVariantArticlePath;