# HG changeset patch
# User Dan
# Date 1250901052 14400
# Node ID be6cfe79128c99466940a61a5b10d79c1a6daa47
# Parent 4252e4d8310224aa2ac88a3ec75cbd81746c43fd
Made internal links to the Admin namespace much smarter. (They do the login box and stuff.)
diff -r 4252e4d83102 -r be6cfe79128c includes/clientside/static/login.js
--- a/includes/clientside/static/login.js Fri Aug 21 15:39:34 2009 -0400
+++ b/includes/clientside/static/login.js Fri Aug 21 20:30:52 2009 -0400
@@ -1247,30 +1247,26 @@
window.location = loc;
}
-var navto_ns;
-var navto_pg;
-var navto_ul;
-
-window.ajaxLoginNavTo = function(namespace, page_id, min_level)
+window.ajaxLoginNavTo = function(namespace, page_id, min_level, get)
{
// IE <6 pseudo-compatibility
if ( KILL_SWITCH )
return true;
- navto_pg = page_id;
- navto_ns = namespace;
- navto_ul = min_level;
+ void(namespace);
+ void(page_id);
+ get = get || false;
if ( auth_level < min_level )
{
ajaxPromptAdminAuth(function(k) {
ENANO_SID = k;
- auth_level = navto_ul;
- var loc = makeUrlNS(navto_ns, navto_pg);
+ auth_level = min_level;
+ var loc = makeUrlNS(namespace, page_id, get);
if ( (ENANO_SID + ' ').length > 1 )
window.location = loc;
}, min_level);
return false;
}
- var loc = makeUrlNS(navto_ns, navto_pg);
+ var loc = makeUrlNS(namespace, page_id, get);
window.location = loc;
}
diff -r 4252e4d83102 -r be6cfe79128c includes/render.php
--- a/includes/render.php Fri Aug 21 15:39:34 2009 -0400
+++ b/includes/render.php Fri Aug 21 20:30:52 2009 -0400
@@ -617,51 +617,15 @@
public static function parse_internal_links($text, $tplcode = false, $do_exist_check = true, $match_page_id = false, $match_namespace = false)
{
global $db, $session, $paths, $template, $plugins; // Common objects
-
- if ( is_string($tplcode) )
- {
- $parser = $template->makeParserText($tplcode);
- }
+
+ $parser = is_string($tplcode) ? $template->makeParserText($tplcode) : false;
// stage 1 - links with alternate text
preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches);
foreach ( $matches[0] as $i => $match )
{
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
- if ( ($pos = strrpos($page_id, '#')) !== false )
- {
- $hash = substr($page_id, $pos);
- $page_id = substr($page_id, 0, $pos);
- }
- else
- {
- $hash = '';
- }
- $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
-
- $url = makeUrl($pid_clean, false, true) . $hash;
- $inner_text = $matches[2][$i];
- $quot = '"';
- $exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
-
- if ( $match_page_id && $match_namespace && $pid_clean === $paths->get_pathskey($match_page_id, $match_namespace) )
- $exists .= ' class="currentpage"';
-
- if ( $tplcode )
- {
- $parser->assign_vars(array(
- 'HREF' => $url,
- 'FLAGS' => $exists,
- 'TEXT' => $inner_text
- ));
- $link = $parser->run();
- }
- else
- {
- $omatch = self::escape_parser_hint_attrib($match);
- $link = "{$inner_text}";
- }
-
+ $link = self::generate_internal_link($namespace, $page_id, $matches[2][$i], $match, $parser, $do_exist_check, $match_page_id, $match_namespace);
$text = str_replace($match, $link, $text);
}
@@ -671,29 +635,9 @@
{
list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
$pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
-
- $url = makeUrl($pid_clean, false, true);
$inner_text = ( isPage($pid_clean) ) ? htmlspecialchars(get_page_title($pid_clean)) : htmlspecialchars($matches[1][$i]);
- $quot = '"';
- $exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
-
- if ( $match_page_id && $match_namespace && $pid_clean === $paths->get_pathskey($match_page_id, $match_namespace) )
- $exists .= ' class="currentpage"';
- if ( $tplcode )
- {
- $parser->assign_vars(array(
- 'HREF' => $url,
- 'FLAGS' => $exists,
- 'TEXT' => $inner_text
- ));
- $link = $parser->run();
- }
- else
- {
- $omatch = self::escape_parser_hint_attrib($match);
- $link = "{$inner_text}";
- }
+ $link = self::generate_internal_link($namespace, $page_id, $inner_text, $match, $parser, $do_exist_check, $match_page_id, $match_namespace);
$text = str_replace($match, $link, $text);
}
@@ -702,6 +646,65 @@
}
/**
+ * Internal link generation function
+ * @access private
+ * @return string HTML
+ */
+
+ private static function generate_internal_link($namespace, $page_id, $inner_text, $match, $parser = false, $do_exist_check = true, $match_page_id = false, $match_namespace = false)
+ {
+ global $db, $session, $paths, $template, $plugins; // Common objects
+
+ if ( ($pos = strrpos($page_id, '#')) !== false )
+ {
+ $hash = substr($page_id, $pos);
+ $page_id = substr($page_id, 0, $pos);
+ }
+ else
+ {
+ $hash = '';
+ }
+
+ if ( $namespace == 'Admin' )
+ {
+ // No linking directly to Admin pages!
+ $get = 'module=' . $paths->nslist[$namespace] . sanitize_page_id($page_id);
+ $pid_clean = $paths->nslist['Special'] . 'Administration';
+ $onclick = ' onclick="ajaxLoginNavTo(\'Special\', \'Administration\', USER_LEVEL_ADMIN, \'' . addslashes($get) . '\'); return false;"';
+ }
+ else
+ {
+ $get = false;
+ $onclick = '';
+ $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
+ }
+
+ $url = makeUrl($pid_clean, $get, true) . $hash;
+ $quot = '"';
+ $exists = ( ($do_exist_check && isPage($pid_clean)) || !$do_exist_check ) ? '' : ' class="wikilink-nonexistent"';
+
+ if ( $match_page_id && $match_namespace && $pid_clean === $paths->get_pathskey($match_page_id, $match_namespace) )
+ $exists .= ' class="currentpage"';
+
+ if ( $parser )
+ {
+ $parser->assign_vars(array(
+ 'HREF' => $url,
+ 'FLAGS' => $exists,
+ 'TEXT' => $inner_text
+ ));
+ $link = $parser->run();
+ }
+ else
+ {
+ $omatch = self::escape_parser_hint_attrib($match);
+ $link = "{$inner_text}";
+ }
+
+ return $link;
+ }
+
+ /**
* Parses a partial template tag in wikitext, and return an array with the parameters.
* @param string The portion of the template tag that contains the parameters.
* @example