Revision [1027]
This is an old revision of RedirectingPages made by DreckFehler on 2004-08-18 23:07:35.
run():
<?
// ...
if ($this->method == "show" && $_REQUEST["redirect"] != "no") $this->GetTargetPage();
$this->ReadInterWikiConfig();
?>
// ...
if ($this->method == "show" && $_REQUEST["redirect"] != "no") $this->GetTargetPage();
$this->ReadInterWikiConfig();
?>
if we want to call the function gettargetpage() we'd better have one:
<?
function GetTargetPage() {
if ($this->HasAccess("read")) {
if (preg_match("/\A\s*=>\s*(.*)/", $this->page["body"], $matches)) {
// patterns of forced links and wikiwords (without the commas) are german umlauts really enough?
preg_match ("/^(\[\[.*?\]\]|[A-ZÄÖÜ][a-zäöüß]+[A-Z0-9ÄÖÜ][A-Z0-9a-zäöüßÄÖÜ]*)/", $matches[1], $matches1);
$target = $matches1[1];
if ($target_page = $this->LoadPage($target)) {
$this->redirect_page = $this->page["tag"];
$this->LoadAllACLs($target_page); // isn't loadallacls better a part of setpage()?
$this->SetPage($target_page);
}
}
} else {
// no idea why a redirector page should have it's own acls. but if user has no read-access he hasn't ;)
print("<p><em>You aren't allowed to read this page.</em></p></div>");
}
}
?>
function GetTargetPage() {
if ($this->HasAccess("read")) {
if (preg_match("/\A\s*=>\s*(.*)/", $this->page["body"], $matches)) {
// patterns of forced links and wikiwords (without the commas) are german umlauts really enough?
preg_match ("/^(\[\[.*?\]\]|[A-ZÄÖÜ][a-zäöüß]+[A-Z0-9ÄÖÜ][A-Z0-9a-zäöüßÄÖÜ]*)/", $matches[1], $matches1);
$target = $matches1[1];
if ($target_page = $this->LoadPage($target)) {
$this->redirect_page = $this->page["tag"];
$this->LoadAllACLs($target_page); // isn't loadallacls better a part of setpage()?
$this->SetPage($target_page);
}
}
} else {
// no idea why a redirector page should have it's own acls. but if user has no read-access he hasn't ;)
print("<p><em>You aren't allowed to read this page.</em></p></div>");
}
}
?>
the showhandler shall provide a link back to the original page. or we'll never have a chance to change the redirector (of course we would, guess how).
handlers/page/show.php
<?
// ...
if ($this->redirect_page) {
print ("<div class='revisioninfo'>Redirected from "); // this div may get it's own class
print ("<a href='".$this->href("", $this->redirect_page, "redirect=no")."'>".$this->redirect_page."</a>");
print ("</div>\n");
}
// display page
print($this->Format($this->page["body"]));
?>
// ...
if ($this->redirect_page) {
print ("<div class='revisioninfo'>Redirected from "); // this div may get it's own class
print ("<a href='".$this->href("", $this->redirect_page, "redirect=no")."'>".$this->redirect_page."</a>");
print ("</div>\n");
}
// display page
print($this->Format($this->page["body"]));
?>
Test,Page
now any page will be redirected to another when it starts with =>TargetPage