--- a/includes/paths.php Wed Jul 02 19:36:44 2008 -0400
+++ b/includes/paths.php Wed Jul 02 22:15:55 2008 -0400
@@ -116,6 +116,7 @@
$this->wiki_mode = ( getConfig('wiki_mode') == '1' ) ? 1 : 0;
$this->template_cache = Array();
}
+
function parse_url($sanitize = true)
{
$title = '';
@@ -150,6 +151,7 @@
}
return ( $sanitize ) ? sanitize_page_id($title) : $title;
}
+
function init()
{
global $db, $session, $paths, $template, $plugins; // Common objects
@@ -161,46 +163,38 @@
eval($cmd);
}
- $e = $db->sql_query('SELECT name,urlname,namespace,special,visible,comments_on,protected,delvotes,' . "\n"
- . ' delvote_ips,wiki_mode,password FROM '.table_prefix.'pages ORDER BY name;');
- if( !$e )
+ $cache_enable = ( getConfig('cache_thumbs') == '1' );
+ $cache_file = ENANO_ROOT . '/cache/cache_page_meta.php';
+ $cache_fresh = ( file_exists($cache_file) ) ? filemtime($cache_file) + 1800 >= time() : false;
+ if ( $cache_enable && $cache_fresh )
{
- $db->_die('The error seems to have occured while selecting the page information. File: includes/paths.php; line: '.__LINE__);
+ require($cache_file);
+ if ( isset($page_cache) && is_array($page_cache) )
+ {
+ $this->pages = array_merge($this->pages, $page_cache);
+ }
}
- while($r = $db->fetchrow())
+ else
{
+ $e = $db->sql_query('SELECT name,urlname,namespace,special,visible,comments_on,protected,delvotes,' . "\n"
+ . ' delvote_ips,wiki_mode,password FROM '.table_prefix.'pages ORDER BY name;');
- $r['urlname_nons'] = $r['urlname'];
- if ( isset($this->nslist[$r['namespace']]) )
+ if( !$e )
{
- $r['urlname'] = $this->nslist[$r['namespace']] . $r['urlname']; // Applies the User:/File:/etc prefixes to the URL names
+ $db->_die('The error seems to have occured while selecting the page information. File: includes/paths.php; line: '.__LINE__);
}
- else
+ while($r = $db->fetchrow())
{
- $ns_char = substr($this->nslist['Special'], -1);
- $r['urlname'] = $r['namespace'] . $ns_char . $r['urlname'];
+ $r = $this->calculate_metadata_from_row($r);
+
+ $this->pages[$r['urlname']] = $r;
+ $this->pages[] =& $this->pages[$r['urlname']];
}
- if ( $r['delvotes'] == null)
- {
- $r['delvotes'] = 0;
- }
- if ( $r['protected'] == 0 || $r['protected'] == 1 )
- {
- $r['really_protected'] = (int)$r['protected'];
- }
- else if ( $r['protected'] == 2 && getConfig('wiki_mode') == '1')
+ if ( $cache_enable )
{
- $r['really_protected'] = 1;
+ $this->update_metadata_cache();
}
- else if ( $r['protected'] == 2 && getConfig('wiki_mode') == '0' )
- {
- $r['really_protected'] = 0;
- }
-
- $this->pages[$r['urlname']] = $r;
- $this->pages[] =& $this->pages[$r['urlname']];
-
}
$db->free_result();
if ( defined('ENANO_INTERFACE_INDEX') || defined('ENANO_INTERFACE_AJAX') || defined('IN_ENANO_UPGRADE') )
@@ -401,7 +395,6 @@
profiler_log('Paths and CMS core initted');
$session->init_permissions();
- profiler_log('Default ACL set retrieved');
}
function add_page($flags)
@@ -584,6 +577,86 @@
}
/**
+ * Updates the cache containing all page metadata.
+ */
+
+ function update_metadata_cache()
+ {
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ $cache_output = <<<EOF
+<?php
+
+/**
+ * Automatically generated cache of page metadata. Do not edit this file as it is updated every 20 minutes.
+ */
+
+\$page_cache = array(
+EOF;
+ $e = $db->sql_unbuffered_query('SELECT name,urlname,namespace,special,visible,comments_on,protected,delvotes,' . "\n"
+ . ' delvote_ips,wiki_mode,password FROM '.table_prefix.'pages ORDER BY name;');
+ if ( !$e )
+ $db->_die();
+
+ while ( $row = $db->fetchrow() )
+ {
+ $row = $this->calculate_metadata_from_row($row);
+ $key = addslashes($row['urlname']);
+ $row = substr(preg_replace('/^/m', ' ', Language::var_export_string($row)), 2);
+ $cache_output .= "\n '$key' => $row,";
+ }
+
+ $cache_output .= "\n);\n";
+ $cache_file = ENANO_ROOT . '/cache/cache_page_meta.php';
+
+ $fh = @fopen($cache_file, 'w');
+ if ( !$fh )
+ return false;
+ fwrite($fh, $cache_output);
+ fclose($fh);
+
+ return true;
+ }
+
+ /**
+ * Takes a result row from the pages table and calculates correct values for it.
+ * @param array
+ * @return array
+ */
+
+ function calculate_metadata_from_row($r)
+ {
+ $r['urlname_nons'] = $r['urlname'];
+ if ( isset($this->nslist[$r['namespace']]) )
+ {
+ $r['urlname'] = $this->nslist[$r['namespace']] . $r['urlname']; // Applies the User:/File:/etc prefixes to the URL names
+ }
+ else
+ {
+ $ns_char = substr($this->nslist['Special'], -1);
+ $r['urlname'] = $r['namespace'] . $ns_char . $r['urlname'];
+ }
+
+ if ( $r['delvotes'] == null)
+ {
+ $r['delvotes'] = 0;
+ }
+ if ( $r['protected'] == 0 || $r['protected'] == 1 )
+ {
+ $r['really_protected'] = (int)$r['protected'];
+ }
+ else if ( $r['protected'] == 2 && getConfig('wiki_mode') == '1')
+ {
+ $r['really_protected'] = 1;
+ }
+ else if ( $r['protected'] == 2 && getConfig('wiki_mode') == '0' )
+ {
+ $r['really_protected'] = 0;
+ }
+ return $r;
+ }
+
+ /**
* Registers a handler to manually process a namespace instead of the default PageProcessor behavior.
* The first and only parameter passed to the processing function will be the PageProcessor instance.
* @param string Namespace to process