Reception123 has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/373567 )

Change subject: Convert ContributionScores to use extension registration.
......................................................................

Convert ContributionScores to use extension registration.

Bug: T174046
Change-Id: I5fbe985cf713634316168ee6bab9a5f5e841227f
---
M ContributionScores.php
M ContributionScores_body.php
A extension.json
3 files changed, 123 insertions(+), 88 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContributionScores 
refs/changes/67/373567/1

diff --git a/ContributionScores.php b/ContributionScores.php
index 508e4d6..74fb368 100644
--- a/ContributionScores.php
+++ b/ContributionScores.php
@@ -3,91 +3,14 @@
  * \brief Contains setup code for the Contribution Scores Extension.
  */
 
-# Not a valid entry point, skip unless MEDIAWIKI is defined
-if ( !defined( 'MEDIAWIKI' ) ) {
-       echo 'Contribution Scores extension';
-       exit( 1 );
-}
-
-$wgExtensionCredits['specialpage'][] = [
-       'path' => __FILE__,
-       'name' => 'Contribution Scores',
-       'url' => 'https://www.mediawiki.org/wiki/Extension:Contribution_Scores',
-       'author' => 'Tim Laqua',
-       'descriptionmsg' => 'contributionscores-desc',
-       'version' => '1.25.0'
-];
-
-define( 'CONTRIBUTIONSCORES_MAXINCLUDELIMIT', 50 );
-$wgContribScoreReports = null;
-
-// These settings can be overridden in LocalSettings.php.
-
-// Set to true to exclude bots from the reporting.
-$wgContribScoreIgnoreBlockedUsers = false;
-
-// Set to true to exclude blocked users from the reporting.
-$wgContribScoreIgnoreBots = false;
-
-// Set to true to use real user names when available. Only for MediaWiki 1.19 
and later.
-$wgContribScoresUseRealName = false;
-
-// Set to true to disable cache for parser function and inclusion of table.
-$wgContribScoreDisableCache = false;
-
-$wgAutoloadClasses['ContributionScores'] = __DIR__ . 
'/ContributionScores_body.php';
-$wgSpecialPages['ContributionScores'] = 'ContributionScores';
-
-$wgMessagesDirs['ContributionScores'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['ContributionScoresAlias'] = __DIR__ . 
'/ContributionScores.alias.php';
-$wgExtensionMessagesFiles['ContributionScoresMagic'] =
-       __DIR__ . '/ContributionScores.i18n.magic.php';
-
-$wgHooks['ParserFirstCallInit'][] = 'efContributionScores_Setup';
-
-function efContributionScores_Setup( &$parser ) {
-       $parser->setFunctionHook( 'cscore', 'efContributionScores_Render' );
-
-       return true;
-}
-
-function efContributionScores_Render( &$parser, $usertext, $metric = 'score' ) 
{
-       global $wgContribScoreDisableCache;
-
-       if ( $wgContribScoreDisableCache ) {
-               $parser->disableCache();
-       }
-
-       $user = User::newFromName( $usertext );
-       $dbr = wfGetDB( DB_SLAVE );
-
-       if ( $user instanceof User && $user->isLoggedIn() ) {
-               global $wgLang;
-
-               if ( $metric == 'score' ) {
-                       $res = $dbr->select( 'revision',
-                               'COUNT(DISTINCT 
rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank',
-                               [ 'rev_user' => $user->getID() ] );
-                       $row = $dbr->fetchObject( $res );
-                       $output = $wgLang->formatNum( round( $row->wiki_rank, 0 
) );
-               } elseif ( $metric == 'changes' ) {
-                       $res = $dbr->select( 'revision',
-                               'COUNT(rev_id) AS rev_count',
-                               [ 'rev_user' => $user->getID() ] );
-                       $row = $dbr->fetchObject( $res );
-                       $output = $wgLang->formatNum( $row->rev_count );
-               } elseif ( $metric == 'pages' ) {
-                       $res = $dbr->select( 'revision',
-                               'COUNT(DISTINCT rev_page) AS page_count',
-                               [ 'rev_user' => $user->getID() ] );
-                       $row = $dbr->fetchObject( $res );
-                       $output = $wgLang->formatNum( $row->page_count );
-               } else {
-                       $output = wfMessage( 'contributionscores-invalidmetric' 
)->text();
-               }
-       } else {
-               $output = wfMessage( 'contributionscores-invalidusername' 
)->text();
-       }
-
-       return $parser->insertStripItem( $output, $parser->mStripState );
-}
+if ( function_exists( 'wfLoadExtension' ) ) {
+       wfLoadExtension( 'ContributionScores' );
+       $wgMessageDirs['ContributionScores'] = __DIR__ . '/i18n';
+       wfWarn(
+               'Deprecated PHP entry point used for ContributionScores 
extension. ' .
+               'Please use wfLoadExtension instead, ' .
+               'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
+       );
+} else {
+       die( 'This version of the ContributionScores extension requires 
MediaWiki 1.29+' );
+}
\ No newline at end of file
diff --git a/ContributionScores_body.php b/ContributionScores_body.php
index aba2370..799354e 100644
--- a/ContributionScores_body.php
+++ b/ContributionScores_body.php
@@ -267,6 +267,53 @@
                        $out->addHTML( $this->genContributionScoreTable( $days, 
$revs ) );
                }
        }
+       function efContributionScores_Setup( &$parser ) {
+       $parser->setFunctionHook( 'cscore', 'efContributionScores_Render' );
+
+       return true;
+}
+
+       function efContributionScores_Render( &$parser, $usertext, $metric = 
'score' ) {
+               global $wgContribScoreDisableCache;
+
+               if ( $wgContribScoreDisableCache ) {
+               $parser->disableCache();
+               }
+
+               $user = User::newFromName( $usertext );
+               $dbr = wfGetDB( DB_SLAVE );
+
+               if ( $user instanceof User && $user->isLoggedIn() ) {
+                       global $wgLang;
+
+                               if ( $metric == 'score' ) {
+                                       $res = $dbr->select( 'revision',
+                               'COUNT(DISTINCT 
rev_page)+SQRT(COUNT(rev_id)-COUNT(DISTINCT rev_page))*2 AS wiki_rank',
+                               [ 'rev_user' => $user->getID() ] );
+                                       $row = $dbr->fetchObject( $res );
+                                       $output = $wgLang->formatNum( round( 
$row->wiki_rank, 0 ) );
+                               } elseif ( $metric == 'changes' ) {
+                                       $res = $dbr->select( 'revision',
+                                       'COUNT(rev_id) AS rev_count',
+                                       [ 'rev_user' => $user->getID() ] );
+                                       $row = $dbr->fetchObject( $res );
+                                       $output = $wgLang->formatNum( 
$row->rev_count );
+                               } elseif ( $metric == 'pages' ) {
+                       $               res = $dbr->select( 'revision',
+                                       'COUNT(DISTINCT rev_page) AS 
page_count',
+                                       [ 'rev_user' => $user->getID() ] );
+                                       $row = $dbr->fetchObject( $res );
+                                       $output = $wgLang->formatNum( 
$row->page_count );
+                               } else {
+                                       $output = wfMessage( 
'contributionscores-invalidmetric' )->text();
+                       }
+                               } else {
+                                       $output = wfMessage( 
'contributionscores-invalidusername' )->text();
+                       }
+
+                               return $parser->insertStripItem( $output, 
$parser->mStripState );
+}
+
 
        protected function getGroupName() {
                return 'wiki';
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..ae7cd39
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,65 @@
+{
+       "name": "ContributionScores",
+       "version": "1.25.0",
+       "author": [
+               "[https://www.mediawiki.org/wiki/User:Tim_Laqua Tim Laqua]"
+       ],
+       "url": "https://www.mediawiki.org/wiki/Extension:ContributionScores";,
+       "descriptionmsg": "contributionscores-desc",
+       "license-name": "GPL-2.0+",
+       "AutoloadClasses": {
+               "ContributionScores": "ContributionScores.body.php"
+       },
+       "MessagesDirs": {
+               "ContributionScores": [
+                       "i18n"
+               ]
+       },
+       "config": {
+               "ContribScoreReports": {
+                       "value": null,
+                       "description": "Each array defines a report - 7,50 is 
"past 7 days" and "LIMIT 50" - Can be omitted."
+               },
+               "ContribScoreIgnoreBlockedUsers": {
+                       "value": false,
+                       "description": "Set to true to exclude blocked users 
from the reporting."
+               },
+               "ContribScoreIgnoreBots": {
+                       "value": false,
+                       "description": "Set to true to exclude bots users from 
the reporting."
+               },
+               "ContribScoresUseRealName": {
+                       "value": false,
+                       "description": "Set to true to use real user names when 
available."
+               },
+               "ContribScoreDisableCache": {
+                       "value": false,
+                       "description": "Set to true to disable cache for parser 
function and inclusion of table."
+               },
+       },
+       "SpecialPages": {
+               "ContributionScores": "ContributionScores"
+       },
+       "Hooks": {
+               "efContributionScores_Setup": 
"ContributionScores::ParserFirstCallInit",
+       },
+       "ExtensionMessagesFiles": {
+               "ContributionScores": "ContributionScores.i18n.php"
+       },
+       "AvailableRights": [
+               "author",
+               "authorprotect"
+       ],
+       "GroupPermissions": {
+               "sysop": {
+                       "author": true
+               },
+               "user": {
+                       "authorprotect": true
+               }
+       },
+       "RestrictionLevels": {
+               "author": true
+       },
+       "manifest_version": 2
+}
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/373567
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5fbe985cf713634316168ee6bab9a5f5e841227f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContributionScores
Gerrit-Branch: master
Gerrit-Owner: Reception123 <[email protected]>

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

Reply via email to