includes/template.php
changeset 211 753dabeca1ee
parent 210 2b283402e4e4
child 212 30b857a6b811
equal deleted inserted replaced
210:2b283402e4e4 211:753dabeca1ee
   196     
   196     
   197     // Get the "article" button text (depends on namespace)
   197     // Get the "article" button text (depends on namespace)
   198     switch($paths->namespace) {
   198     switch($paths->namespace) {
   199       case "Article":
   199       case "Article":
   200       default:
   200       default:
   201         $ns = 'article';
   201         $ns = $lang->get('onpage_lbl_page_article');
   202         break;
   202         break;
   203       case "Admin":
   203       case "Admin":
   204         $ns = 'administration page';
   204         $ns = $lang->get('onpage_lbl_page_admin');
   205         break;
   205         break;
   206       case "System":
   206       case "System":
   207         $ns = 'system message';
   207         $ns = $lang->get('onpage_lbl_page_system');
   208         break;
   208         break;
   209       case "File":
   209       case "File":
   210         $ns = 'uploaded file';
   210         $ns = $lang->get('onpage_lbl_page_file');
   211         break;
   211         break;
   212       case "Help":
   212       case "Help":
   213         $ns = 'documentation page';
   213         $ns = $lang->get('onpage_lbl_page_help');
   214         break;
   214         break;
   215       case "User":
   215       case "User":
   216         $ns = 'user page';
   216         $ns = $lang->get('onpage_lbl_page_user');
   217         break;
   217         break;
   218       case "Special":
   218       case "Special":
   219         $ns = 'special page';
   219         $ns = $lang->get('onpage_lbl_page_special');
   220         break;
   220         break;
   221       case "Template":
   221       case "Template":
   222         $ns = 'template';
   222         $ns = $lang->get('onpage_lbl_page_template');
   223         break;
   223         break;
   224       case "Project":
   224       case "Project":
   225         $ns = 'project page';
   225         $ns = $lang->get('onpage_lbl_page_project');
   226         break;
   226         break;
   227       case "Category":
   227       case "Category":
   228         $ns = 'category';
   228         $ns = $lang->get('onpage_lbl_page_category');
   229         break;
   229         break;
   230     }
   230     }
   231     $this->namespace_string = $ns;
   231     $this->namespace_string = $ns;
       
   232     unset($ns);
   232     $code = $plugins->setHook('page_type_string_set');
   233     $code = $plugins->setHook('page_type_string_set');
   233     foreach ( $code as $cmd )
   234     foreach ( $code as $cmd )
   234     {
   235     {
   235       eval($cmd);
   236       eval($cmd);
   236     }
   237     }
   283       
   284       
   284       $db->free_result();
   285       $db->free_result();
   285       $n = ( $session->get_permissions('mod_comments') ) ? (string)$nc : (string)$na;
   286       $n = ( $session->get_permissions('mod_comments') ) ? (string)$nc : (string)$na;
   286       if ( $session->get_permissions('mod_comments') && $nu > 0 )
   287       if ( $session->get_permissions('mod_comments') && $nu > 0 )
   287       {
   288       {
   288         $n .= ' total/'.$nu.' unapp.';
   289         $subst = array(
       
   290             'num_comments' => $nc,
       
   291             'num_unapp' => $nu
       
   292           );
       
   293         $btn_text = $lang->get('onpage_btn_discussion_unapp', $subst);
       
   294       }
       
   295       else
       
   296       {
       
   297         $subst = array(
       
   298           'num_comments' => $nc
       
   299         );
       
   300         $btn_text = $lang->get('onpage_btn_discussion', $subst);
   289       }
   301       }
   290       
   302       
   291       $button->assign_vars(array(
   303       $button->assign_vars(array(
   292           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxComments()); return false; }" title="View the comments that other users have posted about this page (alt-c)" accesskey="c"',
   304           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxComments()); return false; }" title="View the comments that other users have posted about this page (alt-c)" accesskey="c"',
   293           'PARENTFLAGS' => 'id="mdgToolbar_discussion"',
   305           'PARENTFLAGS' => 'id="mdgToolbar_discussion"',
   294           'HREF' => makeUrl($paths->page, 'do=comments', true),
   306           'HREF' => makeUrl($paths->page, 'do=comments', true),
   295           'TEXT' => 'discussion ('.$n.')',
   307           'TEXT' => $btn_text,
   296         ));
   308         ));
   297       
   309       
   298       $tb .= $button->run();
   310       $tb .= $button->run();
   299     }
   311     }
   300     // Edit button
   312     // Edit button
   302     {
   314     {
   303       $button->assign_vars(array(
   315       $button->assign_vars(array(
   304         'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="Edit the contents of this page (alt-e)" accesskey="e"',
   316         'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="Edit the contents of this page (alt-e)" accesskey="e"',
   305         'PARENTFLAGS' => 'id="mdgToolbar_edit"',
   317         'PARENTFLAGS' => 'id="mdgToolbar_edit"',
   306         'HREF' => makeUrl($paths->page, 'do=edit', true),
   318         'HREF' => makeUrl($paths->page, 'do=edit', true),
   307         'TEXT' => 'edit this page'
   319         'TEXT' => $lang->get('onpage_btn_edit')
   308         ));
   320         ));
   309       $tb .= $button->run();
   321       $tb .= $button->run();
   310     // View source button
   322     // View source button
   311     }
   323     }
   312     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') 
   324     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') 
   313     {
   325     {
   314       $button->assign_vars(array(
   326       $button->assign_vars(array(
   315         'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxViewSource()); return false; }" title="View the source code (wiki markup) that this page uses (alt-e)" accesskey="e"',
   327         'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxViewSource()); return false; }" title="View the source code (wiki markup) that this page uses (alt-e)" accesskey="e"',
   316         'PARENTFLAGS' => 'id="mdgToolbar_edit"',
   328         'PARENTFLAGS' => 'id="mdgToolbar_edit"',
   317         'HREF' => makeUrl($paths->page, 'do=viewsource', true),
   329         'HREF' => makeUrl($paths->page, 'do=viewsource', true),
   318         'TEXT' => 'view source'
   330         'TEXT' => $lang->get('onpage_btn_viewsource')
   319         ));
   331         ));
   320       $tb .= $button->run();
   332       $tb .= $button->run();
   321     }
   333     }
   322     // History button
   334     // History button
   323     if ( $session->get_permissions('read') /* && $paths->wiki_mode */ && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $session->get_permissions('history_view') )
   335     if ( $session->get_permissions('read') /* && $paths->wiki_mode */ && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $session->get_permissions('history_view') )
   324     {
   336     {
   325       $button->assign_vars(array(
   337       $button->assign_vars(array(
   326         'FLAGS'       => 'onclick="if ( !KILL_SWITCH ) { void(ajaxHistory()); return false; }" title="View a log of actions taken on this page (alt-h)" accesskey="h"',
   338         'FLAGS'       => 'onclick="if ( !KILL_SWITCH ) { void(ajaxHistory()); return false; }" title="View a log of actions taken on this page (alt-h)" accesskey="h"',
   327         'PARENTFLAGS' => 'id="mdgToolbar_history"',
   339         'PARENTFLAGS' => 'id="mdgToolbar_history"',
   328         'HREF'        => makeUrl($paths->page, 'do=history', true),
   340         'HREF'        => makeUrl($paths->page, 'do=history', true),
   329         'TEXT'        => 'history'
   341         'TEXT'        => $lang->get('onpage_btn_history')
   330         ));
   342         ));
   331       $tb .= $button->run();
   343       $tb .= $button->run();
   332     }
   344     }
   333     
   345     
   334     $menubtn = $this->makeParserText($tplvars['toolbar_menu_button']);
   346     $menubtn = $this->makeParserText($tplvars['toolbar_menu_button']);
   338     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' )
   350     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' )
   339     {
   351     {
   340       $menubtn->assign_vars(array(
   352       $menubtn->assign_vars(array(
   341           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxRename()); return false; }" title="Change the display name of this page (alt-r)" accesskey="r"',
   353           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxRename()); return false; }" title="Change the display name of this page (alt-r)" accesskey="r"',
   342           'HREF'  => makeUrl($paths->page, 'do=rename', true),
   354           'HREF'  => makeUrl($paths->page, 'do=rename', true),
   343           'TEXT'  => 'rename',
   355           'TEXT'  => $lang->get('onpage_btn_rename'),
   344         ));
   356         ));
   345       $this->toolbar_menu .= $menubtn->run();
   357       $this->toolbar_menu .= $menubtn->run();
   346     }
   358     }
   347     
   359     
   348     // Vote-to-delete button
   360     // Vote-to-delete button
   349     if ( $paths->wiki_mode && $session->get_permissions('vote_delete') && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin')
   361     if ( $paths->wiki_mode && $session->get_permissions('vote_delete') && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin')
   350     {
   362     {
   351       $menubtn->assign_vars(array(
   363       $menubtn->assign_vars(array(
   352           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDelVote()); return false; }" title="Vote to have this page deleted (alt-d)" accesskey="d"',
   364           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDelVote()); return false; }" title="Vote to have this page deleted (alt-d)" accesskey="d"',
   353           'HREF'  => makeUrl($paths->page, 'do=delvote', true),
   365           'HREF'  => makeUrl($paths->page, 'do=delvote', true),
   354           'TEXT'  => 'vote to delete this page',
   366           'TEXT'  => $lang->get('onpage_btn_votedelete'),
   355         ));
   367         ));
   356       $this->toolbar_menu .= $menubtn->run();
   368       $this->toolbar_menu .= $menubtn->run();
   357     }
   369     }
   358     
   370     
   359     // Clear-votes button
   371     // Clear-votes button
   360     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)
   372     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)
   361     {
   373     {
   362       $menubtn->assign_vars(array(
   374       $menubtn->assign_vars(array(
   363           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxResetDelVotes()); return false; }" title="Vote to have this page deleted (alt-y)" accesskey="y"',
   375           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxResetDelVotes()); return false; }" title="Vote to have this page deleted (alt-y)" accesskey="y"',
   364           'HREF'  => makeUrl($paths->page, 'do=resetvotes', true),
   376           'HREF'  => makeUrl($paths->page, 'do=resetvotes', true),
   365           'TEXT'  => 'reset deletion votes',
   377           'TEXT'  => $lang->get('onpage_btn_votedelete_reset'),
   366         ));
   378         ));
   367       $this->toolbar_menu .= $menubtn->run();
   379       $this->toolbar_menu .= $menubtn->run();
   368     }
   380     }
   369     
   381     
   370     // Printable page button
   382     // Printable page button
   371     if ( $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   383     if ( $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   372     {
   384     {
   373       $menubtn->assign_vars(array(
   385       $menubtn->assign_vars(array(
   374           'FLAGS' => 'title="View a version of this page that is suitable for printing"',
   386           'FLAGS' => 'title="View a version of this page that is suitable for printing"',
   375           'HREF'  => makeUrl($paths->page, 'printable=yes', true),
   387           'HREF'  => makeUrl($paths->page, 'printable=yes', true),
   376           'TEXT'  => 'view printable version',
   388           'TEXT'  => $lang->get('onpage_btn_printable'),
   377         ));
   389         ));
   378       $this->toolbar_menu .= $menubtn->run();
   390       $this->toolbar_menu .= $menubtn->run();
   379     }
   391     }
   380     
   392     
   381     // Protect button
   393     // Protect button
   382     if($session->get_permissions('read') && $paths->wiki_mode && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $session->get_permissions('protect'))
   394     if($session->get_permissions('read') && $paths->wiki_mode && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' && $session->get_permissions('protect'))
   383     {
   395     {
   384       
   396       
   385       $label = $this->makeParserText($tplvars['toolbar_label']);
   397       $label = $this->makeParserText($tplvars['toolbar_label']);
   386       $label->assign_vars(array('TEXT' => 'protection:'));
   398       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_protect')));
   387       $t0 = $label->run();
   399       $t0 = $label->run();
   388       
   400       
   389       $ctmp = ''; 
   401       $ctmp = ''; 
   390       if ( $paths->cpage['protected'] == 1 )
   402       if ( $paths->cpage['protected'] == 1 )
   391       {
   403       {
   392         $ctmp=' style="text-decoration: underline;"';
   404         $ctmp=' style="text-decoration: underline;"';
   393       }
   405       }
   394       $menubtn->assign_vars(array(
   406       $menubtn->assign_vars(array(
   395           'FLAGS' => 'accesskey="i" onclick="if ( !KILL_SWITCH ) { ajaxProtect(1); return false; }" id="protbtn_1" title="Prevents all non-administrators from editing this page. [alt-i]"'.$ctmp,
   407           'FLAGS' => 'accesskey="i" onclick="if ( !KILL_SWITCH ) { ajaxProtect(1); return false; }" id="protbtn_1" title="Prevents all non-administrators from editing this page. [alt-i]"'.$ctmp,
   396           'HREF'  => makeUrl($paths->page, 'do=protect&level=1', true),
   408           'HREF'  => makeUrl($paths->page, 'do=protect&level=1', true),
   397           'TEXT'  => 'on'
   409           'TEXT'  => $lang->get('onpage_btn_protect_on')
   398         ));
   410         ));
   399       $t1 = $menubtn->run();
   411       $t1 = $menubtn->run();
   400       
   412       
   401       $ctmp = '';
   413       $ctmp = '';
   402       if ( $paths->cpage['protected'] == 0 )
   414       if ( $paths->cpage['protected'] == 0 )
   404         $ctmp=' style="text-decoration: underline;"';
   416         $ctmp=' style="text-decoration: underline;"';
   405       }
   417       }
   406       $menubtn->assign_vars(array(
   418       $menubtn->assign_vars(array(
   407           'FLAGS' => 'accesskey="o" onclick="if ( !KILL_SWITCH ) { ajaxProtect(0); return false; }" id="protbtn_0" title="Allows everyone to edit this page. [alt-o]"'.$ctmp,
   419           'FLAGS' => 'accesskey="o" onclick="if ( !KILL_SWITCH ) { ajaxProtect(0); return false; }" id="protbtn_0" title="Allows everyone to edit this page. [alt-o]"'.$ctmp,
   408           'HREF'  => makeUrl($paths->page, 'do=protect&level=0', true),
   420           'HREF'  => makeUrl($paths->page, 'do=protect&level=0', true),
   409           'TEXT'  => 'off'
   421           'TEXT'  => $lang->get('onpage_btn_protect_off')
   410         ));
   422         ));
   411       $t2 = $menubtn->run();
   423       $t2 = $menubtn->run();
   412       
   424       
   413       $ctmp = '';
   425       $ctmp = '';
   414       if ( $paths->cpage['protected'] == 2 )
   426       if ( $paths->cpage['protected'] == 2 )
   416         $ctmp = ' style="text-decoration: underline;"';
   428         $ctmp = ' style="text-decoration: underline;"';
   417       }
   429       }
   418       $menubtn->assign_vars(array(
   430       $menubtn->assign_vars(array(
   419           'FLAGS' => 'accesskey="p" onclick="if ( !KILL_SWITCH ) { ajaxProtect(2); return false; }" id="protbtn_2" title="Allows only users who have been registered for 4 days to edit this page. [alt-p]"'.$ctmp,
   431           'FLAGS' => 'accesskey="p" onclick="if ( !KILL_SWITCH ) { ajaxProtect(2); return false; }" id="protbtn_2" title="Allows only users who have been registered for 4 days to edit this page. [alt-p]"'.$ctmp,
   420           'HREF'  => makeUrl($paths->page, 'do=protect&level=2', true),
   432           'HREF'  => makeUrl($paths->page, 'do=protect&level=2', true),
   421           'TEXT'  => 'semi'
   433           'TEXT'  => $lang->get('onpage_btn_protect_semi')
   422         ));
   434         ));
   423       $t3 = $menubtn->run();
   435       $t3 = $menubtn->run();
   424       
   436       
   425       $this->toolbar_menu .= '        <table border="0" cellspacing="0" cellpadding="0">
   437       $this->toolbar_menu .= '        <table border="0" cellspacing="0" cellpadding="0">
   426           <tr>
   438           <tr>
   435     // Wiki mode button
   447     // Wiki mode button
   436     if($session->get_permissions('read') && $paths->page_exists && $session->get_permissions('set_wiki_mode') && $paths->namespace != 'Special' && $paths->namespace != 'Admin')
   448     if($session->get_permissions('read') && $paths->page_exists && $session->get_permissions('set_wiki_mode') && $paths->namespace != 'Special' && $paths->namespace != 'Admin')
   437     {
   449     {
   438       // label at start
   450       // label at start
   439       $label = $this->makeParserText($tplvars['toolbar_label']);
   451       $label = $this->makeParserText($tplvars['toolbar_label']);
   440       $label->assign_vars(array('TEXT' => 'page wiki mode:'));
   452       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_wikimode')));
   441       $t0 = $label->run();
   453       $t0 = $label->run();
   442       
   454       
   443       // on button
   455       // on button
   444       $ctmp = '';
   456       $ctmp = '';
   445       if ( $paths->cpage['wiki_mode'] == 1 )
   457       if ( $paths->cpage['wiki_mode'] == 1 )
   447         $ctmp = ' style="text-decoration: underline;"';
   459         $ctmp = ' style="text-decoration: underline;"';
   448       }
   460       }
   449       $menubtn->assign_vars(array(
   461       $menubtn->assign_vars(array(
   450           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(1); return false; }" id="wikibtn_1" title="Forces wiki functions to be allowed on this page."'. */ $ctmp,
   462           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(1); return false; }" id="wikibtn_1" title="Forces wiki functions to be allowed on this page."'. */ $ctmp,
   451           'HREF' => makeUrl($paths->page, 'do=setwikimode&level=1', true),
   463           'HREF' => makeUrl($paths->page, 'do=setwikimode&level=1', true),
   452           'TEXT' => 'on'
   464           'TEXT' => $lang->get('onpage_btn_wikimode_on')
   453         ));
   465         ));
   454       $t1 = $menubtn->run();
   466       $t1 = $menubtn->run();
   455       
   467       
   456       // off button
   468       // off button
   457       $ctmp = '';
   469       $ctmp = '';
   460         $ctmp=' style="text-decoration: underline;"';
   472         $ctmp=' style="text-decoration: underline;"';
   461       }
   473       }
   462       $menubtn->assign_vars(array(
   474       $menubtn->assign_vars(array(
   463           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(0); return false; }" id="wikibtn_0" title="Forces wiki functions to be disabled on this page."'. */ $ctmp,
   475           'FLAGS' => /* 'onclick="if ( !KILL_SWITCH ) { ajaxSetWikiMode(0); return false; }" id="wikibtn_0" title="Forces wiki functions to be disabled on this page."'. */ $ctmp,
   464           'HREF' => makeUrl($paths->page, 'do=setwikimode&level=0', true),
   476           'HREF' => makeUrl($paths->page, 'do=setwikimode&level=0', true),
   465           'TEXT' => 'off'
   477           'TEXT' => $lang->get('onpage_btn_wikimode_off')
   466         ));
   478         ));
   467       $t2 = $menubtn->run();
   479       $t2 = $menubtn->run();
   468       
   480       
   469       // global button
   481       // global button
   470       $ctmp = ''; 
   482       $ctmp = ''; 
   473         $ctmp=' style="text-decoration: underline;"';
   485         $ctmp=' style="text-decoration: underline;"';
   474       }
   486       }
   475       $menubtn->assign_vars(array(
   487       $menubtn->assign_vars(array(
   476           '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,
   488           '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,
   477           'HREF' => makeUrl($paths->page, 'do=setwikimode&level=2', true),
   489           'HREF' => makeUrl($paths->page, 'do=setwikimode&level=2', true),
   478           'TEXT' => 'global'
   490           'TEXT' => $lang->get('onpage_btn_wikimode_global')
   479         ));
   491         ));
   480       $t3 = $menubtn->run();
   492       $t3 = $menubtn->run();
   481       
   493       
   482       // Tack it onto the list of buttons that are already there...
   494       // Tack it onto the list of buttons that are already there...
   483       $this->toolbar_menu .= '        <table border="0" cellspacing="0" cellpadding="0">
   495       $this->toolbar_menu .= '        <table border="0" cellspacing="0" cellpadding="0">
   494     if ( $session->get_permissions('read') && $session->get_permissions('clear_logs') && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   506     if ( $session->get_permissions('read') && $session->get_permissions('clear_logs') && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   495     {
   507     {
   496       $menubtn->assign_vars(array(
   508       $menubtn->assign_vars(array(
   497           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxClearLogs()); return false; }" title="Remove all edit and action logs for this page from the database. IRREVERSIBLE! (alt-l)" accesskey="l"',
   509           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxClearLogs()); return false; }" title="Remove all edit and action logs for this page from the database. IRREVERSIBLE! (alt-l)" accesskey="l"',
   498           'HREF'  => makeUrl($paths->page, 'do=flushlogs', true),
   510           'HREF'  => makeUrl($paths->page, 'do=flushlogs', true),
   499           'TEXT'  => 'clear page logs',
   511           'TEXT'  => $lang->get('onpage_btn_clearlogs'),
   500         ));
   512         ));
   501       $this->toolbar_menu .= $menubtn->run();
   513       $this->toolbar_menu .= $menubtn->run();
   502     }
   514     }
   503     
   515     
   504     // Delete page button
   516     // Delete page button
   505     if ( $session->get_permissions('read') && $session->get_permissions('delete_page') && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   517     if ( $session->get_permissions('read') && $session->get_permissions('delete_page') && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   506     {
   518     {
   507       $s = 'delete this page';
   519       $s = $lang->get('onpage_btn_deletepage');
   508       if ( $paths->cpage['delvotes'] == 1 )
   520       if ( $paths->cpage['delvotes'] == 1 )
   509       {
   521       {
   510         $s .= ' (<b>'.$paths->cpage['delvotes'].'</b> vote)';
   522         $subst = array(
       
   523           'num_votes' => $paths->cpage['delvotes'],
       
   524           'plural' => ''
       
   525           );
       
   526         $s .= $lang->get('onpage_btn_deletepage_votes', $subst);
   511       }
   527       }
   512       else if ( $paths->cpage['delvotes'] > 1 )
   528       else if ( $paths->cpage['delvotes'] > 1 )
   513       {
   529       {
   514         $s .= ' (<b>'.$paths->cpage['delvotes'].'</b> votes)';
   530         $subst = array(
       
   531           'num_votes' => $paths->cpage['delvotes'],
       
   532           'plural' => $lang->get('meta_plural')
       
   533           );
       
   534         $s .= $lang->get('onpage_btn_deletepage_votes', $subst);
   515       }
   535       }
   516       
   536       
   517       $menubtn->assign_vars(array(
   537       $menubtn->assign_vars(array(
   518           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDeletePage()); return false; }" title="Delete this page. This is always reversible unless the logs are cleared. (alt-k)" accesskey="k"',
   538           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDeletePage()); return false; }" title="Delete this page. This is always reversible unless the logs are cleared. (alt-k)" accesskey="k"',
   519           'HREF'  => makeUrl($paths->page, 'do=deletepage', true),
   539           'HREF'  => makeUrl($paths->page, 'do=deletepage', true),
   541     }
   561     }
   542     if ( $a && $session->get_permissions('read') && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   562     if ( $a && $session->get_permissions('read') && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   543     {
   563     {
   544       // label at start
   564       // label at start
   545       $label = $this->makeParserText($tplvars['toolbar_label']);
   565       $label = $this->makeParserText($tplvars['toolbar_label']);
   546       $label->assign_vars(array('TEXT' => 'page password:'));
   566       $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_password')));
   547       $t0 = $label->run();
   567       $t0 = $label->run();
   548       
   568       
   549       $menubtn->assign_vars(array(
   569       $menubtn->assign_vars(array(
   550           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxSetPassword()); return false; }" title="Require a password in order for this page to be viewed"',
   570           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxSetPassword()); return false; }" title="Require a password in order for this page to be viewed"',
   551           'HREF'  => '#',
   571           'HREF'  => '#',
   552           'TEXT'  => 'set',
   572           'TEXT'  => $lang->get('onpage_btn_password_set'),
   553         ));
   573         ));
   554       $t = $menubtn->run();
   574       $t = $menubtn->run();
   555       
   575       
   556       $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>';
   576       $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>';
   557     }
   577     }
   560     if($session->get_permissions('edit_acl') || $session->user_level >= USER_LEVEL_ADMIN)
   580     if($session->get_permissions('edit_acl') || $session->user_level >= USER_LEVEL_ADMIN)
   561     {
   581     {
   562       $menubtn->assign_vars(array(
   582       $menubtn->assign_vars(array(
   563           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { return ajaxOpenACLManager(); }" title="Manage who can do what with this page (alt-m)" accesskey="m"',
   583           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { return ajaxOpenACLManager(); }" title="Manage who can do what with this page (alt-m)" accesskey="m"',
   564           'HREF'  => makeUrl($paths->page, 'do=aclmanager', true),
   584           'HREF'  => makeUrl($paths->page, 'do=aclmanager', true),
   565           'TEXT'  => 'manage page access',
   585           'TEXT'  => $lang->get('onpage_btn_acl'),
   566         ));
   586         ));
   567       $this->toolbar_menu .= $menubtn->run();
   587       $this->toolbar_menu .= $menubtn->run();
   568     }
   588     }
   569     
   589     
   570     // Administer page button
   590     // Administer page button
   571     if ( $session->user_level >= USER_LEVEL_ADMIN && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   591     if ( $session->user_level >= USER_LEVEL_ADMIN && $paths->page_exists && $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
   572     {
   592     {
   573       $menubtn->assign_vars(array(
   593       $menubtn->assign_vars(array(
   574           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxAdminPage()); return false; }" title="Administrative options for this page" accesskey="g"',
   594           'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxAdminPage()); return false; }" title="Administrative options for this page" accesskey="g"',
   575           'HREF'  => makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'PageManager', true),
   595           'HREF'  => makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'PageManager', true),
   576           'TEXT'  => 'administrative options',
   596           'TEXT'  => $lang->get('onpage_btn_admin'),
   577         ));
   597         ));
   578       $this->toolbar_menu .= $menubtn->run();
   598       $this->toolbar_menu .= $menubtn->run();
   579     }
   599     }
   580     
   600     
   581     if ( strlen($this->toolbar_menu) > 0 )
   601     if ( strlen($this->toolbar_menu) > 0 )
   582     {
   602     {
   583       $button->assign_vars(array(
   603       $button->assign_vars(array(
   584         'FLAGS'       => 'id="mdgToolbar_moreoptions" onclick="if ( !KILL_SWITCH ) { return false; }" title="Additional options for working with this page"',
   604         'FLAGS'       => 'id="mdgToolbar_moreoptions" onclick="if ( !KILL_SWITCH ) { return false; }" title="Additional options for working with this page"',
   585         'PARENTFLAGS' => '',
   605         'PARENTFLAGS' => '',
   586         'HREF'        => makeUrl($paths->page, 'do=moreoptions', true),
   606         'HREF'        => makeUrl($paths->page, 'do=moreoptions', true),
   587         'TEXT'        => 'more options'
   607         'TEXT'        => $lang->get('onpage_btn_moreoptions')
   588         ));
   608         ));
   589       $tb .= $button->run();
   609       $tb .= $button->run();
   590     }
   610     }
   591     
   611     
   592     $is_opera = (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'Opera')) ? true : false;
   612     $is_opera = (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'Opera')) ? true : false;
  1143       // $md5 will be set by the cached file
  1163       // $md5 will be set by the cached file
  1144       // This makes sure that a cached copy of the template is used only if its MD5
  1164       // This makes sure that a cached copy of the template is used only if its MD5
  1145       // matches the MD5 of the file that the compiled file was compiled from.
  1165       // matches the MD5 of the file that the compiled file was compiled from.
  1146       if ( isset($md5) && $md5 == md5($text) )
  1166       if ( isset($md5) && $md5 == md5($text) )
  1147       {
  1167       {
  1148         return str_replace('\\"', '"', $tpl_text);
  1168         return $this->compile_template_text_post(str_replace('\\"', '"', $tpl_text));
  1149       }
  1169       }
  1150     }
  1170     }
  1151     
  1171     
  1152     // We won't use the cached copy here
  1172     // We won't use the cached copy here
  1153     $text = file_get_contents($tpl_file_fullpath);
  1173     $text = file_get_contents($tpl_file_fullpath);
  1182       // $tpl_text actually will contain the compiled code
  1202       // $tpl_text actually will contain the compiled code
  1183       fwrite($h, '<?php ' . $notice . ' $md5 = \'' . $md5 . '\'; $tpl_text = \'' . $text_escaped . '\'; ?>');
  1203       fwrite($h, '<?php ' . $notice . ' $md5 = \'' . $md5 . '\'; $tpl_text = \'' . $text_escaped . '\'; ?>');
  1184       fclose($h);
  1204       fclose($h);
  1185     }
  1205     }
  1186     
  1206     
  1187     return $text; //('<pre>'.htmlspecialchars($text).'</pre>');
  1207     return $this->compile_template_text_post($text); //('<pre>'.htmlspecialchars($text).'</pre>');
  1188   }
  1208   }
  1189   
  1209   
  1190   
  1210   
  1191   /**
  1211   /**
  1192    * Compiles (parses) some template code with the current master set of variables and booleans.
  1212    * Compiles (parses) some template code with the current master set of variables and booleans.
  1195    */
  1215    */
  1196   
  1216   
  1197   function compile_template_text($text)
  1217   function compile_template_text($text)
  1198   {
  1218   {
  1199     // this might do something else in the future, possibly cache large templates
  1219     // this might do something else in the future, possibly cache large templates
  1200     return $this->compile_tpl_code($text);
  1220     return $this->compile_template_text_post($this->compile_tpl_code($text));
  1201   }
  1221   }
  1202   
  1222   
  1203   /**
  1223   /**
  1204    * For convenience - compiles AND parses some template code.
  1224    * For convenience - compiles AND parses some template code.
  1205    * @param string Text to process
  1225    * @param string Text to process
  1207    */
  1227    */
  1208   
  1228   
  1209   function parse($text)
  1229   function parse($text)
  1210   {
  1230   {
  1211     $text = $this->compile_template_text($text);
  1231     $text = $this->compile_template_text($text);
       
  1232     $text = $this->compile_template_text_post($text);
  1212     return eval($text);
  1233     return eval($text);
       
  1234   }
       
  1235   
       
  1236   /**
       
  1237    * Post-processor for template code. Basically what this does is it localizes {lang:foo} blocks.
       
  1238    * @param string Mostly-processed TPL code
       
  1239    * @return string
       
  1240    */
       
  1241   
       
  1242   function compile_template_text_post($text)
       
  1243   {
       
  1244     global $lang;
       
  1245     preg_match_all('/\{lang:([a-z0-9]+_[a-z0-9_]+)\}/', $text, $matches);
       
  1246     foreach ( $matches[1] as $i => $string_id )
       
  1247     {
       
  1248       $string = $lang->get($string_id);
       
  1249       $string = str_replace('\\', '\\\\', $string);
       
  1250       $string = str_replace('\'', '\\\'', $string);
       
  1251       $text = str_replace_once($matches[0][$i], $string, $text);
       
  1252     }
       
  1253     return $text;
  1213   }
  1254   }
  1214   
  1255   
  1215   // Steps to turn this:
  1256   // Steps to turn this:
  1216   //   [[Project:Community Portal]]
  1257   //   [[Project:Community Portal]]
  1217   // into this:
  1258   // into this: