Followup r104688, reintroduce the full PathRouter code now that the bug with url encoded paths is fixed.

This commit is contained in:
Daniel Friesen 2011-11-30 15:12:19 +00:00
parent d6cf8c57b4
commit fba28f5233
3 changed files with 24 additions and 22 deletions

View file

@ -40,7 +40,6 @@ production.
* Installer now issues a warning if mod_security is present. * Installer now issues a warning if mod_security is present.
* (bug 29455) Add support for a filter callback function in jQuery byteLimit * (bug 29455) Add support for a filter callback function in jQuery byteLimit
plugin. plugin.
* Extensions can now participate in the extraction of titles from url paths.
* Added two new GetLocalURL hooks to better serve extensions working on a * Added two new GetLocalURL hooks to better serve extensions working on a
limited type of titles. limited type of titles.
* Added a --no-updates flag to importDump.php that skips updating the links * Added a --no-updates flag to importDump.php that skips updating the links

View file

@ -2191,14 +2191,8 @@ $title: Title object
$redirect: whether the page is a redirect $redirect: whether the page is a redirect
$skin: Skin object $skin: Skin object
'WebRequestGetPathInfoRequestURI': while extracting path info from REQUEST_URI. 'WebRequestPathInfoRouter': While building the PathRouter to parse the REQUEST_URI.
Allows an extension to extend the extraction of titles from paths. $router: The PathRouter instance
Implementing hooks should follow the pattern used in core:
* Use the `$matches = WebRequest::extractTitle` pattern
* Ensure that you test `if ( !$matches ) {` before you try extracting a title
from the path so that you don't override an already found match.
$path: The request path to extract a title from.
&$matches: The array to apply matches to.
'WikiExporter::dumpStableQuery': Get the SELECT query for "stable" revisions 'WikiExporter::dumpStableQuery': Get the SELECT query for "stable" revisions
dumps dumps

View file

@ -93,40 +93,49 @@ class WebRequest {
// Abort to keep from breaking... // Abort to keep from breaking...
return $matches; return $matches;
} }
// Raw PATH_INFO style
$matches = self::extractTitle( $path, "$wgScript/$1" ); $router = new PathRouter;
if( !$matches // Raw PATH_INFO style
&& isset( $_SERVER['SCRIPT_NAME'] ) $router->add( "$wgScript/$1" );
if( isset( $_SERVER['SCRIPT_NAME'] )
&& preg_match( '/\.php5?/', $_SERVER['SCRIPT_NAME'] ) ) && preg_match( '/\.php5?/', $_SERVER['SCRIPT_NAME'] ) )
{ {
# Check for SCRIPT_NAME, we handle index.php explicitly # Check for SCRIPT_NAME, we handle index.php explicitly
# But we do have some other .php files such as img_auth.php # But we do have some other .php files such as img_auth.php
# Don't let root article paths clober the parsing for them # Don't let root article paths clober the parsing for them
$matches = self::extractTitle( $path, $_SERVER['SCRIPT_NAME'] . "/$1" ); $router->add( $_SERVER['SCRIPT_NAME'] . "/$1" );
} }
global $wgArticlePath; global $wgArticlePath;
if( !$matches && $wgArticlePath ) { if( $wgArticlePath ) {
$matches = self::extractTitle( $path, $wgArticlePath ); $router->add( $wgArticlePath );
} }
global $wgActionPaths; global $wgActionPaths;
if( !$matches && $wgActionPaths ) { if( $wgActionPaths ) {
$matches = self::extractTitle( $path, $wgActionPaths, 'action' ); $router->add( $wgActionPaths, array( 'action' => '$key' ) );
} }
global $wgVariantArticlePath, $wgContLang; global $wgVariantArticlePath, $wgContLang;
if( !$matches && $wgVariantArticlePath ) { if( $wgVariantArticlePath ) {
$variantPaths = array(); /*$variantPaths = array();
foreach( $wgContLang->getVariants() as $variant ) { foreach( $wgContLang->getVariants() as $variant ) {
$variantPaths[$variant] = $variantPaths[$variant] =
str_replace( '$2', $variant, $wgVariantArticlePath ); str_replace( '$2', $variant, $wgVariantArticlePath );
} }
$matches = self::extractTitle( $path, $variantPaths, 'variant' ); $router->add( $variantPaths, array( 'parameter' => 'variant' ) );*/
// Maybe actually this?
$router->add( $wgVariantArticlePath,
array( 'variant' => '$2'),
array( '$2' => $wgContLang->getVariants() )
);
} }
wfRunHooks( 'WebRequestGetPathInfoRequestURI', array( $path, &$matches ) ); wfRunHooks( 'WebRequestPathInfoRouter', array( $router ) );
$matches = $router->parse( $path );
} }
} elseif ( isset( $_SERVER['ORIG_PATH_INFO'] ) && $_SERVER['ORIG_PATH_INFO'] != '' ) { } elseif ( isset( $_SERVER['ORIG_PATH_INFO'] ) && $_SERVER['ORIG_PATH_INFO'] != '' ) {
// Mangled PATH_INFO // Mangled PATH_INFO