r77343 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77342‎ | r77343 | r77344 >
Date:19:47, 26 November 2010
Author:ashley
Status:deferred
Tags:
Comment:
SocialProfile: some doc updates, undefined variable fixes and general cleanup for Special:UpdateEditCounts
Modified paths:
  • /trunk/extensions/SocialProfile/UserStats/SpecialUpdateEditCounts.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SocialProfile/UserStats/SpecialUpdateEditCounts.php
@@ -1,24 +1,27 @@
22 <?php
 3+/**
 4+ * A special page for updating users' point counts.
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
39
410 class UpdateEditCounts extends UnlistedSpecialPage {
511
612 /**
7 - * Constructor
 13+ * Constructor -- set up the new special page
814 */
915 public function __construct() {
10 - parent::__construct( 'UpdateEditCounts' );
 16+ parent::__construct( 'UpdateEditCounts', 'updatepoints' );
1117 }
1218
 19+ /**
 20+ * Perform the queries necessary to update the social point counts and
 21+ * purge memcached entries.
 22+ */
1323 function updateMainEditsCount() {
14 - global $wgOut, $wgUser, $wgNamespacesForEditPoints;
 24+ global $wgOut, $wgNamespacesForEditPoints;
1525
16 - $wgOut->setPageTitle( 'Update Edit Counts' );
17 -
18 - if ( !$wgUser->isAllowed( 'updatepoints' ) ) {
19 - $wgOut->errorpage( 'error', 'badaccess' );
20 - return false;
21 - }
22 -
2326 $whereConds = array();
2427 $whereConds[] = 'rev_user <> 0';
2528 // If points are given out for editing non-main namespaces, take that
@@ -47,9 +50,9 @@
4851 $user->loadFromId();
4952
5053 if ( !$user->isAllowed( 'bot' ) ) {
51 - $edit_count = $row->the_count;
 54+ $editCount = $row->the_count;
5255 } else {
53 - $edit_count = 0;
 56+ $editCount = 0;
5457 }
5558
5659 $s = $dbw->selectRow(
@@ -58,7 +61,7 @@
5962 array( 'stats_user_id' => $row->rev_user ),
6063 __METHOD__
6164 );
62 - if ( !$s->stats_user_id ) {
 65+ if ( !$s->stats_user_id || $s === false ) {
6366 $dbw->insert(
6467 'user_stats',
6568 array(
@@ -70,11 +73,11 @@
7174 __METHOD__
7275 );
7376 }
74 - $wgOut->addHTML( "<p>Updating {$row->rev_user_text} with {$edit_count} edits</p>" );
 77+ $wgOut->addHTML( "<p>Updating {$row->rev_user_text} with {$editCount} edits</p>" );
7578
7679 $dbw->update(
7780 'user_stats',
78 - array( 'stats_edit_count = ' . $edit_count ),
 81+ array( 'stats_edit_count = ' . $editCount ),
7982 array( 'stats_user_id' => $row->rev_user ),
8083 __METHOD__
8184 );
@@ -92,14 +95,31 @@
9396 * @param $par Mixed: parameter passed to the page or null
9497 */
9598 public function execute( $par ) {
96 - global $wgUser, $wgOut;
97 - $dbr = wfGetDB( DB_MASTER );
 99+ global $wgOut, $wgUser;
 100+
 101+ $wgOut->setPageTitle( 'Update Edit Counts' );
 102+
 103+ // Check permissions -- we must be allowed to access this special page
 104+ // before we can run any database queries
 105+ if ( !$wgUser->isAllowed( 'updatepoints' ) ) {
 106+ $wgOut->errorpage( 'error', 'badaccess' );
 107+ return false;
 108+ }
 109+
 110+ // And obviously the database needs to be writable before we start
 111+ // running INSERT/UPDATE queries against it...
 112+ if( wfReadOnly() ) {
 113+ $wgOut->readOnlyPage();
 114+ return;
 115+ }
 116+
 117+ $dbw = wfGetDB( DB_MASTER );
98118 $this->updateMainEditsCount();
99119
100120 global $wgUserLevels;
101121 $wgUserLevels = '';
102122
103 - $res = $dbr->select(
 123+ $res = $dbw->select(
104124 'user_stats',
105125 array( 'stats_user_id', 'stats_user_name', 'stats_total_points' ),
106126 array(),
@@ -107,9 +127,13 @@
108128 array( 'ORDER BY' => 'stats_user_name' )
109129 );
110130 $out = '';
 131+ $x = 0;
111132 foreach ( $res as $row ) {
112133 $x++;
113 - $stats = new UserStatsTrack( $row->stats_user_id, $row->stats_user_name );
 134+ $stats = new UserStatsTrack(
 135+ $row->stats_user_id,
 136+ $row->stats_user_name
 137+ );
114138 $stats->updateTotalPoints();
115139 }
116140 $out = "Updated stats for <b>{$x}</b> users";

Status & tagging log