stylize.php.

This commit is contained in:
Siebrand Mazeland 2012-01-05 09:45:01 +00:00
parent 7467195055
commit eeec962440
3 changed files with 53 additions and 53 deletions

View file

@ -4,9 +4,9 @@
*/ */
# Not a valid entry point, skip unless MEDIAWIKI is defined # Not a valid entry point, skip unless MEDIAWIKI is defined
if (!defined('MEDIAWIKI')) { if ( !defined( 'MEDIAWIKI' ) ) {
echo "Contribution Scores extension"; echo "Contribution Scores extension";
exit(1); exit( 1 );
} }
$wgExtensionCredits['specialpage'][] = array( $wgExtensionCredits['specialpage'][] = array(
@ -48,44 +48,44 @@ function efContributionScores_LanguageGetMagic( &$magicWords, $langCode ) {
return true; return true;
} }
function efContributionScores_Render(&$parser, $usertext, $metric='score') { function efContributionScores_Render( &$parser, $usertext, $metric = 'score' ) {
global $wgContribScoreDisableCache; global $wgContribScoreDisableCache;
if ($wgContribScoreDisableCache) { if ( $wgContribScoreDisableCache ) {
$parser->disableCache(); $parser->disableCache();
} }
$user = User::newFromName($usertext); $user = User::newFromName( $usertext );
$dbr = wfGetDB( DB_SLAVE ); $dbr = wfGetDB( DB_SLAVE );
if ( $user instanceof User && $user->isLoggedIn() ) { if ( $user instanceof User && $user->isLoggedIn() ) {
global $wgLang; global $wgLang;
if ($metric=='score') { if ( $metric == 'score' ) {
$res = $dbr->select('revision', $res = $dbr->select( 'revision',
'COUNT(DISTINCT rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank', 'COUNT(DISTINCT rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank',
array('rev_user' => $user->getID())); array( 'rev_user' => $user->getID() ) );
$row = $dbr->fetchObject($res); $row = $dbr->fetchObject( $res );
$output = $wgLang->formatNum( round($row->wiki_rank,0) ); $output = $wgLang->formatNum( round( $row->wiki_rank, 0 ) );
} elseif ($metric=='changes') { } elseif ( $metric == 'changes' ) {
$res = $dbr->select('revision', $res = $dbr->select( 'revision',
'COUNT(rev_id) AS rev_count', 'COUNT(rev_id) AS rev_count',
array('rev_user' => $user->getID())); array( 'rev_user' => $user->getID() ) );
$row = $dbr->fetchObject($res); $row = $dbr->fetchObject( $res );
$output = $wgLang->formatNum( $row->rev_count ); $output = $wgLang->formatNum( $row->rev_count );
} elseif ($metric=='pages') { } elseif ( $metric == 'pages' ) {
$res = $dbr->select('revision', $res = $dbr->select( 'revision',
'COUNT(DISTINCT rev_page) AS page_count', 'COUNT(DISTINCT rev_page) AS page_count',
array('rev_user' => $user->getID())); array( 'rev_user' => $user->getID() ) );
$row = $dbr->fetchObject($res); $row = $dbr->fetchObject( $res );
$output = $wgLang->formatNum( $row->page_count ); $output = $wgLang->formatNum( $row->page_count );
} else { } else {
$output = wfMsg('contributionscores-invalidmetric'); $output = wfMsg( 'contributionscores-invalidmetric' );
} }
} else { } else {
$output = wfMsg('contributionscores-invalidusername'); $output = wfMsg( 'contributionscores-invalidusername' );
} }
return $parser->insertStripItem($output, $parser->mStripState); return $parser->insertStripItem( $output, $parser->mStripState );
} }

View file

@ -3,7 +3,7 @@
* \brief Contains code for the ContributionScores Class (extends SpecialPage). * \brief Contains code for the ContributionScores Class (extends SpecialPage).
*/ */
///Special page class for the Contribution Scores extension /// Special page class for the Contribution Scores extension
/** /**
* Special page that generates a list of wiki contributors based * Special page that generates a list of wiki contributors based
* on edit diversity (unique pages edited) and edit volume (total * on edit diversity (unique pages edited) and edit volume (total
@ -17,7 +17,7 @@ class ContributionScores extends IncludableSpecialPage {
parent::__construct( 'ContributionScores' ); parent::__construct( 'ContributionScores' );
} }
///Generates a "Contribution Scores" table for a given LIMIT and date range /// Generates a "Contribution Scores" table for a given LIMIT and date range
/** /**
* Function generates Contribution Scores tables in HTML format (not wikiText) * Function generates Contribution Scores tables in HTML format (not wikiText)
* *
@ -33,17 +33,17 @@ class ContributionScores extends IncludableSpecialPage {
$dbr = wfGetDB( DB_SLAVE ); $dbr = wfGetDB( DB_SLAVE );
$userTable = $dbr->tableName('user'); $userTable = $dbr->tableName( 'user' );
$userGroupTable = $dbr->tableName('user_groups'); $userGroupTable = $dbr->tableName( 'user_groups' );
$revTable = $dbr->tableName('revision'); $revTable = $dbr->tableName( 'revision' );
$ipBlocksTable = $dbr->tableName('ipblocks'); $ipBlocksTable = $dbr->tableName( 'ipblocks' );
$sqlWhere = ""; $sqlWhere = "";
$nextPrefix = "WHERE"; $nextPrefix = "WHERE";
if ( $days > 0 ) { if ( $days > 0 ) {
$date = time() - (60*60*24*$days); $date = time() - ( 60 * 60 * 24 * $days );
$dateString = $dbr->timestamp($date); $dateString = $dbr->timestamp( $date );
$sqlWhere .= " {$nextPrefix} rev_timestamp > '$dateString'"; $sqlWhere .= " {$nextPrefix} rev_timestamp > '$dateString'";
$nextPrefix = "AND"; $nextPrefix = "AND";
} }
@ -90,8 +90,8 @@ class ContributionScores extends IncludableSpecialPage {
$sortable = in_array( 'nosort', $opts ) ? '' : ' sortable'; $sortable = in_array( 'nosort', $opts ) ? '' : ' sortable';
$output = "<table class=\"wikitable contributionscores plainlinks{$sortable}\" >\n". $output = "<table class=\"wikitable contributionscores plainlinks{$sortable}\" >\n" .
"<tr class='header'>\n". "<tr class='header'>\n" .
Html::element( 'th', array(), wfMsg( 'contributionscores-score' ) ) . Html::element( 'th', array(), wfMsg( 'contributionscores-score' ) ) .
Html::element( 'th', array(), wfMsg( 'contributionscores-pages' ) ) . Html::element( 'th', array(), wfMsg( 'contributionscores-pages' ) ) .
Html::element( 'th', array(), wfMsg( 'contributionscores-changes' ) ) . Html::element( 'th', array(), wfMsg( 'contributionscores-changes' ) ) .
@ -101,7 +101,7 @@ class ContributionScores extends IncludableSpecialPage {
foreach ( $res as $row ) { foreach ( $res as $row ) {
// Use real name if option used and real name present. // Use real name if option used and real name present.
if( $wgContribScoresUseRealName && $row->user_real_name !== '' ) { if ( $wgContribScoresUseRealName && $row->user_real_name !== '' ) {
$userLink = Linker::userLink( $userLink = Linker::userLink(
$row->user_id, $row->user_id,
$row->user_name, $row->user_name,
@ -142,12 +142,12 @@ class ContributionScores extends IncludableSpecialPage {
if ( !empty( $title ) ) if ( !empty( $title ) )
$output = Html::rawElement( 'table', array( 'cellspacing' => 0, 'cellpadding' => 0, $output = Html::rawElement( 'table', array( 'cellspacing' => 0, 'cellpadding' => 0,
'class' => 'contributionscores-wrapper', 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() ), 'class' => 'contributionscores-wrapper', 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() ),
"\n". "\n" .
"<tr>\n". "<tr>\n" .
"<td style='padding: 0px;'>{$title}</td>\n". "<td style='padding: 0px;'>{$title}</td>\n" .
"</tr>\n". "</tr>\n" .
"<tr>\n". "<tr>\n" .
"<td style='padding: 0px;'>{$output}</td>\n". "<td style='padding: 0px;'>{$output}</td>\n" .
"</tr>\n" ); "</tr>\n" );
return $output; return $output;
@ -156,7 +156,7 @@ class ContributionScores extends IncludableSpecialPage {
function execute( $par ) { function execute( $par ) {
$this->setHeaders(); $this->setHeaders();
if( $this->including() ) { if ( $this->including() ) {
$this->showInclude( $par ); $this->showInclude( $par );
} else { } else {
$this->showPage(); $this->showPage();
@ -178,7 +178,7 @@ class ContributionScores extends IncludableSpecialPage {
$options = 'none'; $options = 'none';
if ( !empty( $par ) ) { if ( !empty( $par ) ) {
$params = explode('/', $par ); $params = explode( '/', $par );
$limit = intval( $params[0] ); $limit = intval( $params[0] );
@ -231,7 +231,7 @@ class ContributionScores extends IncludableSpecialPage {
} else { } else {
$reportTitle = wfMsg( 'contributionscores-allrevisions' ); $reportTitle = wfMsg( 'contributionscores-allrevisions' );
} }
$reportTitle .= " " . wfMsgExt('contributionscores-top', 'parsemag', $wgLang->formatNum( $revs ) ); $reportTitle .= " " . wfMsgExt( 'contributionscores-top', 'parsemag', $wgLang->formatNum( $revs ) );
$title = Xml::element( 'h2', array( 'class' => 'contributionscores-title' ), $reportTitle ) . "\n"; $title = Xml::element( 'h2', array( 'class' => 'contributionscores-title' ), $reportTitle ) . "\n";
$wgOut->addHTML( $title ); $wgOut->addHTML( $title );
$wgOut->addHTML( $this->genContributionScoreTable( $days, $revs ) ); $wgOut->addHTML( $this->genContributionScoreTable( $days, $revs ) );