MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / mod / wiki / ewiki / plugins / page / orphanedpages.php
blob17b1979a230ed4654f29fa569583d5bacb56eb86
1 <?php
3 # lists all pages, which are not referenced from others
4 # (works rather unclean and dumb)
7 define("EWIKI_PAGE_ORPHANEDPAGES", "OrphanedPages");
8 $ewiki_plugins["page"][EWIKI_PAGE_ORPHANEDPAGES] = "ewiki_page_orphanedpages";
11 function ewiki_page_orphanedpages($id, $data, $action) {
13 global $ewiki_links;
15 $o = ewiki_make_title($id, $id, 2);
17 $pages = array();
18 $refs = array();
19 $orphaned = array();
21 #-- read database
22 $db = ewiki_database("GETALL", array("refs", "flags"));
23 $n=0;
24 while ($row = $db->get()) {
26 $p = $row["id"];
28 #-- remove self-reference
29 $row["refs"] = str_replace("\n$p\n", "\n", $row["refs"]);
31 #-- add to list of referenced pages
32 $rf = explode("\n", trim($row["refs"]));
33 $refs = array_merge($refs, $rf);
34 if ($n++ > 299) {
35 $refs = array_unique($refs);
36 $n=0;
37 } // (clean-up only every 300th loop)
39 #-- add page name
40 if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
41 $pages[] = $row["id"];
44 $refs = array_unique($refs);
46 #-- check pages to be referenced from somewhere
47 foreach ($pages as $p) {
48 if (!ewiki_in_array($p, $refs)) {
49 if (!EWIKI_PROTECTED_MODE || EWIKI_PROTECTED_MODE_HIDING || ewiki_auth($p, $uu, "view")) {
50 $orphaned[] = $p;
55 #-- output
56 $o .= ewiki_list_pages($orphaned, 0);
58 return($o);