# HG changeset patch # User Dan # Date 1184173219 14400 # Node ID 9dc4fded30e61920eb9eca41450bf55d7989e35d # Parent e9708657875afdad21f74f975ead589d4880a6bb Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!) diff -r e9708657875a -r 9dc4fded30e6 includes/functions.php --- a/includes/functions.php Tue Jul 10 12:31:12 2007 -0400 +++ b/includes/functions.php Wed Jul 11 13:00:19 2007 -0400 @@ -224,6 +224,40 @@ } /** + * Tells you the title for the given page ID string + * @param string Page ID string (ex: Special:Administration) + * @return string + */ + +function get_page_title($page_id) +{ + global $db, $session, $paths, $template, $plugins; // Common objects + + $idata = RenderMan::strToPageID($page_id); + $page_id_key = $paths->nslist[ $idata[1] ] . $idata[0]; + $page_data = $paths->pages[$page_id_key]; + $title = ( isset($page_data['name']) ) ? $page_data['name'] : $paths->nslist[$idata[1]] . str_replace('_', ' ', dirtify_page_id( $idata[0] ) ); + return $title; +} + +/** + * Tells you the title for the given page ID and namespace + * @param string Page ID + * @param string Namespace + * @return string + */ + +function get_page_title_ns($page_id, $namespace) +{ + global $db, $session, $paths, $template, $plugins; // Common objects + + $page_id_key = $paths->nslist[ $namespace ] . $page_id; + $page_data = $paths->pages[$page_id_key]; + $title = ( isset($page_data['name']) ) ? $page_data['name'] : $paths->nslist[$namespace] . str_replace('_', ' ', dirtify_page_id( $page_id ) ); + return $title; +} + +/** * Redirect the user to the specified URL. * @param string $url The URL, either relative or absolute. * @param string $title The title of the message diff -r e9708657875a -r 9dc4fded30e6 includes/pageprocess.php --- a/includes/pageprocess.php Tue Jul 10 12:31:12 2007 -0400 +++ b/includes/pageprocess.php Wed Jul 11 13:00:19 2007 -0400 @@ -32,6 +32,20 @@ var $namespace; /** + * The title of the page sent to the template parser + * @var string + */ + + var $title = ''; + + /** + * The information about the page(s) we were redirected from + * @var array + */ + + var $redirect_stack = array(); + + /** * The revision ID (history entry) to send. If set to 0 (the default) then the most recent revision will be sent. * @var int */ @@ -231,7 +245,6 @@ if ( empty($ob) ) { - die('ob is empty'); $this->err_page_not_existent(); } else @@ -257,7 +270,30 @@ } else { - $this->render( (!$strict_no_headers) ); + $redirect = ( isset($_GET['redirect']) ) ? $_GET['redirect'] : 'YES YOU IDIOT'; + if ( preg_match('/^#redirect \[\[([^\]]+)\]\]/i', $text, $match) && $redirect != 'no' ) + { + // Redirect page! + $page_to = sanitize_page_id($match[1]); + $page_id_data = RenderMan::strToPageID($page_to); + if ( count($this->redirect_stack) >= 3 ) + { + $this->render( (!$strict_no_headers), '
' ); + } + else + { + $result = $this->_handle_redirect($page_id_data[0], $page_id_data[1]); + if ( $result !== true ) + { + // There was some error during the redirect process - usually an infinite redirect + $this->render( (!$strict_no_headers), ' ' ); + } + } + } + else + { + $this->render( (!$strict_no_headers) ); + } } } } @@ -320,6 +356,8 @@ } + $this->title = get_page_title_ns($this->page_id, $this->namespace); + } /** @@ -327,13 +365,79 @@ * @access private */ - function render($incl_inner_headers = true) + function render($incl_inner_headers = true, $_errormsg = false) { + global $db, $session, $paths, $template, $plugins; // Common objects + $text = $this->fetch_text(); + $redir_enabled = false; + if ( preg_match('/^#redirect \[\[([^\]]+?)\]\]/i', $text, $match ) ) + { + $redir_enabled = true; + + $oldtarget = RenderMan::strToPageID($match[1]); + $oldtarget[0] = sanitize_page_id($oldtarget[0]); + + $url = makeUrlNS($oldtarget[1], $oldtarget[0], false, true); + $page_id_key = $paths->nslist[ $oldtarget[1] ] . $oldtarget[0]; + $page_data = $paths->pages[$page_id_key]; + $title = ( isset($page_data['name']) ) ? $page_data['name'] : $paths->nslist[$oldtarget[1]] . htmlspecialchars( str_replace('_', ' ', dirtify_page_id( $oldtarget[0] ) ) ); + if ( !isset($page_data['name']) ) + { + $cls = 'class="wikilink-nonexistent"'; + } + else + { + $cls = ''; + } + $a = '' . $title . ''; + $redir_html = '+ + | +
+ This page is a redirector. + This means that this page will not show its own content by default. Instead it will display the contents of the page it redirects to. + To create a redirect page, make the first characters in the page content #redirect [[Page_ID]]. For more information, see the + Enano Wiki formatting guide. + This page redirects to ' . $a . '. + |
+