Exemplo n.º 1
0
/**
 * Special page "user contributions".
 * Shows a list of the contributions of a user.
 *
 * @return	none
 * @param	$par	String: (optional) user name of the user for which to show the contributions
 */
function wfSpecialContributions($par = null)
{
    global $wgUser, $wgOut, $wgLang, $wgRequest;
    $target = isset($par) ? $par : $wgRequest->getVal('target');
    if (!strlen($target)) {
        $wgOut->showErrorPage('notargettitle', 'notargettext');
        return;
    }
    $nt = Title::newFromURL($target);
    if (!$nt) {
        $wgOut->showErrorPage('notargettitle', 'notargettext');
        return;
    }
    $options = array();
    list($options['limit'], $options['offset']) = wfCheckLimits();
    $options['offset'] = $wgRequest->getVal('offset');
    /* Offset must be an integral. */
    if (!strlen($options['offset']) || !preg_match('/^[0-9]+$/', $options['offset'])) {
        $options['offset'] = '';
    }
    $title = SpecialPage::getTitleFor('Contributions');
    $options['target'] = $target;
    $nt =& Title::makeTitle(NS_USER, $nt->getDBkey());
    $finder = new ContribsFinder($target == 'newbies' ? 'newbies' : $nt->getText());
    $finder->setLimit($options['limit']);
    $finder->setOffset($options['offset']);
    if (($ns = $wgRequest->getVal('namespace', null)) !== null && $ns !== '') {
        $options['namespace'] = intval($ns);
        $finder->setNamespace($options['namespace']);
    } else {
        $options['namespace'] = '';
    }
    if ($wgUser->isAllowed('rollback') && $wgRequest->getBool('bot')) {
        $options['bot'] = '1';
    }
    if ($wgRequest->getText('go') == 'prev') {
        $offset = $finder->getPreviousOffsetForPaging();
        if ($offset !== false) {
            $options['offset'] = $offset;
            $prevurl = $title->getLocalURL(wfArrayToCGI($options));
            $wgOut->redirect($prevurl);
            return;
        }
    }
    if ($wgRequest->getText('go') == 'first' && $target != 'newbies') {
        $offset = $finder->getFirstOffsetForPaging();
        if ($offset !== false) {
            $options['offset'] = $offset;
            $prevurl = $title->getLocalURL(wfArrayToCGI($options));
            $wgOut->redirect($prevurl);
            return;
        }
    }
    if ($target == 'newbies') {
        $wgOut->setSubtitle(wfMsgHtml('sp-contributions-newbies-sub'));
    } else {
        $wgOut->setSubtitle(wfMsgHtml('contribsub', contributionsSub($nt)));
    }
    $id = User::idFromName($nt->getText());
    wfRunHooks('SpecialContributionsBeforeMainOutput', $id);
    $wgOut->addHTML(contributionsForm($options));
    $contribs = $finder->find();
    if (count($contribs) == 0) {
        $wgOut->addWikiText(wfMsg('nocontribs'));
        return;
    }
    list($early, $late) = $finder->getEditLimits();
    $lastts = count($contribs) ? $contribs[count($contribs) - 1]->rev_timestamp : 0;
    $atstart = !count($contribs) || $late == $contribs[0]->rev_timestamp;
    $atend = !count($contribs) || $early == $lastts;
    // These four are defaults
    $newestlink = wfMsgHtml('sp-contributions-newest');
    $oldestlink = wfMsgHtml('sp-contributions-oldest');
    $newerlink = wfMsgHtml('sp-contributions-newer', $options['limit']);
    $olderlink = wfMsgHtml('sp-contributions-older', $options['limit']);
    if (!$atstart) {
        $stuff = $title->escapeLocalURL(wfArrayToCGI(array('offset' => ''), $options));
        $newestlink = "<a href=\"{$stuff}\">{$newestlink}</a>";
        $stuff = $title->escapeLocalURL(wfArrayToCGI(array('go' => 'prev'), $options));
        $newerlink = "<a href=\"{$stuff}\">{$newerlink}</a>";
    }
    if (!$atend) {
        $stuff = $title->escapeLocalURL(wfArrayToCGI(array('go' => 'first'), $options));
        $oldestlink = "<a href=\"{$stuff}\">{$oldestlink}</a>";
        $stuff = $title->escapeLocalURL(wfArrayToCGI(array('offset' => $lastts), $options));
        $olderlink = "<a href=\"{$stuff}\">{$olderlink}</a>";
    }
    if ($target == 'newbies') {
        $firstlast = "({$newestlink})";
    } else {
        $firstlast = "({$newestlink} | {$oldestlink})";
    }
    $urls = array();
    foreach (array(20, 50, 100, 250, 500) as $num) {
        $stuff = $title->escapeLocalURL(wfArrayToCGI(array('limit' => $num), $options));
        $urls[] = "<a href=\"{$stuff}\">" . $wgLang->formatNum($num) . "</a>";
    }
    $bits = implode($urls, ' | ');
    $prevnextbits = $firstlast . ' ' . wfMsgHtml('viewprevnext', $newerlink, $olderlink, $bits);
    $wgOut->addHTML("<p>{$prevnextbits}</p>\n");
    $wgOut->addHTML("<ul>\n");
    $sk = $wgUser->getSkin();
    foreach ($contribs as $contrib) {
        $wgOut->addHTML(ucListEdit($sk, $contrib));
    }
    $wgOut->addHTML("</ul>\n");
    $wgOut->addHTML("<p>{$prevnextbits}</p>\n");
}
Exemplo n.º 2
0
/**
 * Special page "user contributions".
 * Shows a list of the contributions of a user.
 *
 * @return	none
 * @param	$par	String: (optional) user name of the user for which to show the contributions
 */
function wfSpecialContributions($par = null)
{
    global $wgUser, $wgOut, $wgLang, $wgRequest;
    $options = array();
    if (isset($par) && $par == 'newbies') {
        $target = 'newbies';
        $options['contribs'] = 'newbie';
    } elseif (isset($par)) {
        $target = $par;
    } else {
        $target = $wgRequest->getVal('target');
    }
    // check for radiobox
    if ($wgRequest->getVal('contribs') == 'newbie') {
        $target = 'newbies';
        $options['contribs'] = 'newbie';
    }
    $wgOut->addHTML("<div class='section_text' style='font-size: .9em;'>");
    if (!strlen($target)) {
        $wgOut->addHTML(contributionsForm(''));
        return;
    }
    $options['limit'] = $wgRequest->getInt('limit', 50);
    $options['target'] = $target;
    $nt = Title::makeTitleSafe(NS_USER, $target);
    if (!$nt) {
        $wgOut->addHTML(contributionsForm(''));
        return;
    }
    $id = User::idFromName($nt->getText());
    if ($target != 'newbies') {
        $target = $nt->getText();
        $wgOut->setSubtitle(contributionsSub($nt, $id));
    } else {
        $wgOut->setSubtitle(wfMsgHtml('sp-contributions-newbies-sub'));
    }
    if (($ns = $wgRequest->getVal('namespace', null)) !== null && $ns !== '') {
        $options['namespace'] = intval($ns);
    } else {
        $options['namespace'] = '';
    }
    if ($wgUser->isAllowed('markbotedit') && $wgRequest->getBool('bot')) {
        $options['bot'] = '1';
    }
    $skip = $wgRequest->getText('offset') || $wgRequest->getText('dir') == 'prev';
    # Offset overrides year/month selection
    if (($month = $wgRequest->getIntOrNull('month')) !== null && $month !== -1) {
        $options['month'] = intval($month);
    } else {
        $options['month'] = '';
    }
    if (($year = $wgRequest->getIntOrNull('year')) !== null) {
        $options['year'] = intval($year);
    } else {
        if ($options['month']) {
            $thisMonth = intval(gmdate('n'));
            $thisYear = intval(gmdate('Y'));
            if (intval($options['month']) > $thisMonth) {
                $thisYear--;
            }
            $options['year'] = $thisYear;
        } else {
            $options['year'] = '';
        }
    }
    wfRunHooks('SpecialContributionsBeforeMainOutput', array($id));
    $wgOut->addHTML(contributionsForm($options));
    $wgOut->addHTML("<div style='font-size:95%; margin-bottom:10px;'>" . contributionsSub($nt, $id) . "</div>");
    # Show original selected options, don't apply them so as to allow paging
    $_GET['year'] = '';
    // hack for Pager
    $_GET['month'] = '';
    // hack for Pager
    if ($skip) {
        $options['year'] = '';
        $options['month'] = '';
    }
    $pager = new ContribsPager($target, $options['namespace'], $options['year'], $options['month']);
    if (!$pager->getNumRows()) {
        $wgOut->addWikiMsg('nocontribs');
        return;
    }
    # Show a message about slave lag, if applicable
    if (($lag = $pager->getDatabase()->getLag()) > 0) {
        $wgOut->showLagWarning($lag);
    }
    $wgOut->addHTML('<p>' . $pager->getNavigationBar() . '</p>' . $pager->getBody() . '<p>' . $pager->getNavigationBar() . '</p>');
    # If there were contributions, and it was a valid user or IP, show
    # the appropriate "footer" message - WHOIS tools, etc.
    if ($target != 'newbies') {
        $message = IP::isIPAddress($target) ? 'sp-contributions-footer-anon' : 'sp-contributions-footer';
        $text = wfMsgNoTrans($message, $target);
        if (!wfEmptyMsg($message, $text) && $text != '-') {
            $wgOut->addHtml('<div class="mw-contributions-footer">');
            $wgOut->addWikiText($text);
            $wgOut->addHtml('</div>');
        }
    }
    $wgOut->addHTML("</div>");
}
/**
 * Special page "user contributions".
 * Shows a list of the contributions of a user.
 *
 * @return	none
 * @param	$par	String: (optional) user name of the user for which to show the contributions
 */
function wfSpecialContributions($par = null)
{
    global $wgUser, $wgOut, $wgLang, $wgRequest;
    $options = array();
    if (isset($par) && $par == 'newbies') {
        $target = 'newbies';
        $options['contribs'] = 'newbie';
    } elseif (isset($par)) {
        $target = $par;
    } else {
        $target = $wgRequest->getVal('target');
    }
    // check for radiobox
    if ($wgRequest->getVal('contribs') == 'newbie') {
        $target = 'newbies';
        $options['contribs'] = 'newbie';
    }
    if (!strlen($target)) {
        $wgOut->addHTML(contributionsForm(''));
        return;
    }
    $options['limit'] = $wgRequest->getInt('limit', 50);
    $options['target'] = $target;
    $nt = Title::makeTitleSafe(NS_USER, $target);
    if (!$nt) {
        $wgOut->addHTML(contributionsForm(''));
        return;
    }
    $id = User::idFromName($nt->getText());
    if ($target != 'newbies') {
        $target = $nt->getText();
        $wgOut->setSubtitle(contributionsSub($nt, $id));
    } else {
        $wgOut->setSubtitle(wfMsgHtml('sp-contributions-newbies-sub'));
    }
    if (($ns = $wgRequest->getVal('namespace', null)) !== null && $ns !== '') {
        $options['namespace'] = intval($ns);
    } else {
        $options['namespace'] = '';
    }
    /* BizzWiki */
    if ($ns == null || $ns == "") {
        $ns = 0;
    }
    if ($wgUser->isAllowed('rollback', $ns) && $wgRequest->getBool('bot')) {
        $options['bot'] = '1';
    }
    wfRunHooks('SpecialContributionsBeforeMainOutput', $id);
    $wgOut->addHTML(contributionsForm($options));
    $pager = new ContribsPager($target, $options['namespace']);
    if (!$pager->getNumRows()) {
        $wgOut->addWikiText(wfMsg('nocontribs'));
        return;
    }
    $wgOut->addHTML('<p>' . $pager->getNavigationBar() . '</p>' . $pager->getBody() . '<p>' . $pager->getNavigationBar() . '</p>');
    # If there were contributions, and it was a valid user or IP, show
    # the appropriate "footer" message - WHOIS tools, etc.
    if ($target != 'newbies') {
        $message = IP::isIPAddress($target) ? 'sp-contributions-footer-anon' : 'sp-contributions-footer';
        $text = wfMsg($message, $target);
        if (!wfEmptyMsg($message, $text) && $text != '-') {
            $wgOut->addHtml('<div class="mw-contributions-footer">');
            $wgOut->addWikiText($text);
            $wgOut->addHtml('</div>');
        }
    }
}