includes/template.php
changeset 557 26479224936a
parent 555 ac4c6a7f01d8
child 566 06d241de3151
equal deleted inserted replaced
556:63e131c38876 557:26479224936a
    12  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    12  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    13  */
    13  */
    14  
    14  
    15 class template
    15 class template
    16 {
    16 {
    17   var $tpl_strings, $tpl_bool, $theme, $style, $no_headers, $additional_headers, $sidebar_extra, $sidebar_widgets, $toolbar_menu, $theme_list, $named_theme_list, $default_theme, $default_style, $plugin_blocks, $namespace_string, $style_list, $theme_loaded;
    17   var $tpl_strings, $tpl_bool, $vars_assign_history, $theme, $style, $no_headers, $additional_headers, $sidebar_extra, $sidebar_widgets, $toolbar_menu, $theme_list, $named_theme_list, $default_theme, $default_style, $plugin_blocks, $namespace_string, $style_list, $theme_loaded;
    18   
    18   
    19   /**
    19   /**
    20    * The list of themes that are critical for Enano operation. This doesn't include oxygen which
    20    * The list of themes that are critical for Enano operation. This doesn't include oxygen which
    21    * remains a user theme. By default this is admin and printable which have to be loaded on demand.
    21    * remains a user theme. By default this is admin and printable which have to be loaded on demand.
    22    * @var array
    22    * @var array
    54                               <a style="background-image: none; padding-right: 0;" href="http://enanocms.org/" onclick="window.open(this.href); return false;"><img style="border-width: 0;" alt=" " src="'.scriptPath.'/images/about-powered-enano.png" onmouseover="domOpacity(this, 100, 0, 500);" onmouseout="domOpacity(this, 0, 100, 500);" /></a>
    54                               <a style="background-image: none; padding-right: 0;" href="http://enanocms.org/" onclick="window.open(this.href); return false;"><img style="border-width: 0;" alt=" " src="'.scriptPath.'/images/about-powered-enano.png" onmouseover="domOpacity(this, 100, 0, 500);" onmouseout="domOpacity(this, 0, 100, 500);" /></a>
    55                             </div>';
    55                             </div>';
    56     
    56     
    57     $this->theme_list = Array();
    57     $this->theme_list = Array();
    58     $this->named_theme_list = Array();
    58     $this->named_theme_list = Array();
       
    59     
       
    60     $this->vars_assign_history = array(
       
    61         'strings' => array(),
       
    62         'bool' => array()
       
    63       );
    59     
    64     
    60     if ( defined('IN_ENANO_UPGRADE') )
    65     if ( defined('IN_ENANO_UPGRADE') )
    61     {
    66     {
    62       return $this->construct_compat();
    67       return $this->construct_compat();
    63     }
    68     }
   332     // The list of styles for the currently selected theme
   337     // The list of styles for the currently selected theme
   333     $this->style_list =& $this->named_theme_list[ $this->theme ]['css'];
   338     $this->style_list =& $this->named_theme_list[ $this->theme ]['css'];
   334     $this->theme_loaded = true;
   339     $this->theme_loaded = true;
   335   }
   340   }
   336   
   341   
   337   function init_vars()
   342   /**
       
   343    * Initializes all variables related to on-page content. This includes sidebars and what have you.
       
   344    * @param object Optional PageProcessor object to use for passing metadata and permissions on. If omitted, uses information from $paths and $session.
       
   345    */
       
   346   
       
   347   function init_vars($page = false)
   338   {
   348   {
   339     global $db, $session, $paths, $template, $plugins; // Common objects
   349     global $db, $session, $paths, $template, $plugins; // Common objects
   340     global $email;
   350     global $email;
   341     global $lang;
   351     global $lang;
   342     
   352     
   345     if(!$this->theme || !$this->style)
   355     if(!$this->theme || !$this->style)
   346     {
   356     {
   347       $this->load_theme();
   357       $this->load_theme();
   348     }
   358     }
   349     
   359     
   350     if(defined('ENANO_TEMPLATE_LOADED'))
   360     if ( defined('ENANO_TEMPLATE_LOADED') )
   351     {
   361     {
   352       die_semicritical('Illegal call', '<p>$template->load_theme was called multiple times, this is not supposed to happen. Exiting with fatal error.</p>');
   362       // trigger_error("\$template->init_vars() called more than once", E_USER_WARNING);
   353     }
   363       // die_semicritical('Illegal call', '<p>$template->init_vars() was called multiple times, this is not supposed to happen. Exiting with fatal error.</p>');
   354     
   364     }
   355     define('ENANO_TEMPLATE_LOADED', '');
   365     else
       
   366     {
       
   367       @define('ENANO_TEMPLATE_LOADED', '');
       
   368     }
       
   369     
       
   370     if ( is_object($page) && @get_class($page) == 'PageProcessor' )
       
   371     {
       
   372       $page_append = substr($paths->fullpage, strlen($paths->page));
       
   373       if ( isset($paths->nslist[$page->namespace]) )
       
   374       {
       
   375         $local_page = $paths->nslist[$page->namespace] . $page->page_id;
       
   376       }
       
   377       else
       
   378       {
       
   379         $local_page = $page->namespace . substr($paths->nslist['Special'], -1) . $page->page_id . $page_append;
       
   380       }
       
   381       $local_fullpage = $local_page . $page_append;
       
   382       $local_page_id =& $page->page_id;
       
   383       $local_namespace =& $page->namespace;
       
   384       $perms =& $page->perms;
       
   385     }
       
   386     else
       
   387     {
       
   388       $local_page =& $paths->page;
       
   389       $local_page_id =& $paths->page_id;
       
   390       $local_fullpage =& $paths->fullpage;
       
   391       $local_namespace =& $paths->namespace;
       
   392       $perms =& $session;
       
   393     }
   356     
   394     
   357     $tplvars = $this->extract_vars('elements.tpl');
   395     $tplvars = $this->extract_vars('elements.tpl');
   358     
   396     
   359     if(isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
   397     if(isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
   360     {
   398     {
   393         <![endif]-->
   431         <![endif]-->
   394         ');
   432         ');
   395     }
   433     }
   396     
   434     
   397     // Get the "article" button text (depends on namespace)
   435     // Get the "article" button text (depends on namespace)
   398     switch($paths->namespace) {
   436     switch($local_namespace) {
   399       case "Article":
   437       case "Article":
   400       default:
   438       default:
   401         $ns = $lang->get('onpage_lbl_page_article');
   439         $ns = $lang->get('onpage_lbl_page_article');
   402         break;
   440         break;
   403       case "Admin":
   441       case "Admin":
   446     // Create "xx page" button
   484     // Create "xx page" button
   447     
   485     
   448     $btn_selected = ( isset($tplvars['toolbar_button_selected'])) ? $tplvars['toolbar_button_selected'] : $tplvars['toolbar_button'];
   486     $btn_selected = ( isset($tplvars['toolbar_button_selected'])) ? $tplvars['toolbar_button_selected'] : $tplvars['toolbar_button'];
   449     $parser = $this->makeParserText($btn_selected);
   487     $parser = $this->makeParserText($btn_selected);
   450     
   488     
   451     if ( true || !$paths->anonymous_page )
   489     $parser->assign_vars(array(
   452     {
   490         'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxReset()); return false; }" title="' . $lang->get('onpage_tip_article') . '" accesskey="a"',
   453       $parser->assign_vars(array(
   491         'PARENTFLAGS' => 'id="mdgToolbar_article"',
   454           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxReset()); return false; }" title="' . $lang->get('onpage_tip_article') . '" accesskey="a"',
   492         'HREF' => makeUrl($local_page, null, true),
   455           'PARENTFLAGS' => 'id="mdgToolbar_article"',
   493         'TEXT' => $this->namespace_string
   456           'HREF' => makeUrl($paths->page, null, true),
   494       ));
   457           'TEXT' => $this->namespace_string
   495     
   458         ));
   496     $tb .= $parser->run();
   459       
       
   460       $tb .= $parser->run();
       
   461     }
       
   462     
   497     
   463     $button = $this->makeParserText($tplvars['toolbar_button']);
   498     $button = $this->makeParserText($tplvars['toolbar_button']);
   464     
   499     
   465     // Page toolbar
   500     // Page toolbar
   466     // Comments button
   501     // Comments button
   467     if ( $session->get_permissions('read') && getConfig('enable_comments')=='1' && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $paths->cpage['comments_on'] == 1 )
   502     if ( $perms->get_permissions('read') && getConfig('enable_comments')=='1' && $local_namespace != 'Special' && $local_namespace != 'Admin' && $paths->cpage['comments_on'] == 1 )
   468     {
   503     {
   469       
   504       
   470       $e = $db->sql_query('SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$paths->page_id.'\' AND namespace=\''.$paths->namespace.'\';');
   505       $e = $db->sql_query('SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$local_page_id.'\' AND namespace=\''.$local_namespace.'\';');
   471       if ( !$e )
   506       if ( !$e )
   472       {
   507       {
   473         $db->_die();
   508         $db->_die();
   474       }
   509       }
   475       $nc = $db->numrows();
   510       $nc = $db->numrows();
   487           $na++;
   522           $na++;
   488         }
   523         }
   489       }
   524       }
   490       
   525       
   491       $db->free_result();
   526       $db->free_result();
   492       $n = ( $session->get_permissions('mod_comments') ) ? (string)$nc : (string)$na;
   527       $n = ( $perms->get_permissions('mod_comments') ) ? (string)$nc : (string)$na;
   493       if ( $session->get_permissions('mod_comments') && $nu > 0 )
   528       if ( $perms->get_permissions('mod_comments') && $nu > 0 )
   494       {
   529       {
   495         $subst = array(
   530         $subst = array(
   496             'num_comments' => $nc,
   531             'num_comments' => $nc,
   497             'num_unapp' => $nu
   532             'num_unapp' => $nu
   498           );
   533           );
   507       }
   542       }
   508       
   543       
   509       $button->assign_vars(array(
   544       $button->assign_vars(array(
   510           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxComments()); return false; }" title="' . $lang->get('onpage_tip_comments') . '" accesskey="c"',
   545           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxComments()); return false; }" title="' . $lang->get('onpage_tip_comments') . '" accesskey="c"',
   511           'PARENTFLAGS' => 'id="mdgToolbar_discussion"',
   546           'PARENTFLAGS' => 'id="mdgToolbar_discussion"',
   512           'HREF' => makeUrl($paths->page, 'do=comments', true),
   547           'HREF' => makeUrl($local_page, 'do=comments', true),
   513           'TEXT' => $btn_text,
   548           'TEXT' => $btn_text,
   514         ));
   549         ));
   515       
   550       
   516       $tb .= $button->run();
   551       $tb .= $button->run();
   517     }
   552     }
   518     // Edit button
   553     // Edit button
   519     if($session->get_permissions('read') && ($paths->namespace != 'Special' && $paths->namespace != 'Admin' && $paths->namespace != 'Anonymous') && ( $session->get_permissions('edit_page') && ( ( $paths->page_protected && $session->get_permissions('even_when_protected') ) || !$paths->page_protected ) ) )
   554     if($perms->get_permissions('read') && ($local_namespace != 'Special' && $local_namespace != 'Admin' && $local_namespace != 'Anonymous') && ( $perms->get_permissions('edit_page') && ( ( $paths->page_protected && $perms->get_permissions('even_when_protected') ) || !$paths->page_protected ) ) )
   520     {
   555     {
   521       $button->assign_vars(array(
   556       $button->assign_vars(array(
   522         'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="' . $lang->get('onpage_tip_edit') . '" accesskey="e"',
   557         'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="' . $lang->get('onpage_tip_edit') . '" accesskey="e"',
   523         'PARENTFLAGS' => 'id="mdgToolbar_edit"',
   558         'PARENTFLAGS' => 'id="mdgToolbar_edit"',
   524         'HREF' => makeUrl($paths->page, 'do=edit', true),
   559         'HREF' => makeUrl($local_page, 'do=edit', true),
   525         'TEXT' => $lang->get('onpage_btn_edit')
   560         'TEXT' => $lang->get('onpage_btn_edit')
   526         ));
   561         ));
   527       $tb .= $button->run();
   562       $tb .= $button->run();
   528     // View source button
   563     // View source button
   529     }
   564     }
   530     else if($session->get_permissions('view_source') && ( !$session->get_permissions('edit_page') || !$session->get_permissions('even_when_protected') && $paths->page_protected ) && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $paths->namespace != 'Anonymous') 
   565     else if($perms->get_permissions('view_source') && ( !$perms->get_permissions('edit_page') || !$perms->get_permissions('even_when_protected') && $paths->page_protected ) && $local_namespace != 'Special' && $local_namespace != 'Admin' && $local_namespace != 'Anonymous') 
   531     {
   566     {
   532       $button->assign_vars(array(
   567       $button->assign_vars(array(
   533         'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="' . $lang->get('onpage_tip_viewsource') . '" accesskey="e"',
   568         'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="' . $lang->get('onpage_tip_viewsource') . '" accesskey="e"',
   534         'PARENTFLAGS' => 'id="mdgToolbar_edit"',
   569         'PARENTFLAGS' => 'id="mdgToolbar_edit"',
   535         'HREF' => makeUrl($paths->page, 'do=viewsource', true),
   570         'HREF' => makeUrl($local_page, 'do=viewsource', true),
   536         'TEXT' => $lang->get('onpage_btn_viewsource')
   571         'TEXT' => $lang->get('onpage_btn_viewsource')
   537         ));
   572         ));
   538       $tb .= $button->run();
   573       $tb .= $button->run();
   539     }
   574     }
   540     // History button
   575     // History button
   541     if ( $session->get_permissions('read') /* && $paths->wiki_mode */ && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $session->get_permissions('history_view') )
   576     if ( $perms->get_permissions('read') /* && $paths->wiki_mode */ && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' && $perms->get_permissions('history_view') )
   542     {
   577     {
   543       $button->assign_vars(array(
   578       $button->assign_vars(array(
   544         'FLAGS'       => 'onclick="if ( !KILL_SWITCH ) { void(ajaxHistory()); return false; }" title="' . $lang->get('onpage_tip_history') . '" accesskey="h"',
   579         'FLAGS'       => 'onclick="if ( !KILL_SWITCH ) { void(ajaxHistory()); return false; }" title="' . $lang->get('onpage_tip_history') . '" accesskey="h"',
   545         'PARENTFLAGS' => 'id="mdgToolbar_history"',
   580         'PARENTFLAGS' => 'id="mdgToolbar_history"',
   546         'HREF'        => makeUrl($paths->page, 'do=history', true),
   581         'HREF'        => makeUrl($local_page, 'do=history', true),
   547         'TEXT'        => $lang->get('onpage_btn_history')
   582         'TEXT'        => $lang->get('onpage_btn_history')
   548         ));
   583         ));
   549       $tb .= $button->run();
   584       $tb .= $button->run();
   550     }
   585     }
   551     
   586     
   552     $menubtn = $this->makeParserText($tplvars['toolbar_menu_button']);
   587     $menubtn = $this->makeParserText($tplvars['toolbar_menu_button']);
   553     
   588     
   554     // Additional actions menu
   589     // Additional actions menu
   555     // Rename button
   590     // Rename button
   556     if ( $session->get_permissions('read') && $paths->page_exists && ( $session->get_permissions('rename') && ( $paths->page_protected && $session->get_permissions('even_when_protected') || !$paths->page_protected ) ) && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   591     if ( $perms->get_permissions('read') && $paths->page_exists && ( $perms->get_permissions('rename') && ( $paths->page_protected && $perms->get_permissions('even_when_protected') || !$paths->page_protected ) ) && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   557     {
   592     {
   558       $menubtn->assign_vars(array(
   593       $menubtn->assign_vars(array(
   559           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxRename()); return false; }" title="' . $lang->get('onpage_tip_rename') . '" accesskey="r"',
   594           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxRename()); return false; }" title="' . $lang->get('onpage_tip_rename') . '" accesskey="r"',
   560           'HREF'  => makeUrl($paths->page, 'do=rename', true),
   595           'HREF'  => makeUrl($local_page, 'do=rename', true),
   561           'TEXT'  => $lang->get('onpage_btn_rename'),
   596           'TEXT'  => $lang->get('onpage_btn_rename'),
   562         ));
   597         ));
   563       $this->toolbar_menu .= $menubtn->run();
   598       $this->toolbar_menu .= $menubtn->run();
   564     }
   599     }
   565     
   600     
   566     // Vote-to-delete button
   601     // Vote-to-delete button
   567     if ( $paths->wiki_mode && $session->get_permissions('vote_delete') && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin')
   602     if ( $paths->wiki_mode && $perms->get_permissions('vote_delete') && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin')
   568     {
   603     {
   569       $menubtn->assign_vars(array(
   604       $menubtn->assign_vars(array(
   570           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDelVote()); return false; }" title="' . $lang->get('onpage_tip_delvote') . '" accesskey="d"',
   605           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDelVote()); return false; }" title="' . $lang->get('onpage_tip_delvote') . '" accesskey="d"',
   571           'HREF'  => makeUrl($paths->page, 'do=delvote', true),
   606           'HREF'  => makeUrl($local_page, 'do=delvote', true),
   572           'TEXT'  => $lang->get('onpage_btn_votedelete'),
   607           'TEXT'  => $lang->get('onpage_btn_votedelete'),
   573         ));
   608         ));
   574       $this->toolbar_menu .= $menubtn->run();
   609       $this->toolbar_menu .= $menubtn->run();
   575     }
   610     }
   576     
   611     
   577     // Clear-votes button
   612     // Clear-votes button
   578     if ( $session->get_permissions('read') && $paths->wiki_mode && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $session->get_permissions('vote_reset') && $paths->cpage['delvotes'] > 0)
   613     if ( $perms->get_permissions('read') && $paths->wiki_mode && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' && $perms->get_permissions('vote_reset') && $paths->cpage['delvotes'] > 0)
   579     {
   614     {
   580       $menubtn->assign_vars(array(
   615       $menubtn->assign_vars(array(
   581           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxResetDelVotes()); return false; }" title="' . $lang->get('onpage_tip_resetvotes') . '" accesskey="y"',
   616           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxResetDelVotes()); return false; }" title="' . $lang->get('onpage_tip_resetvotes') . '" accesskey="y"',
   582           'HREF'  => makeUrl($paths->page, 'do=resetvotes', true),
   617           'HREF'  => makeUrl($local_page, 'do=resetvotes', true),
   583           'TEXT'  => $lang->get('onpage_btn_votedelete_reset'),
   618           'TEXT'  => $lang->get('onpage_btn_votedelete_reset'),
   584         ));
   619         ));
   585       $this->toolbar_menu .= $menubtn->run();
   620       $this->toolbar_menu .= $menubtn->run();
   586     }
   621     }
   587     
   622     
   588     // Printable page button
   623     // Printable page button
   589     if ( $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   624     if ( $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   590     {
   625     {
   591       $menubtn->assign_vars(array(
   626       $menubtn->assign_vars(array(
   592           'FLAGS' => 'title="' . $lang->get('onpage_tip_printable') . '"',
   627           'FLAGS' => 'title="' . $lang->get('onpage_tip_printable') . '"',
   593           'HREF'  => makeUrl($paths->page, 'printable=yes', true),
   628           'HREF'  => makeUrl($local_page, 'printable=yes', true),
   594           'TEXT'  => $lang->get('onpage_btn_printable'),
   629           'TEXT'  => $lang->get('onpage_btn_printable'),
   595         ));
   630         ));
   596       $this->toolbar_menu .= $menubtn->run();
   631       $this->toolbar_menu .= $menubtn->run();
   597     }
   632     }
   598     
   633     
   599     // Protect button
   634     // Protect button
   600     if($session->get_permissions('read') && $paths->wiki_mode && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $session->get_permissions('protect'))
   635     if($perms->get_permissions('read') && $paths->wiki_mode && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' && $perms->get_permissions('protect'))
   601     {
   636     {
   602       
   637       
   603       $label = $this->makeParserText($tplvars['toolbar_label']);
   638       $label = $this->makeParserText($tplvars['toolbar_label']);
   604       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_protect')));
   639       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_protect')));
   605       $t0 = $label->run();
   640       $t0 = $label->run();
   609       {
   644       {
   610         $ctmp=' style="text-decoration: underline;"';
   645         $ctmp=' style="text-decoration: underline;"';
   611       }
   646       }
   612       $menubtn->assign_vars(array(
   647       $menubtn->assign_vars(array(
   613           'FLAGS' => 'accesskey="i" onclick="if ( !KILL_SWITCH ) { ajaxProtect(1); return false; }" id="protbtn_1" title="' . $lang->get('onpage_tip_protect_on') . '"'.$ctmp,
   648           'FLAGS' => 'accesskey="i" onclick="if ( !KILL_SWITCH ) { ajaxProtect(1); return false; }" id="protbtn_1" title="' . $lang->get('onpage_tip_protect_on') . '"'.$ctmp,
   614           'HREF'  => makeUrl($paths->page, 'do=protect&level=1', true),
   649           'HREF'  => makeUrl($local_page, 'do=protect&level=1', true),
   615           'TEXT'  => $lang->get('onpage_btn_protect_on')
   650           'TEXT'  => $lang->get('onpage_btn_protect_on')
   616         ));
   651         ));
   617       $t1 = $menubtn->run();
   652       $t1 = $menubtn->run();
   618       
   653       
   619       $ctmp = '';
   654       $ctmp = '';
   621       {
   656       {
   622         $ctmp=' style="text-decoration: underline;"';
   657         $ctmp=' style="text-decoration: underline;"';
   623       }
   658       }
   624       $menubtn->assign_vars(array(
   659       $menubtn->assign_vars(array(
   625           'FLAGS' => 'accesskey="o" onclick="if ( !KILL_SWITCH ) { ajaxProtect(0); return false; }" id="protbtn_0" title="' . $lang->get('onpage_tip_protect_off') . '"'.$ctmp,
   660           'FLAGS' => 'accesskey="o" onclick="if ( !KILL_SWITCH ) { ajaxProtect(0); return false; }" id="protbtn_0" title="' . $lang->get('onpage_tip_protect_off') . '"'.$ctmp,
   626           'HREF'  => makeUrl($paths->page, 'do=protect&level=0', true),
   661           'HREF'  => makeUrl($local_page, 'do=protect&level=0', true),
   627           'TEXT'  => $lang->get('onpage_btn_protect_off')
   662           'TEXT'  => $lang->get('onpage_btn_protect_off')
   628         ));
   663         ));
   629       $t2 = $menubtn->run();
   664       $t2 = $menubtn->run();
   630       
   665       
   631       $ctmp = '';
   666       $ctmp = '';
   633       {
   668       {
   634         $ctmp = ' style="text-decoration: underline;"';
   669         $ctmp = ' style="text-decoration: underline;"';
   635       }
   670       }
   636       $menubtn->assign_vars(array(
   671       $menubtn->assign_vars(array(
   637           'FLAGS' => 'accesskey="p" onclick="if ( !KILL_SWITCH ) { ajaxProtect(2); return false; }" id="protbtn_2" title="' . $lang->get('onpage_tip_protect_semi') . '"'.$ctmp,
   672           'FLAGS' => 'accesskey="p" onclick="if ( !KILL_SWITCH ) { ajaxProtect(2); return false; }" id="protbtn_2" title="' . $lang->get('onpage_tip_protect_semi') . '"'.$ctmp,
   638           'HREF'  => makeUrl($paths->page, 'do=protect&level=2', true),
   673           'HREF'  => makeUrl($local_page, 'do=protect&level=2', true),
   639           'TEXT'  => $lang->get('onpage_btn_protect_semi')
   674           'TEXT'  => $lang->get('onpage_btn_protect_semi')
   640         ));
   675         ));
   641       $t3 = $menubtn->run();
   676       $t3 = $menubtn->run();
   642       
   677       
   643       $this->toolbar_menu .= '        <table border="0" cellspacing="0" cellpadding="0">
   678       $this->toolbar_menu .= '        <table border="0" cellspacing="0" cellpadding="0">
   649           </tr>
   684           </tr>
   650         </table>';
   685         </table>';
   651     }
   686     }
   652     
   687     
   653     // Wiki mode button
   688     // Wiki mode button
   654     if($session->get_permissions('read') && $paths->page_exists && $session->get_permissions('set_wiki_mode') && $paths->namespace != 'Special' && $paths->namespace != 'Admin')
   689     if($perms->get_permissions('read') && $paths->page_exists && $perms->get_permissions('set_wiki_mode') && $local_namespace != 'Special' && $local_namespace != 'Admin')
   655     {
   690     {
   656       // label at start
   691       // label at start
   657       $label = $this->makeParserText($tplvars['toolbar_label']);
   692       $label = $this->makeParserText($tplvars['toolbar_label']);
   658       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_wikimode')));
   693       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_wikimode')));
   659       $t0 = $label->run();
   694       $t0 = $label->run();
   664       {
   699       {
   665         $ctmp = ' style="text-decoration: underline;"';
   700         $ctmp = ' style="text-decoration: underline;"';
   666       }
   701       }
   667       $menubtn->assign_vars(array(
   702       $menubtn->assign_vars(array(
   668           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(1); return false; }" id="wikibtn_1" title="Forces wiki functions to be allowed on this page."'. */ $ctmp,
   703           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(1); return false; }" id="wikibtn_1" title="Forces wiki functions to be allowed on this page."'. */ $ctmp,
   669           'HREF' => makeUrl($paths->page, 'do=setwikimode&level=1', true),
   704           'HREF' => makeUrl($local_page, 'do=setwikimode&level=1', true),
   670           'TEXT' => $lang->get('onpage_btn_wikimode_on')
   705           'TEXT' => $lang->get('onpage_btn_wikimode_on')
   671         ));
   706         ));
   672       $t1 = $menubtn->run();
   707       $t1 = $menubtn->run();
   673       
   708       
   674       // off button
   709       // off button
   677       {
   712       {
   678         $ctmp=' style="text-decoration: underline;"';
   713         $ctmp=' style="text-decoration: underline;"';
   679       }
   714       }
   680       $menubtn->assign_vars(array(
   715       $menubtn->assign_vars(array(
   681           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(0); return false; }" id="wikibtn_0" title="Forces wiki functions to be disabled on this page."'. */ $ctmp,
   716           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(0); return false; }" id="wikibtn_0" title="Forces wiki functions to be disabled on this page."'. */ $ctmp,
   682           'HREF' => makeUrl($paths->page, 'do=setwikimode&level=0', true),
   717           'HREF' => makeUrl($local_page, 'do=setwikimode&level=0', true),
   683           'TEXT' => $lang->get('onpage_btn_wikimode_off')
   718           'TEXT' => $lang->get('onpage_btn_wikimode_off')
   684         ));
   719         ));
   685       $t2 = $menubtn->run();
   720       $t2 = $menubtn->run();
   686       
   721       
   687       // global button
   722       // global button
   690       {
   725       {
   691         $ctmp=' style="text-decoration: underline;"';
   726         $ctmp=' style="text-decoration: underline;"';
   692       }
   727       }
   693       $menubtn->assign_vars(array(
   728       $menubtn->assign_vars(array(
   694           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(2); return false; }" id="wikibtn_2" title="Causes this page to use the global wiki mode setting (default)"'. */ $ctmp,
   729           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(2); return false; }" id="wikibtn_2" title="Causes this page to use the global wiki mode setting (default)"'. */ $ctmp,
   695           'HREF' => makeUrl($paths->page, 'do=setwikimode&level=2', true),
   730           'HREF' => makeUrl($local_page, 'do=setwikimode&level=2', true),
   696           'TEXT' => $lang->get('onpage_btn_wikimode_global')
   731           'TEXT' => $lang->get('onpage_btn_wikimode_global')
   697         ));
   732         ));
   698       $t3 = $menubtn->run();
   733       $t3 = $menubtn->run();
   699       
   734       
   700       // Tack it onto the list of buttons that are already there...
   735       // Tack it onto the list of buttons that are already there...
   707           </tr>
   742           </tr>
   708         </table>';
   743         </table>';
   709     }
   744     }
   710     
   745     
   711     // Clear logs button
   746     // Clear logs button
   712     if ( $session->get_permissions('read') && $session->get_permissions('clear_logs') && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   747     if ( $perms->get_permissions('read') && $perms->get_permissions('clear_logs') && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   713     {
   748     {
   714       $menubtn->assign_vars(array(
   749       $menubtn->assign_vars(array(
   715           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxClearLogs()); return false; }" title="' . $lang->get('onpage_tip_flushlogs') . '" accesskey="l"',
   750           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxClearLogs()); return false; }" title="' . $lang->get('onpage_tip_flushlogs') . '" accesskey="l"',
   716           'HREF'  => makeUrl($paths->page, 'do=flushlogs', true),
   751           'HREF'  => makeUrl($local_page, 'do=flushlogs', true),
   717           'TEXT'  => $lang->get('onpage_btn_clearlogs'),
   752           'TEXT'  => $lang->get('onpage_btn_clearlogs'),
   718         ));
   753         ));
   719       $this->toolbar_menu .= $menubtn->run();
   754       $this->toolbar_menu .= $menubtn->run();
   720     }
   755     }
   721     
   756     
   722     // Delete page button
   757     // Delete page button
   723     if ( $session->get_permissions('read') && $session->get_permissions('delete_page') && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   758     if ( $perms->get_permissions('read') && $perms->get_permissions('delete_page') && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   724     {
   759     {
   725       $s = $lang->get('onpage_btn_deletepage');
   760       $s = $lang->get('onpage_btn_deletepage');
   726       if ( $paths->cpage['delvotes'] == 1 )
   761       if ( $paths->cpage['delvotes'] == 1 )
   727       {
   762       {
   728         $subst = array(
   763         $subst = array(
   740         $s .= $lang->get('onpage_btn_deletepage_votes', $subst);
   775         $s .= $lang->get('onpage_btn_deletepage_votes', $subst);
   741       }
   776       }
   742       
   777       
   743       $menubtn->assign_vars(array(
   778       $menubtn->assign_vars(array(
   744           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDeletePage()); return false; }" title="' . $lang->get('onpage_tip_deletepage') . '" accesskey="k"',
   779           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDeletePage()); return false; }" title="' . $lang->get('onpage_tip_deletepage') . '" accesskey="k"',
   745           'HREF'  => makeUrl($paths->page, 'do=deletepage', true),
   780           'HREF'  => makeUrl($local_page, 'do=deletepage', true),
   746           'TEXT'  => $s,
   781           'TEXT'  => $s,
   747         ));
   782         ));
   748       $this->toolbar_menu .= $menubtn->run();
   783       $this->toolbar_menu .= $menubtn->run();
   749       
   784       
   750     }
   785     }
   752     // Password-protect button
   787     // Password-protect button
   753     if(isset($paths->cpage['password']))
   788     if(isset($paths->cpage['password']))
   754     {
   789     {
   755       if ( $paths->cpage['password'] == '' )
   790       if ( $paths->cpage['password'] == '' )
   756       {
   791       {
   757         $a = $session->get_permissions('password_set');
   792         $a = $perms->get_permissions('password_set');
   758       }
   793       }
   759       else
   794       else
   760       {
   795       {
   761         $a = $session->get_permissions('password_reset');
   796         $a = $perms->get_permissions('password_reset');
   762       }
   797       }
   763     }
   798     }
   764     else
   799     else
   765     {
   800     {
   766       $a = $session->get_permissions('password_set');
   801       $a = $perms->get_permissions('password_set');
   767     }
   802     }
   768     if ( $a && $session->get_permissions('read') && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   803     if ( $a && $perms->get_permissions('read') && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   769     {
   804     {
   770       // label at start
   805       // label at start
   771       $label = $this->makeParserText($tplvars['toolbar_label']);
   806       $label = $this->makeParserText($tplvars['toolbar_label']);
   772       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_password')));
   807       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_password')));
   773       $t0 = $label->run();
   808       $t0 = $label->run();
   781       
   816       
   782       $this->toolbar_menu .= '<table border="0" cellspacing="0" cellpadding="0"><tr><td>'.$t0.'</td><td><input type="password" id="mdgPassSetField" size="10" /></td><td>'.$t.'</td></tr></table>';
   817       $this->toolbar_menu .= '<table border="0" cellspacing="0" cellpadding="0"><tr><td>'.$t0.'</td><td><input type="password" id="mdgPassSetField" size="10" /></td><td>'.$t.'</td></tr></table>';
   783     }
   818     }
   784     
   819     
   785     // Manage ACLs button
   820     // Manage ACLs button
   786     if ( !$paths->anonymous_page && ( $session->get_permissions('edit_acl') || ( defined('ACL_ALWAYS_ALLOW_ADMIN_EDIT_ACL') &&  $session->user_level >= USER_LEVEL_ADMIN ) ) )
   821     if ( !$paths->anonymous_page && ( $perms->get_permissions('edit_acl') || ( defined('ACL_ALWAYS_ALLOW_ADMIN_EDIT_ACL') &&  $session->user_level >= USER_LEVEL_ADMIN ) ) )
   787     {
   822     {
   788       $menubtn->assign_vars(array(
   823       $menubtn->assign_vars(array(
   789           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { return ajaxOpenACLManager(); }" title="' . $lang->get('onpage_tip_aclmanager') . '" accesskey="m"',
   824           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { return ajaxOpenACLManager(); }" title="' . $lang->get('onpage_tip_aclmanager') . '" accesskey="m"',
   790           'HREF'  => makeUrl($paths->page, 'do=aclmanager', true),
   825           'HREF'  => makeUrl($local_page, 'do=aclmanager', true),
   791           'TEXT'  => $lang->get('onpage_btn_acl'),
   826           'TEXT'  => $lang->get('onpage_btn_acl'),
   792         ));
   827         ));
   793       $this->toolbar_menu .= $menubtn->run();
   828       $this->toolbar_menu .= $menubtn->run();
   794     }
   829     }
   795     
   830     
   796     // Administer page button
   831     // Administer page button
   797     if ( $session->user_level >= USER_LEVEL_ADMIN && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   832     if ( $session->user_level >= USER_LEVEL_ADMIN && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   798     {
   833     {
   799       $menubtn->assign_vars(array(
   834       $menubtn->assign_vars(array(
   800           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxAdminPage()); return false; }" title="' . $lang->get('onpage_tip_adminoptions') . '" accesskey="g"',
   835           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxAdminPage()); return false; }" title="' . $lang->get('onpage_tip_adminoptions') . '" accesskey="g"',
   801           'HREF'  => makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'PageManager', true),
   836           'HREF'  => makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'PageManager', true),
   802           'TEXT'  => $lang->get('onpage_btn_admin'),
   837           'TEXT'  => $lang->get('onpage_btn_admin'),
   807     if ( strlen($this->toolbar_menu) > 0 )
   842     if ( strlen($this->toolbar_menu) > 0 )
   808     {
   843     {
   809       $button->assign_vars(array(
   844       $button->assign_vars(array(
   810         'FLAGS'       => 'id="mdgToolbar_moreoptions" onclick="if ( !KILL_SWITCH ) { return false; }" title="' . $lang->get('onpage_tip_moreoptions') . '"',
   845         'FLAGS'       => 'id="mdgToolbar_moreoptions" onclick="if ( !KILL_SWITCH ) { return false; }" title="' . $lang->get('onpage_tip_moreoptions') . '"',
   811         'PARENTFLAGS' => '',
   846         'PARENTFLAGS' => '',
   812         'HREF'        => makeUrl($paths->page, 'do=moreoptions', true),
   847         'HREF'        => makeUrl($local_page, 'do=moreoptions', true),
   813         'TEXT'        => $lang->get('onpage_btn_moreoptions')
   848         'TEXT'        => $lang->get('onpage_btn_moreoptions')
   814         ));
   849         ));
   815       $tb .= $button->run();
   850       $tb .= $button->run();
   816     }
   851     }
   817     
   852     
   844     
   879     
   845     $this->tpl_bool['fixed_menus'] = false;
   880     $this->tpl_bool['fixed_menus'] = false;
   846     /* if($this->sidebar_extra == '') $this->tpl_bool['right_sidebar'] = false;
   881     /* if($this->sidebar_extra == '') $this->tpl_bool['right_sidebar'] = false;
   847     else */ $this->tpl_bool['right_sidebar'] = true;
   882     else */ $this->tpl_bool['right_sidebar'] = true;
   848     
   883     
   849     $this->tpl_bool['auth_rename'] = ( $paths->page_exists && ( $session->get_permissions('rename') && ( $paths->page_protected && $session->get_permissions('even_when_protected') || !$paths->page_protected ) ) && $paths->namespace != 'Special' && $paths->namespace != 'Admin');
   884     $this->tpl_bool['auth_rename'] = ( $paths->page_exists && ( $perms->get_permissions('rename') && ( $paths->page_protected && $perms->get_permissions('even_when_protected') || !$paths->page_protected ) ) && $local_namespace != 'Special' && $local_namespace != 'Admin');
   850     
   885     
   851     $this->tpl_bool['enable_uploads'] = ( getConfig('enable_uploads') == '1' && $session->get_permissions('upload_files') ) ? true : false;
   886     $this->tpl_bool['enable_uploads'] = ( getConfig('enable_uploads') == '1' && $perms->get_permissions('upload_files') ) ? true : false;
   852     
   887     
   853     $this->tpl_bool['stupid_mode'] = false;
   888     $this->tpl_bool['stupid_mode'] = false;
   854     
   889     
   855     $this->tpl_bool['in_admin'] = ( ( $paths->page_id == 'Administration' && $paths->namespace == 'Special' ) || $paths->namespace == 'Admin' );
   890     $this->tpl_bool['in_admin'] = ( ( $local_page_id == 'Administration' && $local_namespace == 'Special' ) || $local_namespace == 'Admin' );
   856     
   891     
   857     $p = ( isset($_GET['printable']) ) ? '/printable' : '';
   892     $p = ( isset($_GET['printable']) ) ? '/printable' : '';
   858     
   893     
   859     // Add the e-mail address client code to the header
   894     // Add the e-mail address client code to the header
   860     $this->add_header($email->jscode());
   895     $this->add_header($email->jscode());
   867     // Once again, the new template parsing system can be used here
   902     // Once again, the new template parsing system can be used here
   868     
   903     
   869     $parser = $this->makeParserText($tplvars['sidebar_button']);
   904     $parser = $this->makeParserText($tplvars['sidebar_button']);
   870     
   905     
   871     $parser->assign_vars(Array(
   906     $parser->assign_vars(Array(
   872         'HREF'=>makeUrlNS('Special', 'Logout'),
   907         'HREF'=>makeUrlNS('Special', "Logout/{$session->csrf_token}/{$local_page}"),
   873         'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { mb_logout(); return false; }"',
   908         'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { mb_logout(); return false; }"',
   874         'TEXT'=>$lang->get('sidebar_btn_logout'),
   909         'TEXT'=>$lang->get('sidebar_btn_logout'),
   875       ));
   910       ));
   876     
   911     
   877     $logout_link = $parser->run();
   912     $logout_link = $parser->run();
   878     
   913     
   879     $parser->assign_vars(Array(
   914     $parser->assign_vars(Array(
   880         'HREF'=>makeUrlNS('Special', 'Login/' . $paths->page),
   915         'HREF'=>makeUrlNS('Special', 'Login/' . $local_page),
   881         'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { ajaxStartLogin(); return false; }"',
   916         'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { ajaxStartLogin(); return false; }"',
   882         'TEXT'=>$lang->get('sidebar_btn_login'),
   917         'TEXT'=>$lang->get('sidebar_btn_login'),
   883       ));
   918       ));
   884     
   919     
   885     $login_link = $parser->run();
   920     $login_link = $parser->run();
   886     
   921     
   887     $parser->assign_vars(Array(
   922     $parser->assign_vars(Array(
   888         'HREF'=>makeUrlNS('Special', 'ChangeStyle/'.$paths->page),
   923         'HREF'=>makeUrlNS('Special', 'ChangeStyle/'.$local_page),
   889         'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { ajaxChangeStyle(); return false; }"',
   924         'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { ajaxChangeStyle(); return false; }"',
   890         'TEXT'=>$lang->get('sidebar_btn_changestyle'),
   925         'TEXT'=>$lang->get('sidebar_btn_changestyle'),
   891       ));
   926       ));
   892     
   927     
   893     $theme_link = $parser->run();
   928     $theme_link = $parser->run();
   900     
   935     
   901     $admin_link = $parser->run();
   936     $admin_link = $parser->run();
   902     
   937     
   903     $SID = ($session->sid_super) ? $session->sid_super : '';
   938     $SID = ($session->sid_super) ? $session->sid_super : '';
   904     
   939     
   905     $urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($paths->fullpage)));
   940     $urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($local_fullpage)));
   906     $urlname_clean = strtr( $urlname_clean, array( '<' => '&lt;', '>' => '&gt;' ) );
   941     $urlname_clean = strtr( $urlname_clean, array( '<' => '&lt;', '>' => '&gt;' ) );
   907     
   942     
   908     $urlname_jssafe = sanitize_page_id($paths->fullpage);
   943     $urlname_jssafe = sanitize_page_id($local_fullpage);
   909     
   944     
   910     // Generate the dynamic javascript vars
   945     // Generate the dynamic javascript vars
   911     $js_dynamic = '    <script type="text/javascript">// <![CDATA[
   946     $js_dynamic = '    <script type="text/javascript">// <![CDATA[
   912       // This section defines some basic and very important variables that are used later in the static Javascript library.
   947       // This section defines some basic and very important variables that are used later in the static Javascript library.
   913       // SKIN DEVELOPERS: The template variable for this code block is {JS_DYNAMIC_VARS}. This MUST be inserted BEFORE the tag that links to the main Javascript lib.
   948       // SKIN DEVELOPERS: The template variable for this code block is {JS_DYNAMIC_VARS}. This MUST be inserted BEFORE the tag that links to the main Javascript lib.
   922       var USER_LEVEL_MEMBER = ' . USER_LEVEL_MEMBER . ';
   957       var USER_LEVEL_MEMBER = ' . USER_LEVEL_MEMBER . ';
   923       var USER_LEVEL_CHPREF = ' . USER_LEVEL_CHPREF . ';
   958       var USER_LEVEL_CHPREF = ' . USER_LEVEL_CHPREF . ';
   924       var USER_LEVEL_MOD = ' . USER_LEVEL_MOD . ';
   959       var USER_LEVEL_MOD = ' . USER_LEVEL_MOD . ';
   925       var USER_LEVEL_ADMIN = ' . USER_LEVEL_ADMIN . ';
   960       var USER_LEVEL_ADMIN = ' . USER_LEVEL_ADMIN . ';
   926       var pref_disable_js_fx = ' . ( @$session->user_extra['disable_js_fx'] == 1 ? '1' : '0' ) . ';
   961       var pref_disable_js_fx = ' . ( @$session->user_extra['disable_js_fx'] == 1 ? '1' : '0' ) . ';
       
   962       var csrf_token = "' . $session->csrf_token . '";
   927       var editNotice = \'' . ( (getConfig('wiki_edit_notice')=='1') ? str_replace("\n", "\\\n", RenderMan::render(getConfig('wiki_edit_notice_text'))) : '' ) . '\';
   963       var editNotice = \'' . ( (getConfig('wiki_edit_notice')=='1') ? str_replace("\n", "\\\n", RenderMan::render(getConfig('wiki_edit_notice_text'))) : '' ) . '\';
   928       var prot = ' . ( ($paths->page_protected && !$session->get_permissions('even_when_protected')) ? 'true' : 'false' ) .'; // No, hacking this var won\'t work, it\'s re-checked on the server
   964       var prot = ' . ( ($paths->page_protected && !$perms->get_permissions('even_when_protected')) ? 'true' : 'false' ) .'; // No, hacking this var won\'t work, it\'s re-checked on the server
   929       var ENANO_SPECIAL_CREATEPAGE = \''. makeUrl($paths->nslist['Special'].'CreatePage') .'\';
   965       var ENANO_SPECIAL_CREATEPAGE = \''. makeUrl($paths->nslist['Special'].'CreatePage') .'\';
   930       var ENANO_CREATEPAGE_PARAMS = \'_do=&pagename='. $urlname_clean .'&namespace=' . $paths->namespace . '\';
   966       var ENANO_CREATEPAGE_PARAMS = \'_do=&pagename='. $urlname_clean .'&namespace=' . $local_namespace . '\';
   931       var ENANO_SPECIAL_CHANGESTYLE = \''. makeUrlNS('Special', 'ChangeStyle') .'\';
   967       var ENANO_SPECIAL_CHANGESTYLE = \''. makeUrlNS('Special', 'ChangeStyle') .'\';
   932       var namespace_list = new Array();
   968       var namespace_list = new Array();
   933       var AES_BITS = '.AES_BITS.';
   969       var AES_BITS = '.AES_BITS.';
   934       var AES_BLOCKSIZE = '.AES_BLOCKSIZE.';
   970       var AES_BLOCKSIZE = '.AES_BLOCKSIZE.';
   935       var pagepass = \''. ( ( isset($_REQUEST['pagepass']) ) ? sha1($_REQUEST['pagepass']) : '' ) .'\';
   971       var pagepass = \''. ( ( isset($_REQUEST['pagepass']) ) ? sha1($_REQUEST['pagepass']) : '' ) .'\';
   949       foreach($paths->nslist as $k => $c)
   985       foreach($paths->nslist as $k => $c)
   950       {
   986       {
   951         $js_dynamic .= "namespace_list['{$k}'] = '$c';";
   987         $js_dynamic .= "namespace_list['{$k}'] = '$c';";
   952       }
   988       }
   953       $js_dynamic .= "\n    //]]>\n    </script>";
   989       $js_dynamic .= "\n    //]]>\n    </script>";
   954       
   990     
   955     $tpl_strings = Array(
   991     $tpl_strings = Array(
   956       'PAGE_NAME'=>htmlspecialchars($paths->cpage['name']),
   992       'PAGE_NAME'=>htmlspecialchars($paths->cpage['name']),
   957       'PAGE_URLNAME'=> $urlname_clean,
   993       'PAGE_URLNAME'=> $urlname_clean,
   958       'SITE_NAME'=>htmlspecialchars(getConfig('site_name')),
   994       'SITE_NAME'=>htmlspecialchars(getConfig('site_name')),
   959       'USERNAME'=>$session->username,
   995       'USERNAME'=>$session->username,
   974       'LOGIN_LINK'=>$login_link,
  1010       'LOGIN_LINK'=>$login_link,
   975       'LOGOUT_LINK'=>$logout_link,
  1011       'LOGOUT_LINK'=>$logout_link,
   976       'ADMIN_LINK'=>$admin_link,
  1012       'ADMIN_LINK'=>$admin_link,
   977       'THEME_LINK'=>$theme_link,
  1013       'THEME_LINK'=>$theme_link,
   978       'SEARCH_ACTION'=>makeUrlNS('Special', 'Search'),
  1014       'SEARCH_ACTION'=>makeUrlNS('Special', 'Search'),
   979       'INPUT_TITLE'=>( urlSeparator == '&' ? '<input type="hidden" name="title" value="' . htmlspecialchars( $paths->nslist[$paths->namespace] . $paths->page_id ) . '" />' : ''),
  1015       'INPUT_TITLE'=>( urlSeparator == '&' ? '<input type="hidden" name="title" value="' . htmlspecialchars( $paths->nslist[$local_namespace] . $local_page_id ) . '" />' : ''),
   980       'INPUT_AUTH'=>( $session->sid_super ? '<input type="hidden" name="auth"  value="' . $session->sid_super . '" />' : ''),
  1016       'INPUT_AUTH'=>( $session->sid_super ? '<input type="hidden" name="auth"  value="' . $session->sid_super . '" />' : ''),
   981       'TEMPLATE_DIR'=>scriptPath.'/themes/'.$this->theme,
  1017       'TEMPLATE_DIR'=>scriptPath.'/themes/'.$this->theme,
   982       'THEME_ID'=>$this->theme,
  1018       'THEME_ID'=>$this->theme,
   983       'STYLE_ID'=>$this->style,
  1019       'STYLE_ID'=>$this->style,
   984       'JS_DYNAMIC_VARS'=>$js_dynamic,
  1020       'JS_DYNAMIC_VARS'=>$js_dynamic,
   985       'UNREAD_PMS'=>$session->unread_pms,
  1021       'UNREAD_PMS'=>$session->unread_pms,
   986       'URL_ABOUT_ENANO' => makeUrlNS('Special', 'About_Enano', '', true),
  1022       'URL_ABOUT_ENANO' => makeUrlNS('Special', 'About_Enano', '', true),
   987       'REPORT_URI' => makeUrl($paths->fullpage, 'do=sql_report', true)
  1023       'REPORT_URI' => makeUrl($local_fullpage, 'do=sql_report', true)
   988       );
  1024       );
   989     
  1025     
   990     foreach ( $paths->nslist as $ns_id => $ns_prefix )
  1026     foreach ( $paths->nslist as $ns_id => $ns_prefix )
   991     {
  1027     {
   992       $tpl_strings[ 'NS_' . strtoupper($ns_id) ] = $ns_prefix;
  1028       $tpl_strings[ 'NS_' . strtoupper($ns_id) ] = $ns_prefix;
   993     }
  1029     }
   994     
  1030     
   995     $this->tpl_strings = array_merge($tpl_strings, $this->tpl_strings);
  1031     $this->assign_vars($tpl_strings, true);
       
  1032     
   996     list($this->tpl_strings['SIDEBAR_LEFT'], $this->tpl_strings['SIDEBAR_RIGHT'], $min) = $this->fetch_sidebar();
  1033     list($this->tpl_strings['SIDEBAR_LEFT'], $this->tpl_strings['SIDEBAR_RIGHT'], $min) = $this->fetch_sidebar();
   997     $this->tpl_bool['sidebar_left']  = ( $this->tpl_strings['SIDEBAR_LEFT']  != $min) ? true : false;
  1034     $this->tpl_bool['sidebar_left']  = ( $this->tpl_strings['SIDEBAR_LEFT']  != $min) ? true : false;
   998     $this->tpl_bool['sidebar_right'] = ( $this->tpl_strings['SIDEBAR_RIGHT'] != $min) ? true : false;
  1035     $this->tpl_bool['sidebar_right'] = ( $this->tpl_strings['SIDEBAR_RIGHT'] != $min) ? true : false;
   999     $this->tpl_bool['right_sidebar'] = $this->tpl_bool['sidebar_right']; // backward compatibility
  1036     $this->tpl_bool['right_sidebar'] = $this->tpl_bool['sidebar_right']; // backward compatibility
  1000     
  1037     
  1003     {
  1040     {
  1004       eval($cmd);
  1041       eval($cmd);
  1005     }
  1042     }
  1006     
  1043     
  1007     profiler_log("template: finished var init");
  1044     profiler_log("template: finished var init");
       
  1045   }
       
  1046   
       
  1047   /**
       
  1048    * Performs var init that is common to all pages (IOW, called only once)
       
  1049    * @access private
       
  1050    */
       
  1051   
       
  1052   function init_vars_global()
       
  1053   {
       
  1054     
  1008   }
  1055   }
  1009   
  1056   
  1010   function header($simple = false) 
  1057   function header($simple = false) 
  1011   {
  1058   {
  1012     global $db, $session, $paths, $template, $plugins; // Common objects
  1059     global $db, $session, $paths, $template, $plugins; // Common objects
  1120     else
  1167     else
  1121     {
  1168     {
  1122       return '';
  1169       return '';
  1123     }
  1170     }
  1124   }
  1171   }
       
  1172   
       
  1173   /**
       
  1174    * Assigns an array of string values to the template. Strings can be accessed from the template by inserting {KEY_NAME} in the template file.
       
  1175    * @param $vars array
       
  1176    * @param $from_internal bool Internal switch, just omit (@todo document)
       
  1177    */
       
  1178   
       
  1179   function assign_vars($vars, $from_internal = false)
       
  1180   {
       
  1181     foreach ( $vars as $key => $value )
       
  1182     {
       
  1183       $replace = true;
       
  1184       if ( isset($this->vars_assign_history['strings'][$key]) )
       
  1185       {
       
  1186         if ( $this->vars_assign_history['strings'][$key] == 'api' )
       
  1187         {
       
  1188           $replace = false;
       
  1189         }
       
  1190       }
       
  1191       if ( $replace )
       
  1192       {
       
  1193         $this->tpl_strings[$key] = $value;
       
  1194         $this->vars_assign_history['strings'][$key] = ( $from_internal ) ? 'internal' : 'api';
       
  1195       }
       
  1196     }
       
  1197   }
       
  1198   
       
  1199   /**
       
  1200    * Assigns an array of boolean values to the template. These can be used for <!-- IF ... --> statements.
       
  1201    * @param $vars array
       
  1202    * @param $from_internal bool Internal switch, just omit (@todo document)
       
  1203    */
       
  1204   
       
  1205   function assign_bool($vars)
       
  1206   {
       
  1207     foreach ( $vars as $key => $value )
       
  1208     {
       
  1209       $replace = true;
       
  1210       if ( isset($this->vars_assign_history['bool'][$key]) )
       
  1211       {
       
  1212         if ( $this->vars_assign_history['bool'][$key] == 'api' )
       
  1213         {
       
  1214           $replace = false;
       
  1215         }
       
  1216       }
       
  1217       if ( $replace )
       
  1218       {
       
  1219         $this->tpl_bool[$key] = $value;
       
  1220         $this->vars_assign_history['bool'][$key] = ( $from_internal ) ? 'internal' : 'api';
       
  1221       }
       
  1222     }
       
  1223   }
       
  1224   
       
  1225   #
       
  1226   # COMPILER
       
  1227   #
  1125   
  1228   
  1126   /**
  1229   /**
  1127    * Compiles and executes a template based on the current variables and booleans. Loads
  1230    * Compiles and executes a template based on the current variables and booleans. Loads
  1128    * the theme and initializes variables if needed. This mostly just calls child functions.
  1231    * the theme and initializes variables if needed. This mostly just calls child functions.
  1129    * @param string File to process
  1232    * @param string File to process
  2076   function templateIndividual($text)
  2179   function templateIndividual($text)
  2077   {
  2180   {
  2078     $this->__construct($text);
  2181     $this->__construct($text);
  2079   }
  2182   }
  2080   */
  2183   */
       
  2184   
  2081   /**
  2185   /**
  2082    * Assigns an array of string values to the template. Strings can be accessed from the template by inserting {KEY_NAME} in the template file.
  2186    * Assigns an array of string values to the template. Strings can be accessed from the template by inserting {KEY_NAME} in the template file.
  2083    * @param $vars array
  2187    * @param $vars array
  2084    */
  2188    */
       
  2189   
  2085   function assign_vars($vars)
  2190   function assign_vars($vars)
  2086   {
  2191   {
  2087     $this->tpl_strings = array_merge($this->tpl_strings, $vars);
  2192     $this->tpl_strings = array_merge($this->tpl_strings, $vars);
  2088   }
  2193   }
       
  2194   
  2089   /**
  2195   /**
  2090    * Assigns an array of boolean values to the template. These can be used for <!-- IF ... --> statements.
  2196    * Assigns an array of boolean values to the template. These can be used for <!-- IF ... --> statements.
  2091    * @param $vars array
  2197    * @param $vars array
  2092    */
  2198    */
       
  2199   
  2093   function assign_bool($vars)
  2200   function assign_bool($vars)
  2094   {
  2201   {
  2095     $this->tpl_bool = array_merge($this->tpl_bool, $vars);
  2202     $this->tpl_bool = array_merge($this->tpl_bool, $vars);
  2096   }
  2203   }
       
  2204   
  2097   /**
  2205   /**
  2098    * Compiles and executes the template code.
  2206    * Compiles and executes the template code.
  2099    * @return string
  2207    * @return string
  2100    */
  2208    */
  2101   function run()
  2209   function run()