Index: trunk/extensions/ContributionScores/ContributionScores_body.php |
— | — | @@ -0,0 +1,116 @@ |
| 2 | +<?php |
| 3 | +class ContributionScores extends SpecialPage |
| 4 | +{ |
| 5 | + function ContributionScores() { |
| 6 | + SpecialPage::SpecialPage("ContributionScores"); |
| 7 | + self::loadMessages(); |
| 8 | + } |
| 9 | + |
| 10 | + function genContributionScoreTable( $sql, $dbr, $days, $limit ) { |
| 11 | + global $contribScoreIgnoreBots; |
| 12 | + |
| 13 | + $dbr =& wfGetDB( DB_SLAVE ); |
| 14 | + |
| 15 | + $userTable = $dbr->tableName('user'); |
| 16 | + $userGroupTable = $dbr->tableName('user_groups'); |
| 17 | + $revTable = $dbr->tableName('revision'); |
| 18 | + |
| 19 | + $sql = "SELECT user_id, " . |
| 20 | + "user_name, " . |
| 21 | + "COUNT(DISTINCT rev_page) AS page_count, " . |
| 22 | + "COUNT(rev_id) AS rev_count, " . |
| 23 | + "(COUNT(DISTINCT rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2) AS wikiRank " . |
| 24 | + "FROM $userTable userTable JOIN $revTable revTable ON (userTable.user_id=revTable.rev_user) "; |
| 25 | + |
| 26 | + if ( $days > 0 ) { |
| 27 | + $date = mktime() - (60*60*24*$days); |
| 28 | + $dateString = date("Ymd",$date)."000000"; |
| 29 | + |
| 30 | + $sql .= "WHERE rev_timestamp > '$dateString' "; |
| 31 | + } |
| 32 | + |
| 33 | + if ( $contribScoreIgnoreBots ) { |
| 34 | + if (preg_match("/where/i", $sql)) { |
| 35 | + $sql .= "AND "; |
| 36 | + } else { |
| 37 | + $sql .= "WHERE "; |
| 38 | + } |
| 39 | + $sql .= "user_id NOT IN (SELECT ug_user FROM $userGroupTable WHERE ug_group='bot') "; |
| 40 | + } |
| 41 | + |
| 42 | + |
| 43 | + $sql .= "GROUP BY user_id, user_name " . |
| 44 | + "ORDER BY wikiRank DESC " . |
| 45 | + "LIMIT $limit"; |
| 46 | + |
| 47 | + $res = $dbr->query($sql); |
| 48 | + |
| 49 | + $output = "{|class=\"wikitable sortable\"\n". |
| 50 | + "|-\n". |
| 51 | + "|style=\"font-weight: bold;\"|Score\n". |
| 52 | + "|style=\"font-weight: bold;\"|Pages\n". |
| 53 | + "|style=\"font-weight: bold;\"|Changes\n". |
| 54 | + "|style=\"font-weight: bold;\"|Username\n"; |
| 55 | + |
| 56 | + while ( $row = $dbr->fetchObject( $res ) ) { |
| 57 | + $wikiUserName = $row->user_name; |
| 58 | + $output .= "|-\n|" . |
| 59 | + round($row->wikiRank,0) . "\n|" . |
| 60 | + $row->page_count . "\n|" . |
| 61 | + $row->rev_count . "\n|" . |
| 62 | + "[[User:".$wikiUserName."|".$wikiUserName."]] ([[User_talk:".$wikiUserName."|Talk]] | [[Special:Contributions/".$wikiUserName."|contribs]])" . "\n"; |
| 63 | + } |
| 64 | + $output .= "|}"; |
| 65 | + $dbr->freeResult( $res ); |
| 66 | + |
| 67 | + return $output; |
| 68 | + } |
| 69 | + |
| 70 | + function execute( $par ) { |
| 71 | + global $wgRequest, $wgOut, $contribScoreReports; |
| 72 | + |
| 73 | + $this->setHeaders(); |
| 74 | + |
| 75 | + # Get request data from, e.g. |
| 76 | + $param = $wgRequest->getText('param'); |
| 77 | + |
| 78 | + if (!is_array($contribScoreReports)) { |
| 79 | + $contribScoreReports = array( |
| 80 | + array(7,50), |
| 81 | + array(30,50), |
| 82 | + array(0,50)); |
| 83 | + } |
| 84 | + |
| 85 | + $wgOut->addWikiText ("Scores are calculated as follows:\n". |
| 86 | + "*1 point for each unique page edited\n". |
| 87 | + "*Square Root of (Total Edits Made) - (Total Unique Pages) * 2\n". |
| 88 | + "Scores calculated in this manner weight edit diversity over edit volume. Basically, this score measures". |
| 89 | + " primarily unique pages edited, with consideration for high edit volume - assumed to be a higher quality ". |
| 90 | + "article."); |
| 91 | + |
| 92 | + foreach ( $contribScoreReports as $scoreReport) { |
| 93 | + if ( $scoreReport[0] > 0 ) { |
| 94 | + $reportTitle = "Last $scoreReport[0] Days"; |
| 95 | + } else { |
| 96 | + $reportTitle = "All Revisions"; |
| 97 | + } |
| 98 | + $reportTitle .= " (Top $scoreReport[1])"; |
| 99 | + $wgOut->addWikiText ("== $reportTitle ==\n".$this->genContributionScoreTable($sql,$dbr,$scoreReport[0],$scoreReport[1])); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + |
| 104 | + function loadMessages() { |
| 105 | + static $messagesLoaded = false; |
| 106 | + global $wgMessageCache; |
| 107 | + if ( $messagesLoaded ) return true; |
| 108 | + $messagesLoaded = true; |
| 109 | + |
| 110 | + require( dirname( __FILE__ ) . '/ContributionScores.i18n.php' ); |
| 111 | + foreach ( $allMessages as $lang => $langMessages ) { |
| 112 | + $wgMessageCache->addMessages( $langMessages, $lang ); |
| 113 | + } |
| 114 | + |
| 115 | + return true; |
| 116 | + } |
| 117 | +} |
Property changes on: trunk/extensions/ContributionScores/ContributionScores_body.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 118 | + native |
Index: trunk/extensions/ContributionScores/ContributionScores.i18n.php |
— | — | @@ -0,0 +1,6 @@ |
| 2 | +<?php |
| 3 | +$allMessages = array( |
| 4 | + 'en' => array( |
| 5 | + 'contributionscores' => 'Contribution Scores' |
| 6 | + ) |
| 7 | +); |
Property changes on: trunk/extensions/ContributionScores/ContributionScores.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 8 | + native |
Index: trunk/extensions/ContributionScores/ContributionScores.php |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +<?php |
| 3 | +# Not a valid entry point, skip unless MEDIAWIKI is defined |
| 4 | +if (!defined('MEDIAWIKI')) { |
| 5 | + echo "Contribution Scores extension"; |
| 6 | + exit(1); |
| 7 | +} |
| 8 | + |
| 9 | +$wgExtensionCredits['specialpage'][] = array( |
| 10 | + 'name'=>'Contribution Scores', |
| 11 | + 'url'=>'http://www.mediawiki.org/wiki/Extension:Contribution_Scores', |
| 12 | + 'author'=>'Tim Laqua, t.laqua at gmail dot com', |
| 13 | + 'description'=>'Polls Wiki Database for highest user contribution volume.', |
| 14 | + 'version'=>'1.2' |
| 15 | +); |
| 16 | + |
| 17 | +$wgAutoloadClasses['ContributionScores'] = dirname(__FILE__) . '/ContributionScores_body.php'; |
| 18 | +$wgSpecialPages['ContributionScores'] = 'ContributionScores'; |
| 19 | + |
| 20 | +if ( version_compare( $wgVersion, '1.10.0', '<' ) ) { |
| 21 | + //Extension designed for 1.10.0+, but will work on some older versions |
| 22 | + //LoadAllMessages hook throws errors before 1.10.0 |
| 23 | +} else { |
| 24 | + $wgHooks['LoadAllMessages'][] = 'ContributionScores::loadMessages'; |
| 25 | +} |
Property changes on: trunk/extensions/ContributionScores/ContributionScores.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 26 | + native |
Index: trunk/extensions/googleAnalytics/googleAnalytics.php |
— | — | @@ -0,0 +1,53 @@ |
| 2 | +<?php |
| 3 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 4 | + die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
| 5 | +} |
| 6 | + |
| 7 | +$wgExtensionCredits['parserhook'][] = array( |
| 8 | + 'name'=>'Google Analytics Extension', |
| 9 | + 'url'=>'http://www.mediawiki.org/wiki/Extension:Google_Analytics_Integration', |
| 10 | + 'author'=>'Tim Laqua, t.laqua at gmail dot com', |
| 11 | + 'description'=>'Inserts Google Analytics script (urchin.js) in to MediaWiki pages for tracking.', |
| 12 | + 'version'=>'1.0' |
| 13 | +); |
| 14 | + |
| 15 | +if (!$googleAnalyticsSkinHack) { |
| 16 | + if ($googleAnalyticsMonobook) { |
| 17 | + $wgHooks['MonoBookTemplateToolboxEnd'][] = 'googleAnalyticsHook'; |
| 18 | + } else { |
| 19 | + $wgHooks['BeforePageDisplay'][] = 'googleAnalyticsHook'; |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +function googleAnalyticsHook(&$out) { |
| 24 | + global $googleAnalyticsMonobook; |
| 25 | + if ($googleAnalyticsMonobook) { |
| 26 | + echo(addGoogleAnalytics()); |
| 27 | + } else { |
| 28 | + $out->addHTML(addGoogleAnalytics()); |
| 29 | + } |
| 30 | + return true; |
| 31 | +} |
| 32 | + |
| 33 | +function addGoogleAnalytics() { |
| 34 | + global $googleAnalytics, $wgUser; |
| 35 | + if (!$wgUser->isAllowed('bot')) { |
| 36 | + if (!$wgUser->isAllowed('protect')) { |
| 37 | + if ($googleAnalytics) { |
| 38 | + $funcOutput = "\n<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\">\n</script>\n". |
| 39 | + "<script type=\"text/javascript\">\n". |
| 40 | + "_uacct = "."\"" . $googleAnalytics . "\";\n". |
| 41 | + "urchinTracker();\n". |
| 42 | + "</script>\n"; |
| 43 | + } else { |
| 44 | + $funcOutput = "\n<!-- Set \$googleAnalytics to your uacct # provided by Google Analytics. -->"; |
| 45 | + } |
| 46 | + } else { |
| 47 | + $funcOutput = "\n<!-- Google Analytics tracking is disabled for users with 'protect' rights (I.E. sysops) -->"; |
| 48 | + } |
| 49 | + } else { |
| 50 | + $funcOutput = "\n<!-- Google Analytics tracking is disabled for bots -->"; |
| 51 | + } |
| 52 | + |
| 53 | +return $funcOutput; |
| 54 | +} |
Property changes on: trunk/extensions/googleAnalytics/googleAnalytics.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 55 | + native |