Merge "Setup: Move wgActionPath logic to PathRouter"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 5 Sep 2019 19:17:28 +0000 (19:17 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 5 Sep 2019 19:17:28 +0000 (19:17 +0000)
includes/PathRouter.php
includes/Setup.php
includes/Title.php
includes/WebRequest.php

index 2882e66..4d7bd38 100644 (file)
@@ -401,4 +401,22 @@ class PathRouter {
 
                return $value;
        }
+
+       /**
+        * @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;
+       }
 }
index e55fbe8..cfb2ac1 100644 (file)
@@ -156,12 +156,6 @@ if ( $wgArticlePath === false ) {
        }
 }
 
-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;
 }
index 5d81a8a..1e93c44 100644 (file)
@@ -2087,16 +2087,18 @@ class Title implements LinkTarget, IDBAccessObject {
                                $url = false;
                                $matches = [];
 
-                               if ( !empty( $wgActionPaths )
+                               $articlePaths = PathRouter::getActionPaths( $wgActionPaths, $wgArticlePath );
+
+                               if ( $articlePaths
                                        && 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];
                                                }
-                                               $url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
+                                               $url = str_replace( '$1', $dbkey, $articlePaths[$action] );
                                                if ( $query != '' ) {
                                                        $url = wfAppendQuery( $url, $query );
                                                }
index 9b8f5a6..7b14667 100644 (file)
@@ -162,8 +162,9 @@ class WebRequest {
                        }
 
                        global $wgActionPaths;
-                       if ( $wgActionPaths ) {
-                               $router->add( $wgActionPaths, [ 'action' => '$key' ] );
+                       $articlePaths = PathRouter::getActionPaths( $wgActionPaths, $wgArticlePath );
+                       if ( $articlePaths ) {
+                               $router->add( $articlePaths, [ 'action' => '$key' ] );
                        }
 
                        global $wgVariantArticlePath;