includes/sessions.php
changeset 338 915d399dfdbf
parent 322 5f1cd51bf1be
child 340 993fb077944f
child 440 105457df35e5
--- a/includes/sessions.php	Wed Dec 19 17:15:48 2007 -0500
+++ b/includes/sessions.php	Sun Dec 23 17:58:21 2007 -0500
@@ -2707,6 +2707,13 @@
   var $acl_defaults_used = Array();
   
   /**
+   * Tracks whether Wiki Mode is on for the page we're operating on.
+   * @var bool
+   */
+  
+  var $wiki_mode = false;
+  
+  /**
    * Constructor.
    * @param string $page_id The ID of the page to check
    * @param string $namespace The namespace of the page to check.
@@ -2763,6 +2770,36 @@
     
     $this->page_id = $page_id;
     $this->namespace = $namespace;
+    
+    $pathskey = $paths->nslist[$this->namespace].$this->page_id;
+    $ppwm = 2;
+    if ( isset($paths->pages[$pathskey]) )
+    {
+      if ( isset($paths->pages[$pathskey]['wiki_mode']) )
+        $ppwm = $paths->pages[$pathskey]['wiki_mode'];
+    }
+    if ( $ppwm == 1 && ( $session->user_logged_in || getConfig('wiki_mode_require_login') != '1' ) )
+      $this->wiki_mode = true;
+    else if ( $ppwm == 1 && !$session->user_logged_in && getConfig('wiki_mode_require_login') == '1' )
+      $this->wiki_mode = true;
+    else if ( $ppwm == 0 )
+      $this->wiki_mode = false;
+    else if ( $ppwm == 2 )
+    {
+      if ( $session->user_logged_in )
+      {
+        $this->wiki_mode = ( getConfig('wiki_mode') == '1' );
+      }
+      else
+      {
+        $this->wiki_mode = ( getConfig('wiki_mode') == '1' && getConfig('wiki_mode_require_login') != '1' );
+      }
+    }
+    else
+    {
+      // Ech. Internal logic failure, this should never happen.
+      return false;
+    }
   }
   
   /**
@@ -2776,30 +2813,29 @@
   {
     // echo '<pre>' . print_r($this->perms, true) . '</pre>';
     global $db, $session, $paths, $template, $plugins; // Common objects
+    
     if ( isset( $this->perms[$type] ) )
     {
       if ( $this->perms[$type] == AUTH_DENY )
+      {
         $ret = false;
-      else if ( $this->perms[$type] == AUTH_WIKIMODE &&
-        ( isset($paths->pages[$paths->nslist[$this->namespace].$this->page_id]) && 
-          ( $paths->pages[$paths->nslist[$this->namespace].$this->page_id]['wiki_mode'] == '1' ||
-            ( $paths->pages[$paths->nslist[$this->namespace].$this->page_id]['wiki_mode'] == '2'
-              && getConfig('wiki_mode') == '1'
-          ) ) ) )
+      }
+      else if ( $this->perms[$type] == AUTH_WIKIMODE && $this->wiki_mode )
+      {
         $ret = true;
-      else if ( $this->perms[$type] == AUTH_WIKIMODE && (
-        !isset($paths->pages[$paths->nslist[$this->namespace].$this->page_id])
-        || (
-          isset($paths->pages[$paths->nslist[$this->namespace].$this->page_id]) && (
-            $paths->pages[$paths->nslist[$this->namespace].$this->page_id]['wiki_mode'] == '0'
-            || (
-              $paths->pages[$paths->nslist[$this->namespace].$this->page_id]['wiki_mode'] == '2' && getConfig('wiki_mode') != '1'
-          ) ) ) ) )
+      }
+      else if ( $this->perms[$type] == AUTH_WIKIMODE && !$this->wiki_mode )
+      {
         $ret = false;
+      }
       else if ( $this->perms[$type] == AUTH_ALLOW )
+      {
         $ret = true;
+      }
       else if ( $this->perms[$type] == AUTH_DISALLOW )
+      {
         $ret = false;
+      }
     }
     else if(isset($this->acl_types[$type]))
     {