diff -r d52dfa1f08da -r 323c4cd1aa37 includes/functions.php --- a/includes/functions.php Mon May 04 23:07:00 2009 -0400 +++ b/includes/functions.php Tue May 05 00:10:26 2009 -0400 @@ -380,16 +380,7 @@ global $db, $session, $paths, $template, $plugins; // Common objects $idata = RenderMan::strToPageID($page_id); - $page_id_key = $paths->nslist[ $idata[1] ] . $idata[0]; - $page_id_key = sanitize_page_id($page_id_key); - $page_data = @$paths->pages[$page_id_key]; - $title = ( isset($page_data['name']) ) ? - ( ( $page_data['namespace'] == 'Article' || !$show_ns ) ? - '' : - $paths->nslist[ $idata[1] ] ) - . $page_data['name'] : - ( $show_ns ? $paths->nslist[$idata[1]] : '' ) . str_replace('_', ' ', dirtify_page_id( $idata[0] ) ); - return $title; + return get_page_title_ns($idata[0], $idata[1]); } /** @@ -402,19 +393,9 @@ function get_page_title_ns($page_id, $namespace) { global $db, $session, $paths, $template, $plugins; // Common objects - - $ns_prefix = ( isset($paths->nslist[ $namespace ]) ) ? $paths->nslist[ $namespace ] : $namespace . substr($paths->nslist['Special'], -1); - $page_id_key = $ns_prefix . $page_id; - if ( isPage($page_id_key) ) - { - $page_data = $paths->pages[$page_id_key]; - } - else - { - $page_data = array(); - } - $title = ( isset($page_data['name']) ) ? $page_data['name'] : $ns_prefix . str_replace('_', ' ', dirtify_page_id( $page_id ) ); - return $title; + + $ns = namespace_factory($page_id, $namespace); + return $ns->title; } /** @@ -578,32 +559,24 @@ * @return bool True if the page exists, false otherwise */ -function isPage($p) { +function isPage($p) +{ global $db, $session, $paths, $template, $plugins; // Common objects - - // Try the easy way first ;-) - if ( isset( $paths->pages[ $p ] ) ) - { - return true; - } - - // Special case for Special, Template, and Admin pages that can't have slashes in their URIs - $ns_test = RenderMan::strToPageID( $p ); - - if($ns_test[1] != 'Special' && $ns_test[1] != 'Template' && $ns_test[1] != 'Admin') - { - return false; - } - - $particles = explode('/', $p); - if ( isset ( $paths->pages[ $particles[ 0 ] ] ) ) - { - return true; - } - else - { - return false; - } + static $ispage_cache = array(); + if ( isset($ispage_cache[$p]) ) + return $ispage_cache[$p]; + + list($page_id, $namespace) = RenderMan::strToPageID($p); + $cdata = $paths->get_cdata($page_id, $namespace); + if ( !isset($cdata['page_exists']) ) + { + $class = ( class_exists($_ = "Namespace_$namespace") ) ? $_ : "Namespace_Default"; + $page = new $class($page_id, $namespace); + return $page->exists(); + } + + $ispage_cache[$p] = $cdata['page_exists']; + return $cdata['page_exists']; } /** @@ -615,6 +588,13 @@ function namespace_factory($page_id, $namespace, $revision_id = 0) { + global $db, $session, $paths, $template, $plugins; // Common objects + + static $objcache = array(); + $pathskey = $paths->get_pathskey($page_id, $namespace) . ":$revision_id"; + if ( isset($objcache[$pathskey]) ) + return $objcache[$pathskey]; + if ( !class_exists("Namespace_$namespace") ) { if ( file_exists(ENANO_ROOT . "/includes/namespaces/" . strtolower($namespace) . ".php") ) @@ -626,11 +606,13 @@ { $class = "Namespace_$namespace"; $ns = new $class($page_id, $namespace, $revision_id); + $objcache[$pathskey] = $ns; return $ns; } else { $ns = new Namespace_Default($page_id, $namespace, $revision_id); + $objcache[$pathskey] = $ns; return $ns; } } @@ -915,22 +897,7 @@ function display_page_headers() { - global $db, $session, $paths, $template, $plugins; // Common objects - global $lang; - if($session->get_permissions('vote_reset') && $paths->cpage['delvotes'] > 0) - { - $delvote_ips = unserialize($paths->cpage['delvote_ips']); - $hr = htmlspecialchars(implode(', ', $delvote_ips['u'])); - - $string_id = ( $paths->cpage['delvotes'] == 1 ) ? 'delvote_lbl_votes_one' : 'delvote_lbl_votes_plural'; - $string = $lang->get($string_id, array('num_users' => $paths->cpage['delvotes'])); - - echo '
- ' . $lang->get('etc_lbl_notice') . ' ' . $string . '
- ' . $lang->get('delvote_lbl_users_that_voted') . ' ' . $hr . '
- ' . $lang->get('delvote_btn_deletepage') . ' | ' . $lang->get('delvote_btn_resetvotes') . ' -
'; - } + // Deprecated. } /** @@ -2362,8 +2329,11 @@ $this_page = ceil ( $start / $perpage ); $i = 0; - $paginator = generate_paginator($this_page, $num_pages, $result_url, $perpage, 0); - $out .= $paginator; + if ( $num_results > 0 ) + { + $paginator = generate_paginator($this_page, $num_pages, $result_url, $perpage, 0); + $out .= $paginator; + } $cls = 'row2'; @@ -2386,7 +2356,7 @@ { if ( isset($callers[$j]) ) { - $tmp = ( is_callable($callers[$j]) ) ? @call_user_func($callers[$j], $val, $row) : $val; + $tmp = ( is_callable($callers[$j]) ) ? call_user_func($callers[$j], $val, $row) : $val; if ( is_string($tmp) ) { @@ -2401,7 +2371,8 @@ $out .= $footer; } - $out .= $paginator; + if ( $num_results > 0 ) + $out .= $paginator; return $out; } @@ -2429,9 +2400,8 @@ $this_page = ceil ( $start / $perpage ); $paginator = generate_paginator($this_page, $num_pages, $result_url, $perpage, 0); - $out .= $paginator; - if ( $total > 1 ) + if ( $num_results > 1 ) { $out .= $paginator; } @@ -2457,7 +2427,7 @@ $out .= $footer; } - if ( $total > 1 ) + if ( $num_results > 1 ) $out .= $paginator; return $out; @@ -4617,9 +4587,11 @@ * Logs something in the profiler. * @param string Point name or message * @param bool Optional. If true (default), a backtrace will be generated and added to the profiler data. False disables this, often for security reasons. + * @param resource Optional. If specified, bases the time difference off of this event instead of the previous event/ + * @return resource Event ID */ -function profiler_log($point, $allow_backtrace = true) +function profiler_log($point, $allow_backtrace = true, $parent_event = false) { if ( !defined('ENANO_DEBUG') ) return false; @@ -4634,13 +4606,31 @@ 'point' => $point, 'time' => microtime_float(), 'backtrace' => $backtrace, - 'mem' => false + 'mem' => false, + 'parent_event' => $parent_event ); if ( function_exists('memory_get_usage') ) { $_profiler[ count($_profiler) - 1 ]['mem'] = memory_get_usage(); } - return true; + return count($_profiler) - 1; +} + +/** + * Insert a message (an event without any time data) into the profiler. + * @param string Message + */ + +function profiler_message($message) +{ + if ( !defined('ENANO_DEBUG') ) + return false; + + global $_profiler; + + $_profiler[] = array( + 'message' => $message, + ); } /** @@ -4676,6 +4666,17 @@ // if ( $time_since_last < 0.01 ) // continue; + if ( isset($entry['message']) ) + { + $html .= "\n\n Message $i\n"; + + $html .= '' . "\n"; + $html .= ' Message:' . "\n"; + $html .= ' ' . htmlspecialchars($entry['message']) . '' . "\n"; + $html .= '' . "\n"; + continue; + } + $html .= "\n\n Event $i\n"; $html .= '' . "\n"; @@ -4690,15 +4691,25 @@ $html .= ' ' . $time . 's' . "\n"; $html .= '' . "\n"; + $time_label = 'Time since last event:'; + if ( $entry['parent_event'] && is_int($entry['parent_event']) && isset($profile[$entry['parent_event']]) ) + { + $time_last = $profile[$entry['parent_event']]['time']; + $time_label = "Time since event #{$entry['parent_event']}:"; + } + $time = $entry['time'] - $time_last; if ( $time < 0.0001 ) - $time = 'Marginal'; + $time_html = 'Marginal'; else - $time = "{$time}s"; + $time_html = number_format($time, 6) . "s"; + if ( $time > 0.02 ) + $time_html = "$time_html"; + $html .= '' . "\n"; - $html .= ' Time since last event:' . "\n"; - $html .= ' ' . $time . '' . "\n"; + $html .= ' ' . $time_label . '' . "\n"; + $html .= ' ' . $time_html . '' . "\n"; $html .= '' . "\n"; if ( $entry['backtrace'] ) @@ -4903,6 +4914,7 @@ $cache->purge('page_meta'); $cache->purge('anon_sidebar'); $cache->purge('plugins'); + $cache->purge('wiki_edit_notice'); $data_files = array( 'aes_decrypt.php',