Render / Template: No longer does exist checks for wikilinks on sidebar
authorDan
Wed, 13 May 2009 09:44:46 -0400
changeset 971 bc8f3ab74e5e
parent 970 d894086f38cc
child 972 437f2505d340
Render / Template: No longer does exist checks for wikilinks on sidebar
includes/render.php
includes/template.php
--- a/includes/render.php	Wed May 13 09:43:57 2009 -0400
+++ b/includes/render.php	Wed May 13 09:44:46 2009 -0400
@@ -573,10 +573,11 @@
    * Parses internal links (wikilinks) in a block of text.
    * @param string Text to process
    * @param string Optional. If included will be used as a template instead of using the default syntax.
+   * @param bool If false, does not add wikilink-nonexistent or check for exsistence of pages. Can reduce DB queries; defualts to true.
    * @return string
    */
   
-  public static function parse_internal_links($text, $tplcode = false)
+  public static function parse_internal_links($text, $tplcode = false, $do_exist_check = true)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
     
@@ -604,7 +605,7 @@
       $url = makeUrl($pid_clean, false, true) . $hash;
       $inner_text = $matches[2][$i];
       $quot = '"';
-      $exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';
+      $exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
       
       if ( $tplcode )
       {
@@ -634,7 +635,7 @@
       $url = makeUrl($pid_clean, false, true);
       $inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]);
       $quot = '"';
-      $exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';
+      $exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
       
       if ( $tplcode )
       {
--- a/includes/template.php	Wed May 13 09:43:57 2009 -0400
+++ b/includes/template.php	Wed May 13 09:44:46 2009 -0400
@@ -62,6 +62,7 @@
   function __construct()
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
+    global $cache;
     
     $this->tpl_bool    = Array();
     $this->tpl_strings = Array();
@@ -85,22 +86,29 @@
       return $this->construct_compat();
     }
     
-    $q = $db->sql_query('SELECT theme_id, theme_name, enabled, default_style, group_policy, group_list FROM ' . table_prefix . 'themes;');
-    if ( !$q )
-      $db->_die('template.php selecting theme list');
+    if ( !$this->theme_list = $cache->fetch('themes') )
+    {
+      $q = $db->sql_query('SELECT theme_id, theme_name, enabled, default_style, group_policy, group_list FROM ' . table_prefix . 'themes;');
+      if ( !$q )
+        $db->_die('template.php selecting theme list');
+      
+      $i = 0;
+      while ( $row = $db->fetchrow() )
+      {
+        $this->theme_list[$i] = $row;
+        $i++;
+      }
+      unset($theme);
+      $this->theme_list = array_values($this->theme_list);
+      $cache->store('themes', $this->theme_list, -1);
+    }
     
-    $i = 0;
-    while ( $row = $db->fetchrow() )
-    {
-      $this->theme_list[$i] = $row;
-      $i++;
-    }
-    unset($theme);
-    $this->theme_list = array_values($this->theme_list);
     // Create associative array of themes
     foreach ( $this->theme_list as $i => &$theme )
       $this->named_theme_list[ $theme['theme_id'] ] =& $this->theme_list[$i];
     
+    unset($theme);
+    
     $this->default_theme = ( $_ = getConfig('theme_default') ) ? $_ : $this->theme_list[0]['theme_id'];
     $this->named_theme_list[ $this->default_theme ]['css'] = $this->get_theme_css_files($this->default_theme);
     // Come up with the default style. If the CSS file specified in default_style exists, we're good, just
@@ -752,17 +760,30 @@
     // Comments button
     if ( $conds['comments'] )
     {
-      $e = $db->sql_query('SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$this->page_id.'\' AND namespace=\''.$this->namespace.'\';');
-      if ( !$e )
+      $cdata = $this->page->ns->get_cdata();
+      if ( isset($cdata['comments_approved']) )
       {
-        $db->_die();
+        $approval_counts = array(
+            COMMENT_APPROVED => $cdata['comments_approved'],
+            COMMENT_UNAPPROVED => $cdata['comments_unapproved'],
+            COMMENT_SPAM => $cdata['comments_spam']
+          );
+        $num_comments = array_sum($approval_counts);
       }
-      $num_comments = $db->numrows();
-      $approval_counts = array(COMMENT_UNAPPROVED => 0, COMMENT_APPROVED => 0, COMMENT_SPAM => 0);
-      
-      while ( $r = $db->fetchrow() )
-      {  
-        $approval_counts[$r['approved']]++;
+      else
+      {
+        $e = $db->sql_query('SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$this->page_id.'\' AND namespace=\''.$this->namespace.'\';');
+        if ( !$e )
+        {
+          $db->_die();
+        }
+        $num_comments = $db->numrows();
+        $approval_counts = array(COMMENT_UNAPPROVED => 0, COMMENT_APPROVED => 0, COMMENT_SPAM => 0);
+        
+        while ( $r = $db->fetchrow() )
+        {  
+          $approval_counts[$r['approved']]++;
+        }
       }
       
       $db->free_result();
@@ -1364,7 +1385,7 @@
       $q_loc = '<a href="' . $this->tpl_strings['REPORT_URI'] . '">' . $lang->get('page_msg_stats_sql', array('nq' => $db->num_queries)) . '</a>';
       $dbg = $t_loc;
       $dbg_long = $t_loc_long;
-      if ( $session->user_level >= USER_LEVEL_ADMIN )
+      if ( $session->user_level >= USER_LEVEL_ADMIN || defined('ENANO_DEBUG') )
       {
         $dbg .= "&nbsp;&nbsp;|&nbsp;&nbsp;$q_loc";
         $dbg_long .= "&nbsp;&nbsp;|&nbsp;&nbsp;$q_loc";
@@ -1805,7 +1826,7 @@
     $message = RenderMan::process_imgtags_stage2($message, $taglist);
     
     // Internal links
-    $message = RenderMan::parse_internal_links($message, $tplvars['sidebar_button']);
+    $message = RenderMan::parse_internal_links($message, $tplvars['sidebar_button'], false);
     
     // External links