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.2 (Coblynau) |
5 * Version 1.0.1 (Loch Ness) |
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. |
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); |
|
376 |
374 |
377 $redir_enabled = false; |
375 $redir_enabled = false; |
378 if ( preg_match('/^#redirect \[\[([^\]]+?)\]\]/i', $text, $match ) ) |
376 if ( preg_match('/^#redirect \[\[([^\]]+?)\]\]/i', $text, $match ) ) |
379 { |
377 { |
380 $redir_enabled = true; |
378 $redir_enabled = true; |
632 '<' => '<', |
629 '<' => '<', |
633 '>' => '>' |
630 '>' => '>' |
634 )); |
631 )); |
635 |
632 |
636 $target_username = preg_replace('/^' . preg_quote($paths->nslist['User']) . '/', '', $target_username); |
633 $target_username = preg_replace('/^' . preg_quote($paths->nslist['User']) . '/', '', $target_username); |
637 $target_username = explode('/', $target_username); |
|
638 $target_username = $target_username[0]; |
|
639 |
634 |
640 if ( ( $page_name == str_replace('_', ' ', $this->page_id) || $page_name == $paths->nslist['User'] . str_replace('_', ' ', $this->page_id) ) || !$this->page_exists ) |
635 if ( ( $page_name == str_replace('_', ' ', $this->page_id) || $page_name == $paths->nslist['User'] . str_replace('_', ' ', $this->page_id) ) || !$this->page_exists ) |
641 { |
636 { |
642 $page_name = "$target_username's user page"; |
637 $page_name = "$target_username's user page"; |
643 } |
638 } |
707 if ( !empty($userdata['real_name']) ) |
702 if ( !empty($userdata['real_name']) ) |
708 { |
703 { |
709 echo '<tr><td class="row3">Real name: ' . $userdata['real_name'] . '</td></tr>'; |
704 echo '<tr><td class="row3">Real name: ' . $userdata['real_name'] . '</td></tr>'; |
710 } |
705 } |
711 |
706 |
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 |
|
719 // Comments |
707 // Comments |
720 |
708 |
721 echo '<tr><th class="subhead">' . htmlspecialchars($target_username) . '\'s latest comments</th></tr>'; |
709 echo '<tr><th class="subhead">' . htmlspecialchars($target_username) . '\'s latest comments</th></tr>'; |
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;'); |
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;'); |
723 if ( !$q ) |
711 if ( !$q ) |
940 * @access private |
928 * @access private |
941 */ |
929 */ |
942 |
930 |
943 function _handle_redirect($page_id, $namespace) |
931 function _handle_redirect($page_id, $namespace) |
944 { |
932 { |
945 global $db, $session, $paths, $template, $plugins; // Common objects |
|
946 $arr_pid = array($this->page_id, $this->namespace); |
933 $arr_pid = array($this->page_id, $this->namespace); |
947 if ( $namespace == 'Special' || $namespace == 'Admin' ) |
934 if ( $namespace == 'Special' || $namespace == 'Admin' ) |
948 { |
935 { |
949 return 'This page redirects to a Special or Administration page, which is not allowed.'; |
936 return 'This page redirects to a Special or Administration page, which is not allowed.'; |
950 } |
937 } |
951 if ( in_array($this->redirect_stack, $arr_pid) ) |
938 if ( in_array($this->redirect_stack, $arr_pid) ) |
952 { |
939 { |
953 return 'This page infinitely redirects with another page (or another series of pages), and the infinite redirect was trapped.'; |
940 return 'This page infinitely redirects with another page (or another series of pages), and the infinite redirect was trapped.'; |
954 } |
941 } |
955 $page_id_key = $paths->nslist[ $namespace ] . sanitize_page_id($page_id); |
942 $page_id_key = $paths->nslist[ $namespace ] . $page_id; |
956 if ( !isset($paths->pages[$page_id_key]) ) |
943 if ( !isset($paths->pages[$page_id_key]) ) |
957 { |
944 { |
958 return 'This page redirects to another page that doesn\'t exist.'; |
945 return 'This page redirects to another page that doesn\'t exist.'; |
959 } |
946 } |
960 $this->redirect_stack[] = $arr_pid; |
947 $this->redirect_stack[] = $arr_pid; |
974 |
961 |
975 function err_access_denied() |
962 function err_access_denied() |
976 { |
963 { |
977 global $db, $session, $paths, $template, $plugins; // Common objects |
964 global $db, $session, $paths, $template, $plugins; // Common objects |
978 |
965 |
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 |
|
982 $ob = ''; |
966 $ob = ''; |
983 //$template->tpl_strings['PAGE_NAME'] = 'Access denied'; |
967 $template->tpl_strings['PAGE_NAME'] = 'Access denied'; |
984 $template->tpl_strings['PAGE_NAME'] = htmlspecialchars( $this->title ); |
|
985 |
968 |
986 if ( $this->send_headers ) |
969 if ( $this->send_headers ) |
987 { |
970 { |
988 $ob .= $template->getHeader(); |
971 $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 } |
|
1010 } |
972 } |
1011 |
973 |
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>'; |
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>'; |
1013 |
975 |
1014 if ( $this->send_headers ) |
976 if ( $this->send_headers ) |
1080 |
1042 |
1081 function err_page_not_existent($userpage = false) |
1043 function err_page_not_existent($userpage = false) |
1082 { |
1044 { |
1083 global $db, $session, $paths, $template, $plugins; // Common objects |
1045 global $db, $session, $paths, $template, $plugins; // Common objects |
1084 |
1046 |
|
1047 $this->header(); |
1085 header('HTTP/1.1 404 Not Found'); |
1048 header('HTTP/1.1 404 Not Found'); |
1086 |
|
1087 $this->header(); |
|
1088 $this->do_breadcrumbs(); |
|
1089 |
|
1090 if ( $userpage ) |
1049 if ( $userpage ) |
1091 { |
1050 { |
1092 echo '<h3>There is no page with this title yet.</h3> |
1051 echo '<h3>There is no page with this title yet.</h3> |
1093 <p>This user has not created his or her user page yet.'; |
1052 <p>This user has not created his or her user page yet.'; |
1094 } |
1053 } |
1114 } |
1073 } |
1115 if ( $db->numrows() > 0 ) |
1074 if ( $db->numrows() > 0 ) |
1116 { |
1075 { |
1117 $r = $db->fetchrow(); |
1076 $r = $db->fetchrow(); |
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&id='.$r['time_id']).'" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">roll back</a> the deletion.</p>'; |
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&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 } |
|
1123 } |
1078 } |
1124 $db->free_result(); |
1079 $db->free_result(); |
1125 } |
1080 } |
1126 echo '<p> |
1081 echo '<p> |
1127 HTTP Error: 404 Not Found |
1082 HTTP Error: 404 Not Found |
1128 </p>'; |
1083 </p>'; |
1129 $this->footer(); |
1084 $this->footer(); |
1130 } |
1085 } |
1131 |
1086 |
1132 /** |
1087 /** |
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 ' » '; |
|
1177 } |
|
1178 echo '</div> |
|
1179 <!-- End breadcrumbs --> |
|
1180 '; |
|
1181 } |
|
1182 } |
|
1183 |
|
1184 /** |
|
1185 * PHP 4 constructor. |
1088 * PHP 4 constructor. |
1186 * @see PageProcessor::__construct() |
1089 * @see PageProcessor::__construct() |
1187 */ |
1090 */ |
1188 |
1091 |
1189 function PageProcessor( $page_id, $namespace, $revision_id = 0 ) |
1092 function PageProcessor( $page_id, $namespace, $revision_id = 0 ) |