/** * Query for RisingStars Written **/ function getRisingStar($starttimestamp, $lb_user = '', $getArticles = false) { global $wgMemc; if ($getArticles) { $key = "leaderboard:risingstars_received:{$starttimestamp}:{$lb_user}"; } else { $key = "leaderboard:risingstars_received:{$starttimestamp}"; } $cachekey = wfMemcKey($key); $val = $wgMemc->get($cachekey); if (is_array($val)) { return $val; } $dbr = wfGetDB(DB_SLAVE); $data = array(); $bots = WikihowUser::getBotIDs(); $bot = ""; if (sizeof($bots) > 0) { $bot = " AND rc_user NOT IN (" . $dbr->makeList($bots) . ") "; } $sql = "SELECT distinct(rc_title) " . "FROM recentchanges " . "WHERE rc_timestamp >= '{$starttimestamp}' AND rc_comment like 'Marking new article as a Rising Star from From%' " . $bot . "AND rc_namespace=" . NS_TALK . " "; $res = $dbr->query($sql, __METHOD__); foreach ($res as $row) { $t = Title::newFromText($row->rc_title); $a = new Article($t); if ($a->isRedirect()) { $t = Title::newFromRedirect($a->fetchContent()); $a = new Article($t); } $author = $a->getContributors()->current(); $username = $author ? $author->getName() : ''; if ($getArticles) { if ($lb_user == $username) { $data[$t->getPartialURL()] = $t->getPrefixedText(); } } else { $data[$username]++; } } $wgMemc->set($cachekey, $data, 3600); return $data; }
function execute($par) { global $wgRequest, $wgOut, $wgUser, $wgLang, $wgLanguageCode; if ($wgLanguageCode != 'en') { $wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext'); return; } $target = isset($par) ? $par : $wgRequest->getVal('target'); $sk = $wgUser->getSkin(); $dbr =& wfGetDB(DB_SLAVE); $wgOut->addHTML(' <style type="text/css" media="all">/*<![CDATA[*/ @import "/extensions/wikihow/authors/Authorleaderboard.css"; /*]]>*/</style>'); $me = Title::makeTitle(NS_SPECIAL, "Authorleaderboard"); if (date('w', time()) == 1) { // Special case for the day it switches since strtotime is not consistent $startdate = strtotime('monday'); $nextdate = strtotime('next monday'); } else { $startdate = strtotime('last monday'); $nextdate = strtotime('next monday'); } $date1 = date('m/d/Y', $startdate); $date2 = date('m/d/Y', $nextdate); $starttimestamp = date('Ymd', $startdate) . '000000'; // DB query new articles $sqlfe = "SELECT * " . "FROM firstedit " . "WHERE fe_timestamp >= '{$starttimestamp}'"; $resfe = $dbr->query($sqlfe); // DB query rising star articles $sql2 = "SELECT distinct(rc_title) " . "FROM recentchanges " . "WHERE rc_timestamp >= '{$starttimestamp}' AND rc_comment like 'Marking new article as a Rising Star from From%' " . "AND rc_namespace=" . NS_TALK . " "; $res2 = $dbr->query($sql2); $total_newarticles = $dbr->numRows($resfe); // Setup array for new articles while (($row = $dbr->fetchObject($resfe)) != null) { $t = Title::newFromID($row->fe_page); if (isset($t)) { if ($t->getArticleID() > 0) { //if (!preg_match('/\d+\.\d+\.\d+\.\d+/',$row->fe_user_text)) $leader_articles[$row->fe_user_text]++; } } } $total_risingstar = $dbr->numRows($res2); $leader_rs = array(); // Setup array for rising star articles while (($row = $dbr->fetchObject($res2)) != null) { $t = Title::newFromText($row->rc_title); $r = Revision::newFromTitle($t); if (preg_match("/#REDIRECT \\[\\[(.*?)\\]\\].*?/", $r->getText(), $matches)) { $t = Title::newFromText($matches[1]); } $a = new Article($t); $author = $a->getContributors(); $user = $author[0]; $username = $user[1]; $leader_rs[$username]++; } /****** * New Articles Table * * ****/ $wgOut->addHTML("\n<div id='Authorleaderboard'>\n"); $wgOut->addHTML(wfMsg('leaderboard_total', number_format($total_newarticles, 0, '', ','), $date1, $date2) . "<br/><br/><center>"); $wgOut->addHTML("<br/><table width='500px' align='center' class='status'>"); // display header $index = 1; $wgOut->addHTML("<tr>\n\t <td></td>\n\t <td>User</td>\n\t <td align='right'>" . wfMsg('leaderboard_articleswritten_header') . "</td>\n\t </tr>\n\t "); //display difference in only new articles arsort($leader_articles); foreach ($leader_articles as $key => $value) { $u = new User(); $u->setName($key); if ($value > 0 && $key != '') { $class = ""; if ($index % 2 == 1) { $class = 'class="odd"'; } $wgOut->addHTML("<tr {$class}>\n\t\t\t\t\t<td>{$index}</td>\n\t\t\t\t\t<td>" . $sk->makeLinkObj($u->getUserPage(), $u->getName()) . "</td>\n\t\t\t\t\t<td align='right'>{$value}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t"); $leader_articles[$key] = $value * -1; $index++; } if ($index > 20) { break; } } $wgOut->addHTML("</table><br/><br/>"); /****** * Rising Star Table * * ****/ $wgOut->addHTML(wfMsg('leaderboard_rs_total', number_format($total_risingstar, 0, '', ','), $date1, $date2) . "<br/><br/><center>"); $wgOut->addHTML("<br/><table width='500px' align='center' class='status'>"); // display header $index = 1; $wgOut->addHTML("<tr>\n\t <td></td>\n\t <td>User</td>\n\t <td align='right'>" . wfMsg('leaderboard_risingstar_header') . "</td>\n\t </tr>\n\t "); arsort($leader_rs); foreach ($leader_rs as $key => $value) { $u = new User(); $u->setName($key); $class = ""; if ($index % 2 == 1) { $class = 'class="odd"'; } $wgOut->addHTML("<tr {$class}>\n\t\t\t\t<td>{$index}</td>\n\t\t\t\t<td>" . $sk->makeLinkObj($u->getUserPage(), $u->getName()) . "</td>\n\t\t\t\t<td align='right'>" . $leader_rs[$key] . "</td>\n\t\t\t\t</tr>\n\t\t\t"); $leader_articles[$key] = -1; $index++; if ($index > 20) { break; } } $wgOut->addHTML("</table>"); $wgOut->addHTML("</center>"); $wgOut->addHTML("</div>\n"); }
/** * Get a list of contributors of $article * @param $article Article object * @param $cnt Int: maximum list of contributors to show * @param $showIfMax Bool: whether to contributors if there more than $cnt * @return String: html */ protected static function getContributors(Article $article, $cnt, $showIfMax) { global $wgLang, $wgAllowRealName; $contributors = $article->getContributors(); $others_link = ''; # Hmm... too many to fit! if ($cnt > 0 && $contributors->count() > $cnt) { $others_link = self::othersLink($article); if (!$showIfMax) { return wfMsg('othercontribs', $others_link); } } $real_names = array(); $user_names = array(); $anon = 0; # Sift for real versus user names foreach ($contributors as $user) { $cnt--; if ($user->isLoggedIn()) { $link = self::link($user); if ($wgAllowRealName && $user->getRealName()) { $real_names[] = $link; } else { $user_names[] = $link; } } else { $anon++; } if ($cnt == 0) { break; } } # Two strings: real names, and user names $real = $wgLang->listToText($real_names); $user = $wgLang->listToText($user_names); if ($anon) { $anon = wfMsgExt('anonymous', array('parseinline'), $anon); } # "ThisSite user(s) A, B and C" if (!empty($user)) { $user = wfMsgExt('siteusers', array('parsemag'), $user, count($user_names)); } # This is the big list, all mooshed together. We sift for blank strings $fulllist = array(); foreach (array($real, $user, $anon, $others_link) as $s) { if (!empty($s)) { array_push($fulllist, $s); } } # Make the list into text... $creds = $wgLang->listToText($fulllist); # "Based on work by ..." return empty($creds) ? '' : wfMsg('othercontribs', $creds); }
/** * Query for RisingStars Boosted **/ function getRisingStarsNABed($starttimestamp, $lb_user = '', $getArticles = false) { global $wgMemc; if ($getArticles) { $key = "leaderboard:risingstars_nabed:{$starttimestamp}:{$lb_user}"; } else { $key = "leaderboard:risingstars_nabed:{$starttimestamp}"; } $cachekey = wfMemcKey($key); $val = $wgMemc->get($cachekey); if ($val) { return $val; } $dbr = wfGetDB(DB_SLAVE); $data = array(); $bots = WikihowUser::getBotIDs(); $bot = ""; if (sizeof($bots) > 0) { $bot = " AND rc_user NOT IN (" . $dbr->makeList($bots) . ") "; } $sql = "SELECT rc_title,rc_user_text " . "FROM recentchanges " . "WHERE rc_timestamp >= '{$starttimestamp}' AND rc_comment like 'Marking new article as a Rising Star from From%' " . $bot . "AND rc_namespace=" . NS_TALK . " AND rc_user_text != 'WRM' "; $res = $dbr->query($sql, __METHOD__); while (($row = $dbr->fetchObject($res)) != null) { $t = Title::newFromText($row->rc_title); $a = new Article($t); $author = $a->getContributors(); $user = $author[0]; $username = $user[1]; if ($getArticles) { if ($lb_user == $row->rc_user_text) { $data[$t->getPartialURL()] = $t->getPrefixedText(); } } else { $data[$row->rc_user_text]++; } } $wgMemc->set($cachekey, $data, 3600); return $data; }
function genLeaderBoard() { global $wgRequest, $wgOut, $wgUser, $wgLang, $IP; $wgOut->addHTML(' <style type="text/css" media="all">/*<![CDATA[*/ @import "/extensions/wikihow/Authorleaderboard.css"; /*]]>*/</style>'); $me = Title::makeTitle(NS_SPECIAL, "Charityleaderboard"); $startdate = strtotime('09/01/2009'); $enddate = strtotime('09/30/2009'); $boostenddate = strtotime('10/02/2009'); $date1 = date('m/d/Y', $startdate); $date2 = date('m/d/Y', $enddate); $starttimestamp = date('Ymd', $startdate) . '000000'; $endtimestamp = date('Ymd', $enddate) . '999999'; $boostendtimestamp = date('Ymd', $boostenddate) . '999999'; // DB query new articles $sqlfe = "SELECT * " . "FROM firstedit " . "WHERE fe_timestamp >= '{$starttimestamp}' AND fe_timestamp <= '{$endtimestamp}' AND fe_user != 0 AND fe_user_text != 'WRM'"; $resfe = $dbr->query($sqlfe); // DB query rising star articles $sql2 = "SELECT rc_title,rc_user_text " . "FROM recentchanges " . "WHERE rc_timestamp >= '{$starttimestamp}' AND rc_timestamp <= '{$boostendtimestamp}' AND rc_comment like 'Marking new article as a Rising Star from From%' " . "AND rc_namespace=" . NS_TALK . " "; $res2 = $dbr->query($sql2); $total_newarticles = 0; while (($row = $dbr->fetchObject($resfe)) != null) { $t = Title::newFromID($row->fe_page); if (isset($t)) { if ($t->getArticleID() > 0) { if (!preg_match('/\\d+\\.\\d+\\.\\d+\\.\\d+/', $row->fe_user_text)) { $leader_articles[$row->fe_user_text]['count']++; $leader_articles[$row->fe_user_text]['name'] = $row->fe_user_text; $total_newarticles++; } } } } $total_risingstar = $res2->numRows(); // Setup array for rising star articles foreach ($res2 as $row) { $t = Title::newFromText($row->rc_title); $a = new Article($t); $author = $a->getContributors(1)->current(); $username = $author->getName(); if (!preg_match('/\\d+\\.\\d+\\.\\d+\\.\\d+/', $username)) { if ($username != 'WRM') { $leader_articles[$username][rs]++; $leader_articles[$username]['name'] = $username; $leader_articles[$username]['count'] += 0; $total_newarticles++; } } $leader_articles[$row->rc_user_text][boost]++; $leader_articles[$row->rc_user_text]['name'] = $row->rc_user_text; $leader_articles[$row->rc_user_text]['count'] += 0; $total_newarticles++; } // New Articles Table $wgOut->addHTML(wfMsg('charityleaderboard_title', number_format($total_newarticles), $date1, $date2) . "<br/><br/><center>"); $wgOut->addHTML("<br/><table width='500px' align='center' class='status'>"); // display header $index = 1; $wgOut->addHTML("<tr>\n\t\t\t<td align='center'>" . wfMsg('charityleaderboard_header_contrib') . "</td>\n\t\t\t<td align='center'>" . wfMsg('charityleaderboard_header_articles') . "</td>\n\t\t\t<td align='center'>" . wfMsg('charityleaderboard_header_rs') . "</td>\n\t\t\t<td align='center'>" . wfMsg('charityleaderboard_header_books') . "</td>\n\t\t\t</tr>\n\t\t"); // display table $maxdisplay = 500000; $bookstotal = 0; if (count($leader_articles) > 0) { uasort($leader_articles, array($this, "cmp")); foreach ($leader_articles as $key => $value) { $u = new User(); $u->setName($key); if ($key != '') { $books = $value['count'] + $value['rs'] + $value['boost']; $rsnum = $value['rs'] + $value['boost']; if ($rsnum == 0) { $rsnum = ''; } $class = ""; if ($index % 2 == 1) { $class = 'class="odd"'; } $wgOut->addHTML("<tr {$class}>\n\t\t\t\t\t\t<td>" . $sk->makeLinkObj($u->getUserPage(), $u->getName()) . "</td>\n\t\t\t\t\t\t<td align='center'>" . $value['count'] . "</td>\n\t\t\t\t\t\t<!-- <td align='center'>" . $rsnum . " [" . $value['rs'] . " + " . $value['boost'] . "]</td> -->\n\t\t\t\t\t\t<td align='center'>" . $rsnum . "</td>\n\t\t\t\t\t\t<td align='center'>{$books}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t"); //$leader_articles[$key] = $value * -1; $index++; } $bookstotal += $books; if ($index > $maxdisplay) { break; } } } $wgOut->addHTML("<tr {$class}>\n\t\t\t<td> </td>\n\t\t\t<td> </td>\n\t\t\t<td align='right'>Total:</td>\n\t\t\t<td align='center'>{$bookstotal}</td>\n\t\t\t</tr>\n\t\t"); $wgOut->addHTML("</table><br/><br/>"); }
function execute($par) { global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname; global $wgRequest, $wgSitename, $wgLanguageCode, $IP; global $wgScript, $wgFilterCallback, $wgScriptPath; $this->setHeaders(); require_once "{$IP}/extensions/wikihow/EditPageWrapper.php"; require_once "{$IP}/includes/EditPage.php"; $target = isset($par) ? $par : $wgRequest->getVal('target'); if (!$target) { $wgOut->addHTML("No target specified. In order to thank a group of authors, a page must be provided."); return; } $title = Title::newFromDBKey($target); $me = Title::makeTitle(NS_SPECIAL, "ThankAuthors"); if (!$wgRequest->getVal('token')) { $sk = $wgUser->getSkin(); $talk_page = $title->getTalkPage(); $token = $this->getToken1(); $thanks_msg = wfMsg('thank-you-kudos', $title->getFullURL(), wfMsg('howto', $title->getText())); // add the form HTML $wgOut->addHTML(<<<EOHTML \t\t\t\t<script type='text/javascript'> \t\t\t\t\tfunction submitThanks () { \t\t\t\t\t\tvar message = \$('#details').val(); \t\t\t\t\t\tif(message == "") { \t\t\t\t\t\t\talert("Please enter a message."); \t\t\t\t\t\t\treturn false; \t\t\t\t\t\t} \t\t\t\t\t\tvar url = '{$me->getFullURL()}?token=' + \$('#token')[0].value + '&target=' + \$('#target')[0].value + '&details=' + \$('#details')[0].value; \t\t\t\t\t\tvar form = \$('#thanks_form'); \t\t\t\t\t\tform.html(\$('#thanks_response').html()); \t\t\t\t\t\t\$.get(url); \t\t\t\t\t\treturn true; \t\t\t\t\t} \t\t\t\t</script> \t\t\t\t<div id="thanks_response" style="display:none;">{$thanks_msg}</div> \t\t\t\t<div id="thanks_form"><div class="section_text"> EOHTML ); $wgOut->addWikiText(wfMsg('enjoyed-reading-article', $title->getFullText(), $talk_page->getFullText())); $wgOut->addHTML("<input id=\"target\" type=\"hidden\" name=\"target\" value=\"{$target}\"/>\n\t\t\t\t<input id=\"token\" type=\"hidden\" name=\"{$token}\" value=\"{$token}\"/>\n\t\t\t\t"); $wgOut->addHTML("<br />\n\t\t\t\t<textarea style='width:98%;' id=\"details\" rows=\"5\" cols=\"100\" name=\"details\"></textarea><br/>\n\t\t\t\t<br /><button onclick='submitThanks();' class='button primary'>" . wfMsg('submit') . "</button>\n\t\t\t\t</div></div>"); } else { // this is a post, accept the POST data and create the // Request article wfLoadExtensionMessages('Postcomment'); $wgOut->setArticleBodyOnly(true); $article = new Article($title); // stupid bug that doesn't load the last edit unless you ask it to $article->loadLastEdit(); $contributors = $article->getContributors(0, 0, true); $user = $wgUser->getName(); $real_name = User::whoIsReal($wgUser->getID()); if ($real_name == "") { $real_name = $user; } $dateStr = $wgLang->timeanddate(wfTimestampNow()); $comment = $wgRequest->getVal("details"); $text = $title->getFullText(); wfDebug("STA: got text..."); // filter out links $preg = "/[^\\s]*\\.[a-z][a-z][a-z]?[a-z]?/i"; $matches = array(); if (preg_match($preg, $comment, $matches) > 0) { $wgOut->addHTML(wfMsg('no_urls_in_kudos', $matches[0])); return; } $comment = strip_tags($comment); $formattedComment = wfMsg('postcomment_formatted_thanks', $dateStr, $user, $real_name, $comment, $text); wfDebug("STA: comment {$formattedComment}\n"); wfDebug("STA: Checking blocks..."); $tmp = ""; if ($wgUser->isBlocked()) { $this->blockedIPpage(); return; } if (!$wgUser->getID() && $wgWhitelistEdit) { $this->userNotLoggedInPage(); return; } if ($target == "Spam-Blacklist") { $wgOut->readOnlyPage(); return; } wfDebug("STA: checking read only\n"); if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } wfDebug("STA: checking rate limiter\n"); if ($wgUser->pingLimiter('userkudos')) { $wgOut->rateLimited(); return; } wfDebug("STA: checking blacklist\n"); if ($wgFilterCallback && $wgFilterCallback($title, $comment, "")) { // Error messages or other handling should be // performed by the filter function return; } wfDebug("STA: checking tokens\n"); $usertoken = $wgRequest->getVal('token'); $token1 = $this->getToken1(); $token2 = $this->getToken2(); if ($usertoken != $token1 && $usertoken != $token2) { wfDebug("STA: User kudos token doesn't match user: {$usertoken} token1: {$token1} token2: {$token2}"); return; } wfDebug("STA: going through contributors\n"); foreach ($contributors as $c) { $id = $c[0]; $u = $c[1]; wfDebug("STA: going through contributors {$u} {$id}\n"); if ($id == "0") { continue; } // forget the anon users. $t = Title::newFromText("User_kudos:" . $u); $a = new Article($t); $update = $t->getArticleID() > 0; $text = ""; if ($update) { $text = $a->getContent(true); $text .= "\n\n" . $formattedComment; if ($wgFilterCallback && $wgFilterCallback($t, $text, $text)) { // Error messages or other handling should be // performed by the filter function return; } } if ($update) { $a->updateArticle($text, "", true, false, false, '', false); } else { $a->insertNewArticle($text, "", true, false, false, false, false); } } wfDebug("STA: done\n"); $wgOut->addHTML("Done."); $wgOut->redirect(''); } }
/** * Get a list of contributors of $article * @param $article Article object * @param $cnt Int: maximum list of contributors to show * @param $showIfMax Bool: whether to contributors if there more than $cnt * @return String: html */ protected static function getContributors(Article $article, $cnt, $showIfMax) { global $wgLang, $wgHiddenPrefs; $contributors = $article->getContributors(); $others_link = false; # Hmm... too many to fit! if ($cnt > 0 && $contributors->count() > $cnt) { $others_link = self::othersLink($article); if (!$showIfMax) { return wfMsgExt('othercontribs', 'parsemag', $others_link, $contributors->count()); } } $real_names = array(); $user_names = array(); $anon_ips = array(); # Sift for real versus user names foreach ($contributors as $user) { $cnt--; if ($user->isLoggedIn()) { $link = self::link($user); if (!in_array('realname', $wgHiddenPrefs) && $user->getRealName()) { $real_names[] = $link; } else { $user_names[] = $link; } } else { $anon_ips[] = self::link($user); } if ($cnt == 0) { break; } } if (count($real_names)) { $real = $wgLang->listToText($real_names); } else { $real = false; } # "ThisSite user(s) A, B and C" if (count($user_names)) { $user = wfMsgExt('siteusers', 'parsemag', $wgLang->listToText($user_names), count($user_names)); } else { $user = false; } if (count($anon_ips)) { $anon = wfMsgExt('anonusers', 'parsemag', $wgLang->listToText($anon_ips), count($anon_ips)); } else { $anon = false; } # This is the big list, all mooshed together. We sift for blank strings $fulllist = array(); foreach (array($real, $user, $anon, $others_link) as $s) { if ($s) { array_push($fulllist, $s); } } # Make the list into text... $creds = $wgLang->listToText($fulllist); # "Based on work by ..." return strlen($creds) ? wfMsgExt('othercontribs', 'parsemag', $creds, count($fulllist)) : ''; }