My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/*
redirect.php : redirect from one page to another
source: http://wikkawiki.org/RedirectingPages?show_comments=1#comment_6130

Copyright 2003 Eric FELDSTEIN
Copyright 2003 David DELON
Copyright 2004 Jean Christophe ANDRE
Copyright 2009 Sebastien CELLES
Copyright 2010 Tom at klenwell@gmail.com
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.

You should have received a copy of the GNU General Public License

along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

/*
Parameters : page : WikiName of the page where you want to redirect
example : {{redirect page="HomePage"}}
*/

// Defaults
$ActionDefaults = array(
'show_circular_error' => 1,
'usage' => '{{redirect page="HomePage"}}',
'session_key' => 'wikka_redirect',
'catch_timeout' => 5,
'now' => microtime(1)
);

$ActionErrors = array(
'no_page' => 'redirect page not set',
'redirect_self' => 'a page cannot redirect to itself',
'circular' => 'circular redirection'
);

// Initialize
$redirect_page = ( isset($vars['page']) ) ? $vars['page'] : '';
$redirect_page = trim($redirect_page);
$page_tag = $this->GetPageTag();
$WikkaRedirectList = array();


// Handle redirect
# Non-show method
if ( $this->GetHandler() != 'show' ) {
$f = 'redirecting to %s';
$output = sprintf($f, $redirect_page);
}

# Empty page parameter
elseif ( empty($redirect_page) ) {
$f = '//%s//: ""<tt>%s</tt>""';
$output = sprintf($f, $ActionErrors['no_page'], $ActionDefaults['usage']);
}

# Redirect to self
elseif ( strtolower($redirect_page) == strtolower($page_tag) ) {
$output = sprintf('//%s//', $ActionErrors['redirect_self']);
}

# Proper request
else {
/* Redirect Guard
Want to avoid circular redirects, e.g.:
FooPage -> BarPage -> WtfPage -> FooPage

Ideally, we would set a cookie on redirect-from page and clear on
redirect-to page. But redirect-to page will not call this action.
So instead, we save the page each redirect comes from for so many
seconds (set by $ActionDefaults['catch_timeout']). If the same page
(this page) is redirected to within that time, we print an error
with a link to the redirect page.
*/
$k1 = $ActionDefaults['session_key'];
$k2 = $page_tag;

$ActiveRedirectSessions = array();
foreach ( $_SESSION[$k1] as $from_tag => $time ) {
if ( $ActionDefaults['now'] - $time < $ActionDefaults['catch_timeout'] ) {
$ActiveRedirectSessions[] = $from_tag;
}
else {
unset($_SESSION[$k1][$from_tag]);
}
}

if ( in_array($from_tag, $ActiveRedirectSessions) ) {
$age = sprintf('%.2f', $ActionDefaults['now'] - $_SESSION[$k1][$from_tag]);
$exp = sprintf('%.2f', $ActionDefaults['catch_timeout'] - $age);

# show error message or hide in comment
$ef = "%s: redirected from this page %s s ago, auto-redirect block expires in %s s";
if ( ! $ActionDefaults['show_circular_error'] ) {
$ef = sprintf('""<!-- %s -->""', $ef);
}
$e = sprintf($ef, $ActionErrors['circular'], $age, $exp);

$f = "page redirects to [[%s]]\n%s";
$output = sprintf($f, $redirect_page, $e);
}
else {
$_SESSION[$k1][$k2] = microtime(1);
$this->Redirect($this->Href('', $redirect_page));
}
}

print $this->Format($output);

?>

Change log

r279 by klenwell on Jan 15, 2012   Diff
updates wikka redirect action for version
1.3
Go to: 
Project members, sign in to write a code review

Older revisions

r252 by klenwell on Apr 26, 2010   Diff
moving wikka scripts to plugins dir
r241 by klenwell on Mar 28, 2010   Diff
minor improvements to wikka redirect
action
r240 by klenwell on Mar 27, 2010   Diff
adding wikka redirect action
All revisions of this file

File info

Size: 4019 bytes, 121 lines

File properties

svn:mime-type
text/x-php
svn:eol-style
native
svn:keywords
Id Rev Date
Powered by Google Project Hosting