includes/pageprocess.php
changeset 229 97ae8e9d5e29
parent 147 d8156d18ac58
parent 166 d53cc29308f4
child 304 e2cb5f1432c8
equal deleted inserted replaced
147:d8156d18ac58 229:97ae8e9d5e29
     1 <?php
     1 <?php
     2 
     2 
     3 /*
     3 /*
     4  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
     4  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
     5  * Version 1.0.1 (Loch Ness)
     5  * Version 1.1.1
     6  * pageprocess.php - intelligent retrieval of pages
     6  * pageprocess.php - intelligent retrieval of pages
     7  * Copyright (C) 2006-2007 Dan Fuhry
     7  * Copyright (C) 2006-2007 Dan Fuhry
     8  *
     8  *
     9  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
     9  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
    10  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    10  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
   210                 <p>$message</p>";
   210                 <p>$message</p>";
   211         }
   211         }
   212         return false;
   212         return false;
   213       }
   213       }
   214     }
   214     }
   215     else if ( $this->namespace == 'User' )
   215     else if ( $this->namespace == 'User' && strpos($this->page_id, '/') === false )
   216     {
   216     {
   217       $this->_handle_userpage();
   217       $this->_handle_userpage();
   218     }
   218     }
   219     else if ( ( $this->namespace == 'Template' || $this->namespace == 'System' ) && $this->page_exists )
   219     else if ( ( $this->namespace == 'Template' || $this->namespace == 'System' ) && $this->page_exists )
   220     {
   220     {
   369   function render($incl_inner_headers = true, $_errormsg = false)
   369   function render($incl_inner_headers = true, $_errormsg = false)
   370   {
   370   {
   371     global $db, $session, $paths, $template, $plugins; // Common objects
   371     global $db, $session, $paths, $template, $plugins; // Common objects
   372     
   372     
   373     $text = $this->fetch_text();
   373     $text = $this->fetch_text();
       
   374     $text = preg_replace('/([\s]*)__NOBREADCRUMBS__([\s]*)/', '', $text);
       
   375     $text = preg_replace('/([\s]*)__NOTOC__([\s]*)/', '', $text);
   374     
   376     
   375     $redir_enabled = false;
   377     $redir_enabled = false;
   376     if ( preg_match('/^#redirect \[\[([^\]]+?)\]\]/i', $text, $match ) )
   378     if ( preg_match('/^#redirect \[\[([^\]]+?)\]\]/i', $text, $match ) )
   377     {
   379     {
   378       $redir_enabled = true;
   380       $redir_enabled = true;
   416     }
   418     }
   417     
   419     
   418     $template->tpl_strings['PAGE_NAME'] = htmlspecialchars( $this->title );
   420     $template->tpl_strings['PAGE_NAME'] = htmlspecialchars( $this->title );
   419     
   421     
   420     $this->header();
   422     $this->header();
       
   423     $this->do_breadcrumbs();
   421     
   424     
   422     if ( $_errormsg )
   425     if ( $_errormsg )
   423     {
   426     {
   424       echo $_errormsg;
   427       echo $_errormsg;
   425     }
   428     }
   629         '<' => '&lt;',
   632         '<' => '&lt;',
   630         '>' => '&gt;'
   633         '>' => '&gt;'
   631         ));
   634         ));
   632     
   635     
   633     $target_username = preg_replace('/^' . preg_quote($paths->nslist['User']) . '/', '', $target_username);
   636     $target_username = preg_replace('/^' . preg_quote($paths->nslist['User']) . '/', '', $target_username);
       
   637     $target_username = explode('/', $target_username);
       
   638     $target_username = $target_username[0];
   634     
   639     
   635     if ( ( $page_name == str_replace('_', ' ', $this->page_id) || $page_name == $paths->nslist['User'] . str_replace('_', ' ', $this->page_id) ) || !$this->page_exists )
   640     if ( ( $page_name == str_replace('_', ' ', $this->page_id) || $page_name == $paths->nslist['User'] . str_replace('_', ' ', $this->page_id) ) || !$this->page_exists )
   636     {
   641     {
   637       $page_name = "$target_username's user page";
   642       $page_name = "$target_username's user page";
   638     }
   643     }
   702     if ( !empty($userdata['real_name']) )
   707     if ( !empty($userdata['real_name']) )
   703     {
   708     {
   704       echo '<tr><td class="row3">Real name: ' . $userdata['real_name'] . '</td></tr>';
   709       echo '<tr><td class="row3">Real name: ' . $userdata['real_name'] . '</td></tr>';
   705     }
   710     }
   706     
   711     
       
   712     // Administer user button
       
   713     
       
   714     if ( $session->user_level >= USER_LEVEL_ADMIN )
       
   715     {
       
   716       echo '<tr><td class="row1"><a href="' . makeUrlNS('Special', 'Administration', 'module=' . $paths->nslist['Admin'] . 'UserManager&src=get&user=' . urlencode($target_username), true) . '" onclick="ajaxAdminUser(\'' . addslashes($target_username) . '\'); return false;">Administer user</a></td></tr>';
       
   717     }
       
   718     
   707     // Comments
   719     // Comments
   708     
   720     
   709     echo '<tr><th class="subhead">' . htmlspecialchars($target_username) . '\'s latest comments</th></tr>';
   721     echo '<tr><th class="subhead">' . htmlspecialchars($target_username) . '\'s latest comments</th></tr>';
   710     $q = $db->sql_query('SELECT page_id, namespace, subject, time FROM '.table_prefix.'comments WHERE name=\'' . $db->escape($target_username) . '\' AND user_id=' . $userdata['authoritative_uid'] . ' AND approved=1 ORDER BY time DESC LIMIT 5;');
   722     $q = $db->sql_query('SELECT page_id, namespace, subject, time FROM '.table_prefix.'comments WHERE name=\'' . $db->escape($target_username) . '\' AND user_id=' . $userdata['authoritative_uid'] . ' AND approved=1 ORDER BY time DESC LIMIT 5;');
   711     if ( !$q )
   723     if ( !$q )
   928    * @access private
   940    * @access private
   929    */
   941    */
   930   
   942   
   931   function _handle_redirect($page_id, $namespace)
   943   function _handle_redirect($page_id, $namespace)
   932   {
   944   {
       
   945     global $db, $session, $paths, $template, $plugins; // Common objects
   933     $arr_pid = array($this->page_id, $this->namespace);
   946     $arr_pid = array($this->page_id, $this->namespace);
   934     if ( $namespace == 'Special' || $namespace == 'Admin' )
   947     if ( $namespace == 'Special' || $namespace == 'Admin' )
   935     {
   948     {
   936       return 'This page redirects to a Special or Administration page, which is not allowed.';
   949       return 'This page redirects to a Special or Administration page, which is not allowed.';
   937     }
   950     }
   938     if ( in_array($this->redirect_stack, $arr_pid) )
   951     if ( in_array($this->redirect_stack, $arr_pid) )
   939     {
   952     {
   940       return 'This page infinitely redirects with another page (or another series of pages), and the infinite redirect was trapped.';
   953       return 'This page infinitely redirects with another page (or another series of pages), and the infinite redirect was trapped.';
   941     }
   954     }
   942     $page_id_key = $paths->nslist[ $namespace ] . $page_id;
   955     $page_id_key = $paths->nslist[ $namespace ] . sanitize_page_id($page_id);
   943     if ( !isset($paths->pages[$page_id_key]) )
   956     if ( !isset($paths->pages[$page_id_key]) )
   944     {
   957     {
   945       return 'This page redirects to another page that doesn\'t exist.';
   958       return 'This page redirects to another page that doesn\'t exist.';
   946     }
   959     }
   947     $this->redirect_stack[] = $arr_pid;
   960     $this->redirect_stack[] = $arr_pid;
   961   
   974   
   962   function err_access_denied()
   975   function err_access_denied()
   963   {
   976   {
   964     global $db, $session, $paths, $template, $plugins; // Common objects
   977     global $db, $session, $paths, $template, $plugins; // Common objects
   965     
   978     
       
   979     // Log it for crying out loud
       
   980     $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,author,edit_summary,page_text) VALUES(\'security\', \'illegal_page\', '.time().', \''.date('d M Y h:i a').'\', \''.$db->escape($session->username).'\', \''.$db->escape($_SERVER['REMOTE_ADDR']).'\', \'' . $db->escape(serialize(array($this->page_id, $this->namespace))) . '\')');
       
   981     
   966     $ob = '';
   982     $ob = '';
   967     $template->tpl_strings['PAGE_NAME'] = 'Access denied';
   983     //$template->tpl_strings['PAGE_NAME'] = 'Access denied';
       
   984     $template->tpl_strings['PAGE_NAME'] = htmlspecialchars( $this->title );
   968       
   985       
   969     if ( $this->send_headers )
   986     if ( $this->send_headers )
   970     {
   987     {
   971       $ob .= $template->getHeader();
   988       $ob .= $template->getHeader();
       
   989     }
       
   990     
       
   991     if ( count($this->redirect_stack) > 0 )
       
   992     {
       
   993       $stack = array_reverse($this->redirect_stack);
       
   994       foreach ( $stack as $oldtarget )
       
   995       {
       
   996         $url = makeUrlNS($oldtarget[1], $oldtarget[0], 'redirect=no', true);
       
   997         $page_id_key = $paths->nslist[ $oldtarget[1] ] . $oldtarget[0];
       
   998         $page_data = $paths->pages[$page_id_key];
       
   999         $title = ( isset($page_data['name']) ) ? $page_data['name'] : $paths->nslist[$oldtarget[1]] . htmlspecialchars( str_replace('_', ' ', dirtify_page_id( $oldtarget[0] ) ) );
       
  1000         $a = '<a href="' . $url . '">' . $title . '</a>';
       
  1001         
       
  1002         $url = makeUrlNS($this->namespace, $this->page_id, 'redirect=no', true);
       
  1003         $page_id_key = $paths->nslist[ $this->namespace ] . $this->page_id;
       
  1004         $page_data = $paths->pages[$page_id_key];
       
  1005         $title = ( isset($page_data['name']) ) ? $page_data['name'] : $paths->nslist[$this->namespace] . htmlspecialchars( str_replace('_', ' ', dirtify_page_id( $this->page_id ) ) );
       
  1006         $b = '<a href="' . $url . '">' . $title . '</a>';
       
  1007         
       
  1008         $ob .= '<small>(Redirected to ' . $b . ' from ' . $a . ')<br /></small>';
       
  1009       }
   972     }
  1010     }
   973     
  1011     
   974     $ob .= '<div class="error-box"><b>Access to this page is denied.</b><br />This may be because you are not logged in or you have not met certain criteria for viewing this page.</div>';
  1012     $ob .= '<div class="error-box"><b>Access to this page is denied.</b><br />This may be because you are not logged in or you have not met certain criteria for viewing this page.</div>';
   975     
  1013     
   976     if ( $this->send_headers )
  1014     if ( $this->send_headers )
  1042    
  1080    
  1043   function err_page_not_existent($userpage = false)
  1081   function err_page_not_existent($userpage = false)
  1044   {
  1082   {
  1045     global $db, $session, $paths, $template, $plugins; // Common objects
  1083     global $db, $session, $paths, $template, $plugins; // Common objects
  1046     
  1084     
       
  1085     header('HTTP/1.1 404 Not Found');
       
  1086     
  1047     $this->header();
  1087     $this->header();
  1048     header('HTTP/1.1 404 Not Found');
  1088     $this->do_breadcrumbs();
       
  1089     
  1049     if ( $userpage )
  1090     if ( $userpage )
  1050     {
  1091     {
  1051       echo '<h3>There is no page with this title yet.</h3>
  1092       echo '<h3>There is no page with this title yet.</h3>
  1052              <p>This user has not created his or her user page yet.';
  1093              <p>This user has not created his or her user page yet.';
  1053     }
  1094     }
  1073       }
  1114       }
  1074       if ( $db->numrows() > 0 )
  1115       if ( $db->numrows() > 0 )
  1075       {
  1116       {
  1076         $r = $db->fetchrow();
  1117         $r = $db->fetchrow();
  1077         echo '<p><b>This page was deleted on ' . $r['date_string'] . '.</b> The stated reason was:</p><blockquote>' . $r['edit_summary'] . '</blockquote><p>You can probably <a href="'.makeUrl($paths->page, 'do=rollback&amp;id='.$r['time_id']).'" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">roll back</a> the deletion.</p>';
  1118         echo '<p><b>This page was deleted on ' . $r['date_string'] . '.</b> The stated reason was:</p><blockquote>' . $r['edit_summary'] . '</blockquote><p>You can probably <a href="'.makeUrl($paths->page, 'do=rollback&amp;id='.$r['time_id']).'" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">roll back</a> the deletion.</p>';
       
  1119         if ( $session->user_level >= USER_LEVEL_ADMIN )
       
  1120         {
       
  1121           echo '<p>Additional admin options: <a href="' . makeUrl($paths->page, 'do=detag', true) . '" title="Remove any tags on this page">detag page</a></p>';
       
  1122         }
  1078       }
  1123       }
  1079       $db->free_result();
  1124       $db->free_result();
  1080     }
  1125     }
  1081     echo '<p>
  1126     echo '<p>
  1082             HTTP Error: 404 Not Found
  1127             HTTP Error: 404 Not Found
  1083           </p>';
  1128           </p>';
  1084     $this->footer();
  1129     $this->footer();
  1085   }
  1130   }
  1086   
  1131   
  1087   /**
  1132   /**
       
  1133    * Echoes out breadcrumb data, if appropriate.
       
  1134    * @access private
       
  1135    */
       
  1136   
       
  1137   function do_breadcrumbs()
       
  1138   {
       
  1139     global $db, $session, $paths, $template, $plugins; // Common objects
       
  1140     if ( strpos($this->text_cache, '__NOBREADCRUMBS__') !== false )
       
  1141       return false;
       
  1142     $breadcrumb_data = explode('/', $this->page_id);
       
  1143     if ( count($breadcrumb_data) > 1 )
       
  1144     {
       
  1145       echo '<!-- Start breadcrumbs -->
       
  1146             <div class="breadcrumbs">
       
  1147               ';
       
  1148       foreach ( $breadcrumb_data as $i => $higherpage )
       
  1149       {
       
  1150         $higherpage = $paths->nslist[$this->namespace] . sanitize_page_id(implode('/', array_slice($breadcrumb_data, 0, ($i+1))));
       
  1151         if ( ($i + 1) == count($breadcrumb_data) )
       
  1152         {
       
  1153           $title = get_page_title($higherpage, false);
       
  1154           if ( !$this->page_exists )
       
  1155           {
       
  1156             $title = explode('/', $title);
       
  1157             $title = array_reverse($title);
       
  1158             $title = $title[0];
       
  1159           }
       
  1160           echo htmlspecialchars($title);
       
  1161           break;
       
  1162         }
       
  1163         else if ( isPage($higherpage) )
       
  1164         {
       
  1165           $title = get_page_title($higherpage, false);
       
  1166           echo '<a href="' . makeUrl($higherpage, false, true) . '">' . htmlspecialchars($title) . '</a>';
       
  1167         }
       
  1168         else
       
  1169         {
       
  1170           $title = get_page_title($higherpage, false);
       
  1171           $title = explode('/', $title);
       
  1172           $title = array_reverse($title);
       
  1173           $title = $title[0];
       
  1174           echo '<a href="' . makeUrl($higherpage, false, true) . '" class="wikilink-nonexistent">' . htmlspecialchars($title) . '</a>';
       
  1175         }
       
  1176         echo ' &raquo; ';
       
  1177       }
       
  1178       echo '</div>
       
  1179             <!-- End breadcrumbs -->
       
  1180             ';
       
  1181     }
       
  1182   }
       
  1183   
       
  1184   /**
  1088    * PHP 4 constructor.
  1185    * PHP 4 constructor.
  1089    * @see PageProcessor::__construct()
  1186    * @see PageProcessor::__construct()
  1090    */
  1187    */
  1091   
  1188   
  1092   function PageProcessor( $page_id, $namespace, $revision_id = 0 )
  1189   function PageProcessor( $page_id, $namespace, $revision_id = 0 )