9f9325811885d957fa6987d1654e67ed1fada347
[atutor.git] / mods / wiki / plugins / linking / linkdatabase.php
1 <?php
2
3 /*
4    This plugin implements the LinkDatabase like by UseMod/MeatballWiki
5    (which summarizes pages and all links inside of it, each entry line
6    separated by a <br />).
7 */
8
9
10 $ewiki_plugins["page"]["LinkDatabase"] = "ewiki_linkdatabase";
11 $ewiki_plugins["handler"][] = "ewiki_linkdatabase";
12
13
14 function ewiki_linkdatabase($id, &$data, $action) {
15
16    if (($_REQUEST["action"]=="links") && ($id=="action=links") && empty($_REQUEST["id"])) {
17
18       $o = array(
19          "editlink" => 0,
20          "empty" => 0,
21          "names" => 1,
22          "unique" => 1,  #012     unimplemented
23          "sort" => 1,
24          "exists" => 2,
25          "url" => 0,     #012
26          "inter" => 0,   #012
27          "search" => "",
28       );
29       $o = array_merge($o, $_REQUEST);
30
31       #-- first read in all pages
32       $res = ewiki_db::GETALL(array("flags", "version", "refs"));
33       $all = array();
34       while ($row = $res->get()) {
35          if (($row["version"]&EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
36             $refs = trim($row["refs"]);
37             if (!$o["empty"] && empty($refs)) {
38                continue;
39             }
40             $all[$row["id"]] = $refs;
41          }
42       }
43
44       #-- sort
45       ksort($all);
46
47       #-- output
48       $out = "";
49       foreach ($all as $i=>$refs) {
50          $refs = explode("\n", $refs);
51          if ($refs) {
52             $refs = ewiki_db::FIND($refs);
53          }
54          foreach ($refs as $ri=>$rv) {
55             if ($o["exists"]!= 2) {
56                if ($rv != $o["exists"]) {
57                   unset($refs[$ri]);
58                }
59             }
60             if ($o["url"] != 1) {
61                if ($o["url"] XOR strpos($ri, "://")) {
62                   unset($refs[$ri]);
63                }
64             }
65             if ($o["inter"] != 1) {
66                if ($o["inter"] XOR strpos($ri, ":") && !strpos($ri, "://")) {
67                   unset($refs[$ri]);
68                }
69             }
70             if ($o["search"] && (strpos($ri, $o["search"])===false)) {
71                unset($refs[$ri]);
72             }
73          }
74          if (!$o["empty"] && empty($refs)) {
75             continue;
76          }
77          if ($o["sort"]) {
78             asort($refs);
79          }
80          $out .= "<a href=\"" . ewiki_script("", $i) . "\">$i</a>  ";
81          foreach ($refs as $i=>$rv) {
82             $title = $o[names] ? $i : " ";
83             if ($rv) {
84                $out .= " <a href=\"" . ewiki_script("", $i) . "\">$title</a>";
85             }
86             else {
87                $out .= " $title";
88                if ($o["editlink"]) {
89                   $out .= "<a href=\"" . ewiki_script("", $i) . "\">?</a>";
90                }
91             }
92          }
93          $out .= "\n";
94       }
95       return("\n<pre>\n\n\n\n$out</pre>\n");
96    }
97    elseif ($id == "LinkDatabase") {
98       $url = "url:?";
99 #      $url = "ErfurtWiki:";
100       return ewiki_format(<<<EOT
101 !!! LinkDatabase
102
103 The LinkDatabase provides a list of all internal pages together with the
104 links outgoing from each.
105
106 * [{$url}action=links] list pages and links, using default options
107 * [{$url}action=links&editlink=1] add the "?" link for not existent pages
108 * [{$url}action=links&empty=1] allowes listing of pages without forward links
109 * [{$url}action=links&names=0] no link title, just the <a href="...">
110 * [{$url}action=links&sort=0] order pages and their links
111 * [{$url}action=links&exists=0] only links to not existing pages
112 * [{$url}action=links&exists=1] only existing page links
113 * [{$url}action=links&url=1] add URLs
114 * [{$url}action=links&url=2] __only__ URLs
115 * [{$url}action=links&inter=1] add ~InterWiki:Links
116 * [{$url}action=links&inter=2] __only__ ~InterWiki:Links
117 * [{$url}action=links&search=google] apply search pattern to page links
118
119 handy combinations
120 * [{$url}action=links&inter=1&editlink=1&empty=1&url=1&sort=0&names=1] show all links
121 * [{$url}action=links&search=sourceforge&url=2] only URL links to sourceforge
122 * [{$url}action=links&sort=0&exists=0] unsorted missing pages
123
124 Only [{$url}action=links&unique=0] has not been implemented.
125
126 EOT
127       );
128    }
129 }
130
131
132 ?>