2015-09-30 13:03:41 +00:00
< ? php
2015-10-03 09:26:25 +00:00
register_module ([
" name " => " Redirect pages " ,
2017-06-28 10:42:11 +00:00
" version " => " 0.3.1 " ,
2015-10-03 09:26:25 +00:00
" author " => " Starbeamrainbowlabs " ,
" description " => " Adds support for redirect pages. Uses the same syntax that Mediawiki does. " ,
" id " => " feature-redirect " ,
" code " => function () {
2015-12-21 08:45:38 +00:00
global $settings ;
2018-07-02 22:44:10 +00:00
register_save_preprocessor ( " update_redirect_metadata " );
2015-12-21 08:45:38 +00:00
// Register a help section
add_help_section ( " 25-redirect " , " Redirect Pages " , " <p> $settings->sitename supports redirect pages. To create a redirect page, enter something like <code># REDIRECT [[pagename]]</code> on the first line of the redirect page's content. This <em>must</em> appear as the first line of the page, with no whitespace before it. You can include content beneath the redirect if you want, too (such as a reason for redirecting the page).</p> " );
2015-10-03 09:26:25 +00:00
}
]);
2015-09-30 13:03:41 +00:00
2018-07-02 22:44:10 +00:00
/**
* Updates the metadata associated with redirects in the pageindex entry
* specified utilising the provided page content .
* @ param object $index_entry The page index entry object to update .
* @ param string $pagedata The page content to operate on .
*/
function update_redirect_metadata ( & $index_entry , & $pagedata ) {
$matches = [];
if ( preg_match ( " /^# ?REDIRECT ? \ [ \ [([^ \ ]]+) \ ] \ ]/i " , $pagedata , $matches ) === 1 )
{
//error_log("matches: " . var_export($matches, true));
// 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 ( isset ( $index_entry -> redirect ))
unset ( $index_entry -> redirect );
if ( isset ( $index_entry -> redirect_target ))
unset ( $index_entry -> redirect_target );
}
}
2015-09-30 13:03:41 +00:00
?>