2015-09-30 13:03:41 +00:00
|
|
|
<?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() {
|
2015-10-03 11:22:54 +00:00
|
|
|
register_save_preprocessor(function(&$index_entry, &$pagedata) {
|
2015-10-03 09:26:25 +00:00
|
|
|
$matches = [];
|
2015-10-03 12:21:43 +00:00
|
|
|
if(preg_match("/^# ?REDIRECT ?\[\[([^\]]+)\]\]/i", $pagedata, $matches) === 1)
|
2015-10-03 09:26:25 +00:00
|
|
|
{
|
2015-10-03 12:21:43 +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.
|
2015-10-04 13:04:42 +00:00
|
|
|
if(isset($index_entry->redirect))
|
2015-10-03 09:26:25 +00:00
|
|
|
unset($index_entry->redirect);
|
2015-10-04 13:04:42 +00:00
|
|
|
if(isset($index_entry->redirect_target))
|
2015-10-03 09:26:25 +00:00
|
|
|
unset($index_entry->redirect_target);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
]);
|
2015-09-30 13:03:41 +00:00
|
|
|
|
|
|
|
?>
|