# HG changeset patch # User Dan # Date 1250901438 14400 # Node ID 73abd46f5148181403d83a9eff9b87962efce90b # Parent be6cfe79128c99466940a61a5b10d79c1a6daa47 A bit of shuffling around code related to determining the page title from the URL. It's done in common now, and $paths becomes more of an information repository rather than an information gatherer. Note: This BREAKS $paths->fullpage/$paths->getParam() in *_preloader! diff -r be6cfe79128c -r 73abd46f5148 includes/common.php --- a/includes/common.php Fri Aug 21 20:30:52 2009 -0400 +++ b/includes/common.php Fri Aug 21 20:37:18 2009 -0400 @@ -381,22 +381,25 @@ profiler_log('Finished base_classes_initted hook'); - // For special and administration pages, sometimes there is a "preloader" function that must be run - // before the session manager and/or path manager get the init signal. Call it here. - $p = RenderMan::strToPageId($paths->get_pageid_from_url()); - if( ( $p[1] == 'Admin' || $p[1] == 'Special' ) && function_exists('page_'.$p[1].'_'.$p[0].'_preloader')) - { - call_user_func('page_'.$p[1].'_'.$p[0].'_preloader'); - } - - profiler_log('Checked for preloader'); - // One quick security check... if ( !is_valid_ip($_SERVER['REMOTE_ADDR']) ) { die('SECURITY: spoofed IP address: ' . htmlspecialchars($_SERVER['REMOTE_ADDR'])); } - + + // For special and administration pages, sometimes there is a "preloader" function that must be run + // before the session manager and/or path manager get the init signal. Call it here. + $title = get_title(true); + list($page_id, $namespace) = RenderMan::strToPageID($title); + list($page_id_top) = explode('/', $page_id); + $fname = "page_{$namespace}_{$page_id_top}_preloader"; + if( ( $namespace == 'Admin' || $namespace == 'Special' ) && function_exists($fname)) + { + call_user_func($fname); + } + + profiler_log('Checked for (and ran, if applicable) preloader'); + // All checks passed! Start the main components up. $session->start(); @@ -423,7 +426,7 @@ profiler_log('Ran session_started hook'); - $paths->init(); + $paths->init($title); // setup output format if ( defined('ENANO_OUTPUT_FORMAT') ) diff -r be6cfe79128c -r 73abd46f5148 includes/common_cli.php --- a/includes/common_cli.php Fri Aug 21 20:30:52 2009 -0400 +++ b/includes/common_cli.php Fri Aug 21 20:37:18 2009 -0400 @@ -180,16 +180,6 @@ profiler_log('Finished base_classes_initted hook'); - // For special and administration pages, sometimes there is a "preloader" function that must be run - // before the session manager and/or path manager get the init signal. Call it here. - $p = RenderMan::strToPageId($paths->get_pageid_from_url()); - if( ( $p[1] == 'Admin' || $p[1] == 'Special' ) && function_exists('page_'.$p[1].'_'.$p[0].'_preloader')) - { - call_user_func('page_'.$p[1].'_'.$p[0].'_preloader'); - } - - profiler_log('Checked for preloader'); - // One quick security check... if ( isset($_SERVER['REMOTE_ADDR']) ) { diff -r be6cfe79128c -r 73abd46f5148 includes/functions.php --- a/includes/functions.php Fri Aug 21 20:30:52 2009 -0400 +++ b/includes/functions.php Fri Aug 21 20:37:18 2009 -0400 @@ -246,6 +246,56 @@ } /** + * Get the requested page title, taking into account all the different possible URL parsing schemes. + * @param bool If true (default), runs the result through sanitize_page_id(). + * @param bool If true (default is false), and the return is a Special or Admin page, trims off anything beyond and including the first slash. + * @return string + */ + +function get_title($sanitize = true, $chop_special = false) +{ + $title = ''; + if ( isset($_GET['title']) ) + { + $title = $_GET['title']; + } + else if ( isset($_SERVER['PATH_INFO']) ) + { + // fix for apache + CGI (occurred on a GoDaddy server, thanks mm3) + if ( @substr(@$_SERVER['GATEWAY_INTERFACE'], 0, 3) === 'CGI' && $_SERVER['PATH_INFO'] == scriptPath . '/index.php' ) + { + // do nothing; ignore PATH_INFO + } + else + { + $title = substr($_SERVER['PATH_INFO'], ( strpos($_SERVER['PATH_INFO'], '/') ) + 1 ); + } + } + else + { + // This method really isn't supported because apache has a habit of passing dots as underscores, thus corrupting the request + // If you really want to try it, the URI format is yoursite.com/?/Page_title + if ( !empty($_SERVER['QUERY_STRING']) && substr($_SERVER['QUERY_STRING'], 0, 1) == '/' ) + { + $pos = ( ($_ = strpos($_SERVER['QUERY_STRING'], '&')) !== false ) ? $_ - 1: 0x7FFFFFFF; + $title = substr($_SERVER['QUERY_STRING'], 1, $pos); + } + } + + if ( $chop_special ) + { + list(, $ns) = RenderMan::strToPageID($title); + if ( $ns == 'Special' || $ns == 'Admin' ) + { + list($title) = explode('/', $title); + } + } + + return ( $sanitize ) ? sanitize_page_id($title) : $title; +} + + +/** * Enano replacement for date(). Accounts for individual users' timezone preferences. * @param string Date-formatted string * @param int Optional - UNIX timestamp value to use. If omitted, the current time is used. @@ -264,7 +314,7 @@ $time_fmt = is_object($session) ? $session->time_format : TIME_24_NS; // within a week? use a relative date - if ( $timestamp + ( 86400 * 7 ) >= time() && $string & ED_DATE && is_object($lang) && is_object($session) ) + if ( $timestamp + ( 86400 * 7 ) >= time() && $string & ED_DATE && is_object($lang) && is_object($session) && !($string & ED_DATE_FULL) ) { $relative_date = get_relative_date($timestamp); if ( $string === ED_DATE ) @@ -3426,6 +3476,7 @@ // 2001:470-471:054-b02b::5-bb // up to: // 2001:0470-0471:0054-b02b:0000:0000:0000:0005-00bb + $range = preg_replace('/^:/', '0000:', $range); $range = explode(':', $range); $expanded = ''; $size = count($range); @@ -3650,6 +3701,36 @@ } /** + * Expand an IPv6 address to full form + * @param string ::1, 2001:470:e054::2 + * @return string 0000:0000:0000:0000:0000:0000:0000:0001, 2001:0470:e054:0000:0000:0000:0000:0002 + */ + +function expand_ipv6_address($addr) +{ + $expanded = array(); + $addr = explode(':', $addr); + foreach ( $addr as $i => $bytepair ) + { + if ( empty($bytepair) ) + { + // :: + while ( count($expanded) < (8 - count($addr) + $i + 1) ) + { + $expanded[] = '0000'; + } + } + else + { + while ( strlen($bytepair) < 4 ) + $bytepair = "0$bytepair"; + $expanded[] = $bytepair; + } + } + return implode(':', $expanded); +} + +/** * Validates an e-mail address. Uses a compacted version of the regular expression generated by the scripts at . * @param string E-mail address * @return bool diff -r be6cfe79128c -r 73abd46f5148 includes/paths.php --- a/includes/paths.php Fri Aug 21 20:30:52 2009 -0400 +++ b/includes/paths.php Fri Aug 21 20:37:18 2009 -0400 @@ -18,7 +18,7 @@ class pathManager { - public $pages, $custom_page, $cpage, $page, $fullpage, $page_exists, $page_id, $namespace, $nslist, $admin_tree, $wiki_mode, $page_protected, $template_cache, $external_api_page; + public $title, $pages, $custom_page, $cpage, $page, $fullpage, $page_exists, $page_id, $namespace, $nslist, $admin_tree, $wiki_mode, $page_protected, $template_cache, $external_api_page; /** * List of custom processing functions for namespaces. This is protected so trying to do anything with it will throw an error. @@ -118,39 +118,7 @@ $this->template_cache = Array(); } - function parse_url($sanitize = true) - { - $title = ''; - if ( isset($_GET['title']) ) - { - $title = $_GET['title']; - } - else if ( isset($_SERVER['PATH_INFO']) ) - { - // fix for apache + CGI (occurred on a GoDaddy server, thanks mm3) - if ( @substr(@$_SERVER['GATEWAY_INTERFACE'], 0, 3) === 'CGI' && $_SERVER['PATH_INFO'] == scriptPath . '/index.php' ) - { - // do nothing; ignore PATH_INFO - } - else - { - $title = substr($_SERVER['PATH_INFO'], ( strpos($_SERVER['PATH_INFO'], '/') ) + 1 ); - } - } - else - { - // This method really isn't supported because apache has a habit of passing dots as underscores, thus corrupting the request - // If you really want to try it, the URI format is yoursite.com/?/Page_title - if ( !empty($_SERVER['QUERY_STRING']) && substr($_SERVER['QUERY_STRING'], 0, 1) == '/' ) - { - $pos = ( ($_ = strpos($_SERVER['QUERY_STRING'], '&')) !== false ) ? $_ - 1: 0x7FFFFFFF; - $title = substr($_SERVER['QUERY_STRING'], 1, $pos); - } - } - return ( $sanitize ) ? sanitize_page_id($title) : $title; - } - - function init() + function init($title) { global $db, $session, $paths, $template, $plugins; // Common objects global $lang; @@ -164,7 +132,9 @@ if ( defined('ENANO_INTERFACE_INDEX') || defined('ENANO_INTERFACE_AJAX') || defined('IN_ENANO_UPGRADE') ) { - $title = $this->parse_url(false); + if ( empty($title) ) + $title = get_title(); + if ( empty($title) && get_main_page() != '' ) { $this->main_page(); @@ -470,16 +440,7 @@ } function get_pageid_from_url() { - $url = $this->parse_url(); - if ( substr($url, 0, strlen($this->nslist['Special'])) == $this->nslist['Special'] || - substr($url, 0, strlen($this->nslist['Admin'])) == $this->nslist['Admin']) - { - list(, $ns) = RenderMan::strToPageID($url); - $upart = substr($url, strlen($this->nslist[$ns])); - list($upart) = explode('/', $upart); - $url = $this->nslist[$ns] . $upart; - } - return $url; + return get_title(true, true); } // Parses a (very carefully formed) array into Javascript code compatible with the Tigra Tree Menu used in the admin menu function parseAdminTree() @@ -590,7 +551,7 @@ } function getParam($id = 0) { - $title = $this->parse_url(false); + $title = $this->fullpage; list(, $ns) = RenderMan::strToPageID($title); $title = substr($title, strlen($this->nslist[$ns])); $regex = '/^' . str_replace('/', '\\/', preg_quote($this->nslist[$ns])) . '\\/?/'; @@ -602,7 +563,7 @@ function getAllParams() { - $title = $this->parse_url(false); + $title = $this->fullpage; $regex = '/^' . str_replace('/', '\\/', preg_quote($this->nslist[$this->namespace])) . '\\/?/'; $title = preg_replace($regex, '', $title); $title = explode('/', $title); diff -r be6cfe79128c -r 73abd46f5148 plugins/SpecialAdmin.php --- a/plugins/SpecialAdmin.php Fri Aug 21 20:30:52 2009 -0400 +++ b/plugins/SpecialAdmin.php Fri Aug 21 20:37:18 2009 -0400 @@ -2226,26 +2226,22 @@
nslist); - for ( $i = 0; $i < sizeof($paths->nslist); $i++ ) + list($module) = explode('/', $_GET['module']); + list($page_id, $namespace) = RenderMan::strToPageID($module); + if ( $namespace != 'Admin' ) { - $ln = strlen( $paths->nslist[ $k[ $i ] ] ); - if ( substr($_GET['module'], 0, $ln) == $paths->nslist[$k[$i]] ) - { - $ns = $k[$i]; - $nm = substr($_GET['module'], $ln, strlen($_GET['module'])); - } + echo '
Module must be in the Admin namespace
'; } - $fname = 'page_'.$ns.'_'.$nm; - $s = strpos($fname, '?noheaders'); - if($s) $fname = substr($fname, 0, $s); - $paths->cpage['module'] = $_GET['module']; - if ( function_exists($fname) && $_GET['module'] != $paths->nslist['Special'] . 'Administration' ) + else { - call_user_func($fname); + $paths->fullpage = $_GET['module']; + $paths->cpage['module'] = $_GET['module']; + $page = new PageProcessor($page_id, $namespace); + $page->send_headers = false; + $page->send(); + $paths->fullpage = $paths->page; } } else diff -r be6cfe79128c -r 73abd46f5148 plugins/admin/UserManager.php --- a/plugins/admin/UserManager.php Fri Aug 21 20:30:52 2009 -0400 +++ b/plugins/admin/UserManager.php Fri Aug 21 20:37:18 2009 -0400 @@ -328,7 +328,7 @@ # END VALIDATION # } - else if ( isset($_POST['action']['go']) || ( isset($_GET['src']) && $_GET['src'] == 'get' ) ) + else if ( isset($_POST['action']['go']) || ( isset($_GET['src']) && $_GET['src'] == 'get' ) || ($pathsuser = $paths->getParam(0)) ) { if ( isset($_GET['user']) ) { @@ -342,6 +342,10 @@ { $username =& $_POST['username']; } + else if ( $pathsuser ) + { + $username = str_replace('_', ' ', dirtify_page_id($pathsuser)); + } else { echo 'No username provided';