code changes to add new metric "Pages created"

Jump to: navigation, search

Had a little programming fun and implemented the new metric Page Creations (for MW 1.13). Only new pages created with a minimum of 256Bytes will count, in order to avoid having Users try to boost their score by creating lots of empty pages. As well file uploads are logged as 0 length new page creations. I'd rather not have those count either.

Note: I use a different formula than the one that was precoded. I'm not much of a sql wizard. And never used php before. So be weary of this code ;-)


ContributionScores.php: these changes will add a new metric {{#cscore:Rst|pagecreations}} and change how the score metric is calculated.

              if ($metric=='score') {
                       $res = $dbr->select('revision',
                                                                       'COUNT(DISTINCT rev_page)+(COUNT(rev_id)-COUNT(DISTINCT rev_page))/2 AS wiki_rank',
                                                                       array('rev_user' => $user->getID()));
                       $row = $dbr->fetchObject($res);
                       $wiki_rank = $row->wiki_rank;
                       $userid = $user->getID();
                       $res = $dbr->query("SELECT COUNT(rev_id) AS pagecreation_count FROM revision WHERE rev_parent_id=0 AND rev_len>256 AND rev_user={$userid}");
                       $row = $dbr->fetchObject($res);
                       $wiki_rank = $wiki_rank + $row->pagecreation_count/2;
                       $output = round($wiki_rank,0);
               } elseif ($metric=='pagecreations') {
                       $userid = $user->getID();
                       $res = $dbr->query("SELECT COUNT(rev_id) AS pagecreation_count FROM revision WHERE rev_parent_id=0 AND rev_len>256 AND rev_user={$userid}");
                       $row = $dbr->fetchObject($res);
                       $output = $row->pagecreation_count;
               }


ContributionScores_body.php: these changes will add new column Pages Created to the Lists:

               $sqlMostNewPages = "SELECT rev_user,
                                                 COUNT(DISTINCT rev_page) AS newpage_count
                                                 FROM {$revTable}
                                                 {$sqlWhere} AND rev_parent_id=0 AND rev_len > 256
                                                 GROUP BY rev_user
                                                 ORDER BY newpage_count DESC
                                                 LIMIT {$limit}";
                $sqltmp =  "SELECT user_id, " .
                                                "user_name, " .
                                                "page_count, " .
                                                "rev_count " .
                                                "FROM $userTable u JOIN (($sqlMostPages) UNION ($sqlMostRevs)) s ON (user_id=rev_user) " .
                                                "LIMIT $limit";

                $sql =  "SELECT res1.user_id, " .
                                                "res1.user_name, " .
                                                "res1.page_count, " .
                                                "res2.newpage_count, " .
                                                "res1.rev_count, " .
                                                "res1.page_count+(res1.rev_count-res1.page_count)/2 + res2.newpage_count/2 AS wiki_rank " .
                                                "FROM ( ($sqltmp) as res1, ($sqlMostNewPages) as res2 ) " .
                                                "WHERE res1.user_id=res2.rev_user ORDER BY wiki_rank DESC " .
                                                "LIMIT $limit";

               $output = "<table class=\"wikitable contributionscores plainlinks{$sortable}\" >\n".
                        "<tr class='header'>\n".
                        "<td>" . wfMsgHtml( 'contributionscores-score' ) . "</td>\n" .
                        "<td>" . wfMsgHtml( 'contributionscores-pages' ) . "</td>\n" .
                        "<td>" . wfMsgHtml( 'contributionscores-changes' ) . "</td>\n" .
                        "<td>" . wfMsgHtml( 'contributionscores-newpages' ) . "</td>\n" .
                        "<td>" . wfMsgHtml( 'contributionscores-username' ) . "</td>\n";

               $output .= "</tr><tr class='{$altrow}'>\n<td class='content'>" .
                                round($row->wiki_rank,0) . "\n</td><td class='content'>" .
                                $row->page_count . "\n</td><td class='content'>" .
                                $row->rev_count . "\n</td><td class='content'>" .
                                $row->newpage_count . "\n</td><td class='content'>" .
                                $skin->userLink( $row->user_id, $row->user_name );


ContributionScores.i18n.php: only showing en changes:

$messages['en'] = array(
        'contributionscores'                 => 'Contribution scores',
        'contributionscores-desc'            => 'Polls the wiki database for highest [[Special:ContributionScores|user contribution volume]]',
        'contributionscores-info'            => "Scores are calculated as follows:
*One (1) point for each unique page edited
*(total edits made - total unique pages) / 2
*Half a point for each newly created Page with content
Scores calculated in this manner weight edit diversity over edit volume.
Basically, this score measures primarily unique pages edited, with consideration for high edit volume - assumed to be a higher quality page.",
        'contributionscores-top'             => '(Top $1)',
        'contributionscores-days'            => 'Last $1 days',
        'contributionscores-allrevisions'    => 'All revisions',
        'contributionscores-score'           => 'Score',
        'contributionscores-pages'           => 'Pages',
        'contributionscores-changes'         => 'Changes',
        'contributionscores-newpages'        => 'Page creations',
        'contributionscores-username'        => 'Username',
        'contributionscores-invalidusername' => 'Invalid username',
        'contributionscores-invalidmetric'   => 'Invalid metric',
);
—The preceding unsigned comment was added by an unknown user on a unknown date.06:08, 5 January 2012
Personal tools

Variants
Actions
Navigation
Support
Download
Development
Communication
Toolbox