3216db411c1294a77b9188c854e0d3db268cf34a
[atutor.git] / mods / wiki / tools / cron.d / S56gagalinks.php
1 <?php
2 /*
3    This replaces Admin/PrepareAutolinking and enables itself if you
4    have the "plugins/linking/autolinking.php" enabled.
5
6    -> creates a cache entry for pages with single-word and non-wiki names
7 */
8
9 #-- cfg (already in the according plugin)
10 // define("EWIKI_AUTOLINKING_CACHE", "system/tmp/autolinking");
11
12
13 #-- start if plugin loaded / constant defined
14 if (defined("EWIKI_AUTOLINKING_CACHE")) {
15
16    #-- start list
17    $pages = array();
18
19    #-- find AllPages
20    $result = ewiki_db::GETALL(array("id", "flags"));
21    while ($row = $result->get()) {
22
23       if (EWIKI_DB_F_TEXT != ($row["flags"] & EWIKI_DB_F_TYPE)) {
24          continue;
25       }
26       $id = $row["id"];
27
28       #-- only care about pagenames, which are words but no WikiWords
29       if (!strpos($id, " ") && preg_match('/^\w+$/', $id)
30       && !preg_match('/^(['.EWIKI_CHARS_U.']+['.EWIKI_CHARS_L.']+){2,}[\w\d]*$/', $id))
31       {
32          $pages[] = $id;
33       }
34
35    }
36
37    #-- save found pages in cache entry
38    $DEST = EWIKI_AUTOLINKING_CACHE;
39    $save = array(
40       "id" => $DEST,
41       "version" => 1,
42       "flags" => EWIKI_DB_F_SYSTEM,
43       "created" => time(),
44       "lastmodified" => time(),
45       "author" => ewiki_author("PrepareAutolinking"),
46       "content" => "",
47       "meta" => "",
48       "refs" => "\n\n" . implode("\n", $pages) . "\n\n",
49    );
50    $ok = ewiki_db::WRITE($save, true);
51
52    #-- output results
53    if ($ok) {
54       echo "[$cron]: Written informations about ".count($pages)." pages into the database cache entry '$DEST'"
55          . "\n   These pages will then get autolinked by the according plugin.\n";
56    }
57    else {
58       echo "[$cron]: Error writing the database cache entry '$DEST'. Autolinking pages won't work now.\n";
59    }
60
61 }
62
63 ?>