OSDN Git Service

Added related-action plugin for backlinks, instead of search via GET method
authorhenoheno <henoheno>
Wed, 12 Jan 2005 14:02:36 +0000 (23:02 +0900)
committerhenoheno <henoheno>
Wed, 12 Jan 2005 14:02:36 +0000 (23:02 +0900)
lib/html.php
plugin/related.inc.php [new file with mode: 0644]

index e54c2b1..aafb63a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: html.php,v 1.25 2005/01/10 00:45:50 henoheno Exp $
+// $Id: html.php,v 1.26 2005/01/12 14:02:36 henoheno Exp $
 //
 // HTML-publishing related functions
 
@@ -300,7 +300,7 @@ function strip_htmltag($str)
        return preg_replace('/<[^>]+>/', '', $str);
 }
 
-// Make a search-link of the page name, by the page name, for the page name
+// Make a backlink. searching-link of the page name, by the page name, for the page name
 function make_search($page)
 {
        global $script;
@@ -308,11 +308,7 @@ function make_search($page)
        $s_page = htmlspecialchars($page);
        $r_page = rawurlencode($page);
 
-       //WikiWikiWeb like...
-       //if(preg_match("/^$WikiName$/", $page))
-       //      $name = preg_replace('/([A-Z][a-z]+)/', '$1 ', $name);
-
-       return '<a href="' . $script . '?cmd=search&amp;word=' . $r_page .
+       return '<a href="' . $script . '?plugin=related&amp;page=' . $r_page .
                '">' . $s_page . '</a> ';
 }
 
diff --git a/plugin/related.inc.php b/plugin/related.inc.php
new file mode 100644 (file)
index 0000000..19b271a
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+// PukiWiki - Yet another WikiWikiWeb clone
+// $Id: related.inc.php,v 1.1 2005/01/12 14:02:05 henoheno Exp $
+//
+// Related plugin: Show Backlinks for the page
+
+// TODO: move '#related' here
+//function plugin_related_convert()
+//{
+//     global $related_link;
+//     $related_link = 0;
+//     // Do
+//}
+
+// Show Backlinks: via related caches for the page
+function plugin_related_action()
+{
+       global $vars, $script, $non_list, $defaultpage, $whatsnew;
+
+       $_page = isset($vars['page']) ? $vars['page'] : '';
+       if ($_page == '') $_page = $defaultpage;
+
+       // Get related from cache
+       $data = links_get_related_db($_page);
+       $non_list_pattern = '/' . $non_list . '/';
+       foreach(array_keys($data) as $page)
+               if ($page == $whatsnew || preg_match($non_list_pattern, $page))
+                       unset($data[$page]);
+
+       // Result
+       $s_word = htmlspecialchars($_page);
+       $msg = '<a href="' . $script . '?' . $s_word . '">' .
+               'Backlinks for: ' . $s_word . '</a>';
+
+       if (empty($data)) {
+               return array('msg'=>$msg, 'body'=>'No related pages found.');
+       } else {
+               // Show count($data)?
+               ksort($data);
+               $retval = '<ul>' . "\n";
+               foreach ($data as $page=>$time) {
+                       $r_page  = rawurlencode($page);
+                       $s_page  = htmlspecialchars($page);
+                       $passage = get_passage($time);
+                       $retval .= ' <li><a href="' . $script . '?' . $r_page . '">' . $s_page .
+                               '</a> ' . $passage . '</li>' . "\n";
+               }
+               $retval .= '</ul>' . "\n";
+               return array('msg'=>$msg, 'body'=>$retval);
+       }
+}
+?>