public function getLeaderboard(&$dbr) { global $wgUser; $sk = $wgUser->getSkin(); $startdate = strtotime('7 days ago'); $starttimestamp = date('YmdG', $startdate) . floor(date('i', $startdate) / 10) . '00000'; $data = $this->getLeaderboardData($dbr, $starttimestamp); $count = 0; $leaderboardData = array(); foreach ($data as $key => $value) { $u = new User(); $u->setName($key); if ($value > 0 && $key != '' && $u->getName() != "WRM") { $leaderboardData[$count] = array(); $img = Avatar::getPicture($u->getName(), true); if ($img == '') { $img = Avatar::getDefaultPicture(); } $leaderboardData[$count]['img'] = $img; $leaderboardData[$count]['user'] = $sk->makeLinkObj($u->getUserPage(), $u->getName()); $leaderboardData[$count]['count'] = $value; $data[$key] = $value * -1; $count++; if ($count >= 6) { break; } } } $html = ""; $count = 0; foreach ($leaderboardData as $leader) { if ($count == 0) { $html .= "<tr class='first'>"; } else { $html .= "<tr>"; } $html .= "<td class='cd-avatar'>" . $leader['img'] . "</td>"; $html .= "<td class='cd-user'>" . $leader['user'] . "</td>"; $html .= "<td class='cd-count'>" . $leader['count'] . "</td>"; $html .= "</tr>"; $count++; } $jsondata = array(); $jsondata['leaderboard'] = $html; return json_encode($jsondata); }
function getTopAuthorWidget() { global $wgUser; $startdate = strtotime('7 days ago'); $starttimestamp = date('Ymd-G', $startdate) . '!' . floor(date('i', $startdate) / 10) . '00000'; $data = LeaderBoard::getArticlesWritten($starttimestamp); arsort($data); $html = "<h3>Top Authors - Last 7 Days</h3><table class='stleaders'>"; $index = 1; $sk = $wgUser->getSkin(); foreach ($data as $key => $value) { $u = new User(); $value = number_format($value, 0, "", ','); $u->setName($key); if ($value > 0 && $key != '') { $class = ""; if ($index % 2 == 1) { $class = 'class="odd"'; } $img = Avatar::getPicture($u->getName(), true); if ($img == '') { $img = Avatar::getDefaultPicture(); } $html .= "<tr {$class}>\n\t\t\t\t\t<td class='leader_image'>" . $img . "</td>\n\t\t\t\t\t<td class='leader_user'>" . $sk->makeLinkObj($u->getUserPage(), $u->getName()) . "</td>\n\t\t\t\t\t<td class='leader_count'><a href='/Special:Leaderboard/{$target}?action=articlelist&period={$period}&lb_name=" . $u->getName() . "' >{$value}</a> </td>\n\t\t\t\t</tr> "; $data[$key] = $value * -1; $index++; } if ($index > 6) { break; } } $html .= "</table>"; return $html; }
function execute($par) { global $wgRequest, $wgOut, $wgUser, $wgLang; $target = isset($par) ? $par : $wgRequest->getVal('target'); $action = $wgRequest->getVal('action'); if ($target == '') { $wgOut->redirect($wgServer . "/Special:Leaderboard/articles_written"); return; } $wgOut->setPageTitle(wfMsg('leaderboard_title')); $wgOut->setRobotpolicy('noindex,nofollow'); $wgHooks["pageTabs"][] = "wfLeaderboardTabs"; $sk = $wgUser->getSkin(); $dbr = wfGetDB(DB_SLAVE); $me = Title::makeTitle(NS_SPECIAL, "Leaderboard"); $period = $wgRequest->getVal('period'); $startdate = '000000'; if ($period == 31) { $startdate = strtotime('31 days ago'); $period31selected = 'SELECTED'; } else { if ($period == 7) { $startdate = strtotime('7 days ago'); $period7selected = 'SELECTED'; } else { $period = 24; $startdate = strtotime('24 hours ago'); $period24selected = 'SELECTED'; } } //$starttimestamp = date('YmdG',$startdate) . '000000'; $starttimestamp = date('YmdG', $startdate) . floor(date('i', $startdate) / 10) . '00000'; if ($action == 'articles') { $this->showArticles($target, $starttimestamp, $wgRequest->getVal('lb_name')); return; } $wgOut->addScript(HtmlSnips::makeUrlTags('css', array('Leaderboard.css'), 'extensions/wikihow', false)); $wgOut->addScript(HtmlSnips::makeUrlTags('js', array('Leaderboard.js'), 'extensions/wikihow', false)); /* if ($action == 'articlelist') { $u = User::newFromName( $wgRequest->getVal( 'lb_name' ) ); if (isset($u)) { $this->showArticlesPage( $target, $period, $starttimestamp, $u->getName() ); } return; } */ $data = array(); // WHICH LB TO SHOW switch ($target) { case 'total_edits': $section = 'Other'; $learnlink = '/wikiHow:LB-Total-Edits'; $columnHeader = 'TotalEdits'; $data = $this->getTotalEdits($starttimestamp); break; case 'articles_categorized': $section = 'Other'; $learnlink = '/wikiHow:LB-Articles-Categorized'; $columnHeader = 'Articles Categorized'; $data = $this->getArticlesCategorized($starttimestamp); break; case 'images_added': $section = 'Imagevideo'; $learnlink = '/wikiHow:LB-Images-Added'; $columnHeader = 'Images Added'; $data = $this->getImagesAdded($starttimestamp); break; case 'videos_reviewed': $section = 'Imagevideo'; $learnlink = '/wikiHow:LB-Videos-Reviewed'; $columnHeader = 'Videos Reviewed'; $data = $this->getVideosReviewed($starttimestamp); break; case 'articles_nabed': $section = 'RCNAB'; $learnlink = '/wikiHow:LB-Articles-NABed'; $columnHeader = 'Articles NABed'; $data = $this->getArticlesNABed($starttimestamp); break; case 'risingstars_nabed': $section = 'RCNAB'; $learnlink = '/wikiHow:LB-Rising-Stars-NABed'; $columnHeader = 'Rising Stars NABed'; $data = $this->getRisingStarsNABed($starttimestamp); break; case 'rc_edits': $section = 'RCNAB'; $learnlink = '/wikiHow:LB-RC-Edits'; $columnHeader = 'RC Edits'; $data = $this->getRCEdits($starttimestamp); break; case 'rc_quick_edits': $section = 'RCNAB'; $learnlink = '/wikiHow:LB-RC-Quick-Edits'; $columnHeader = 'RC Quick Edits'; $data = $this->getRCQuickEdits($starttimestamp); break; case 'qc': $section = 'RCNAB'; $learnlink = '/wikiHow:Top-Guardians'; $columnHeader = 'Top Guardians'; $data = $this->getQCPatrols($starttimestamp); break; case 'requested_topics': $section = 'Writing'; $learnlink = '/wikiHow:LB-Requested-Topics'; $columnHeader = 'Requested Topics'; $data = $this->getRequestedTopics($starttimestamp); break; case 'risingstars_received': $section = 'Writing'; $learnlink = '/wikiHow:Rising-Star'; $columnHeader = 'Rising Stars Received'; $data = $this->getRisingStar($starttimestamp); break; case 'articles_written': $section = 'Writing'; $learnlink = '/wikiHow:LB-Articles-Written'; $columnHeader = 'Articles Written'; $data = $this->getArticlesWritten($starttimestamp); break; case 'repair_format': $section = 'Greenhouse'; $learnlink = '/wikiHow:LB-Repair_Format'; $columnHeader = 'Formats Fixed'; $data = $this->getArticlesRepaired($starttimestamp, 'format'); break; case 'repair_stub': $section = 'Greenhouse'; $learnlink = '/wikiHow:LB-Repair_Stub'; $columnHeader = 'Stubs Fixed'; $data = $this->getArticlesRepaired($starttimestamp, 'stub'); break; case 'repair_topic': $section = 'Greenhouse'; $learnlink = '/wikiHow:LB-Repair_Topic'; $columnHeader = 'Cultivated by Topic'; $data = $this->getArticlesRepaired($starttimestamp, 'topic'); break; case 'repair_cleanup': $section = 'Greenhouse'; $learnlink = '/wikiHow:LB-Repair_Cleanup'; $columnHeader = 'Cleanups Fixed'; $data = $this->getArticlesRepaired($starttimestamp, 'cleanup'); break; case 'repair_copyedit': $section = 'Greenhouse'; $learnlink = '/wikiHow:LB-Repair_Copyedit'; $columnHeader = 'Copyedits Fixed'; $data = $this->getArticlesRepaired($starttimestamp, 'copyedit'); break; case 'nfd': $section = 'Other'; $learnlink = '/wikiHow:NFD-Guardian'; $columnHeader = 'NFDs Reviewed'; $data = $this->getNfdsReviewed($starttimestamp); break; case 'thumbs_up': $section = 'Other'; $learnlink = '/wikiHow:Thumbs-Up'; $columnHeader = 'Thumbs Up'; $data = $this->getThumbsUp($starttimestamp); break; case 'spellchecked': $section = 'Writing'; $learnlink = '/wikiHow:Spellchecker'; $columnHeader = 'Articles Spell Checked'; $data = $this->getSpellchecked($starttimestamp); break; case 'methodguardian': $section = 'Other'; $learnlink = '/wikiHow:LB-Method-Guardian'; $columnHeader = 'Methods Guarded'; $data = $this->getMethodGuardian($starttimestamp); break; case 'methodeditor': $section = 'Other'; $learnlink = '/wikiHow:LB-Method-Editor'; $columnHeader = 'Methods Edited'; $data = $this->getMethodEditor($starttimestamp); break; case 'welcomewagon': $section = 'Other'; $learnlink = '/wikiHow:LB-Welcome-Wagon'; $columnHeader = 'Welcome Wagon'; $data = $this->getWelcomeWagon($starttimestamp); break; default: $wgOut->redirect($wgServer . "/Special:Leaderboard/articles_written"); return; } switch ($section) { case 'Other': $sectionStyleOther = "class='on'"; break; case 'RCNAB': $sectionStyleRCNAB = "class='on'"; break; case 'Writing': $sectionStyleWriting = "class='on'"; break; case 'Greenhouse': $sectionStyleGreenhouse = "class='on'"; break; case "Imagevideo": $sectionStyleImagevideo = "class='on'"; break; } // Vu Note: Due to the reskin adding elements above the articl_tab_line, I had use javascript to inject the tabs above the article_inner. hacky i know, but otherwise it would have to go into the skin which is worse. $dropdown = " <span style='float:right;'>In the last <select id='period' onChange='changePeriod(this);'> <option {$period24selected} value='24'>24 hours</option> <option {$period7selected} value='7'>7 days</option> <option {$period31selected} value='31'>31 days</option> </select> </span>"; $tabs_main = "<ul id='tabs'><li><a href='/Special:Leaderboard/articles_written' {$sectionStyleWriting} >Writing</a></li><li><a href='/Special:Leaderboard/articles_nabed' {$sectionStyleRCNAB} >RC and NAB</a></li><li><a href='/Special:Leaderboard/repair_format' {$sectionStyleGreenhouse} >Greenhouse</a></li><li><a href='/Special:Leaderboard/images_added' {$sectionStyleImagevideo} >Images/Videos</a></li><li><a href='/Special:Leaderboard/total_edits' {$sectionStyleOther} >Other</a></li></ul>"; $tabs_sub = $this->getTabs($section, $target); if ($action != 'articlelist') { $tabs_sub .= "<div class='clearall'></div>"; } $tab_sub .= "<div style='clear:both;'></div>"; $wgOut->addHTML("<div id='leaderboard_tabs'>{$dropdown}{$tabs_main}{$tabs_sub}</div>"); $wgOut->addHTML(" <style type='text/css' media='all'>/*<![CDATA[*/ @import '" . wfGetPad('/extensions/min/f/extensions/wikihow/winpop.css?rev=') . WH_SITEREV . "'; /*]]>*/</style>\n\t\t\t<script type='text/javascript' language='javascript' src='" . wfGetPad('/extensions/min/f/extensions/wikihow/winpop.js?rev=') . WH_SITEREV . "'></script>"); $wgOut->addHTML(" <script type='text/javascript'>\n\t\t\t\tvar lb_page = '{$target}';\n\t\t\t\tvar lb_period = '{$period}';\n\t\t\t</script>\n"); // //MAIN PAGE SECTION // if ($action == 'articlelist') { $u = User::newFromName($wgRequest->getVal('lb_name')); if (isset($u)) { $this->showArticlesPage($target, $period, $starttimestamp, $u->getName()); } else { echo wfMsg('leaderboard-invalid-user'); } return; } $wgOut->addHTML("<div id='Leaderboard' class='section_text'>\n\t\t\t<p class='leader_head'>Leaders: {$columnHeader}</p> <span class='leader_learn'><img src='" . wfGetPad('/skins/WikiHow/images/icon_help.jpg') . "'><a href='{$learnlink}'>Learn about this activity</a></span>\n\t\t"); $wgOut->addHTML("\n\t\t\t<table class='leader_table'>\n\t\t\t\t<tr> <td colspan='3' class='leader_title'>{$columnHeader}:</td> </tr> "); $index = 1; //display difference in only new articles //don't sort nfd b/c numbers can be big and include "," so don't sort nicely if ($target != 'rc_edits' && $target != 'nfd') { arsort($data); } foreach ($data as $key => $value) { $u = new User(); $u->setName($key); if ($value > 0 && $key != '' && $u->getName() != "WRM") { $class = ""; if ($index % 2 == 1) { $class = 'class="odd"'; } $img = Avatar::getPicture($u->getName(), true); if ($img == '') { $img = Avatar::getDefaultPicture(); } $wgOut->addHTML("\n\t\t\t\t<tr {$class}>\n\t\t\t\t\t<td class='leader_image'>" . $img . "</td>\n\t\t\t\t\t<td class='leader_user'>" . $sk->makeLinkObj($u->getUserPage(), $u->getName()) . "</td>\n\t\t\t\t\t<td class='leader_count'><a href='/Special:Leaderboard/{$target}?action=articlelist&period={$period}&lb_name=" . $u->getName() . "' >{$value}</a> </td>\n\t\t\t\t</tr> "); $data[$key] = $value * -1; $index++; } if ($index > 20) { break; } } $wgOut->addHTML("</table></div>"); }
/** * * For a given user id, returns the html * for an avatar to be displayed on the right * rail or in the info box * */ static function getUserInfo($user_id) { if ($user_id) { $u = new User(); $u->setID($user_id); $img = Avatar::getAvatarURL($u->getName()); if ($img == '') { $img = Avatar::getDefaultPicture(); } else { $img = "<img src='{$img}' />"; } $avatar = "<span><a href='{$u->getUserPage()->getFullURL()}' target='_blank' class='tooltip'>{$img}</a>"; $avatar .= "<span class='tooltip_span'>Hi, I'm {$u->getName()}</span></span>"; $avatar .= "<a target='new' href='{$u->getUserPage()->getFullURL()}'>{$u->getName()}</a>"; } return $avatar; }
/** * Display the HTML for this special page with all the widgets in it */ private function displayContainer() { global $wgWidgetList, $wgUser, $wgWidgetShortCodes; $containerJS = array('community-dashboard.js', 'dashboard-widget.js', 'jquery.ui.sortable.min.js', 'jquery.json-2.2.min.js'); $containerCSS = array('community-dashboard.css'); $jsTags = $this->makeUrlTags('js', $containerJS); $cssTags = $this->makeUrlTags('css', $containerCSS); // get all commonly updating stats, to see the initial widget // displays with $this->refreshData = $this->dashboardData->getStatsData(); // get all data such as wikihow-defined structure goals, dynamic // global data, and user-specific data $staticData = $this->dashboardData->loadStaticGlobalOpts(); $priorities = json_decode($staticData['cdo_priorities_json'], true); if (!is_array($priorities)) { $priorities = array(); } $thresholds = json_decode($staticData['cdo_thresholds_json'], true); DashboardWidget::setThresholds($thresholds); $baselines = (array) json_decode($staticData['cdo_baselines_json']); DashboardWidget::setBaselines($baselines); DashboardWidget::setMaxUsernameLength(CommunityDashboard::USERNAME_MAX_LENGTH); // display the user-defined ordering of widgets inside an outside // container $userData = $this->dashboardData->loadUserData(); $prefs = !empty($userData['prefs']) ? $userData['prefs'] : array(); $userOrdering = isset($prefs['ordering']) ? $prefs['ordering'] : array(); $completion = !empty($userData['completion']) ? $userData['completion'] : array(); DashboardWidget::setCompletion($completion); // add any new widgets that have been added since the user last // customized foreach ($wgWidgetList as $name) { $found = false; foreach ($userOrdering as $arr) { if ($arr['wid'] == $name) { $found = true; break; } } if (!$found) { $userOrdering[] = array('wid' => $name, 'show' => 1); } } // create the user-defined ordering list, removing any community // priority widgets from the list so their not displayed twice $userWidgets = array(); foreach ($userOrdering as $arr) { $found = false; foreach ($priorities as $name) { if ($arr['wid'] == $name) { $found = true; break; } } if (!$found && $arr['show']) { $userWidgets[] = $arr['wid']; } } $func = array($this, 'displayWidgets'); $out = call_user_func($func, array('test')); $langKeys = array('howto', 'cd-pause-updates', 'cd-resume-updates', 'cd-current-priority', 'cd-network-error'); $langScript = Wikihow_i18n::genJSMsgs($langKeys); //TODO: Likely should move this somewhere else //but not sure where yet //load user specific info that only needs to be loaded //once if ($wgUser->getID() > 0) { $u = new User(); $u->setID($wgUser->getID()); $img = Avatar::getPicture($u->getName(), true); if ($img == '') { $img = Avatar::getDefaultPicture(); } $sk = $wgUser->getSkin(); $userName = $sk->makeLinkObj($u->getUserPage(), $u->getName()); $tipsLink = "/Special:TipsPatrol"; } else { $tipsLink = "/Special:Userlogin?returnto=Special:TipsPatrol"; } $tmpl = new EasyTemplate(dirname(__FILE__)); $tmpl->set_vars(array('jsTags' => $jsTags, 'cssTags' => $cssTags, 'thresholds' => $staticData['cdo_thresholds_json'], 'GLOBAL_DATA_REFRESH_TIME_SECS' => self::GLOBAL_DATA_REFRESH_TIME_SECS, 'USER_DATA_REFRESH_TIME_SECS' => self::USER_DATA_REFRESH_TIME_SECS, 'USERNAME_MAX_LENGTH' => self::USERNAME_MAX_LENGTH, 'widgetTitles' => DashboardData::getTitles(), 'priorityWidgets' => $priorities, 'userWidgets' => $userWidgets, 'prefsOrdering' => $userOrdering, 'userCounts' => $userData['counts'], 'userImage' => $img, 'userName' => $userName, 'displayWidgetsFunc' => array($this, 'displayWidgets'), 'appShortCodes' => $wgWidgetShortCodes, 'tipsLink' => $tipsLink)); $html = $tmpl->execute('dashboard-container.tmpl.php'); return $langScript . $html; }
private function getUserAvatar($user, $guestId) { if ($user->isAnon()) { // look for the guest_id cookie value to // give them the right avatar image $userAvatar = Avatar::getAnonAvatar($guestId); return $userAvatar; } $avatar = Avatar::getPicture($user->getName(), false); if ($avatar == '') { $avatar = Avatar::getDefaultPicture(); } $userName = Linker::linkKnown($user->getUserPage(), $user->getName()); $userAvatar = array("name" => $userName, "image" => $avatar); return $userAvatar; }
function getReviewersTable() { $rankings = self::getWeekRankings(); $table = "<table>"; $index = 0; if (isset($rankings) && is_array($rankings)) { foreach ($rankings as $u => $c) { $u = User::newFromID($u); $u->load(); $img = Avatar::getPicture($u->getName(), true); if ($img == '') { $img = Avatar::getDefaultPicture(); } $table .= "<tr><td class='va_image'>{$img}</td><td class='va_reviewer'><a href='{$u->getUserPage()->getFullURL()}' target='new'>{$u->getName()}</a></td><td class='va_stat'>{$c}</td></tr>"; $index++; if ($index == 5) { break; } } } $table .= "</table>"; return $table; }
/** * getStandingsTable * returns just the raw table for the standings, useful for ajax calls **/ function getStandingsTable() { global $wgUser; $fname = "StandingsGroup::getStandingsTable"; wfProfileIn($fname); $display = "<table>"; $startdate = strtotime('7 days ago'); $starttimestamp = date('YmdG', $startdate) . floor(date('i', $startdate) / 10) . '00000'; $data = $this->getStandingsFromCache(); $count = 0; foreach ($data as $key => $value) { $u = new User(); $u->setName($key); if ($value > 0 && $key != '') { $img = Avatar::getPicture($u->getName(), true); if ($img == '') { $img = Avatar::getDefaultPicture(); } $id = ""; if ($wgUser->getName() == $u->getName()) { $id = "id='iia_stats_group'"; } $display .= "<tr><td class='leader_image'>{$img}</td><td class='leader_name'>" . Linker::link($u->getUserPage(), $u->getName()) . "</td><td class='leader_count' {$id}>{$value}</td></tr>"; $count++; } if ($count > 5) { break; } } $display .= "\n\t\t</table>"; wfProfileOut($fname); return $display; }