diff options
Diffstat (limited to 'lib/exe/indexer.php')
-rw-r--r-- | lib/exe/indexer.php | 114 |
1 files changed, 94 insertions, 20 deletions
diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php index 1c4128eb7..f8e2f7981 100644 --- a/lib/exe/indexer.php +++ b/lib/exe/indexer.php @@ -8,8 +8,6 @@ if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); define('DOKU_DISABLE_GZIP_OUTPUT',1); require_once(DOKU_INC.'inc/init.php'); -require_once(DOKU_INC.'inc/auth.php'); -require_once(DOKU_INC.'inc/events.php'); session_write_close(); //close session if(!defined('NL')) define('NL',"\n"); @@ -37,6 +35,7 @@ if ($evt->advise_before()) { runIndexer() or metaUpdate() or runSitemapper() or + sendDigest() or runTrimRecentChanges() or runTrimRecentChanges(true) or $evt->advise_after(); @@ -135,18 +134,6 @@ function runIndexer(){ global $conf; print "runIndexer(): started".NL; - // Move index files (if needed) - // Uses the importoldindex plugin to upgrade the index automatically. - // FIXME: Remove this from runIndexer when it is no longer needed. - if (@file_exists($conf['cachedir'].'/page.idx') && - (!@file_exists($conf['indexdir'].'/page.idx') || - !filesize($conf['indexdir'].'/page.idx')) && - !@file_exists($conf['indexdir'].'/index_importing')) { - echo "trigger TEMPORARY_INDEX_UPGRADE_EVENT\n"; - $tmp = array(); // no event data - trigger_event('TEMPORARY_INDEX_UPGRADE_EVENT', $tmp); - } - if(!$ID) return false; // check if indexing needed @@ -176,8 +163,6 @@ function runIndexer(){ } if($conf['dperm']) chmod($lock, $conf['dperm']); - require_once(DOKU_INC.'inc/indexer.php'); - // upgrade to version 2 if (!@file_exists($conf['indexdir'].'/pageword.idx')) idx_upgradePageWords(); @@ -210,11 +195,8 @@ function metaUpdate(){ if (@file_exists($file)) return false; if (!@file_exists(wikiFN($ID))) return false; - require_once(DOKU_INC.'inc/common.php'); - require_once(DOKU_INC.'inc/parserutils.php'); global $conf; - // gather some additional info from changelog $info = io_grep($conf['changelog'], '/^(\d+)\t(\d+\.\d+\.\d+\.\d+)\t'.preg_quote($ID,'/').'\t([^\t]+)\t([^\t\n]+)/', @@ -273,7 +255,7 @@ function runSitemapper(){ return false; } - $pages = file($conf['indexdir'].'/page.idx'); + $pages = idx_getIndex('page', ''); print 'runSitemapper(): creating sitemap using '.count($pages).' pages'.NL; // build the sitemap @@ -335,6 +317,98 @@ function runSitemapper(){ } /** + * Send digest and list mails for all subscriptions which are in effect for the + * current page + * + * @author Adrian Lang <lang@cosmocode.de> + */ +function sendDigest() { + echo 'sendDigest(): start'.NL; + global $ID; + global $conf; + if (!$conf['subscribers']) { + return; + } + $subscriptions = subscription_find($ID, array('style' => '(digest|list)', + 'escaped' => true)); + global $auth; + global $lang; + global $conf; + global $USERINFO; + + // remember current user info + $olduinfo = $USERINFO; + $olduser = $_SERVER['REMOTE_USER']; + + foreach($subscriptions as $id => $users) { + if (!subscription_lock($id)) { + continue; + } + foreach($users as $data) { + list($user, $style, $lastupdate) = $data; + $lastupdate = (int) $lastupdate; + if ($lastupdate + $conf['subscribe_time'] > time()) { + // Less than the configured time period passed since last + // update. + continue; + } + + // Work as the user to make sure ACLs apply correctly + $USERINFO = $auth->getUserData($user); + $_SERVER['REMOTE_USER'] = $user; + if ($USERINFO === false) { + continue; + } + + if (substr($id, -1, 1) === ':') { + // The subscription target is a namespace + $changes = getRecentsSince($lastupdate, null, getNS($id)); + } else { + if(auth_quickaclcheck($id) < AUTH_READ) continue; + + $meta = p_get_metadata($id); + $changes = array($meta['last_change']); + } + + // Filter out pages only changed in small and own edits + $change_ids = array(); + foreach($changes as $rev) { + $n = 0; + while (!is_null($rev) && $rev['date'] >= $lastupdate && + ($_SERVER['REMOTE_USER'] === $rev['user'] || + $rev['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT)) { + $rev = getRevisions($rev['id'], $n++, 1); + $rev = (count($rev) > 0) ? $rev[0] : null; + } + + if (!is_null($rev) && $rev['date'] >= $lastupdate) { + // Some change was not a minor one and not by myself + $change_ids[] = $rev['id']; + } + } + + if ($style === 'digest') { + foreach($change_ids as $change_id) { + subscription_send_digest($USERINFO['mail'], $change_id, + $lastupdate); + } + } elseif ($style === 'list') { + subscription_send_list($USERINFO['mail'], $change_ids, $id); + } + // TODO: Handle duplicate subscriptions. + + // Update notification time. + subscription_set($user, $id, $style, time(), true); + } + subscription_unlock($id); + } + + // restore current user info + $USERINFO = $olduinfo; + $_SERVER['REMOTE_USER'] = $olduser; +} + +/** * Formats a timestamp as ISO 8601 date * * @author <ungu at terong dot com> |