jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/380988 )
Change subject: Add composer/phpcs and fix some sniff violations ...................................................................... Add composer/phpcs and fix some sniff violations Bug: T176878 Change-Id: Ib29e3cedf2ebd9bdb65c288b9cb8806e02e46d5e --- A .gitignore M ArticleRatings.alias.php M ArticleRatingsHooks.php M RatingDataClass.php M SpecialChangeRating.php M SpecialMassRatings.php A composer.json A phpcs.xml 8 files changed, 102 insertions(+), 57 deletions(-) Approvals: SamanthaNguyen: Looks good to me, approved jenkins-bot: Verified diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8cbff68 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.kate-swp +*~ +.*.swp +.svn +/node_modules/ +/vendor/ +composer.lock diff --git a/ArticleRatings.alias.php b/ArticleRatings.alias.php index 969d3c1..461d7e2 100644 --- a/ArticleRatings.alias.php +++ b/ArticleRatings.alias.php @@ -6,10 +6,10 @@ * @ingroup Extensions */ -$specialPageAliases = array(); +$specialPageAliases = []; /** English */ -$specialPageAliases['en'] = array( - 'ChangeRating' => array( 'ChangeRating' ), - 'MassRatings' => array( 'MassRatings' ), -); +$specialPageAliases['en'] = [ + 'ChangeRating' => [ 'ChangeRating' ], + 'MassRatings' => [ 'MassRatings' ], +]; diff --git a/ArticleRatingsHooks.php b/ArticleRatingsHooks.php index 3f52157..eb177e6 100644 --- a/ArticleRatingsHooks.php +++ b/ArticleRatingsHooks.php @@ -17,7 +17,7 @@ * @return bool */ public static function onParserFirstCallInit( Parser $parser ) { - $parser->setHook( 'rating', array( __CLASS__, 'renderRating' ) ); + $parser->setHook( 'rating', [ __CLASS__, 'renderRating' ] ); return true; } @@ -73,10 +73,10 @@ $field = $dbr->selectField( 'ratings', 'ratings_rating', - array( + [ 'ratings_title' => $title->getDBkey(), 'ratings_namespace' => $title->getNamespace(), - ), + ], __METHOD__ ); @@ -89,7 +89,8 @@ if ( isset( $args['initial-rating'] ) ) { foreach ( $ratings as $rating ) { - if ( $args['initial-rating'] == $rating->getCodename() ) { // check if the rating actually exists + // check if the rating actually exists + if ( $args['initial-rating'] == $rating->getCodename() ) { $useRating = $rating; } } @@ -99,11 +100,11 @@ $dbw->insert( 'ratings', - array( + [ 'ratings_rating' => $useRating->getCodename(), 'ratings_title' => $title->getDBkey(), 'ratings_namespace' => $title->getNamespace() - ), + ], __METHOD__ ); } @@ -124,14 +125,14 @@ $res = $dbw->update( 'ratings', - array( + [ 'ratings_title' => $newTitle->getDBkey(), 'ratings_namespace' => $newTitle->getNamespace() - ), - array( + ], + [ 'ratings_title' => $title->getDBkey(), 'ratings_namespace' => $title->getNamespace() - ), + ], __METHOD__ ); @@ -146,18 +147,19 @@ $res = $dbr->select( 'ratings', 'ratings_rating', - array( + [ 'ratings_title' => $title->getDBkey(), 'ratings_namespace' => $title->getNamespace() - ), + ], __METHOD__ ); if ( $res && $res->numRows() ) { - $toolbox['rating'] = array( + $toolbox['rating'] = [ 'text' => $skin->getSkin()->msg( 'are-change-rating' )->text(), - 'href' => SpecialPage::getTitleFor( 'ChangeRating', $title->getFullText() )->getFullURL() - ); + 'href' => SpecialPage::getTitleFor( 'ChangeRating', $title->getFullText() ) + ->getFullURL() + ]; } } @@ -168,24 +170,27 @@ * Hook to remove the ratings DB entry when a page is deleted. * While not actually needed for pages, prevents deleted pages appearing on MassRaitings - * @param WikiPage $article - * @param User $user + * @param WikiPage &$article + * @param User &$user * @param string $reason * @param int $id * @param unknown $content * @param unknown $logEntry + * @return bool */ - public static function onArticleDeleteComplete( WikiPage &$article, User &$user, $reason, $id, $content, $logEntry ) { + public static function onArticleDeleteComplete( + WikiPage &$article, User &$user, $reason, $id, $content, $logEntry + ) { $title = $article->getTitle(); $dbw = wfGetDB( DB_MASTER ); $res = $dbw->delete( 'ratings', - array( + [ 'ratings_title' => $title->getDBkey(), 'ratings_namespace' => $title->getNamespace() - ), + ], __METHOD__ ); @@ -201,7 +206,7 @@ */ public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) { $file = __DIR__ . '/ratings.sql'; - $updater->addExtensionUpdate( array( 'addTable', 'ratings', $file, true ) ); + $updater->addExtensionUpdate( [ 'addTable', 'ratings', $file, true ] ); return true; } } diff --git a/RatingDataClass.php b/RatingDataClass.php index 18e770a..e056b4e 100644 --- a/RatingDataClass.php +++ b/RatingDataClass.php @@ -12,7 +12,7 @@ public static function getAllRatings() { $JSON = self::getJSON(); - $returners = array(); + $returners = []; foreach ( $JSON as $data ) { $returners[] = new Rating( $data['codename'] ); @@ -30,7 +30,7 @@ class Rating { protected $codename; - protected $data = array(); + protected $data = []; public function __construct( $codename ) { if ( empty( $codename ) ) { @@ -45,7 +45,7 @@ return; } } - //trigger_error( 'No rating found for the codename ' . $this->codename ); + // trigger_error( 'No rating found for the codename ' . $this->codename ); } public function getCodename() { @@ -70,12 +70,12 @@ return ''; } $image = $file->getCanonicalUrl(); - $pic = Html::element( 'img', array( + $pic = Html::element( 'img', [ 'class' => 'mw-rating-img', 'src' => $image, 'height' => '20px', 'width' => '20px' - ) ) . wfMessage( 'word-separator' )->parse(); + ] ) . wfMessage( 'word-separator' )->parse(); return $pic; } @@ -84,8 +84,9 @@ global $wgArticlePath; $url = str_replace( '$1', $this->getLink(), $wgArticlePath ); - $label = '<a class="mw-rating-about-link" href="' . $url . '" target="_blank">' . $this->getName() . '</a>'; + $label = '<a class="mw-rating-about-link" href="' . $url . '" target="_blank">' + . $this->getName() . '</a>'; return $label; } -} \ No newline at end of file +} diff --git a/SpecialChangeRating.php b/SpecialChangeRating.php index 39d3fb3..04dced5 100644 --- a/SpecialChangeRating.php +++ b/SpecialChangeRating.php @@ -38,10 +38,10 @@ $res = $dbr->selectField( 'ratings', 'ratings_rating', - array( + [ 'ratings_title' => $title->getDBkey(), 'ratings_namespace' => $title->getNamespace() - ), + ], __METHOD__ ); $oldrating = new Rating( $res ); @@ -50,11 +50,11 @@ $res = $dbw->update( 'ratings', - array( 'ratings_rating' => $ratingto ), - array( + [ 'ratings_rating' => $ratingto ], + [ 'ratings_title' => $title->getDBkey(), 'ratings_namespace' => $title->getNamespace() - ), + ], __METHOD__ ); @@ -66,10 +66,10 @@ $logEntry = new ManualLogEntry( 'ratings', 'change' ); $logEntry->setPerformer( $this->getUser() ); $logEntry->setTarget( $title ); - $logEntry->setParameters( array( + $logEntry->setParameters( [ '4::newrating' => $rating->getName(), '5::oldrating' => $oldrating->getName() - ) ); + ] ); if ( !is_null( $reason ) ) { $logEntry->setComment( $reason ); } @@ -78,15 +78,16 @@ $logEntry->publish( $logId ); } - $output = $this->msg( 'changerating-intro-text', $title->getFullText() )->parseAsBlock() . '<form name="change-rating" action="" method="get">'; + $output = $this->msg( 'changerating-intro-text', $title->getFullText() )->parseAsBlock() + . '<form name="change-rating" action="" method="get">'; $currentRating = $dbr->selectField( 'ratings', 'ratings_rating', - array( + [ 'ratings_title' => $title->getDBkey(), 'ratings_namespace' => $title->getNamespace() - ), + ], __METHOD__ ); @@ -94,9 +95,9 @@ foreach ( $ratings as $rating ) { if ( $rating->getCodename() == $currentRating ) { - $attribs = array( 'checked' => 'checked' ); + $attribs = [ 'checked' => 'checked' ]; } else { - $attribs = array(); + $attribs = []; } $output .= Html::input( 'ratingTo', $rating->getCodename(), 'radio', $attribs ); @@ -131,4 +132,4 @@ $out->addHTML( $output ); } } -} \ No newline at end of file +} diff --git a/SpecialMassRatings.php b/SpecialMassRatings.php index f191176..f4fa458 100644 --- a/SpecialMassRatings.php +++ b/SpecialMassRatings.php @@ -6,8 +6,8 @@ } function getQueryInfo() { - $where = array(); - $selectedRatings = array(); + $where = []; + $selectedRatings = []; $ratings = RatingData::getAllRatings(); @@ -18,22 +18,22 @@ } if ( $selectedRatings ) { - $where = array( 'ratings_rating' => $selectedRatings ); + $where = [ 'ratings_rating' => $selectedRatings ]; } - return array( + return [ 'tables' => 'ratings', - 'fields' => array( + 'fields' => [ 'namespace' => 'ratings_namespace', 'title' => 'ratings_title', 'value' => 'ratings_rating' - ), + ], 'conds' => $where - ); + ]; } function getOrderFields() { - return array( 'ratings_title' ); + return [ 'ratings_title' ]; } function sortDescending() { @@ -52,9 +52,9 @@ $label = $rating->getAboutLink(); $pic = $rating->getImage(); - $attribs = array(); + $attribs = []; if ( $this->getRequest()->getVal( $rating->getCodename() ) == 'true' ) { - $attribs = array( 'checked' => 'checked' ); + $attribs = [ 'checked' => 'checked' ]; } $input = Html::input( $rating->getCodename(), 'true', 'checkbox', $attribs ); @@ -88,9 +88,10 @@ * Ensure rating paramters in URL are passed if the user does a "next 500" or whatever * * @see QueryPage::linkParameters() + * @return array */ function linkParameters() { - $params = array(); + $params = []; $ratings = RatingData::getAllRatings(); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..ac291c0 --- /dev/null +++ b/composer.json @@ -0,0 +1,14 @@ +{ + "require-dev": { + "jakub-onderka/php-console-highlighter": "0.3.2", + "jakub-onderka/php-parallel-lint": "0.9.2", + "mediawiki/mediawiki-codesniffer": "13.0.0" + }, + "scripts": { + "test": [ + "parallel-lint . --exclude vendor --exclude node_modules", + "phpcs -p -s" + ], + "fix": "phpcbf" + } +} diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..9c93f17 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<ruleset> + <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"> + <exclude name="MediaWiki.Files.ClassMatchesFilename.NotMatch" /> + <exclude name="MediaWiki.Files.OneClassPerFile.MultipleFound" /> + <exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" /> + <exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic" /> + <exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationProtected" /> + <exclude name="MediaWiki.Commenting.FunctionComment.MissingParamComment" /> + <exclude name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment" /> + </rule> + <file>.</file> + <arg name="bootstrap" value="./vendor/mediawiki/mediawiki-codesniffer/utils/bootstrap-ci.php"/> + <arg name="extensions" value="php,php5,inc"/> + <arg name="encoding" value="UTF-8"/> +</ruleset> -- To view, visit https://gerrit.wikimedia.org/r/380988 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib29e3cedf2ebd9bdb65c288b9cb8806e02e46d5e Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/ArticleRatings Gerrit-Branch: master Gerrit-Owner: MarcoAurelio <maure...@tools.wmflabs.org> Gerrit-Reviewer: SamanthaNguyen <samanthanguyen1...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits