1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 16:33:00 +00:00
Pepperminty-Wiki/modules/feature-redirect.php

34 lines
1,012 B
PHP
Raw Normal View History

<?php
2015-10-03 09:26:25 +00:00
register_module([
"name" => "Redirect pages",
"version" => "0.1",
"author" => "Starbeamrainbowlabs",
"description" => "Adds support for redirect pages. Uses the same syntax that Mediawiki does.",
"id" => "feature-redirect",
"code" => function() {
register_save_preprocessor(function(&$index_entry, &$pagedata) {
2015-10-03 09:26:25 +00:00
$matches = [];
if(preg_match("/^# ?REDIRECT ?\[\[([^\]]+)\]\]/i", $pagedata, $matches) === 1)
2015-10-03 09:26:25 +00:00
{
error_log("matches: " . var_export($matches, true));
2015-10-03 09:26:25 +00:00
// We have found a redirect page!
// Update the metadata to reflect this.
$index_entry->redirect = true;
$index_entry->redirect_target = $matches[1];
}
else
{
// This page isn't a redirect. Unset the metadata just in case.
if(isseet($index_entry->redirect))
unset($index_entry->redirect);
if(isseet($index_entry->redirect_target))
unset($index_entry->redirect_target);
}
});
2015-10-03 09:27:18 +00:00
// Todo register a function somewhere else to detect reedirects in the front end
2015-10-03 09:26:25 +00:00
}
]);
?>