OSDN Git Service

BugTrack/2396 Redirect pages by Site Administrator
authorumorigu <umorigu@gmail.com>
Sun, 13 Nov 2016 20:01:35 +0000 (05:01 +0900)
committerumorigu <umorigu@gmail.com>
Mon, 14 Nov 2016 17:40:00 +0000 (02:40 +0900)
Add new property - $page_redirect_rules in pukiwiki.ini.php

lib/func.php
lib/pukiwiki.php
pukiwiki.ini.php

index 05a6fe8..7421f33 100644 (file)
@@ -730,6 +730,29 @@ function htmlsc($string = '', $flags = ENT_COMPAT, $charset = CONTENT_CHARSET)
        return htmlspecialchars($string, $flags, $charset);     // htmlsc()
 }
 
+// Redirect from an old page to new page
+function manage_page_redirect() {
+       global $page_redirect_rules, $vars;
+       if (isset($vars['page'])) {
+               $page = $vars['page'];
+               foreach ($page_redirect_rules as $rule => $replace) {
+                       if (preg_match($rule, $page)) {
+                               if (is_string($replace)) {
+                                       $new_page = preg_replace($rule, $replace, $page);
+                               } elseif (is_object($replace) && is_callable($replace)) {
+                                       $new_page = preg_replace_callback($rule, $replace, $page);
+                               } else {
+                                       die_message('Invalid redirect rule: ' . $rule . '=>' . $replace);
+                               }
+                               header('Location: ' . get_script_uri() . '?' .
+                                       pagename_urlencode($new_page));
+                               return TRUE;
+                       }
+               }
+       }
+       return FALSE;
+}
+
 
 //// Compat ////
 
index 62f6d52..043e9b2 100644 (file)
@@ -1,32 +1,12 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: pukiwiki.php,v 1.23 2011/01/25 15:01:01 henoheno Exp $
+// pukiwiki.php
+// Copyright
+//   2002-2016 PukiWiki Development Team
+//   2001-2002 Originally written by yu-ji
+// License: GPL v2 or (at your option) any later version
 //
-// PukiWiki 1.4.*
-//  Copyright (C) 2002-2005 by PukiWiki Development Team
-//  http://pukiwiki.osdn.jp/
-//
-// PukiWiki 1.3.*
-//  Copyright (C) 2002-2004 by PukiWiki Development Team
-//  http://pukiwiki.osdn.jp/
-//
-// PukiWiki 1.3 (Base)
-//  Copyright (C) 2001-2002 by yu-ji <sng@factage.com>
-//  http://factage.com/sng/pukiwiki/
-//
-// Special thanks
-//  YukiWiki by Hiroshi Yuki <hyuki@hyuki.com>
-//  http://www.hyuki.com/yukiwiki/
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
+// PukiWiki main script
 
 if (! defined('DATA_HOME')) define('DATA_HOME', '');
 
@@ -65,7 +45,9 @@ if ($notify) {
 
 /////////////////////////////////////////////////
 // Main
-
+if (manage_page_redirect()) {
+       exit;
+}
 $retvars = array();
 $is_cmd = FALSE;
 if (isset($vars['cmd'])) {
@@ -121,4 +103,3 @@ if (isset($retvars['body']) && $retvars['body'] != '') {
 
 // Output
 catbody($title, $page, $body);
-exit;
index 1c60643..4dda53d 100644 (file)
@@ -419,6 +419,13 @@ $non_list = '^\:';
 // Search ignored pages
 $search_non_list = 1;
 
+
+// Page redirect rules
+$page_redirect_rules = array(
+       //'#^FromProject($|(/(.+)$))#' => 'ToProject$1',
+       //'#^FromProject($|(/(.+)$))#' => function($matches) { return 'ToProject' . $matches[1]; },
+);
+
 /////////////////////////////////////////////////
 // Template setting