예제 #1
0
function WidgetAncientPages($id, $params)
{
    wfProfileIn(__METHOD__);
    global $wgTitle, $wgLang, $wgOut;
    // load class if it's not loaded yet...
    if (!class_exists('AncientPagesPage')) {
        require_once $IP . 'includes/SpecialAncientpages.php';
    }
    if (!is_object($wgTitle)) {
        $wgTitle = Title::newMainPage();
    }
    $offset = 0;
    $limit = intval($params['limit']);
    $limit = $limit <= 0 || $limit > 50 ? 10 : $limit;
    $pages = array();
    // query the special page object
    $showSpecial = false;
    $app = new WidgetAncientPagesPage($showSpecial);
    $app->setListoutput(TRUE);
    $app->doQuery($offset, $limit, $showSpecial);
    $items = array();
    $aRows = $app->getResult();
    if (!empty($aRows) && is_array($aRows)) {
        foreach ($aRows as $sTitle => $sTimestamp) {
            $date = $wgLang->sprintfDate('j M Y', date('YmdHis', $sTimestamp));
            $oTitle = Title::newFromText($sTitle, NS_MAIN);
            if ($oTitle instanceof Title) {
                $items[] = array('name' => $oTitle->getText(), 'href' => $oTitle->getLocalURL(), 'title' => wfMsg('lastmodifiedat', date('H:i', $sTimestamp), $date));
            }
        }
    }
    wfProfileOut(__METHOD__);
    return WidgetFramework::wrapLinks($items) . WidgetFramework::moreLink(Title::newFromText('Ancientpages', NS_SPECIAL)->getLocalURL());
}
예제 #2
0
function WidgetTopContent($id, $params)
{
    wfProfileIn(__METHOD__);
    // select active section
    $active = $params['at'];
    list($sections, $default) = WidgetTopContentGetSectionsList();
    if (!array_key_exists($active, $sections)) {
        $active = $default;
    }
    // ...and get its content
    $section = WidgetTopContentGetSection($active, $sections[$active]);
    // select box
    $provider =& DataProvider::singleton();
    // don't show select box when being rendered by WidgetTag
    if (!isset($params['_widgetTag'])) {
        $out_selector = '<select onchange="WidgetTopContentSwitchSection(this);" id="' . $id . '_select">';
        $out_sections = '';
        foreach ($sections as $key => $val) {
            $out_selector .= '<option value="' . $key . '"' . ($key == $active ? ' selected="selected"' : '') . '>' . $provider->Translate($key) . '</option>';
        }
        $out_selector .= '</select>';
    } else {
        $out_selector = '';
    }
    // more link
    $more = Title::makeTitle(NS_SPECIAL, 'Top')->getLocalURL() . '/' . $active;
    wfProfileOut(__METHOD__);
    return array('body' => $section . $out_selector . WidgetFramework::moreLink($more));
}
예제 #3
0
function WidgetActiveTalkPages($id, $params)
{
    global $wgLang;
    wfProfileIn(__METHOD__);
    // get last edits from API
    $results = WidgetFramework::callAPI(array('action' => 'query', 'list' => 'recentchanges', 'rcnamespace' => NS_TALK, 'rcprop' => 'title|timestamp|ids|user|loginfo', 'rclimit' => 150));
    $list = array();
    if (!empty($results['query']['recentchanges'])) {
        // prevent showing the same page more then once
        foreach ($results['query']['recentchanges'] as $edit) {
            if (isset($edit['logtype']) && $edit['logtype'] == 'delete') {
                continue;
            }
            $timestamp = strtotime($edit['timestamp']);
            $date = $wgLang->sprintfDate('j M Y (H:i)', date('YmdHis', $timestamp));
            $title = Title::newFromText($edit['title'], $edit['ns']);
            if ($title !== null && !isset($list[$edit['title']])) {
                $list[$edit['title']] = array('href' => $title->getLocalURL('diff=' . $edit['revid']), 'title' => $date . ' (rev #' . $edit['revid'] . ')', 'name' => $title->getText());
            }
        }
    }
    $limit = intval($params['limit']);
    $limit = $limit <= 0 || $limit > 50 ? 15 : $limit;
    // limit results list
    $list = array_slice($list, 0, $limit);
    // 'more' link...
    $more = Title::newFromText('Recentchanges', NS_SPECIAL)->getLocalURL('namespace=1');
    return WidgetFramework::wrapLinks($list) . WidgetFramework::moreLink($more);
}
예제 #4
0
function WidgetContribs($id, $params)
{
    wfProfileIn(__METHOD__);
    global $wgUser;
    // limit amount of messages
    $limit = intval($params['limit']);
    $limit = $limit <= 0 || $limit > 50 ? 10 : $limit;
    // get last edits from API
    $results = WidgetFramework::callAPI(array('action' => 'query', 'list' => 'usercontribs', 'ucuser' => $wgUser->getName(), 'uclimit' => $limit));
    $ret = '';
    if (!empty($results['query']['usercontribs'])) {
        $list = array();
        foreach ($results['query']['usercontribs'] as $contrib) {
            $title = Title::newFromText($contrib['title'], $contrib['ns']);
            if (empty($title)) {
                //bad title returned, cant use it, dont display it
                //note: how did the api return an unusable/bad pagename?
                continue;
            }
            $list[] = array('href' => $title->getLocalURL(), 'name' => $contrib['title']);
        }
        $ret = WidgetFramework::wrapLinks($list);
        // 'more' link...
        $more = Title::newFromText('Contributions/' . $wgUser->getName(), NS_SPECIAL)->getLocalURL();
        $ret .= WidgetFramework::moreLink($more);
    } else {
        $ret = wfMsg('widget-contribs-empty');
    }
    wfProfileOut(__METHOD__);
    return $ret;
}
예제 #5
0
function WidgetNewPages($id, $params)
{
    wfProfileIn(__METHOD__);
    $items = array();
    if (class_exists('DataProvider')) {
        $items = DataProvider::singleton()->GetNewlyCreatedArticles();
    }
    wfProfileOut(__METHOD__);
    return count($items) > 0 ? WidgetFramework::wrapLinks($items) . WidgetFramework::moreLink(Title::newFromText('Newpages', NS_SPECIAL)->getLocalURL()) : wfMsg('widget-empty-list');
}
예제 #6
0
function WidgetMostVisited($id, $params)
{
    wfProfileIn(__METHOD__);
    $items = array();
    if (class_exists('DataProvider')) {
        $articles =& DataProvider::singleton()->GetMostVisitedArticles();
        if (is_array($articles) && count($articles) > 0) {
            foreach ($articles as $article) {
                $items[] = array('href' => $article['url'], 'name' => $article['text']);
            }
        }
    }
    //print_pre($items);
    wfProfileOut(__METHOD__);
    return count($items) > 0 ? WidgetFramework::wrapLinks($items) . WidgetFramework::moreLink(Title::newFromText('Top', NS_SPECIAL)->getLocalURL() . '/most_visited') : wfMsg('widget-empty-list');
}
예제 #7
0
function WidgetProblemReports($id, $params)
{
    // check whether ProblemReports extension is enabled on this wiki
    global $wgProblemReportsEnable;
    if (!isset($wgProblemReportsEnable) || !$wgProblemReportsEnable) {
        return '<em>Extension ProblemReports not enabled on this wiki</em>';
        // fallback message
    }
    $params['limit'] = intval($params['limit']);
    $apiParams = array('wkshowall' => $params['pr_raports_from_this_wikia'] == 0 && WikiaApiQueryProblemReports::userCanDoActions() ? 1 : NULL, 'wktype' => intval($params['pr_table_problem_type']) >= 0 ? intval($params['pr_table_problem_type']) : NULL, 'wkstaff' => $params['show'] == 2 ? 1 : NULL, 'wkarchived' => $params['show'] == 1 ? 1 : NULL, 'wklimit' => $params['limit'] <= 0 || $params['limit'] > 50 ? 25 : $params['limit']);
    $apiParams['action'] = 'query';
    $apiParams['list'] = 'problemreports';
    //print_pre($apiParams);
    $data = WidgetFramework::callAPI($apiParams);
    $count = intval($data['query']['reports']);
    if ($count == 0) {
        return array('title' => wfMsg('problemreports'), 'body' => wfMsg('pr_no_reports'));
    }
    $reports = $data['query']['problemreports'];
    $problemTypes = array(wfMsg('pr_what_problem_spam_short'), wfMsg('pr_what_problem_vandalised_short'), wfMsg('pr_what_problem_incorrect_content_short'), wfMsg('pr_what_problem_software_bug_short'), wfMsg('pr_what_problem_other_short'));
    // list reports
    $items = array();
    //url used for linking to PR ids
    $baseUrl = Title::newFromText('ProblemReports', NS_SPECIAL)->getLocalURL();
    // build params for 'more' link based on this widget's settings
    $urlParams = array();
    if ($params['show'] == 2) {
        $urlParams[] = 'staff=1';
    } elseif ($params['show'] == 1) {
        $urlParams[] = 'archived=1';
    }
    if ($apiParams['wkshowall'] == 1) {
        $urlParams[] = 'showall=1';
    }
    if ($apiParams['wktype'] != NULL) {
        $urlParams[] = 'problem=' . $apiParams['wktype'];
    }
    // smush
    $urlParams = implode('&', $urlParams);
    // apply and build
    $moreUrl = Title::newFromText('ProblemReports', NS_SPECIAL)->getLocalURL($urlParams);
    foreach ($reports as $problem) {
        $date = date('d m Y', strtotime($problem['date']));
        $items[] = array('href' => $baseUrl . '/' . $problem['id'], 'title' => '#' . $problem['id'] . ' - ' . wfMsg('pr_table_date_submitted') . ': ' . $date, 'name' => wfShortenText($problem['title'], 25) . ' [' . $problemTypes[$problem['type']] . ($apiParams['wkshowall'] == 1 ? ' | ' . str_replace(array('http://', '.wikia.com', '.wikia-inc.com'), '', $problem['server']) : '') . ']');
    }
    return array('title' => wfMsg('problemreports') . ' (' . $count . ')', 'body' => WidgetFramework::wrapLinks($items) . WidgetFramework::moreLink($moreUrl));
}
예제 #8
0
function WidgetEditedRecently($id, $params)
{
    wfProfileIn(__METHOD__);
    global $wgTitle, $wgRequest;
    if ((!is_object($wgTitle) || $wgTitle->mArticleID == -1) && $wgRequest->getVal('actionType') == 'add') {
        // ask for page refresh
        wfProfileOut(__METHOD__);
        return wfMsg('refreshpage') . '<br /><br /><button onclick="window.location.reload()">' . wfMsg('go') . '</button>';
    }
    $limit = intval($params['limit']);
    $limit = $limit <= 0 || $limit > 50 ? 15 : $limit;
    $title = ($wgTitle->getNamespace() != NS_MAIN ? $wgTitle->getNsText() . ':' : '') . $wgTitle->getText();
    $res = WidgetFramework::callAPI(array('action' => 'query', 'prop' => 'revisions', 'titles' => $title, 'rvprop' => 'user', 'rvlimit' => $limit));
    // create list of recent contributors
    $items = array();
    if (!empty($res['query']['pages'])) {
        $contribs = array_shift($res['query']['pages']);
        if (!empty($contribs['revisions'])) {
            foreach ($contribs['revisions'] as $contrib) {
                $is_anon = isset($contrib['anon']);
                $author = $contrib['user'];
                if ($is_anon) {
                    // don't show anon edits - requested by JohnQ
                    continue;
                } else {
                    $oUser = User::newFromName($author);
                    if ($oUser instanceof User && !$oUser->isBlocked()) {
                        $userPage = $oUser->getUserPage();
                        if ($userPage instanceof Title && $userPage->exists()) {
                            $items[$author] = array('href' => $userPage->getLocalURL(), 'name' => $author);
                        }
                    }
                }
            }
        }
    }
    wfProfileOut(__METHOD__);
    if (count($items) > 0) {
        return WidgetFramework::wrapLinks($items) . WidgetFramework::moreLink($wgTitle->getLocalURL('action=history'));
    } else {
        return wfMsg('nocontributors');
    }
}
예제 #9
0
function WidgetWatchlist($id, $params)
{
    wfProfileIn(__METHOD__);
    // get last edits from API
    $results = WidgetFramework::callAPI(array('action' => 'query', 'list' => 'watchlist', 'wllimit' => 25));
    $ret = '';
    if (!empty($results['query']['watchlist'])) {
        $list = array();
        foreach ($results['query']['watchlist'] as $watch) {
            $title = Title::newFromText($watch['title'], $watch['ns']);
            $list[] = array('href' => $title->getLocalURL(), 'name' => $watch['title']);
        }
        $ret = WidgetFramework::wrapLinks($list);
    } else {
        $ret = wfMsg('nowatchlist');
    }
    // 'more' link...
    $more = Title::newFromText('Watchlist', NS_SPECIAL)->getLocalURL();
    $ret .= WidgetFramework::moreLink($more);
    wfProfileOut(__METHOD__);
    return $ret;
}
예제 #10
0
function WidgetShoutBox($id, $params)
{
    global $wgUser, $wgTitle, $wgRequest, $wgSitename, $wgLang, $wgEnableWidgetShoutbox;
    wfProfileIn(__METHOD__);
    // check if widget is enabled for this wiki and quit early if not
    if (isset($wgEnableWidgetShoutbox) && !$wgEnableWidgetShoutbox) {
        return wfMsg('widget-shoutbox-disabled');
    }
    // maybe user is trying to add a message to chat
    if ($wgRequest->getVal('message') && $wgRequest->getVal('rs') == 'WidgetFrameworkAjax') {
        $showChat = WidgetShoutBoxAddMessage($wgRequest->getVal('message'));
    } elseif ($wgRequest->getVal('msgid') && $wgRequest->getVal('rs') == 'WidgetFrameworkAjax') {
        //remove a message
        WidgetShoutBoxRemoveMessage($wgRequest->getVal('msgid'));
    }
    $ret = '';
    // should we show "chat" part of widget?
    $showChat = isset($showChat) || isset($_COOKIE[$id . '_showChat']) && intval($_COOKIE[$id . '_showChat']) == 1;
    $online = WidgetShoutBoxGetOnline();
    //WhosOnline is turned on
    if (is_array($online)) {
        // generate HTML for "who's online" part of widget
        $ret .= '<div id="' . $id . '_online"' . ($showChat ? ' style="display:none"' : '') . '>';
        $ret .= '<h5>' . wfMsg('monaco-whos-online') . ' (<a onclick="WidgetShoutboxTabToogle(\'' . $id . '\', 0)" style="cursor: pointer">chat! &raquo;</a>)</h5>' . '<p style="margin:8px 0">Guests: ' . $online['anons'] . ' <span style="margin-left: 10px">Users: ' . $online['users'] . '</span></p>';
        $list = array();
        foreach ($online['whosonline'] as $user) {
            $url = Title::newFromText($user['user'], NS_USER);
            $list[] = array('href' => $url->getLocalURL(), 'name' => $user['user']);
        }
        $more = Title::newFromText('WhosOnline', NS_SPECIAL);
        $ret .= WidgetFramework::wrapLinks($list) . WidgetFramework::moreLink($more->getLocalURL());
        unset($list, $more);
        $ret .= '</div>';
    } else {
        // fallback when WhosOnline is turned off
        $showChat = true;
    }
    // generate HTML for "chat" part of widget
    $ret .= '<div id="' . $id . '_chat" class="WidgetShoutBoxChat"' . (!$showChat ? ' style="display:none"' : '') . '>';
    #temp disable header. (remove hardcoded 'Chat' text + WhosOnline has been disabled forever, and not coming back?)
    #$ret .= '<h5>Chat' . ($online !== false ? ' (<a onclick="WidgetShoutboxTabToogle(\''.$id.'\', 1)" style="cursor: pointer">'.
    #	wfMsg('monaco-whos-online').'? &raquo;</a>)' : '') . '</h5>';
    $msgs = WidgetShoutBoxGetMessages();
    // date limiter - dates after that timestamp will be outputed in HH:mm (9:38) format, before in d M (8 Sep)
    $midnight = strtotime('today 00:00');
    // time offset (set by user in his preferences)
    $time_offset = $wgUser->getOption('timecorrection') ? (int) $wgUser->getOption('timecorrection') * 3600 : 0;
    $count = 0;
    // limit amount of messages
    $limit = intval($params['limit']);
    $limit = $limit <= 0 || $limit > 50 ? 15 : $limit;
    $msgs = array_slice($msgs, 0, $limit);
    // last message author
    $last_msg_author = '';
    $last_msg_time = 0;
    $ret .= '<ul>';
    $id = intval(substr($id, 7));
    if (count($msgs) == 0) {
        $ret .= '<li>&lt;' . htmlspecialchars($wgSitename) . '&gt; ' . wfMsg('wt_shoutbox_initial_message') . '</li>';
    } else {
        // create parser instance
        $options = new ParserOptions();
        $options->setMaxIncludeSize(100);
        // refs #1939
        $parser = new Parser();
        // display messages
        foreach (array_reverse($msgs) as $msg) {
            // trim message
            $msg['message'] = trim($msg['message']);
            // include offset in timestamp
            $msg['time'] += $time_offset;
            //add remove link for privlidged users
            $removeLink = '';
            if (!isset($params['_widgetTag']) && $wgUser->isAllowed('shoutboxremove')) {
                $removeLink = '<a href="#" onclick="WidgetShoutBoxRemoveMsg(' . $id . ', ' . $msg['id'] . '); return false;">x</a> ';
            }
            // time
            //adjust user's timezone
            $msg['time'] = intval($wgLang->sprintfDate('U', $wgLang->userAdjust(wfTimestamp(TS_MW, $msg['time']))));
            $ret .= '<li' . ($count++ % 2 ? ' class="msgOdd"' : '') . '>' . $removeLink . htmlspecialchars('[' . date($msg['time'] < $midnight ? 'j M' : 'G:i', $msg['time']) . ']') . '&nbsp;';
            // user page link
            $userPage = Title::newFromText($msg['user'], NS_USER);
            $userLink = '<a href="' . $userPage->getLocalURL() . '">' . htmlspecialchars($msg['user']) . '</a>';
            // interprete IRC-like command (e.g. /me is going away for a while)
            //
            // @see www.ircbeginner.com/ircinfo/ircc-commands.html
            //
            if (substr($msg['message'], 0, 1) == '/') {
                $cmd = substr($msg['message'], 1, strpos($msg['message'], ' ') - 1);
                $msg['message'] = substr($msg['message'], 2 + strlen($cmd));
            } else {
                $cmd = '';
            }
            // parse message
            $parsedMsg = $parser->parse($msg['message'], $wgTitle, $options)->getText();
            // remove unwanted HTML tags
            $parsedMsg = strip_tags($parsedMsg, '<i><b><a>');
            // remove wrapping <p></p> tags
            $parsedMsg = trim(str_replace(array('<p>', '</p>'), '', $parsedMsg));
            // interpret irc-like command
            switch ($cmd) {
                case 'me':
                    // macbre: that's the only one that might me useful for us - ideas?
                    $ret .= '<strong>* ' . $userLink . ' <span class="shoutBoxMsg">' . $parsedMsg . '</span></strong>';
                    $last_msg_author = '';
                    $last_msg_time = 0;
                    break;
                default:
                    // repeating authors folding (Skype a'like ;)
                    $ret .= ($last_msg_author == $msg['user'] && $msg['time'] - $last_msg_time < 1200 ? '<strong>...</strong> ' : '&lt;' . $userLink . '&gt; ') . '<span class="shoutBoxMsg">' . $parsedMsg . '</span>';
                    $last_msg_author = $msg['user'];
                    $last_msg_time = $msg['time'];
            }
            // close message
            $ret .= '</li>';
        }
    }
    $ret .= '</ul>';
    // show form only for non-blocked and logged in users
    if ($wgUser->isLoggedIn() && !$wgUser->isBlocked() && !isset($params['_widgetTag'])) {
        $ret .= '<form onsubmit="WidgetShoutBoxSend(' . $id . '); return false;" action="">' . "\n";
        $ret .= '<input type="text" name="message" autocomplete="off" id="widget_' . $id . '_message" maxlength="100" />' . "\n";
        $ret .= '<input type="submit" value="' . wfMsg('send') . '" />' . "\n";
        $ret .= '</form>';
    }
    $ret .= '</div>';
    // close chat div
    wfProfileOut(__METHOD__);
    return $ret;
}