/**
 * Generate (prev x| next x) (20|50|100...) type links for paging
 *
 * @param $offset String
 * @param $limit Integer
 * @param $link String
 * @param $query String: optional URL query parameter string
 * @param $atend Bool: optional param for specified if this is the last page
 * @return String
 */
function wfViewPrevNext($offset, $limit, $link, $query = '', $atend = false)
{
    global $wgLang;
    $fmtLimit = $wgLang->formatNum($limit);
    // @todo FIXME: Why on earth this needs one message for the text and another one for tooltip?
    # Get prev/next link display text
    $prev = wfMsgExt('prevn', array('parsemag', 'escape'), $fmtLimit);
    $next = wfMsgExt('nextn', array('parsemag', 'escape'), $fmtLimit);
    # Get prev/next link title text
    $pTitle = wfMsgExt('prevn-title', array('parsemag', 'escape'), $fmtLimit);
    $nTitle = wfMsgExt('nextn-title', array('parsemag', 'escape'), $fmtLimit);
    # Fetch the title object
    if (is_object($link)) {
        $title =& $link;
    } else {
        $title = Title::newFromText($link);
        if (is_null($title)) {
            return false;
        }
    }
    # Make 'previous' link
    if (0 != $offset) {
        $po = $offset - $limit;
        $po = max($po, 0);
        $q = "limit={$limit}&offset={$po}";
        if ($query != '') {
            $q .= '&' . $query;
        }
        $plink = '<a href="' . $title->escapeLocalURL($q) . "\" title=\"{$pTitle}\" class=\"mw-prevlink\">{$prev}</a>";
    } else {
        $plink = $prev;
    }
    # Make 'next' link
    $no = $offset + $limit;
    $q = "limit={$limit}&offset={$no}";
    if ($query != '') {
        $q .= '&' . $query;
    }
    if ($atend) {
        $nlink = $next;
    } else {
        $nlink = '<a href="' . $title->escapeLocalURL($q) . "\" title=\"{$nTitle}\" class=\"mw-nextlink\">{$next}</a>";
    }
    # Make links to set number of items per page
    $nums = $wgLang->pipeList(array(wfNumLink($offset, 20, $title, $query), wfNumLink($offset, 50, $title, $query), wfNumLink($offset, 100, $title, $query), wfNumLink($offset, 250, $title, $query), wfNumLink($offset, 500, $title, $query)));
    return wfMsgHtml('viewprevnext', $plink, $nlink, $nums);
}
Example #2
0
/**
 * @todo document
 */
function wfViewPrevNext($offset, $limit, $link, $query = '', $atend = false)
{
    global $wgLang;
    $fmtLimit = $wgLang->formatNum($limit);
    $prev = wfMsg('prevn', $fmtLimit);
    $next = wfMsg('nextn', $fmtLimit);
    if (is_object($link)) {
        $title =& $link;
    } else {
        $title = Title::newFromText($link);
        if (is_null($title)) {
            return false;
        }
    }
    if (0 != $offset) {
        $po = $offset - $limit;
        if ($po < 0) {
            $po = 0;
        }
        $q = "limit={$limit}&offset={$po}";
        if ('' != $query) {
            $q .= '&' . $query;
        }
        $plink = '<a href="' . $title->escapeLocalUrl($q) . "\">{$prev}</a>";
    } else {
        $plink = $prev;
    }
    $no = $offset + $limit;
    $q = 'limit=' . $limit . '&offset=' . $no;
    if ('' != $query) {
        $q .= '&' . $query;
    }
    if ($atend) {
        $nlink = $next;
    } else {
        $nlink = '<a href="' . $title->escapeLocalUrl($q) . "\">{$next}</a>";
    }
    $nums = wfNumLink($offset, 20, $title, $query) . ' | ' . wfNumLink($offset, 50, $title, $query) . ' | ' . wfNumLink($offset, 100, $title, $query) . ' | ' . wfNumLink($offset, 250, $title, $query) . ' | ' . wfNumLink($offset, 500, $title, $query);
    return wfMsg('viewprevnext', $plink, $nlink, $nums);
}