includes/template.php
changeset 566 06d241de3151
parent 557 26479224936a
child 571 66e14e61613e
equal deleted inserted replaced
565:df5a40ca2f7a 566:06d241de3151
   379         $local_page = $page->namespace . substr($paths->nslist['Special'], -1) . $page->page_id . $page_append;
   379         $local_page = $page->namespace . substr($paths->nslist['Special'], -1) . $page->page_id . $page_append;
   380       }
   380       }
   381       $local_fullpage = $local_page . $page_append;
   381       $local_fullpage = $local_page . $page_append;
   382       $local_page_id =& $page->page_id;
   382       $local_page_id =& $page->page_id;
   383       $local_namespace =& $page->namespace;
   383       $local_namespace =& $page->namespace;
       
   384       $local_page_exists =& $page->page_exists;
   384       $perms =& $page->perms;
   385       $perms =& $page->perms;
   385     }
   386     }
   386     else
   387     else
   387     {
   388     {
   388       $local_page =& $paths->page;
   389       $local_page =& $paths->page;
   389       $local_page_id =& $paths->page_id;
   390       $local_page_id =& $paths->page_id;
   390       $local_fullpage =& $paths->fullpage;
   391       $local_fullpage =& $paths->fullpage;
   391       $local_namespace =& $paths->namespace;
   392       $local_namespace =& $paths->namespace;
       
   393       $local_page_exists =& $paths->page_exists;
       
   394       $local_page_protected =& $paths->page_protected;
   392       $perms =& $session;
   395       $perms =& $session;
       
   396     }
       
   397     
       
   398     if ( $local_page_exists && isset($paths->pages[$local_page]) )
       
   399     {
       
   400       $local_cdata =& $paths->pages[$local_page];
       
   401     }
       
   402     else
       
   403     {
       
   404       // if the page doesn't exist but we're trying to load it, it was requested manually and $paths->cpage should match it.
       
   405       if ( $paths->page_id == $local_page_id )
       
   406       {
       
   407         // load metadata from cpage
       
   408         $local_cdata =& $paths->cpage;
       
   409       }
       
   410       else
       
   411       {
       
   412         // generate our own failsafe metadata
       
   413         $local_cdata = array(
       
   414             'urlname' => $local_page,
       
   415             'urlname_nons' => $local_page_id,
       
   416             'namespace' => $local_namespace,
       
   417             'name' => get_page_title_ns($local_page_id, $local_namespace),
       
   418             'comments_on' => 0,
       
   419             'protected' => 0,
       
   420             'wiki_mode' => 2,
       
   421             'delvotes' => 0,
       
   422             'delvote_ips' => serialize(array())
       
   423           );
       
   424       }
       
   425     }
       
   426     
       
   427     // calculate protection
       
   428     if ( !isset($local_page_protected) )
       
   429     {
       
   430       if ( $local_cdata['protected'] == 0 )
       
   431       {
       
   432         $local_page_protected = false;
       
   433       }
       
   434       else if ( $local_cdata['protected'] == 1 )
       
   435       {
       
   436         $local_page_protected = true;
       
   437       }
       
   438       else if ( $local_cdata['protected'] == 2 )
       
   439       {
       
   440         if (
       
   441              ( !$session->user_logged_in || // Is the user logged in?
       
   442                ( $session->user_logged_in && $session->reg_time + ( 4 * 86400 ) >= time() ) ) // If so, have they been registered for 4 days?
       
   443              && !$perms->get_permissions('even_when_protected') ) // And of course, is there an ACL that overrides semi-protection?
       
   444         {
       
   445           $local_page_protected = true;
       
   446         }
       
   447         else
       
   448         {
       
   449           $local_page_protected = false;
       
   450         }
       
   451       }
   393     }
   452     }
   394     
   453     
   395     $tplvars = $this->extract_vars('elements.tpl');
   454     $tplvars = $this->extract_vars('elements.tpl');
   396     
   455     
   397     if(isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
   456     if(isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
   497     
   556     
   498     $button = $this->makeParserText($tplvars['toolbar_button']);
   557     $button = $this->makeParserText($tplvars['toolbar_button']);
   499     
   558     
   500     // Page toolbar
   559     // Page toolbar
   501     // Comments button
   560     // Comments button
   502     if ( $perms->get_permissions('read') && getConfig('enable_comments')=='1' && $local_namespace != 'Special' && $local_namespace != 'Admin' && $paths->cpage['comments_on'] == 1 )
   561     if ( $perms->get_permissions('read') && getConfig('enable_comments')=='1' && $local_namespace != 'Special' && $local_namespace != 'Admin' && $local_cdata['comments_on'] == 1 )
   503     {
   562     {
   504       
   563       
   505       $e = $db->sql_query('SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$local_page_id.'\' AND namespace=\''.$local_namespace.'\';');
   564       $e = $db->sql_query('SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$local_page_id.'\' AND namespace=\''.$local_namespace.'\';');
   506       if ( !$e )
   565       if ( !$e )
   507       {
   566       {
   571         'TEXT' => $lang->get('onpage_btn_viewsource')
   630         'TEXT' => $lang->get('onpage_btn_viewsource')
   572         ));
   631         ));
   573       $tb .= $button->run();
   632       $tb .= $button->run();
   574     }
   633     }
   575     // History button
   634     // History button
   576     if ( $perms->get_permissions('read') /* && $paths->wiki_mode */ && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' && $perms->get_permissions('history_view') )
   635     if ( $perms->get_permissions('read') /* && $paths->wiki_mode */ && $local_page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' && $perms->get_permissions('history_view') )
   577     {
   636     {
   578       $button->assign_vars(array(
   637       $button->assign_vars(array(
   579         'FLAGS'       => 'onclick="if ( !KILL_SWITCH ) { void(ajaxHistory()); return false; }" title="' . $lang->get('onpage_tip_history') . '" accesskey="h"',
   638         'FLAGS'       => 'onclick="if ( !KILL_SWITCH ) { void(ajaxHistory()); return false; }" title="' . $lang->get('onpage_tip_history') . '" accesskey="h"',
   580         'PARENTFLAGS' => 'id="mdgToolbar_history"',
   639         'PARENTFLAGS' => 'id="mdgToolbar_history"',
   581         'HREF'        => makeUrl($local_page, 'do=history', true),
   640         'HREF'        => makeUrl($local_page, 'do=history', true),
   586     
   645     
   587     $menubtn = $this->makeParserText($tplvars['toolbar_menu_button']);
   646     $menubtn = $this->makeParserText($tplvars['toolbar_menu_button']);
   588     
   647     
   589     // Additional actions menu
   648     // Additional actions menu
   590     // Rename button
   649     // Rename button
   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' )
   650     if ( $perms->get_permissions('read') && $local_page_exists && ( $perms->get_permissions('rename') && ( $paths->page_protected && $perms->get_permissions('even_when_protected') || !$paths->page_protected ) ) && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   592     {
   651     {
   593       $menubtn->assign_vars(array(
   652       $menubtn->assign_vars(array(
   594           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxRename()); return false; }" title="' . $lang->get('onpage_tip_rename') . '" accesskey="r"',
   653           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxRename()); return false; }" title="' . $lang->get('onpage_tip_rename') . '" accesskey="r"',
   595           'HREF'  => makeUrl($local_page, 'do=rename', true),
   654           'HREF'  => makeUrl($local_page, 'do=rename', true),
   596           'TEXT'  => $lang->get('onpage_btn_rename'),
   655           'TEXT'  => $lang->get('onpage_btn_rename'),
   597         ));
   656         ));
   598       $this->toolbar_menu .= $menubtn->run();
   657       $this->toolbar_menu .= $menubtn->run();
   599     }
   658     }
   600     
   659     
   601     // Vote-to-delete button
   660     // Vote-to-delete button
   602     if ( $paths->wiki_mode && $perms->get_permissions('vote_delete') && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin')
   661     if ( $paths->wiki_mode && $perms->get_permissions('vote_delete') && $local_page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin')
   603     {
   662     {
   604       $menubtn->assign_vars(array(
   663       $menubtn->assign_vars(array(
   605           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDelVote()); return false; }" title="' . $lang->get('onpage_tip_delvote') . '" accesskey="d"',
   664           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDelVote()); return false; }" title="' . $lang->get('onpage_tip_delvote') . '" accesskey="d"',
   606           'HREF'  => makeUrl($local_page, 'do=delvote', true),
   665           'HREF'  => makeUrl($local_page, 'do=delvote', true),
   607           'TEXT'  => $lang->get('onpage_btn_votedelete'),
   666           'TEXT'  => $lang->get('onpage_btn_votedelete'),
   608         ));
   667         ));
   609       $this->toolbar_menu .= $menubtn->run();
   668       $this->toolbar_menu .= $menubtn->run();
   610     }
   669     }
   611     
   670     
   612     // Clear-votes button
   671     // Clear-votes button
   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)
   672     if ( $perms->get_permissions('read') && $paths->wiki_mode && $local_page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' && $perms->get_permissions('vote_reset') && $local_cdata['delvotes'] > 0)
   614     {
   673     {
   615       $menubtn->assign_vars(array(
   674       $menubtn->assign_vars(array(
   616           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxResetDelVotes()); return false; }" title="' . $lang->get('onpage_tip_resetvotes') . '" accesskey="y"',
   675           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxResetDelVotes()); return false; }" title="' . $lang->get('onpage_tip_resetvotes') . '" accesskey="y"',
   617           'HREF'  => makeUrl($local_page, 'do=resetvotes', true),
   676           'HREF'  => makeUrl($local_page, 'do=resetvotes', true),
   618           'TEXT'  => $lang->get('onpage_btn_votedelete_reset'),
   677           'TEXT'  => $lang->get('onpage_btn_votedelete_reset'),
   619         ));
   678         ));
   620       $this->toolbar_menu .= $menubtn->run();
   679       $this->toolbar_menu .= $menubtn->run();
   621     }
   680     }
   622     
   681     
   623     // Printable page button
   682     // Printable page button
   624     if ( $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   683     if ( $local_page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   625     {
   684     {
   626       $menubtn->assign_vars(array(
   685       $menubtn->assign_vars(array(
   627           'FLAGS' => 'title="' . $lang->get('onpage_tip_printable') . '"',
   686           'FLAGS' => 'title="' . $lang->get('onpage_tip_printable') . '"',
   628           'HREF'  => makeUrl($local_page, 'printable=yes', true),
   687           'HREF'  => makeUrl($local_page, 'printable=yes', true),
   629           'TEXT'  => $lang->get('onpage_btn_printable'),
   688           'TEXT'  => $lang->get('onpage_btn_printable'),
   630         ));
   689         ));
   631       $this->toolbar_menu .= $menubtn->run();
   690       $this->toolbar_menu .= $menubtn->run();
   632     }
   691     }
   633     
   692     
   634     // Protect button
   693     // Protect button
   635     if($perms->get_permissions('read') && $paths->wiki_mode && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' && $perms->get_permissions('protect'))
   694     if($perms->get_permissions('read') && $paths->wiki_mode && $local_page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' && $perms->get_permissions('protect'))
   636     {
   695     {
   637       
   696       
   638       $label = $this->makeParserText($tplvars['toolbar_label']);
   697       $label = $this->makeParserText($tplvars['toolbar_label']);
   639       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_protect')));
   698       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_protect')));
   640       $t0 = $label->run();
   699       $t0 = $label->run();
   641       
   700       
   642       $ctmp = ''; 
   701       $ctmp = ''; 
   643       if ( $paths->cpage['protected'] == 1 )
   702       if ( $local_cdata['protected'] == 1 )
   644       {
   703       {
   645         $ctmp=' style="text-decoration: underline;"';
   704         $ctmp=' style="text-decoration: underline;"';
   646       }
   705       }
   647       $menubtn->assign_vars(array(
   706       $menubtn->assign_vars(array(
   648           'FLAGS' => 'accesskey="i" onclick="if ( !KILL_SWITCH ) { ajaxProtect(1); return false; }" id="protbtn_1" title="' . $lang->get('onpage_tip_protect_on') . '"'.$ctmp,
   707           'FLAGS' => 'accesskey="i" onclick="if ( !KILL_SWITCH ) { ajaxProtect(1); return false; }" id="protbtn_1" title="' . $lang->get('onpage_tip_protect_on') . '"'.$ctmp,
   650           'TEXT'  => $lang->get('onpage_btn_protect_on')
   709           'TEXT'  => $lang->get('onpage_btn_protect_on')
   651         ));
   710         ));
   652       $t1 = $menubtn->run();
   711       $t1 = $menubtn->run();
   653       
   712       
   654       $ctmp = '';
   713       $ctmp = '';
   655       if ( $paths->cpage['protected'] == 0 )
   714       if ( $local_cdata['protected'] == 0 )
   656       {
   715       {
   657         $ctmp=' style="text-decoration: underline;"';
   716         $ctmp=' style="text-decoration: underline;"';
   658       }
   717       }
   659       $menubtn->assign_vars(array(
   718       $menubtn->assign_vars(array(
   660           'FLAGS' => 'accesskey="o" onclick="if ( !KILL_SWITCH ) { ajaxProtect(0); return false; }" id="protbtn_0" title="' . $lang->get('onpage_tip_protect_off') . '"'.$ctmp,
   719           'FLAGS' => 'accesskey="o" onclick="if ( !KILL_SWITCH ) { ajaxProtect(0); return false; }" id="protbtn_0" title="' . $lang->get('onpage_tip_protect_off') . '"'.$ctmp,
   662           'TEXT'  => $lang->get('onpage_btn_protect_off')
   721           'TEXT'  => $lang->get('onpage_btn_protect_off')
   663         ));
   722         ));
   664       $t2 = $menubtn->run();
   723       $t2 = $menubtn->run();
   665       
   724       
   666       $ctmp = '';
   725       $ctmp = '';
   667       if ( $paths->cpage['protected'] == 2 )
   726       if ( $local_cdata['protected'] == 2 )
   668       {
   727       {
   669         $ctmp = ' style="text-decoration: underline;"';
   728         $ctmp = ' style="text-decoration: underline;"';
   670       }
   729       }
   671       $menubtn->assign_vars(array(
   730       $menubtn->assign_vars(array(
   672           'FLAGS' => 'accesskey="p" onclick="if ( !KILL_SWITCH ) { ajaxProtect(2); return false; }" id="protbtn_2" title="' . $lang->get('onpage_tip_protect_semi') . '"'.$ctmp,
   731           'FLAGS' => 'accesskey="p" onclick="if ( !KILL_SWITCH ) { ajaxProtect(2); return false; }" id="protbtn_2" title="' . $lang->get('onpage_tip_protect_semi') . '"'.$ctmp,
   684           </tr>
   743           </tr>
   685         </table>';
   744         </table>';
   686     }
   745     }
   687     
   746     
   688     // Wiki mode button
   747     // Wiki mode button
   689     if($perms->get_permissions('read') && $paths->page_exists && $perms->get_permissions('set_wiki_mode') && $local_namespace != 'Special' && $local_namespace != 'Admin')
   748     if($perms->get_permissions('read') && $local_page_exists && $perms->get_permissions('set_wiki_mode') && $local_namespace != 'Special' && $local_namespace != 'Admin')
   690     {
   749     {
   691       // label at start
   750       // label at start
   692       $label = $this->makeParserText($tplvars['toolbar_label']);
   751       $label = $this->makeParserText($tplvars['toolbar_label']);
   693       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_wikimode')));
   752       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_wikimode')));
   694       $t0 = $label->run();
   753       $t0 = $label->run();
   695       
   754       
   696       // on button
   755       // on button
   697       $ctmp = '';
   756       $ctmp = '';
   698       if ( $paths->cpage['wiki_mode'] == 1 )
   757       if ( $local_cdata['wiki_mode'] == 1 )
   699       {
   758       {
   700         $ctmp = ' style="text-decoration: underline;"';
   759         $ctmp = ' style="text-decoration: underline;"';
   701       }
   760       }
   702       $menubtn->assign_vars(array(
   761       $menubtn->assign_vars(array(
   703           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(1); return false; }" id="wikibtn_1" title="Forces wiki functions to be allowed on this page."'. */ $ctmp,
   762           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(1); return false; }" id="wikibtn_1" title="Forces wiki functions to be allowed on this page."'. */ $ctmp,
   706         ));
   765         ));
   707       $t1 = $menubtn->run();
   766       $t1 = $menubtn->run();
   708       
   767       
   709       // off button
   768       // off button
   710       $ctmp = '';
   769       $ctmp = '';
   711       if ( $paths->cpage['wiki_mode'] == 0 )
   770       if ( $local_cdata['wiki_mode'] == 0 )
   712       {
   771       {
   713         $ctmp=' style="text-decoration: underline;"';
   772         $ctmp=' style="text-decoration: underline;"';
   714       }
   773       }
   715       $menubtn->assign_vars(array(
   774       $menubtn->assign_vars(array(
   716           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(0); return false; }" id="wikibtn_0" title="Forces wiki functions to be disabled on this page."'. */ $ctmp,
   775           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(0); return false; }" id="wikibtn_0" title="Forces wiki functions to be disabled on this page."'. */ $ctmp,
   719         ));
   778         ));
   720       $t2 = $menubtn->run();
   779       $t2 = $menubtn->run();
   721       
   780       
   722       // global button
   781       // global button
   723       $ctmp = ''; 
   782       $ctmp = ''; 
   724       if ( $paths->cpage['wiki_mode'] == 2 )
   783       if ( $local_cdata['wiki_mode'] == 2 )
   725       {
   784       {
   726         $ctmp=' style="text-decoration: underline;"';
   785         $ctmp=' style="text-decoration: underline;"';
   727       }
   786       }
   728       $menubtn->assign_vars(array(
   787       $menubtn->assign_vars(array(
   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,
   788           '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,
   753         ));
   812         ));
   754       $this->toolbar_menu .= $menubtn->run();
   813       $this->toolbar_menu .= $menubtn->run();
   755     }
   814     }
   756     
   815     
   757     // Delete page button
   816     // Delete page button
   758     if ( $perms->get_permissions('read') && $perms->get_permissions('delete_page') && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   817     if ( $perms->get_permissions('read') && $perms->get_permissions('delete_page') && $local_page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   759     {
   818     {
   760       $s = $lang->get('onpage_btn_deletepage');
   819       $s = $lang->get('onpage_btn_deletepage');
   761       if ( $paths->cpage['delvotes'] == 1 )
   820       if ( $local_cdata['delvotes'] == 1 )
   762       {
   821       {
   763         $subst = array(
   822         $subst = array(
   764           'num_votes' => $paths->cpage['delvotes'],
   823           'num_votes' => $local_cdata['delvotes'],
   765           'plural' => ''
   824           'plural' => ''
   766           );
   825           );
   767         $s .= $lang->get('onpage_btn_deletepage_votes', $subst);
   826         $s .= $lang->get('onpage_btn_deletepage_votes', $subst);
   768       }
   827       }
   769       else if ( $paths->cpage['delvotes'] > 1 )
   828       else if ( $local_cdata['delvotes'] > 1 )
   770       {
   829       {
   771         $subst = array(
   830         $subst = array(
   772           'num_votes' => $paths->cpage['delvotes'],
   831           'num_votes' => $local_cdata['delvotes'],
   773           'plural' => $lang->get('meta_plural')
   832           'plural' => $lang->get('meta_plural')
   774           );
   833           );
   775         $s .= $lang->get('onpage_btn_deletepage_votes', $subst);
   834         $s .= $lang->get('onpage_btn_deletepage_votes', $subst);
   776       }
   835       }
   777       
   836       
   783       $this->toolbar_menu .= $menubtn->run();
   842       $this->toolbar_menu .= $menubtn->run();
   784       
   843       
   785     }
   844     }
   786     
   845     
   787     // Password-protect button
   846     // Password-protect button
   788     if(isset($paths->cpage['password']))
   847     if(isset($local_cdata['password']))
   789     {
   848     {
   790       if ( $paths->cpage['password'] == '' )
   849       if ( $local_cdata['password'] == '' )
   791       {
   850       {
   792         $a = $perms->get_permissions('password_set');
   851         $a = $perms->get_permissions('password_set');
   793       }
   852       }
   794       else
   853       else
   795       {
   854       {
   798     }
   857     }
   799     else
   858     else
   800     {
   859     {
   801       $a = $perms->get_permissions('password_set');
   860       $a = $perms->get_permissions('password_set');
   802     }
   861     }
   803     if ( $a && $perms->get_permissions('read') && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   862     if ( $a && $perms->get_permissions('read') && $local_page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   804     {
   863     {
   805       // label at start
   864       // label at start
   806       $label = $this->makeParserText($tplvars['toolbar_label']);
   865       $label = $this->makeParserText($tplvars['toolbar_label']);
   807       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_password')));
   866       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_password')));
   808       $t0 = $label->run();
   867       $t0 = $label->run();
   827         ));
   886         ));
   828       $this->toolbar_menu .= $menubtn->run();
   887       $this->toolbar_menu .= $menubtn->run();
   829     }
   888     }
   830     
   889     
   831     // Administer page button
   890     // Administer page button
   832     if ( $session->user_level >= USER_LEVEL_ADMIN && $paths->page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   891     if ( $session->user_level >= USER_LEVEL_ADMIN && $local_page_exists && $local_namespace != 'Special' && $local_namespace != 'Admin' )
   833     {
   892     {
   834       $menubtn->assign_vars(array(
   893       $menubtn->assign_vars(array(
   835           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxAdminPage()); return false; }" title="' . $lang->get('onpage_tip_adminoptions') . '" accesskey="g"',
   894           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxAdminPage()); return false; }" title="' . $lang->get('onpage_tip_adminoptions') . '" accesskey="g"',
   836           'HREF'  => makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'PageManager', true),
   895           'HREF'  => makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'PageManager', true),
   837           'TEXT'  => $lang->get('onpage_btn_admin'),
   896           'TEXT'  => $lang->get('onpage_btn_admin'),
   879     
   938     
   880     $this->tpl_bool['fixed_menus'] = false;
   939     $this->tpl_bool['fixed_menus'] = false;
   881     /* if($this->sidebar_extra == '') $this->tpl_bool['right_sidebar'] = false;
   940     /* if($this->sidebar_extra == '') $this->tpl_bool['right_sidebar'] = false;
   882     else */ $this->tpl_bool['right_sidebar'] = true;
   941     else */ $this->tpl_bool['right_sidebar'] = true;
   883     
   942     
   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');
   943     $this->tpl_bool['auth_rename'] = ( $local_page_exists && ( $perms->get_permissions('rename') && ( $paths->page_protected && $perms->get_permissions('even_when_protected') || !$paths->page_protected ) ) && $local_namespace != 'Special' && $local_namespace != 'Admin');
   885     
   944     
   886     $this->tpl_bool['enable_uploads'] = ( getConfig('enable_uploads') == '1' && $perms->get_permissions('upload_files') ) ? true : false;
   945     $this->tpl_bool['enable_uploads'] = ( getConfig('enable_uploads') == '1' && $perms->get_permissions('upload_files') ) ? true : false;
   887     
   946     
   888     $this->tpl_bool['stupid_mode'] = false;
   947     $this->tpl_bool['stupid_mode'] = false;
   889     
   948     
   939     
   998     
   940     $urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($local_fullpage)));
   999     $urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($local_fullpage)));
   941     $urlname_clean = strtr( $urlname_clean, array( '<' => '&lt;', '>' => '&gt;' ) );
  1000     $urlname_clean = strtr( $urlname_clean, array( '<' => '&lt;', '>' => '&gt;' ) );
   942     
  1001     
   943     $urlname_jssafe = sanitize_page_id($local_fullpage);
  1002     $urlname_jssafe = sanitize_page_id($local_fullpage);
       
  1003     $physical_urlname_jssafe = sanitize_page_id($paths->fullpage);
   944     
  1004     
   945     // Generate the dynamic javascript vars
  1005     // Generate the dynamic javascript vars
   946     $js_dynamic = '    <script type="text/javascript">// <![CDATA[
  1006     $js_dynamic = '    <script type="text/javascript">// <![CDATA[
   947       // This section defines some basic and very important variables that are used later in the static Javascript library.
  1007       // This section defines some basic and very important variables that are used later in the static Javascript library.
   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.
  1008       // 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.
   949       var title=\''. $urlname_jssafe .'\';
  1009       var title = \''. $urlname_jssafe .'\';
   950       var page_exists='. ( ( $paths->page_exists) ? 'true' : 'false' ) .';
  1010       var physical_title = \'' . $physical_urlname_jssafe . '\';
   951       var scriptPath=\''. scriptPath .'\';
  1011       var page_exists = '. ( ( $local_page_exists) ? 'true' : 'false' ) .';
   952       var contentPath=\''.contentPath.'\';
  1012       var scriptPath = \''. scriptPath .'\';
   953       var ENANO_SID =\'' . $SID . '\';
  1013       var contentPath = \''.contentPath.'\';
   954       var user_level=' . $session->user_level . ';
  1014       var ENANO_SID = \'' . $SID . '\';
   955       var auth_level=' . $session->auth_level . ';
  1015       var user_level = ' . $session->user_level . ';
       
  1016       var auth_level = ' . $session->auth_level . ';
   956       var USER_LEVEL_GUEST = ' . USER_LEVEL_GUEST . ';
  1017       var USER_LEVEL_GUEST = ' . USER_LEVEL_GUEST . ';
   957       var USER_LEVEL_MEMBER = ' . USER_LEVEL_MEMBER . ';
  1018       var USER_LEVEL_MEMBER = ' . USER_LEVEL_MEMBER . ';
   958       var USER_LEVEL_CHPREF = ' . USER_LEVEL_CHPREF . ';
  1019       var USER_LEVEL_CHPREF = ' . USER_LEVEL_CHPREF . ';
   959       var USER_LEVEL_MOD = ' . USER_LEVEL_MOD . ';
  1020       var USER_LEVEL_MOD = ' . USER_LEVEL_MOD . ';
   960       var USER_LEVEL_ADMIN = ' . USER_LEVEL_ADMIN . ';
  1021       var USER_LEVEL_ADMIN = ' . USER_LEVEL_ADMIN . ';
       
  1022       var disable_redirect = ' . ( isset($_GET['redirect']) && $_GET['redirect'] == 'no' ? 'true' : 'false' ) . ';
   961       var pref_disable_js_fx = ' . ( @$session->user_extra['disable_js_fx'] == 1 ? '1' : '0' ) . ';
  1023       var pref_disable_js_fx = ' . ( @$session->user_extra['disable_js_fx'] == 1 ? '1' : '0' ) . ';
   962       var csrf_token = "' . $session->csrf_token . '";
  1024       var csrf_token = "' . $session->csrf_token . '";
   963       var editNotice = \'' . ( (getConfig('wiki_edit_notice')=='1') ? str_replace("\n", "\\\n", RenderMan::render(getConfig('wiki_edit_notice_text'))) : '' ) . '\';
  1025       var editNotice = \'' . ( (getConfig('wiki_edit_notice')=='1') ? str_replace("\n", "\\\n", RenderMan::render(getConfig('wiki_edit_notice_text'))) : '' ) . '\';
   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
  1026       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
   965       var ENANO_SPECIAL_CREATEPAGE = \''. makeUrl($paths->nslist['Special'].'CreatePage') .'\';
  1027       var ENANO_SPECIAL_CREATEPAGE = \''. makeUrl($paths->nslist['Special'].'CreatePage') .'\';
   987         $js_dynamic .= "namespace_list['{$k}'] = '$c';";
  1049         $js_dynamic .= "namespace_list['{$k}'] = '$c';";
   988       }
  1050       }
   989       $js_dynamic .= "\n    //]]>\n    </script>";
  1051       $js_dynamic .= "\n    //]]>\n    </script>";
   990     
  1052     
   991     $tpl_strings = Array(
  1053     $tpl_strings = Array(
   992       'PAGE_NAME'=>htmlspecialchars($paths->cpage['name']),
  1054       'PAGE_NAME'=>htmlspecialchars($local_cdata['name']),
   993       'PAGE_URLNAME'=> $urlname_clean,
  1055       'PAGE_URLNAME'=> $urlname_clean,
   994       'SITE_NAME'=>htmlspecialchars(getConfig('site_name')),
  1056       'SITE_NAME'=>htmlspecialchars(getConfig('site_name')),
   995       'USERNAME'=>$session->username,
  1057       'USERNAME'=>$session->username,
   996       'SITE_DESC'=>htmlspecialchars(getConfig('site_desc')),
  1058       'SITE_DESC'=>htmlspecialchars(getConfig('site_desc')),
   997       'TOOLBAR'=>$tb,
  1059       'TOOLBAR'=>$tb,
  2036   
  2098   
  2037   $keywords = implode('|', $keywords);
  2099   $keywords = implode('|', $keywords);
  2038   
  2100   
  2039   // Matches
  2101   // Matches
  2040   //          1     2                 3                 4   56                       7     8        9
  2102   //          1     2                 3                 4   56                       7     8        9
  2041   $regexp = '/(<!-- ('. $keywords .') ([A-z0-9_-]+) -->)(.*)((<!-- BEGINELSE \\3 -->)(.*))?(<!-- END(IF)? \\3 -->)/isU';
  2103   $regexp = '/(<!-- ?(' . $keywords . ') ([A-z0-9_-]+) ?-->)([\w\W]*)((<!-- ?BEGINELSE \\3 ?-->)([\w\W]*))?(<!-- ?END(IF)? \\3 ?-->)/isU';
  2042   
  2104   
  2043   /*
  2105   /*
  2044   The way this works is: match all blocks using the standard form with a different keyword in the block each time,
  2106   The way this works is: match all blocks using the standard form with a different keyword in the block each time,
  2045   and replace them with appropriate PHP logic. Plugin-extensible now. :-)
  2107   and replace them with appropriate PHP logic. Plugin-extensible now. :-)
  2046   */
  2108   */
  2047   
  2109   
  2048   profiler_log("[template] compiler matchout start");
  2110   // This is a workaround for what seems like a PCRE bug
  2049   preg_match_all($regexp, $text, $matches);
  2111   while ( ( profiler_log("[template] compiler matchout start") || true ) && preg_match_all($regexp, $text, $matches) )
       
  2112   {
       
  2113   
  2050   profiler_log("[template] compiler core loop start");
  2114   profiler_log("[template] compiler core loop start");
  2051   for ( $i = 0; $i < count($matches[0]); $i++ )
  2115   for ( $i = 0; $i < count($matches[0]); $i++ )
  2052   {
  2116   {
  2053     $start_tag =& $matches[1][$i];
  2117     $start_tag =& $matches[1][$i];
  2054     $type =& $matches[2][$i];
  2118     $type =& $matches[2][$i];
  2103     }
  2167     }
  2104     echo '
  2168     echo '
  2105 TPLCODE;
  2169 TPLCODE;
  2106     
  2170     
  2107     $text = str_replace_once($matches[0][$i], $tag_complete, $text);
  2171     $text = str_replace_once($matches[0][$i], $tag_complete, $text);
       
  2172   }
  2108   }
  2173   }
  2109   
  2174   
  2110   profiler_log("[template] compiler core loop end");
  2175   profiler_log("[template] compiler core loop end");
  2111   
  2176   
  2112   // For debugging ;-)
  2177   // For debugging ;-)