Topic on Extension talk:Contribution Scores

Mattsmith321 (talkcontribs)

I wanted a column to show the user's rank in the table. That way it is a little easier to see where you stand in a list of 50 people. The Score column is great and is what is used for Rank but if people start raising their Score they still need an easy way to see if they are improving their relative position among the other editors.

I made the following changes in ContributionsScore_body.php (lines 107-145):

Old code:

		$altrow = '';

		foreach ( $res as $row ) {
			// Use real name if option used and real name present.
			if ( $wgContribScoresUseRealName && $row->user_real_name !== '' ) {
				$userLink = Linker::userLink(
					$row->user_id,
					$row->user_name,
					$row->user_real_name
				);
			} else {
				$userLink = Linker::userLink(
					$row->user_id,
					$row->user_name
				);
			}

			$output .= Html::closeElement( 'tr' );
			$output .= "<tr class='{$altrow}'>\n<td class='content'>" .
				$wgLang->formatNum( round( $row->wiki_rank, 0 ) ) . "\n</td><td class='content'>" .
				$wgLang->formatNum( $row->page_count ) . "\n</td><td class='content'>" .
				$wgLang->formatNum( $row->rev_count ) . "\n</td><td class='content'>" .
				$userLink;

			# Option to not display user tools
			if ( !in_array( 'notools', $opts ) ) {
				$output .= Linker::userToolLinks( $row->user_id, $row->user_name );
			}

			$output .= Html::closeElement( 'td' ) . "\n";

			if ( $altrow == '' && empty( $sortable ) ) {
				$altrow = 'odd ';
			} else {
				$altrow = '';
			}
		}

New code:

		$altrow = '';
		$userRank = 1;

		foreach ( $res as $row ) {
			// Use real name if option used and real name present.
			if ( $wgContribScoresUseRealName && $row->user_real_name !== '' ) {
				$userLink = Linker::userLink(
					$row->user_id,
					$row->user_name,
					$row->user_real_name
				);
			} else {
				$userLink = Linker::userLink(
					$row->user_id,
					$row->user_name
				);
			}

			$output .= Html::closeElement( 'tr' );
			$output .= "<tr class='{$altrow}'>\n<td class='content' style='padding-right:10px;text-align:right;'>" .
				$wgLang->formatNum( round( $userRank, 0 ) ) . "\n</td><td class='content' style='padding-right:10px;text-align:right;'>" .
				$wgLang->formatNum( round( $row->wiki_rank, 0 ) ) . "\n</td><td class='content' style='padding-right:10px;text-align:right;'>" .
				$wgLang->formatNum( $row->page_count ) . "\n</td><td class='content' style='padding-right:10px;text-align:right;'>" .
				$wgLang->formatNum( $row->rev_count ) . "\n</td><td class='content'>" .
				$userLink;

			# Option to not display user tools
			if ( !in_array( 'notools', $opts ) ) {
				$output .= Linker::userToolLinks( $row->user_id, $row->user_name );
			}

			$output .= Html::closeElement( 'td' ) . "\n";

			if ( $altrow == '' && empty( $sortable ) ) {
				$altrow = 'odd ';
			} else {
				$altrow = '';
			}
			$userRank++;
		}

In addition to the new column, I right-justified the numeric columns. Keep in mind that this code is not fully-baked in that there are several items that are hard-coded.

Enjoy!

Nemo bis (talkcontribs)

Hi! Thank you for sharing your patch, could you please add it to our repository? See Git/Tutorial.

Mattsmith321 (talkcontribs)

Trying to get it added. I am struggling with the git-review piece of gerrit in a Windows world. I've got my changes committed locally and ready to push but getting stuck on needing the change-id. I will have to try it later when I have a little more time to work through it.

Mattsmith321 (talkcontribs)

Holy cow! I think I actually got it submitted. You will definitely want to review everything. Let me know if there are any issues or what I might have done wrong so that I can do better next time.

Thanks!

Mattsmith321 (talk) 15:31, 23 September 2013 (UTC)

Nemo bis (talkcontribs)

Thanks for sending it. We know that it's hard for Windows users. :(

Reply to "Add column for rank"