Example #1
0
 /**
  * Ensure that raw parameter values do not have any variable replacements or urldecoding
  */
 public function testRawParamValue()
 {
     $router = new PathRouter();
     $router->add("/wiki/\$1", array('title' => array('value' => 'bar%20$1')));
     $matches = $router->parse("/wiki/Foo");
     $this->assertEquals($matches, array('title' => 'bar%20$1'));
 }
Example #2
0
 /**
  * Extract relevant query arguments from the http request uri's path
  * to be merged with the normal php provided query arguments.
  * Tries to use the REQUEST_URI data if available and parses it
  * according to the wiki's configuration looking for any known pattern.
  *
  * If the REQUEST_URI is not provided we'll fall back on the PATH_INFO
  * provided by the server if any and use that to set a 'title' parameter.
  *
  * @param string $want If this is not 'all', then the function
  * will return an empty array if it determines that the URL is
  * inside a rewrite path.
  *
  * @return Array: Any query arguments found in path matches.
  */
 public static function getPathInfo($want = 'all')
 {
     global $wgUsePathInfo;
     // PATH_INFO is mangled due to http://bugs.php.net/bug.php?id=31892
     // And also by Apache 2.x, double slashes are converted to single slashes.
     // So we will use REQUEST_URI if possible.
     $matches = array();
     if (!empty($_SERVER['REQUEST_URI'])) {
         // Slurp out the path portion to examine...
         $url = $_SERVER['REQUEST_URI'];
         if (!preg_match('!^https?://!', $url)) {
             $url = 'http://unused' . $url;
         }
         wfSuppressWarnings();
         $a = parse_url($url);
         wfRestoreWarnings();
         if ($a) {
             $path = isset($a['path']) ? $a['path'] : '';
             global $wgScript;
             if ($path == $wgScript && $want !== 'all') {
                 // Script inside a rewrite path?
                 // Abort to keep from breaking...
                 return $matches;
             }
             $router = new PathRouter();
             // Raw PATH_INFO style
             $router->add("{$wgScript}/\$1");
             if (isset($_SERVER['SCRIPT_NAME']) && preg_match('/\\.php5?/', $_SERVER['SCRIPT_NAME'])) {
                 # Check for SCRIPT_NAME, we handle index.php explicitly
                 # But we do have some other .php files such as img_auth.php
                 # Don't let root article paths clober the parsing for them
                 $router->add($_SERVER['SCRIPT_NAME'] . "/\$1");
             }
             global $wgArticlePath;
             if ($wgArticlePath) {
                 $router->add($wgArticlePath);
             }
             global $wgActionPaths;
             if ($wgActionPaths) {
                 $router->add($wgActionPaths, array('action' => '$key'));
             }
             global $wgVariantArticlePath, $wgContLang;
             if ($wgVariantArticlePath) {
                 $router->add($wgVariantArticlePath, array('variant' => '$2'), array('$2' => $wgContLang->getVariants()));
             }
             wfRunHooks('WebRequestPathInfoRouter', array($router));
             $matches = $router->parse($path);
         }
     } elseif ($wgUsePathInfo) {
         if (isset($_SERVER['ORIG_PATH_INFO']) && $_SERVER['ORIG_PATH_INFO'] != '') {
             // Mangled PATH_INFO
             // http://bugs.php.net/bug.php?id=31892
             // Also reported when ini_get('cgi.fix_pathinfo')==false
             $matches['title'] = substr($_SERVER['ORIG_PATH_INFO'], 1);
         } elseif (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] != '') {
             // Regular old PATH_INFO yay
             $matches['title'] = substr($_SERVER['PATH_INFO'], 1);
         }
     }
     return $matches;
 }