jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/305676 )
Change subject: Add composer.json including phpcs package ...................................................................... Add composer.json including phpcs package Make phpcs pass by fixing the issues Bug: T134933 Change-Id: Icdfd9fc0fbb580f328049d5d425197232cce2f71 --- M .gitignore M Contributors.alias.php M Contributors.i18n.php M Contributors.php M api/ApiQueryCncontributors.php A composer.json M includes/Contributors.php M includes/ContributorsHooks.php M includes/ContributorsTablePager.php M includes/SpecialContributors.php M maintenance/PopulateContributorsTable.php A phpcs.xml 12 files changed, 88 insertions(+), 43 deletions(-) Approvals: Umherirrender: Looks good to me, but someone else must approve Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/.gitignore b/.gitignore index 1689d7a..35dff22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ *~ *.kate-swp .*.swp -node_modules/** +/composer.lock +/vendor/ +/node_modules/ diff --git a/Contributors.alias.php b/Contributors.alias.php index 1561c53..4f801d1 100644 --- a/Contributors.alias.php +++ b/Contributors.alias.php @@ -5,7 +5,6 @@ * @file * @ingroup Extensions */ -// @codingStandardsIgnoreFile $specialPageAliases = array(); @@ -392,4 +391,4 @@ /** Traditional Chinese (中文(繁體)) */ $specialPageAliases['zh-hant'] = array( 'Contributors' => array( '貢獻者' ), -); \ No newline at end of file +); diff --git a/Contributors.i18n.php b/Contributors.i18n.php index d59c1f2..b299016 100644 --- a/Contributors.i18n.php +++ b/Contributors.i18n.php @@ -15,7 +15,7 @@ function wfJsonI18nShimea0a5e62e5f1189e( $cache, $code, &$cachedData ) { $codeSequence = array_merge( array( $code ), $cachedData['fallbackSequence'] ); foreach ( $codeSequence as $csCode ) { - $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json"; + $fileName = __DIR__ . "/i18n/$csCode.json"; if ( is_readable( $fileName ) ) { $data = FormatJson::decode( file_get_contents( $fileName ), true ); foreach ( array_keys( $data ) as $key ) { diff --git a/Contributors.php b/Contributors.php index 817785b..cb75eea 100644 --- a/Contributors.php +++ b/Contributors.php @@ -6,7 +6,8 @@ $wgExtensionMessagesFiles['ContributorsAlias'] = __DIR__ . '/Contributors.alias.php'; $wgExtensionMessagesFiles['ContributorsMagic'] = __DIR__ . '/Contributors.magic.php'; /* wfWarn( - 'Deprecated PHP entry point used for Contributors extension. Please use wfLoadExtension instead, ' . + 'Deprecated PHP entry point used for Contributors extension. ' . + 'Please use wfLoadExtension instead, ' . 'see https://www.mediawiki.org/wiki/Extension_registration for more details.' ); */ return; diff --git a/api/ApiQueryCncontributors.php b/api/ApiQueryCncontributors.php index 52650e9..4e85e87 100644 --- a/api/ApiQueryCncontributors.php +++ b/api/ApiQueryCncontributors.php @@ -2,7 +2,7 @@ class ApiQueryCnContributors extends ApiQueryBase { - public function __construct( ApiQuery $query, $moduleName ) { + public function __construct( ApiQuery $query, $moduleName ) { parent::__construct( $query, $moduleName, 'cn' ); } @@ -15,8 +15,8 @@ $result = $this->getResult(); foreach ( $res as $row ) { - - $result->addValue( 'query', $this->getModuleName() , $row->cn_user_text , $row->cn_revision_count ); + $result->addValue( + 'query', $this->getModuleName(), $row->cn_user_text, $row->cn_revision_count ); } } private function buildDbQuery( array $params ) { @@ -51,4 +51,4 @@ => 'apihelp-query+contributors-example-1', ); } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..614a3f3 --- /dev/null +++ b/composer.json @@ -0,0 +1,17 @@ +{ + "type": "mediawiki-extension", + "require-dev": { + "jakub-onderka/php-parallel-lint": "0.9.2", + "jakub-onderka/php-console-highlighter": "0.3.2", + "mediawiki/mediawiki-codesniffer": "0.7.2" + }, + "scripts": { + "test": [ + "parallel-lint . --exclude vendor", + "phpcs -p -s" + ], + "fix": [ + "phpcbf" + ] + } +} diff --git a/includes/Contributors.php b/includes/Contributors.php index c1195bf..aa597ca 100644 --- a/includes/Contributors.php +++ b/includes/Contributors.php @@ -124,7 +124,7 @@ $pageId = $this->getTarget()->getArticleID(); $contributors = array(); - if ( array_key_exists( 'filteranon', $opts ) && $opts['filteranon'] ) { + if ( array_key_exists( 'filteranon', $opts ) && $opts['filteranon'] ) { $cond = array( 'cn_page_id' => $pageId , 'cn_user_id !=0' ); } else { $cond = array( 'cn_page_id' => $pageId ); @@ -139,8 +139,11 @@ 'ORDER BY' => 'cn_revision_count DESC', ) ); if ( $res && $dbr->numRows( $res ) > 0 ) { - while ( $row = $dbr->fetchObject( $res ) ) { - $contributors[ $row->cn_user_text ] = array( $row->cn_user_text , $row->cn_revision_count ); + foreach ( $res as $row ) { + $contributors[ $row->cn_user_text ] = array( + $row->cn_user_text, + $row->cn_revision_count + ); } } return $contributors; @@ -212,6 +215,5 @@ } return $output; } - } diff --git a/includes/ContributorsHooks.php b/includes/ContributorsHooks.php index 8fc0df2..d9d7269 100644 --- a/includes/ContributorsHooks.php +++ b/includes/ContributorsHooks.php @@ -106,12 +106,14 @@ */ public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) { $updater->addExtensionTable( 'contributors', __DIR__ . '/sql/contributors.sql' ); - $updater->addExtensionField( 'contributors', 'cn_first_edit', __DIR__ . '/sql/contributors-add-timestamps.sql' ); - $updater->addExtensionField( 'contributors', 'cn_last_edit', __DIR__ . '/sql/contributors-add-timestamps.sql' ); + $updater->addExtensionField( 'contributors', 'cn_first_edit', + __DIR__ . '/sql/contributors-add-timestamps.sql' ); + $updater->addExtensionField( 'contributors', 'cn_last_edit', + __DIR__ . '/sql/contributors-add-timestamps.sql' ); return true; } -/** + /** * Updates the contributors table with each edit made by a user to a page * @param WikiPage $article * @param User $user @@ -126,7 +128,19 @@ * @param $baseRevId * @throws Exception */ - public static function onPageContentSaveComplete( $article, $user, $content, $summary, $isMinor, $isWatch, $section, $flags, $revision, $status, $baseRevId ) { + public static function onPageContentSaveComplete( + $article, + $user, + $content, + $summary, + $isMinor, + $isWatch, + $section, + $flags, + $revision, + $status, + $baseRevId + ) { $dbw = wfGetDB( DB_MASTER ); $dbr = wfGetDB( DB_SLAVE ); $pageId = $article->getId(); @@ -137,13 +151,12 @@ $cond = array( 'cn_page_id' => $pageId, 'cn_user_id' => $userId, 'cn_user_text' => $text ); $res = $dbr->select( - 'contributors', - 'cn_revision_count', - $cond, - __METHOD__ - ); - if ( $res->numRows() == 0 ) - { + 'contributors', + 'cn_revision_count', + $cond, + __METHOD__ + ); + if ( $res->numRows() == 0 ) { $dbw->insert( 'contributors', array( 'cn_page_id' => $pageId, @@ -154,9 +167,7 @@ ), __METHOD__ ); - } - else - { + } else { foreach ( $res as $row ) { $dbw->upsert( 'contributors', diff --git a/includes/ContributorsTablePager.php b/includes/ContributorsTablePager.php index 009504b..3b24c35 100644 --- a/includes/ContributorsTablePager.php +++ b/includes/ContributorsTablePager.php @@ -7,7 +7,13 @@ protected $articleId; protected $opts; - public function __construct( $articleId , $opts , $target , IContextSource $context = null, IDatabase $readDb = null ) { + public function __construct( + $articleId, + $opts, + $target, + IContextSource $context = null, + IDatabase $readDb = null + ) { if ( $readDb !== null ) { $this->mDb = $readDb; } @@ -16,7 +22,6 @@ $this->target = $target; $this->mDefaultDirection = true; parent::__construct( $context ); - } public function getFieldNames() { @@ -41,8 +46,8 @@ case 'cn_user_text': $formatted = - Linker::userLink( $row->cn_user_text , $row->cn_user_text ) . ' ' . - Linker::userToolLinks( $row->cn_user_text ,$row->cn_user_text ); + Linker::userLink( $row->cn_user_text, $row->cn_user_text ) . ' ' . + Linker::userToolLinks( $row->cn_user_text, $row->cn_user_text ); return $formatted; break; case 'cn_revision_count': @@ -50,7 +55,7 @@ return $formatted; break; case 'cn_first_edit': - $formatted = $lang->timeanddate( $row->cn_first_edit, true); + $formatted = $lang->timeanddate( $row->cn_first_edit, true ); return $formatted; break; case 'cn_last_edit': @@ -58,7 +63,6 @@ return $formatted; break; } - } public function getQueryInfo() { @@ -67,8 +71,7 @@ if ( $this->opts['filteranon'] == true ) { $conds = array( 'cn_page_id' => (int)$this->articleId , 'cn_user_id !=0' ); - } - elseif ( $this->opts['pagePrefix'] == true ) { + } elseif ( $this->opts['pagePrefix'] == true ) { $conds = [ 'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ) ]; } else { $conds = array( 'cn_page_id' => (int)$this->articleId ); diff --git a/includes/SpecialContributors.php b/includes/SpecialContributors.php index ca16d1b..902360c 100644 --- a/includes/SpecialContributors.php +++ b/includes/SpecialContributors.php @@ -89,7 +89,7 @@ $opts->add( 'target', '', FormOptions::STRING ); $opts->add( 'filteranon', false ); - $opts->add( 'pagePrefix' , false ); + $opts->add( 'pagePrefix', false ); $opts->add( 'action', 'view', FormOptions::STRING ); return $opts; @@ -155,7 +155,7 @@ ->rawParams( $link )->escaped() . '</h2>' ); $out = $this->getOutput(); - $pager = new ContributorsTablePager( $articleId , $opts , $target ); + $pager = new ContributorsTablePager( $articleId, $opts, $target ); $pager->doQuery(); $result = $pager->getResult(); if ( $result && $result->numRows() !== 0 ) { diff --git a/maintenance/PopulateContributorsTable.php b/maintenance/PopulateContributorsTable.php index f351590..6bb45a0 100644 --- a/maintenance/PopulateContributorsTable.php +++ b/maintenance/PopulateContributorsTable.php @@ -1,9 +1,9 @@ <?php -if (getenv('MW_INSTALL_PATH') !== false) { - require_once(getenv('MW_INSTALL_PATH') . '/maintenance/Maintenance.php'); +if ( getenv( 'MW_INSTALL_PATH' ) !== false ) { + require_once getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'; } else { - require_once(__DIR__ . '/../../../maintenance/Maintenance.php'); + require_once __DIR__ . '/../../../maintenance/Maintenance.php'; } /** @@ -44,11 +44,11 @@ ); $res = $dbr->select( 'revision', - array('COUNT(*) AS cn_revision_count', 'rev_user', 'rev_user_text', 'rev_page' , - 'MIN(rev_timestamp) AS cn_first_edit' , 'MAX(rev_timestamp) AS cn_last_edit' ), + array( 'COUNT(*) AS cn_revision_count', 'rev_user', 'rev_user_text', 'rev_page', + 'MIN(rev_timestamp) AS cn_first_edit', 'MAX(rev_timestamp) AS cn_last_edit' ), $cond, __METHOD__, - array( 'GROUP BY' => array( 'rev_page', 'rev_user','rev_user_text' ) ) + array( 'GROUP BY' => array( 'rev_page', 'rev_user', 'rev_user_text' ) ) ); $this->output( "Writing data into Contributors Table.. \n" ); diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..d4b2b99 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<ruleset> + <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"> + <exclude name="Generic.Arrays.DisallowLongArraySyntax.Found"/> + </rule> + <file>.</file> + <arg name="extensions" value="php,php5,inc"/> + <arg name="encoding" value="UTF-8"/> + <exclude-pattern>vendor</exclude-pattern> +</ruleset> -- To view, visit https://gerrit.wikimedia.org/r/305676 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Icdfd9fc0fbb580f328049d5d425197232cce2f71 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/Contributors Gerrit-Branch: master Gerrit-Owner: Devirk <devikrishna...@gmail.com> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: Niharika29 <nko...@wikimedia.org> Gerrit-Reviewer: Reedy <re...@wikimedia.org> Gerrit-Reviewer: Umherirrender <umherirrender_de...@web.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits