https://www.mediawiki.org/wiki/Special:Code/MediaWiki/102132

Revision: 102132
Author:   ashley
Date:     2011-11-06 00:17:46 +0000 (Sun, 06 Nov 2011)
Log Message:
-----------
SocialProfile: as per Markus' in-depth review:
*move hook registration to the top of the file
*documentation updates
*i18n
*moved inline CSS to the CSS file
*removed some duplicate code
*return an array when we're supposed to return one instead of returning a string

Modified Paths:
--------------
    trunk/extensions/SocialProfile/UserStats/EditCount.php
    trunk/extensions/SocialProfile/UserStats/GenerateTopUsersReport.php
    trunk/extensions/SocialProfile/UserStats/SpecialUpdateEditCounts.php
    trunk/extensions/SocialProfile/UserStats/TopFansByStat.php
    trunk/extensions/SocialProfile/UserStats/TopFansRecent.php
    trunk/extensions/SocialProfile/UserStats/TopList.css
    trunk/extensions/SocialProfile/UserStats/TopUsers.php
    trunk/extensions/SocialProfile/UserStats/UserStats.i18n.php
    trunk/extensions/SocialProfile/UserStats/UserStatsClass.php

Modified: trunk/extensions/SocialProfile/UserStats/EditCount.php
===================================================================
--- trunk/extensions/SocialProfile/UserStats/EditCount.php      2011-11-05 
23:57:07 UTC (rev 102131)
+++ trunk/extensions/SocialProfile/UserStats/EditCount.php      2011-11-06 
00:17:46 UTC (rev 102132)
@@ -7,8 +7,19 @@
        die( "This is not a valid entry point.\n" );
 }
 
+/**
+ * For the UserLevels (points) functionality to work, you will need to
+ * define $wgUserLevels and require_once() this file in your wiki's
+ * LocalSettings.php file.
+ */
 $wgHooks['NewRevisionFromEditComplete'][] = 'incEditCount';
+$wgHooks['ArticleDelete'][] = 'removeDeletedEdits';
+$wgHooks['ArticleUndelete'][] = 'restoreDeletedEdits';
 
+/**
+ * Updates user's points after they've made an edit in a namespace that is
+ * listed in the $wgNamespacesForEditPoints array.
+ */
 function incEditCount( $article, $revision, $baseRevId ) {
        global $wgUser, $wgNamespacesForEditPoints;
 
@@ -24,8 +35,10 @@
        return true;
 }
 
-$wgHooks['ArticleDelete'][] = 'removeDeletedEdits';
-
+/**
+ * Updates user's points after a page in a namespace that is listed in the
+ * $wgNamespacesForEditPoints array that they've edited has been deleted.
+ */
 function removeDeletedEdits( &$article, &$user, &$reason ) {
        global $wgNamespacesForEditPoints;
 
@@ -51,8 +64,11 @@
        return true;
 }
 
-$wgHooks['ArticleUndelete'][] = 'restoreDeletedEdits';
-
+/**
+ * Updates user's points after a page in a namespace that is listed in the
+ * $wgNamespacesForEditPoints array that they've edited has been restored after
+ * it was originally deleted.
+ */
 function restoreDeletedEdits( &$title, $new ) {
        global $wgNamespacesForEditPoints;
 

Modified: trunk/extensions/SocialProfile/UserStats/GenerateTopUsersReport.php
===================================================================
--- trunk/extensions/SocialProfile/UserStats/GenerateTopUsersReport.php 
2011-11-05 23:57:07 UTC (rev 102131)
+++ trunk/extensions/SocialProfile/UserStats/GenerateTopUsersReport.php 
2011-11-06 00:17:46 UTC (rev 102132)
@@ -79,6 +79,8 @@
                // Add CSS
                $wgOut->addExtensionStyle( $wgScriptPath . 
'/extensions/SocialProfile/UserStats/TopList.css' );
 
+               // Used as the LIMIT for SQL queries; basically, show this many 
users
+               // in the generated reports.
                $user_count = $wgRequest->getInt( 'user_count', 10 );
 
                if( $period == 'weekly' ) {
@@ -101,7 +103,11 @@
                );
 
                $last_rank = 0;
+               $last_total = 0;
+               $x = 1;
 
+               $users = array();
+
                // Initial run is a special case
                if ( $dbw->numRows( $res ) <= 0 ) {
                        // For the initial run, everybody's a winner!
@@ -122,11 +128,6 @@
 
                        $out = '<div class="top-users">';
 
-                       $last_total = 0;
-                       $x = 1;
-
-                       $users = array();
-
                        foreach( $res as $row ) {
                                if( $row->stats_total_points == $last_total ) {
                                        $rank = $last_rank;
@@ -146,11 +147,6 @@
                } else {
                        $out = '<div class="top-users">';
 
-                       $last_total = 0;
-                       $x = 1;
-
-                       $users = array();
-
                        foreach( $res as $row ) {
                                if( $row->up_points == $last_total ) {
                                        $rank = $last_rank;

Modified: trunk/extensions/SocialProfile/UserStats/SpecialUpdateEditCounts.php
===================================================================
--- trunk/extensions/SocialProfile/UserStats/SpecialUpdateEditCounts.php        
2011-11-05 23:57:07 UTC (rev 102131)
+++ trunk/extensions/SocialProfile/UserStats/SpecialUpdateEditCounts.php        
2011-11-06 00:17:46 UTC (rev 102132)
@@ -73,7 +73,14 @@
                                        __METHOD__
                                );
                        }
-                       $wgOut->addHTML( "<p>Updating {$row->rev_user_text} 
with {$editCount} edits</p>" );
+                       $wgOut->addHTML(
+                               wfMsgExt(
+                                       'updateeditcounts-updating',
+                                       'parsemag',
+                                       $row->rev_user_text,
+                                       $editCount
+                               )
+                       );
 
                        $dbw->update(
                                'user_stats',
@@ -97,8 +104,6 @@
        public function execute( $par ) {
                global $wgOut, $wgUser;
 
-               $wgOut->setPageTitle( 'Update Edit Counts' );
-
                // Check permissions -- we must be allowed to access this 
special page
                // before we can run any database queries
                if ( !$wgUser->isAllowed( 'updatepoints' ) ) {
@@ -112,6 +117,9 @@
                        return;
                }
 
+               // Set the page title, robot policies, etc.
+               $this->setHeaders();
+
                $dbw = wfGetDB( DB_MASTER );
                $this->updateMainEditsCount();
 
@@ -125,7 +133,7 @@
                        __METHOD__,
                        array( 'ORDER BY' => 'stats_user_name' )
                );
-               $out = '';
+
                $x = 0;
                foreach ( $res as $row ) {
                        $x++;
@@ -135,7 +143,7 @@
                        );
                        $stats->updateTotalPoints();
                }
-               $out = "Updated stats for <b>{$x}</b> users";
-               $wgOut->addHTML( $out );
+
+               $wgOut->addHTML( wfMsgExt( 'updateeditcounts-updated', 
'parsemag', $x ) );
        }
 }

Modified: trunk/extensions/SocialProfile/UserStats/TopFansByStat.php
===================================================================
--- trunk/extensions/SocialProfile/UserStats/TopFansByStat.php  2011-11-05 
23:57:07 UTC (rev 102131)
+++ trunk/extensions/SocialProfile/UserStats/TopFansByStat.php  2011-11-06 
00:17:46 UTC (rev 102132)
@@ -56,7 +56,6 @@
                        $params['ORDER BY'] = "{$column} DESC";
                        $params['LIMIT'] = $count;
 
-                       $dbr = wfGetDB( DB_SLAVE );
                        $res = $dbr->select(
                                'user_stats',
                                array( 'stats_user_id', 'stats_user_name', 
$column ),
@@ -96,7 +95,7 @@
                $message = wfMsgForContent( 'topfans-by-category' );
 
                if ( !wfEmptyMsg( 'topfans-by-category', $message ) ) {
-                       $out .= '<h1 style="margin-top:15px !important;">' .
+                       $out .= '<h1 class="top-title">' .
                                wfMsg( 'top-fans-by-category-nav-header' ) . 
'</h1>';
 
                        $lines = explode( "\n", $message );

Modified: trunk/extensions/SocialProfile/UserStats/TopFansRecent.php
===================================================================
--- trunk/extensions/SocialProfile/UserStats/TopFansRecent.php  2011-11-05 
23:57:07 UTC (rev 102131)
+++ trunk/extensions/SocialProfile/UserStats/TopFansRecent.php  2011-11-06 
00:17:46 UTC (rev 102132)
@@ -95,7 +95,7 @@
                $message = wfMsgForContent( 'topfans-by-category' );
 
                if ( !wfEmptyMsg( 'topfans-by-category', $message ) ) {
-                       $out .= '<h1 style="margin-top:15px !important;">' .
+                       $out .= '<h1 class="top-title">' .
                                wfMsg( 'top-fans-by-category-nav-header' ) . 
'</h1>';
 
                        $lines = explode( "\n", $message );

Modified: trunk/extensions/SocialProfile/UserStats/TopList.css
===================================================================
--- trunk/extensions/SocialProfile/UserStats/TopList.css        2011-11-05 
23:57:07 UTC (rev 102131)
+++ trunk/extensions/SocialProfile/UserStats/TopList.css        2011-11-06 
00:17:46 UTC (rev 102132)
@@ -73,7 +73,13 @@
        width: 200px;
        padding: 5px;
 }
+
 .top-fan-nav a {
        font-weight: bold;
        text-decoration: none;
 }
+
+/* A "Top users by category" <h1> on Special:TopFansByStatistics and 
Special:TopUsersRecent */
+.top-title {
+       margin-top: 15px !important;
+}
\ No newline at end of file

Modified: trunk/extensions/SocialProfile/UserStats/TopUsers.php
===================================================================
--- trunk/extensions/SocialProfile/UserStats/TopUsers.php       2011-11-05 
23:57:07 UTC (rev 102131)
+++ trunk/extensions/SocialProfile/UserStats/TopUsers.php       2011-11-06 
00:17:46 UTC (rev 102132)
@@ -57,7 +57,7 @@
                                        );
                                        $loop++;
                                }
-                               if ( $loop >= 50 ) {
+                               if ( $loop >= $realcount ) {
                                        break;
                                }
                        }

Modified: trunk/extensions/SocialProfile/UserStats/UserStats.i18n.php
===================================================================
--- trunk/extensions/SocialProfile/UserStats/UserStats.i18n.php 2011-11-05 
23:57:07 UTC (rev 102131)
+++ trunk/extensions/SocialProfile/UserStats/UserStats.i18n.php 2011-11-06 
00:17:46 UTC (rev 102132)
@@ -72,6 +72,10 @@
 
 Click $3
 and change your settings to disable e-mail notifications.',
+       // Special:UpdateEditCounts
+       'updateeditcounts' => 'Update Edit Counts',
+       'updateeditcounts-updated' => "Updated stats for '''$1''' 
{{PLURAL:$1|user|users}}",
+       'updateeditcounts-updating' => 'Updating $1 with $2 
{{PLURAL:$2|edit|edits}}',
        // Special:GenerateTopUsersReport
        'generatetopusersreport' => 'Generate Top Users Report',
        'user-stats-weekly-winners' => 'Weekly {{PLURAL:$1|Winner|Winners}}',

Modified: trunk/extensions/SocialProfile/UserStats/UserStatsClass.php
===================================================================
--- trunk/extensions/SocialProfile/UserStats/UserStatsClass.php 2011-11-05 
23:57:07 UTC (rev 102131)
+++ trunk/extensions/SocialProfile/UserStats/UserStatsClass.php 2011-11-06 
00:17:46 UTC (rev 102132)
@@ -581,7 +581,7 @@
                global $wgEnableFacebook, $wgUserLevels;
 
                if ( $this->user_id == 0 ) {
-                       return '';
+                       return array();
                }
 
                $stats_data = array();
@@ -775,7 +775,7 @@
         *                                      amount of points the user has
         */
        static function getTopFansList( $limit = 10 ) {
-               $dbr = wfGetDB( DB_MASTER );
+               $dbr = wfGetDB( DB_SLAVE );
 
                $res = $dbr->select(
                        'user_stats',


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to