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); }
function WidgetRecentChanges($id, $params) { wfProfileIn(__METHOD__); $limit = intval($params['limit']); $limit = $limit <= 0 || $limit > 50 ? 15 : $limit; $api_params = array('action' => 'query', 'list' => 'recentchanges', 'rctype' => 'edit|new', 'rclimit' => $limit); if (!empty($params['hidebots'])) { $api_params['rcshow'] = '!bot'; } $res = WidgetFramework::callAPI($api_params); $ret = '<ul>'; if (!empty($res) && is_array($res['query']['recentchanges'])) { foreach ($res['query']['recentchanges'] as $change) { if ($change['pageid'] > 0) { $title = Title::newFromText($change['title'], $change['ns']); if (is_object($title)) { $display = htmlspecialchars($change['title']); $ret .= '<li><a href="' . $title->getLocalURL() . '" title="' . $display . '">' . $display . '</a>' . '<a class="WidgetRecentChangesDiffLink" href="' . htmlspecialchars($title->getLocalURL('diff=' . $change['revid'])) . '">diff</a></li>'; } } } } $ret .= '</ul>'; wfProfileOut(__METHOD__); return $ret; }
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; }
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)); }
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'); } }
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; }
function WidgetShoutBoxGetOnline() { global $wgEnableWhosOnlineExt, $wgMemc; if (empty($wgEnableWhosOnlineExt)) { return false; } wfProfileIn(__METHOD__); // try memcache $key = wfMemcKey('widget::shoutbox::online'); $online = $wgMemc->get($key); // return cached online data if (is_array($online)) { wfProfileOut(__METHOD__); return $online; } $online = WidgetFramework::callAPI(array('action' => 'query', 'list' => 'whosonline', 'wklimit' => '10')); // store in memcache if (is_array($online) && isset($online['query'])) { $wgMemc->set($key, $online['query'], 600); } else { $online['query'] = false; } wfProfileOut(__METHOD__); return $online['query']; }
function WidgetReferrers($id, $params) { wfProfileIn(__METHOD__); global $wgUser, $wgLang, $wgMemc, $wgCityId; $limit = array_key_exists('limit', $params) && !empty($params['limit']) ? $params['limit'] : 25; $wkuseext = array_key_exists('wt_show_referrers', $params) ? $params['wt_show_referrers'] : 1; $wkparamdate = $wkfromdate = array_key_exists('wt_show_period', $params) && !empty($params['wt_show_period']) ? $params['wt_show_period'] : ""; $memcKey = wfMemcKey('widgets:referers:cloud:' . $limit . ':' . $wkuseext . ':' . $wkparamdate); $cloud = $wgMemc->get($memcKey); if (is_string($cloud)) { //if ( false ) { wfProfileOut(__METHOD__); return '<!-- using memcache: yes ("' . $memcKey . '") -->' . $cloud; } wfProfileIn(__METHOD__ . '::miss'); // get last edits from API $api_param = array('action' => 'query', 'list' => 'wkreferer', 'wkcity' => $wgCityId, 'wkusefulldomain' => 1, 'wkuseext' => $wkuseext, 'wknodomain' => 'Unneeded_referrers', 'wklimit' => $limit, 'wkoffset' => 0, 'wkfromdate' => $wkfromdate); $results = WidgetFramework::callAPI($api_param); if (count($results['query']['wkreferer']) == 0) { # show default link to wikia.com $default = '<span title="www.wikia.com/1" class="widgetReferrersDomainTag" style="font-size:1em">'; $default .= '<a href="http://www.wikia.com">www.wikia.com</a></span>'; return '<div style="text-align:center">' . $default . '</div>'; } $domains = array(); // prevent showing the IP'like and "wikia.com" domain names foreach ($results['query']['wkreferer'] as $domain) { if (!User::isIP($domain['domain']) && User::isIP(gethostbyname(trim($domain['domain'])))) { if ($wkuseext == 1 && strpos($domain['domain'], 'wikia.com') !== false) { continue; } $domains[$domain['domain']] = $domain['count']; } } // exit early if no domains were found if (empty($domains)) { $wgMemc->set($memcKey, '', 7200); // store for 2h // FIXME: should probably give some sort of message to the user return ''; } ksort($domains); //print_pre($wgCityId);print_pre($results);print_pre($domains); // sizing (high math - oh yes ;) $min = log(min($domains)); $max = log(max($domains)); $min_size = 1; $max_size = 3; $tags = array(); // prepare cloud elements if ($max) { foreach ($domains as $name => $count) { $tags[$name] = array('name' => str_replace(array('.com', '.org', '.net', 'www.'), '', $name), 'url' => 'http://' . $name, 'count' => number_format($count, 0, ',', ' '), 'size' => round($min_size + (log($count) - $min) / $max * ($max_size - $min_size), 3)); } } //print_pre($tags); $ret = '<!-- city: ' . $wgCityId . ' -->'; foreach ($tags as $tag) { $ret .= '<span title="' . htmlspecialchars($tag['name']) . ' / ' . $tag['count'] . '" class="widgetReferrersDomainTag" style="font-size:' . $tag['size'] . 'em">' . '<a href="' . $tag['url'] . '">' . htmlspecialchars($tag['name']) . '</a></span> '; } $cloud = '<div style="text-align:center">' . $ret . '</div>'; $wgMemc->set($memcKey, $cloud, 7200); // store for 2h wfProfileOut(__METHOD__ . '::miss'); wfProfileOut(__METHOD__); return $cloud; }