includes/sessions.php
changeset 749 ea3045a3bcbd
parent 735 f191cb6bd0ca
child 770 62fed244fa1c
equal deleted inserted replaced
748:e39454295bbb 749:ea3045a3bcbd
  3092    * Tell us if the dependencies for a given permission are met.
  3092    * Tell us if the dependencies for a given permission are met.
  3093    * @param string The ACL permission ID
  3093    * @param string The ACL permission ID
  3094    * @return bool
  3094    * @return bool
  3095    */
  3095    */
  3096    
  3096    
  3097   function acl_check_deps($type)
  3097   function acl_check_deps($type, $debug = false)
  3098   {
  3098   {
  3099     if(!isset($this->acl_deps[$type])) // This will only happen if the permissions table is hacked or improperly accessed
  3099     // This will only happen if the permissions table is hacked or improperly accessed
       
  3100     if(!isset($this->acl_deps[$type]))
  3100       return true;
  3101       return true;
       
  3102     // Permission has no dependencies?
  3101     if(sizeof($this->acl_deps[$type]) < 1)
  3103     if(sizeof($this->acl_deps[$type]) < 1)
  3102       return true;
  3104       return true;
       
  3105     // go through them all and build a flat list of dependencies
  3103     $deps = $this->acl_deps[$type];
  3106     $deps = $this->acl_deps[$type];
  3104     while(true)
  3107     while(true)
  3105     {
  3108     {
  3106       $full_resolved = true;
       
  3107       $j = sizeof($deps);
  3109       $j = sizeof($deps);
  3108       for ( $i = 0; $i < $j; $i++ )
  3110       for ( $i = 0; $i < $j; $i++ )
  3109       {
  3111       {
  3110         $b = $deps;
  3112         $b = $deps;
  3111         $deps = array_merge($deps, $this->acl_deps[$deps[$i]]);
  3113         $deps = array_merge($deps, $this->acl_deps[$deps[$i]]);
  3114           break 2;
  3116           break 2;
  3115         }
  3117         }
  3116         $j = sizeof($deps);
  3118         $j = sizeof($deps);
  3117       }
  3119       }
  3118     }
  3120     }
  3119     //die('<pre>'.print_r($deps, true).'</pre>');
  3121     $debugdata = array();
  3120     foreach($deps as $d)
  3122     foreach($deps as $d)
  3121     {
  3123     {
  3122       if ( !$this->get_permissions($d) )
  3124       // Our dependencies are fully resolved, so tell get_permissions() to not recursively call this function
  3123       {
  3125       if ( !$this->get_permissions($d, true) )
  3124         return false;
  3126       {
  3125       }
  3127         if ( $debug )
  3126     }
  3128         {
  3127     return true;
  3129           $debugdata[] = $d;
       
  3130         }
       
  3131         else
       
  3132         {
       
  3133           return false;
       
  3134         }
       
  3135       }
       
  3136     }
       
  3137     return $debug ? $debugdata : true;
  3128   }
  3138   }
  3129   
  3139   
  3130   /**
  3140   /**
  3131    * Makes a CAPTCHA code and caches the code in the database
  3141    * Makes a CAPTCHA code and caches the code in the database
  3132    * @param int $len The length of the code, in bytes
  3142    * @param int $len The length of the code, in bytes
  3932     }
  3942     }
  3933     
  3943     
  3934     $this->page_id = $page_id;
  3944     $this->page_id = $page_id;
  3935     $this->namespace = $namespace;
  3945     $this->namespace = $namespace;
  3936     
  3946     
  3937     $pathskey = $paths->nslist[$this->namespace].$this->page_id;
  3947     $pathskey = $paths->nslist[$this->namespace].sanitize_page_id($this->page_id);
  3938     $ppwm = 2;
  3948     $ppwm = 2;
  3939     if ( isset($paths->pages[$pathskey]) )
  3949     if ( isset($paths->pages[$pathskey]) )
  3940     {
  3950     {
  3941       if ( isset($paths->pages[$pathskey]['wiki_mode']) )
  3951       if ( isset($paths->pages[$pathskey]['wiki_mode']) )
  3942         $ppwm = $paths->pages[$pathskey]['wiki_mode'];
  3952         $ppwm = $paths->pages[$pathskey]['wiki_mode'];
  3947       $this->wiki_mode = true;
  3957       $this->wiki_mode = true;
  3948     else if ( $ppwm == 0 )
  3958     else if ( $ppwm == 0 )
  3949       $this->wiki_mode = false;
  3959       $this->wiki_mode = false;
  3950     else if ( $ppwm == 2 )
  3960     else if ( $ppwm == 2 )
  3951     {
  3961     {
  3952       if ( $session->user_logged_in )
  3962       if ( $this->user_id > 1 )
  3953       {
  3963       {
  3954         $this->wiki_mode = ( getConfig('wiki_mode') == '1' );
  3964         $this->wiki_mode = ( getConfig('wiki_mode') == '1' );
  3955       }
  3965       }
  3956       else
  3966       else
  3957       {
  3967       {
  4044   }
  4054   }
  4045   
  4055   
  4046   /**
  4056   /**
  4047    * Tell us if the dependencies for a given permission are met.
  4057    * Tell us if the dependencies for a given permission are met.
  4048    * @param string The ACL permission ID
  4058    * @param string The ACL permission ID
       
  4059    * @param bool If true, does not return a boolean value, but instead returns array of dependencies that fail
  4049    * @return bool
  4060    * @return bool
  4050    */
  4061    */
  4051    
  4062    
  4052   function acl_check_deps($type)
  4063   function acl_check_deps($type, $debug = false)
  4053   {
  4064   {
  4054     if(!isset($this->acl_deps[$type])) // This will only happen if the permissions table is hacked or improperly accessed
  4065     // This will only happen if the permissions table is hacked or improperly accessed
  4055       return true;
  4066     if(!isset($this->acl_deps[$type]))
       
  4067       return $debug ? array() : true;
       
  4068     // Permission has no dependencies?
  4056     if(sizeof($this->acl_deps[$type]) < 1)
  4069     if(sizeof($this->acl_deps[$type]) < 1)
  4057       return true;
  4070       return $debug ? array() : true;
       
  4071     // go through them all and build a flat list of dependencies
  4058     $deps = $this->acl_deps[$type];
  4072     $deps = $this->acl_deps[$type];
  4059     while(true)
  4073     while(true)
  4060     {
  4074     {
  4061       $full_resolved = true;
       
  4062       $j = sizeof($deps);
  4075       $j = sizeof($deps);
  4063       for ( $i = 0; $i < $j; $i++ )
  4076       for ( $i = 0; $i < $j; $i++ )
  4064       {
  4077       {
  4065         $b = $deps;
  4078         $b = $deps;
  4066         $deps = array_merge($deps, $this->acl_deps[$deps[$i]]);
  4079         $deps = array_merge($deps, $this->acl_deps[$deps[$i]]);
  4069           break 2;
  4082           break 2;
  4070         }
  4083         }
  4071         $j = sizeof($deps);
  4084         $j = sizeof($deps);
  4072       }
  4085       }
  4073     }
  4086     }
  4074     //die('<pre>'.print_r($deps, true).'</pre>');
  4087     $debugdata = array();
  4075     foreach($deps as $d)
  4088     foreach($deps as $d)
  4076     {
  4089     {
  4077       if ( !$this->get_permissions($d) )
  4090       // Our dependencies are fully resolved, so tell get_permissions() to not recursively call this function
  4078       {
  4091       if ( !$this->get_permissions($d, true) )
  4079         return false;
  4092       {
  4080       }
  4093         if ( $debug )
  4081     }
  4094         {
  4082     return true;
  4095           $debugdata[] = $d;
       
  4096         }
       
  4097         else
       
  4098         {
       
  4099           return false;
       
  4100         }
       
  4101       }
       
  4102     }
       
  4103     return $debug ? $debugdata : true;
  4083   }
  4104   }
  4084   
  4105   
  4085   /**
  4106   /**
  4086    * Merges the ACL array sent with the current permissions table, deciding precedence based on whether defaults are in effect or not.
  4107    * Merges the ACL array sent with the current permissions table, deciding precedence based on whether defaults are in effect or not.
  4087    * @param array The array to merge into the master ACL list
  4108    * @param array The array to merge into the master ACL list