Commit MetaInfo

修订版c7a32f7e9d6b9ec074fe0faa7de8241f9db5cff4 (tree)
时间2016-11-15 01:57:41
作者umorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2396 Redirect pages by Site Administrator

Add new property - $page_redirect_rules in pukiwiki.ini.php

更改概述

差异

--- a/lib/func.php
+++ b/lib/func.php
@@ -730,6 +730,29 @@ function htmlsc($string = '', $flags = ENT_COMPAT, $charset = CONTENT_CHARSET)
730730 return htmlspecialchars($string, $flags, $charset); // htmlsc()
731731 }
732732
733+// Redirect from an old page to new page
734+function manage_page_redirect() {
735+ global $page_redirect_rules, $vars;
736+ if (isset($vars['page'])) {
737+ $page = $vars['page'];
738+ foreach ($page_redirect_rules as $rule => $replace) {
739+ if (preg_match($rule, $page)) {
740+ if (is_string($replace)) {
741+ $new_page = preg_replace($rule, $replace, $page);
742+ } elseif (is_object($replace) && is_callable($replace)) {
743+ $new_page = preg_replace_callback($rule, $replace, $page);
744+ } else {
745+ die_message('Invalid redirect rule: ' . $rule . '=>' . $replace);
746+ }
747+ header('Location: ' . get_script_uri() . '?' .
748+ pagename_urlencode($new_page));
749+ return TRUE;
750+ }
751+ }
752+ }
753+ return FALSE;
754+}
755+
733756
734757 //// Compat ////
735758
--- a/lib/pukiwiki.php
+++ b/lib/pukiwiki.php
@@ -65,19 +65,9 @@ if ($notify) {
6565
6666 /////////////////////////////////////////////////
6767 // Main
68-
69-if (isset($vars['page'])) {
70- $page = $vars['page'];
71- foreach ($redirect_rules as $rule => $replace) {
72- if (preg_match($rule, $page)) {
73- $new_page = preg_replace($rule, $replace, $page);
74- header('Location: ' . get_script_uri() . '?' .
75- pagename_urlencode($new_page));
76- exit;
77- }
78- }
68+if (manage_page_redirect()) {
69+ exit;
7970 }
80-
8171 $retvars = array();
8272 $is_cmd = FALSE;
8373 if (isset($vars['cmd'])) {
--- a/pukiwiki.ini.php
+++ b/pukiwiki.ini.php
@@ -421,8 +421,9 @@ $search_non_list = 1;
421421
422422
423423 // Page redirect rules
424-$redirect_rules = array(
425- //'#^RenamedOldProject($|(/(.+)$))#' => 'NewProject$1',
424+$page_redirect_rules = array(
425+ //'#^FromProject($|(/(.+)$))#' => 'ToProject$1',
426+ //'#^FromProject($|(/(.+)$))#' => function($matches) { return 'ToProject' . $matches[1]; },
426427 );
427428
428429 /////////////////////////////////////////////////
Show on old repository browser