Exemple #1
0
/**
 * returns an array of files changed since a given time using the
 * changelog
 *
 * The following constants can be used to control which changes are
 * included. Add them together as needed.
 *
 * RECENTS_SKIP_DELETED   - don't include deleted pages
 * RECENTS_SKIP_MINORS    - don't include minor changes
 * RECENTS_SKIP_SUBSPACES - don't include subspaces
 * RECENTS_MEDIA_CHANGES  - return media changes instead of page changes
 *
 * @param int    $from    date of the oldest entry to return
 * @param int    $to      date of the newest entry to return (for pagination, optional)
 * @param string $ns      restrict to given namespace (optional)
 * @param bool   $flags   see above (optional)
 *
 * @author Michael Hamann <*****@*****.**>
 * @author Ben Coburn <*****@*****.**>
 */
function getRecentsSince($from, $to = null, $ns = '', $flags = 0)
{
    global $conf;
    $recent = array();
    if ($to && $to < $from) {
        return $recent;
    }
    // read all recent changes. (kept short)
    if ($flags & RECENTS_MEDIA_CHANGES) {
        $lines = @file($conf['media_changelog']);
    } else {
        $lines = @file($conf['changelog']);
    }
    // we start searching at the end of the list
    $lines = array_reverse($lines);
    // handle lines
    $seen = array();
    // caches seen lines, _handleRecent() skips them
    foreach ($lines as $line) {
        $rec = _handleRecent($line, $ns, $flags, $seen);
        if ($rec !== false) {
            if ($rec['date'] >= $from) {
                if (!$to || $rec['date'] <= $to) {
                    $recent[] = $rec;
                }
            } else {
                break;
            }
        }
    }
    return array_reverse($recent);
}
/**
 * returns an array of recently changed files using the
 * changelog
 *
 * The following constants can be used to control which changes are
 * included. Add them together as needed.
 *
 * RECENTS_SKIP_DELETED   - don't include deleted pages
 * RECENTS_SKIP_MINORS    - don't include minor changes
 * RECENTS_SKIP_SUBSPACES - don't include subspaces
 *
 * @param int    $first   number of first entry returned (for paginating
 * @param int    $num     return $num entries
 * @param string $ns      restrict to given namespace
 * @param bool   $flags   see above
 *
 * @author Ben Coburn <*****@*****.**>
 */
function getRecents($first, $num, $ns = '', $flags = 0)
{
    global $conf;
    $recent = array();
    $count = 0;
    if (!$num) {
        return $recent;
    }
    // read all recent changes. (kept short)
    $lines = @file($conf['changelog']);
    // handle lines
    for ($i = count($lines) - 1; $i >= 0; $i--) {
        $rec = _handleRecent($lines[$i], $ns, $flags);
        if ($rec !== false) {
            if (--$first >= 0) {
                continue;
            }
            // skip first entries
            $recent[] = $rec;
            $count++;
            // break when we have enough entries
            if ($count >= $num) {
                break;
            }
        }
    }
    return $recent;
}