Samwilson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/387075 )
Change subject: Add phpcs and fix up some coding standards and HTML generation ...................................................................... Add phpcs and fix up some coding standards and HTML generation Bug: T179245 Change-Id: Ie3a62fe21420bb1a3aab5552aee1792bd4e4737e --- M .gitignore A .phpcs.xml A composer.json M extension.json R includes/RandomFeaturedUser.php 5 files changed, 55 insertions(+), 19 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/RandomFeaturedUser refs/changes/75/387075/1 diff --git a/.gitignore b/.gitignore index a30a7d4..dd69b6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ /node_modules/ +/vendor/ .svn *~ *.kate-swp .*.swp +/composer.lock diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..95b1ff2 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,8 @@ +<?xml version="1.0"?> +<ruleset> + <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki" /> + <file>.</file> + <arg name="extensions" value="php,php5,inc" /> + <arg name="encoding" value="utf8" /> + <exclude-pattern>vendor</exclude-pattern> +</ruleset> diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..40246f4 --- /dev/null +++ b/composer.json @@ -0,0 +1,14 @@ +{ + "require-dev": { + "jakub-onderka/php-parallel-lint": "0.9.2", + "mediawiki/mediawiki-codesniffer": "14.1.0", + "jakub-onderka/php-console-highlighter": "0.3.2" + }, + "scripts": { + "fix": "phpcbf", + "test": [ + "parallel-lint . --exclude vendor", + "phpcs -p -s" + ] + } +} diff --git a/extension.json b/extension.json index 9b859a8..a9249b4 100644 --- a/extension.json +++ b/extension.json @@ -22,7 +22,7 @@ ] }, "AutoloadClasses": { - "RandomFeaturedUser": "includes/RandomFeaturedUser.class.php" + "RandomFeaturedUser": "includes/RandomFeaturedUser.php" }, "Hooks": { "ParserFirstCallInit": "RandomFeaturedUser::onParserFirstCallInit" diff --git a/includes/RandomFeaturedUser.class.php b/includes/RandomFeaturedUser.php similarity index 79% rename from includes/RandomFeaturedUser.class.php rename to includes/RandomFeaturedUser.php index 317d71c..ae03bad 100644 --- a/includes/RandomFeaturedUser.class.php +++ b/includes/RandomFeaturedUser.php @@ -25,15 +25,21 @@ /** * Set up the <randomfeatureduser> tag * - * @param Parser $parser + * @param Parser &$parser The parser. * @return bool */ public static function onParserFirstCallInit( &$parser ) { - $parser->setHook( 'randomfeatureduser', array( __CLASS__, 'getRandomUser' ) ); + $parser->setHook( 'randomfeatureduser', [ __CLASS__, 'getRandomUser' ] ); return true; } - public static function getRandomUser( $input, $args, $parser ) { + /** + * @param string $input The contents of the randomfeatureduser tag. + * @param string[] $args The arguments to the randomfeatureduser tag. + * @param Parser $parser The parser. + * @return string + */ + public static function getRandomUser( $input, $args, Parser $parser ) { global $wgMemc, $wgRandomFeaturedUser; $parser->disableCache(); @@ -46,7 +52,7 @@ // Add CSS $parser->getOutput()->addModuleStyles( 'ext.RandomFeaturedUser.css' ); - $user_list = array(); + $user_list = []; $count = 20; $realCount = 10; @@ -63,24 +69,24 @@ $dbr = wfGetDB( DB_REPLICA ); $res = $dbr->select( 'user_points_' . $period, - array( 'up_user_id', 'up_user_name', 'up_points' ), - array( 'up_user_id <> 0' ), + [ 'up_user_id', 'up_user_name', 'up_points' ], + [ 'up_user_id <> 0' ], __METHOD__, - array( + [ 'ORDER BY' => 'up_points DESC', 'LIMIT' => $count - ) + ] ); $loop = 0; foreach ( $res as $row ) { // Prevent blocked users from appearing $user = User::newFromId( $row->up_user_id ); if ( !$user->isBlocked() ) { - $user_list[] = array( + $user_list[] = [ 'user_id' => $row->up_user_id, 'user_name' => $row->up_user_name, 'points' => $row->up_points - ); + ]; $loop++; } if ( $loop >= 10 ) { @@ -118,13 +124,19 @@ $avatar = new wAvatar( $random_user['user_id'], 'ml' ); $avatarImage = $avatar->getAvatarURL(); - $output .= "<a href=\"" . htmlspecialchars( $user_title->getFullURL() ) . "\">{$avatarImage}</a>\n"; + $output .= Html::element( + 'a', + [ 'href' => $user_title->getFullURL() ], + $avatarImage + ); } - $output .= "<div class=\"random-featured-user-title\"> - <a href=\"" . htmlspecialchars( $user_title->getFullURL() ) . "\">" . - wordwrap( $random_user['user_name'], 12, "<br />\n", true ) . - "</a><br /> " . + $link = Html::element( + 'a', + [ 'href' => $user_title->getFullURL() ], + wordwrap( $random_user['user_name'], 12, "<br />\n", true ) + ); + $output .= "<div class=\"random-featured-user-title\">$link<br /> " . wfMessage( "random-user-points-{$period}", $points )->text() . "</div>\n\n"; @@ -136,10 +148,10 @@ // Remove templates $about = preg_replace( '@{{.*?}}@si', '', $about ); if ( !empty( $about ) ) { - global $wgTitle, $wgOut; + global $wgOut; $output .= '<div class="random-featured-user-about-title">' . wfMessage( 'random-user-about-me' )->text() . '</div>' . - $p->parse( $about, $wgTitle, $wgOut->parserOptions(), false )->getText(); + $p->parse( $about, $parser->getTitle(), $wgOut->parserOptions(), false )->getText(); } } @@ -148,4 +160,4 @@ return $output; } -} \ No newline at end of file +} -- To view, visit https://gerrit.wikimedia.org/r/387075 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie3a62fe21420bb1a3aab5552aee1792bd4e4737e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/RandomFeaturedUser Gerrit-Branch: master Gerrit-Owner: Samwilson <s...@samwilson.id.au> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits