1<?php
2
3if(!defined('DOKU_INC')) die();
4if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
5require_once(DOKU_PLUGIN.'action.php');
6
7class action_plugin_mredirect extends DokuWiki_Action_Plugin {
8
9    function register(Doku_Event_Handler $controller){
10        $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'handle_start', array());
11    }
12
13    function handle_start(&$event, $param){
14        global $ID;
15        global $ACT;
16        global $INFO;
17
18      if ($ACT != 'show') return;
19      if (!($INFO['exists'])) return;          # don't try to read an article that doesn't exist
20
21      $all = rtrim(rawWiki($ID)); $inner = substr ($all, 2, -2);
22      if (($all == '[[' . $inner . ']]') and (strpos ($inner, '[[') === false) and (strpos ($inner, ']]') === false)) {
23          if (!strpos ($inner, '://') === false) {
24              $url = $inner;    # link is URL already
25          } else {
26              msg (sprintf ('From: <a href="'.wl($ID,'do=edit').'">'.hsc($ID).'</a>'));
27              $parts = explode('|', $inner);
28              $url = html_wikilink ($parts[0], $name=null, $search='');
29              $url = substr ($url, strpos ($url, '"') + 1);
30              $url = substr ($url, 0, strpos ($url, '"'));
31          }
32          idx_addPage($ID);  # ensure fulltext search indexing of referrer article - to put it on the backlink page of target article
33          send_redirect($url);
34      }
35    }
36}
37?>
38