Index: trunk/extensions/SocialProfile/UserStats/UserStats.i18n.php |
— | — | @@ -41,6 +41,7 @@ |
42 | 42 | 'top-fans-stats-comment-score-negative-given' => '{{PLURAL:$1|Thumb down given|Thumbs down given}}', |
43 | 43 | 'top-fans-stats-gifts-rec-count' => '{{PLURAL:$1|Gift received|Gifts received}}', |
44 | 44 | 'top-fans-stats-gifts-sent-count' => '{{PLURAL:$1|Gift sent|Gifts sent}}', |
| 45 | + 'right-updatepoints' => 'Update edit counts', |
45 | 46 | 'level-advance-subject' => 'You are now a "$1" on {{SITENAME}}!', |
46 | 47 | 'level-advance-body' => 'Hi $1. |
47 | 48 | |
— | — | @@ -518,7 +519,7 @@ |
519 | 520 | ); |
520 | 521 | |
521 | 522 | /** Finnish (Suomi) |
522 | | - * @author Jack Phoenix |
| 523 | + * @author Jack Phoenix <jack@countervandalism.net> |
523 | 524 | */ |
524 | 525 | $messages['fi'] = array( |
525 | 526 | 'user-stats-alltime-title' => 'Kaikkien aikojen suurimmat pistemäärät', |
— | — | @@ -540,6 +541,7 @@ |
541 | 542 | 'top-fans-stats-foe-count' => '{{PLURAL:$1|vihollinen|vihollista}}', |
542 | 543 | 'top-fans-stats-gifts-rec-count' => '{{PLURAL:$1|saatu lahja|saatua lahjaa}}', |
543 | 544 | 'top-fans-stats-gifts-sent-count' => '{{PLURAL:$1|lähetetty lahja|lähetettyä lahjaa}}', |
| 545 | + 'right-updatepoints' => 'Päivittää muokkausmääriä', |
544 | 546 | 'level-advance-subject' => 'Olet nyt "$1" {{GRAMMAR:inessive|{{SITENAME}}}}!', |
545 | 547 | 'level-advance-body' => 'Hei $1: |
546 | 548 | |
Index: trunk/extensions/SocialProfile/UserStats/EditCount.php |
— | — | @@ -1,4 +1,12 @@ |
2 | 2 | <?php |
| 3 | +/** |
| 4 | + * Protect against register_globals vulnerabilities. |
| 5 | + * This line must be present before any global variable is referenced. |
| 6 | + */ |
| 7 | +if ( !defined( 'MEDIAWIKI' ) ){ |
| 8 | + die( "This is not a valid entry point.\n" ); |
| 9 | +} |
| 10 | + |
3 | 11 | $wgHooks['NewRevisionFromEditComplete'][] = 'incEditCount'; |
4 | 12 | |
5 | 13 | function incEditCount( &$article, $revision, $baseRevId ) { |
— | — | @@ -7,7 +15,7 @@ |
8 | 16 | // only keep tally for allowable namespaces |
9 | 17 | if( !is_array( $wgNamespacesForEditPoints ) || in_array( $wgTitle->getNamespace(), $wgNamespacesForEditPoints ) ){ |
10 | 18 | $stats = new UserStatsTrack( $wgUser->getID(), $wgUser->getName() ); |
11 | | - $stats->incStatField('edit'); |
| 19 | + $stats->incStatField( 'edit' ); |
12 | 20 | } |
13 | 21 | return true; |
14 | 22 | } |
— | — | @@ -15,14 +23,18 @@ |
16 | 24 | $wgHooks['ArticleDelete'][] = 'removeDeletedEdits'; |
17 | 25 | |
18 | 26 | function removeDeletedEdits( &$article, &$user, &$reason ){ |
19 | | - global $wgUser, $wgTitle, $wgDBprefix, $wgNamespacesForEditPoints; |
| 27 | + global $wgUser, $wgTitle, $wgNamespacesForEditPoints; |
20 | 28 | |
21 | 29 | // only keep tally for allowable namespaces |
22 | 30 | if( !is_array( $wgNamespacesForEditPoints ) || in_array( $wgTitle->getNamespace(), $wgNamespacesForEditPoints ) ){ |
23 | 31 | |
24 | 32 | $dbr = wfGetDB( DB_MASTER ); |
25 | | - $sql = "SELECT rev_user_text, rev_user, count(*) AS the_count FROM ".$wgDBprefix."revision WHERE rev_page = {$article->getID()} AND rev_user <> 0 GROUP BY rev_user_text"; |
26 | | - $res = $dbr->query($sql); |
| 33 | + $res = $dbr->select( 'revision', |
| 34 | + array( 'rev_user_text', 'rev_user', 'COUNT(*) AS the_count' ), |
| 35 | + array( 'rev_page' => $article->getID(), 'rev_user <> 0' ), |
| 36 | + __METHOD__, |
| 37 | + array( 'GROUP BY' => 'rev_user_text' ) |
| 38 | + ); |
27 | 39 | while( $row = $dbr->fetchObject( $res ) ) { |
28 | 40 | $stats = new UserStatsTrack( $row->rev_user, $row->rev_user_text ); |
29 | 41 | $stats->decStatField( 'edit', $row->the_count ); |
— | — | @@ -34,14 +46,18 @@ |
35 | 47 | $wgHooks['ArticleUndelete'][] = 'restoreDeletedEdits'; |
36 | 48 | |
37 | 49 | function restoreDeletedEdits( &$title, $new ){ |
38 | | - global $wgUser, $wgDBprefix, $wgNamespacesForEditPoints; |
| 50 | + global $wgUser, $wgNamespacesForEditPoints; |
39 | 51 | |
40 | 52 | // only keep tally for allowable namespaces |
41 | 53 | if( !is_array( $wgNamespacesForEditPoints ) || in_array( $title->getNamespace(), $wgNamespacesForEditPoints ) ){ |
42 | 54 | |
43 | 55 | $dbr = wfGetDB( DB_MASTER ); |
44 | | - $sql = "SELECT rev_user_text, rev_user, count(*) AS the_count FROM ".$wgDBprefix."revision WHERE rev_page = {$title->getArticleID()} AND rev_user <> 0 GROUP BY rev_user_text"; |
45 | | - $res = $dbr->query($sql); |
| 56 | + $res = $dbr->select( 'revision', |
| 57 | + array( 'rev_user_text', 'rev_user', 'COUNT(*) AS the_count' ), |
| 58 | + array( 'rev_page' => $title->getArticleID(), 'rev_user <> 0' ), |
| 59 | + __METHOD__, |
| 60 | + array( 'GROUP BY' => 'rev_user_text' ) |
| 61 | + ); |
46 | 62 | while( $row = $dbr->fetchObject( $res ) ) { |
47 | 63 | $stats = new UserStatsTrack( $row->rev_user, $row->rev_user_text ); |
48 | 64 | $stats->incStatField( 'edit', $row->the_count ); |
Index: trunk/extensions/SocialProfile/UserStats/SpecialUpdateEditCounts.php |
— | — | @@ -5,53 +5,59 @@ |
6 | 6 | /** |
7 | 7 | * Constructor |
8 | 8 | */ |
9 | | - function __construct(){ |
| 9 | + public function __construct(){ |
10 | 10 | parent::__construct( 'UpdateEditCounts' ); |
11 | 11 | } |
12 | 12 | |
13 | 13 | function updateMainEditsCount(){ |
14 | | - global $wgOut, $wgUser, $wgDBprefix; |
| 14 | + global $wgOut, $wgUser; |
15 | 15 | |
16 | | - $wgOut->setPageTitle('Update Edit Counts'); |
| 16 | + $wgOut->setPageTitle( 'Update Edit Counts' ); |
17 | 17 | |
18 | | - if( !in_array( 'staff', ( $wgUser->getGroups() ) ) ){ |
| 18 | + if( !$wgUser->isAllowed( 'updatepoints' ) ){ |
19 | 19 | $wgOut->errorpage( 'error', 'badaccess' ); |
20 | 20 | return false; |
21 | 21 | } |
22 | 22 | |
23 | 23 | $dbw = wfGetDB( DB_MASTER ); |
24 | | - $sql = "SELECT rev_user_text, rev_user, count(*) AS the_count FROM ".$wgDBprefix."revision INNER JOIN ".$wgDBprefix."page ON page_id = rev_page WHERE page_namespace = 0 AND rev_user <> 0 GROUP BY rev_user_text "; |
25 | | - $res = $dbw->query($sql); |
| 24 | + $res = $dbw->select( |
| 25 | + array( 'revision', 'page' ), |
| 26 | + array( 'rev_user_text', 'rev_user', 'COUNT(*) AS the_count' ), |
| 27 | + array( 'page_namespace = 0', 'rev_user <> 0' ), |
| 28 | + __METHOD__, |
| 29 | + array( 'GROUP BY' => 'rev_user_text' ), |
| 30 | + array( 'page' => array( 'INNER JOIN', 'page_id = rev_page' ) ) |
| 31 | + ); |
26 | 32 | while( $row = $dbw->fetchObject( $res ) ) { |
27 | 33 | |
28 | | - $user = User::newFromId($row->rev_user); |
29 | | - $user->loadFromId(); |
| 34 | + $user = User::newFromId( $row->rev_user ); |
| 35 | + $user->loadFromId(); |
30 | 36 | |
31 | | - if( !$user->isAllowed( 'bot' ) ){ |
32 | | - $edit_count = $row->the_count; |
33 | | - } else { |
34 | | - $edit_count = 0; |
35 | | - } |
| 37 | + if( !$user->isAllowed( 'bot' ) ){ |
| 38 | + $edit_count = $row->the_count; |
| 39 | + } else { |
| 40 | + $edit_count = 0; |
| 41 | + } |
36 | 42 | |
37 | | - $s = $dbw->selectRow( 'user_stats', array( 'stats_user_id' ), array( 'stats_user_id' => $row->rev_user ), __METHOD__ ); |
38 | | - if ( !$s->stats_user_id ) { |
| 43 | + $s = $dbw->selectRow( 'user_stats', array( 'stats_user_id' ), array( 'stats_user_id' => $row->rev_user ), __METHOD__ ); |
| 44 | + if ( !$s->stats_user_id ) { |
| 45 | + $dbw->insert( 'user_stats', |
| 46 | + array( |
| 47 | + 'stats_year_id' => 0, |
| 48 | + 'stats_user_id' => $row->rev_user, |
| 49 | + 'stats_user_name' => $row->rev_user_text, |
| 50 | + 'stats_total_points' => 1000 |
| 51 | + ), __METHOD__ |
| 52 | + ); |
| 53 | + } |
| 54 | + $wgOut->addHTML("<p>Updating {$row->rev_user_text} with {$edit_count} edits</p>"); |
39 | 55 | |
40 | | - $dbw->insert( 'user_stats', |
41 | | - array( |
42 | | - 'stats_year_id' => 0, |
43 | | - 'stats_user_id' => $row->rev_user, |
44 | | - 'stats_user_name' => $row->rev_user_text, |
45 | | - 'stats_total_points' => 1000 |
46 | | - ), __METHOD__ |
| 56 | + $dbw->update( 'user_stats', |
| 57 | + array( 'stats_edit_count = ' . $edit_count ), |
| 58 | + array( 'stats_user_id' => $row->rev_user ), |
| 59 | + __METHOD__ |
47 | 60 | ); |
48 | | - } |
49 | | - $wgOut->addHTML("<p>Updating {$row->rev_user_text} with {$edit_count} edits</p>"); |
50 | 61 | |
51 | | - $dbw->update( 'user_stats', |
52 | | - array( "stats_edit_count=".$edit_count ), |
53 | | - array( 'stats_user_id' => $row->rev_user ), |
54 | | - __METHOD__ ); |
55 | | - |
56 | 62 | global $wgMemc; |
57 | 63 | // clear stats cache for current user |
58 | 64 | $key = wfMemcKey( 'user', 'stats', $row->rev_user ); |
— | — | @@ -66,22 +72,26 @@ |
67 | 73 | * @param $par Mixed: parameter passed to the page or null |
68 | 74 | */ |
69 | 75 | public function execute( $par ){ |
70 | | - global $wgUser, $wgOut, $wgDBprefix; |
| 76 | + global $wgUser, $wgOut; |
71 | 77 | $dbr = wfGetDB( DB_MASTER ); |
72 | 78 | $this->updateMainEditsCount(); |
73 | 79 | |
74 | 80 | global $wgUserLevels; |
75 | 81 | $wgUserLevels = ''; |
76 | 82 | |
77 | | - $sql = "SELECT stats_user_id,stats_user_name, stats_total_points FROM ".$wgDBprefix."user_stats ORDER BY stats_user_name"; |
78 | | - $res = $dbr->query($sql); |
| 83 | + $res = $dbr->select( 'user_stats', |
| 84 | + array( 'stats_user_id', 'stats_user_name', 'stats_total_points' ), |
| 85 | + array(), |
| 86 | + __METHOD__, |
| 87 | + array( 'ORDER BY' => 'stats_user_name' ) |
| 88 | + ); |
79 | 89 | $out = ''; |
80 | 90 | while ( $row = $dbr->fetchObject( $res ) ) { |
81 | 91 | $x++; |
82 | | - $stats = new UserStatsTrack($row->stats_user_id, $row->stats_user_name); |
| 92 | + $stats = new UserStatsTrack( $row->stats_user_id, $row->stats_user_name ); |
83 | 93 | $stats->updateTotalPoints(); |
84 | 94 | } |
85 | 95 | $out = "Updated stats for <b>{$x}</b> users"; |
86 | | - $wgOut->addHTML($out); |
| 96 | + $wgOut->addHTML( $out ); |
87 | 97 | } |
88 | 98 | } |