896f263fe50bc895c3afebe76100a487bc7c388c
[atutor.git] / mods / wiki / spages / OrphanedPages.php
1 <?php
2 /*
3    lists all pages, which are not referenced from others, the opposite
4    of LinkLessPages;
5    (works rather unclean and dumb)
6 */
7
8  global $ewiki_links;
9  echo ewiki_make_title($id, $id, 2);
10
11  $pages = array();
12  $refs = array();
13  $orphaned = array();
14
15  #-- read database
16  $db = ewiki_db::GETALL(array("refs", "flags"));
17  $n=0;
18  while ($row = $db->get()) {
19
20     $p = $row["id"];
21
22     #-- remove self-reference
23     $row["refs"] = str_replace("\n$p\n", "\n", $row["refs"]);
24
25     #-- add to list of referenced pages
26     $rf = explode("\n", trim($row["refs"]));
27     $refs = array_merge($refs, $rf);
28     if ($n++ > 299) {
29        $refs = array_unique($refs);
30        $n=0;
31     } // (clean-up only every 300th loop)
32
33     #-- add page name
34     if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
35        $pages[] = $row["id"];
36     }
37  }
38  $refs = array_unique($refs);
39
40  #-- check pages to be referenced from somewhere
41  foreach ($pages as $p) {
42     if (!ewiki_in_array($p, $refs)) {
43        if (!EWIKI_PROTECTED_MODE || !EWIKI_PROTECTED_MODE_HIDING || ewiki_auth($p, $uu, "view")) {
44           $orphaned[] = $p;    
45        }  
46     }
47  }
48
49  #-- output
50  echo ewiki_list_pages($orphaned, 0);
51
52 ?>