Siebrand has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/242341

Change subject: Add tests
......................................................................

Add tests

Fix all issues so tests pass.

Change-Id: I353593e72e219bf9a1e8591bce1e1c0e6c16824b
---
M .gitignore
D AllTimeZones.i18n.php
M AllTimeZones.php
A Gruntfile.js
A composer.json
A package.json
A phpcs.xml
7 files changed, 81 insertions(+), 63 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AllTimeZones 
refs/changes/41/242341/1

diff --git a/.gitignore b/.gitignore
index 98b092a..854a2d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
-.svn
 *~
 *.kate-swp
 .*.swp
+node_modules/
+/composer.lock
+/vendor/
diff --git a/AllTimeZones.i18n.php b/AllTimeZones.i18n.php
deleted file mode 100644
index 0bbb7c3..0000000
--- a/AllTimeZones.i18n.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * This is a backwards-compatibility shim, generated by:
- * 
https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php
- *
- * Beginning with MediaWiki 1.23, translation strings are stored in json files,
- * and the EXTENSION.i18n.php file only exists to provide compatibility with
- * older releases of MediaWiki. For more information about this migration, see:
- * https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format
- *
- * This shim maintains compatibility back to MediaWiki 1.17.
- */
-$messages = array();
-if ( !function_exists( 'wfJsonI18nShim925706569316083e' ) ) {
-       function wfJsonI18nShim925706569316083e( $cache, $code, &$cachedData ) {
-               $codeSequence = array_merge( array( $code ), 
$cachedData['fallbackSequence'] );
-               foreach ( $codeSequence as $csCode ) {
-                       $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json";
-                       if ( is_readable( $fileName ) ) {
-                               $data = FormatJson::decode( file_get_contents( 
$fileName ), true );
-                               foreach ( array_keys( $data ) as $key ) {
-                                       if ( $key === '' || $key[0] === '@' ) {
-                                               unset( $data[$key] );
-                                       }
-                               }
-                               $cachedData['messages'] = array_merge( $data, 
$cachedData['messages'] );
-                       }
-
-                       $cachedData['deps'][] = new FileDependency( $fileName );
-               }
-               return true;
-       }
-
-       $GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 
'wfJsonI18nShim925706569316083e';
-}
diff --git a/AllTimeZones.php b/AllTimeZones.php
index 516d7dc..09d6f32 100644
--- a/AllTimeZones.php
+++ b/AllTimeZones.php
@@ -14,49 +14,47 @@
  * Protect against register_globals vulnerabilities.
  * This line must be present before any global variable is referenced.
  */
-if( !defined( 'MEDIAWIKI' ) ) {
-       echo( "This is an extension to the MediaWiki package and cannot be run 
standalone.\n" );
+if ( !defined( 'MEDIAWIKI' ) ) {
+       echo "This is an extension to the MediaWiki package and cannot be run 
standalone.\n";
        die( -1 );
 }
 
 // Extension credits that will show up on Special:Version
 $wgExtensionCredits['parserhook'][] = array(
-       'path'           => __FILE__,
-       'name'           => 'AllTimeZones',
-       'version'        => '0.2.0',
-       'author'         => 'Nischay Nahata',
-       'url'            => 
'https://www.mediawiki.org/wiki/Extension:AllTimeZones',
+       'path' => __FILE__,
+       'name' => 'AllTimeZones',
+       'version' => '0.3.0',
+       'author' => 'Nischay Nahata',
+       'url' => 'https://www.mediawiki.org/wiki/Extension:AllTimeZones',
        'descriptionmsg' => 'alltimezones-desc',
 );
 
-$wgAllTimeZonesIP = dirname( __FILE__ ) . '/';
 $wgMessagesDirs['AllTimeZones'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['AllTimeZones'] = $wgAllTimeZonesIP . 
'AllTimeZones.i18n.php';
 
 $wgHooks['ParserFirstCallInit'][] = 'wfTimezoneSetup';
 
 function wfTimezoneSetup( Parser $parser ) {
        $parser->setHook( 'timezone', 'wfTimezone' );
+
        return true;
 }
 
 function wfTimezone( $input, array $args, Parser $parser, PPFrame $frame ) {
-
-       //time to convert (format specified below)
-       //$time = 'Tuesday, April 21, 2009 2:32:46 PM';
+       // time to convert (format specified below)
+       // $time = 'Tuesday, April 21, 2009 2:32:46 PM';
        $time = $args['time'];
 
-       //time zone provided by the user
+       // time zone provided by the user
        $inputTz = $args['zone'];
 
        // create the DateTimeZone object
-       $dtzone = new DateTimeZone($inputTz);
+       $dtzone = new DateTimeZone( $inputTz );
 
        // now create the DateTime object for this time and user time zone
-       $dtime = new DateTime($time, $dtzone);
+       $dtime = new DateTime( $time, $dtzone );
 
        // Get the timestamp
-       $timestamp = $dtime->format('U');
+       $timestamp = $dtime->format( 'U' );
 
        // create an array listing the time zones
        $timezones = array(
@@ -185,30 +183,31 @@
                'Pacific/Fiji' => '(GMT+12:00) Fiji',
                'Asia/Kamchatka' => '(GMT+12:00) Kamchatka',
                'Pacific/Auckland' => '(GMT+12:00) Auckland',
-               'Pacific/Tongatapu' => '(GMT+13:00) Nukualofa');
+               'Pacific/Tongatapu' => '(GMT+13:00) Nukualofa' );
 
        $html = Xml::openElement( 'select', array( 'name' => 'tz' ) );
 
-       foreach( $timezones as $tz => $tzDescription ){
+       foreach ( $timezones as $tz => $tzDescription ) {
                // create the DateTimeZone object
-               $dtzone = new DateTimeZone($tz);
+               $dtzone = new DateTimeZone( $tz );
 
                // first convert the timestamp into a string representing the 
local time
-               $time = date('r', $timestamp);
+               $time = date( 'r', $timestamp );
 
                // now create the DateTime object for this time
-               $dtime = new DateTime($time);
+               $dtime = new DateTime( $time );
 
                // convert this to the specific timezone using the DateTimeZone 
object
-               $dtime->setTimeZone($dtzone);
+               $dtime->setTimeZone( $dtzone );
 
                // print the time using your preferred format
                // TODO add new formats
-               $time = $dtime->format('g:i A m/d/y');
-               if($tz==$inputTz)
-                       $html .= Xml::option( $tz.' '.$time, $tzDescription, 
true );
-               else
-                       $html .= Xml::option( $tz.' '.$time, $tzDescription, 
false );
+               $time = $dtime->format( 'g:i A m/d/y' );
+               if ( $tz == $inputTz ) {
+                       $html .= Xml::option( $tz . ' ' . $time, 
$tzDescription, true );
+               } else {
+                       $html .= Xml::option( $tz . ' ' . $time, 
$tzDescription, false );
+               }
        }
 
        $html .= Xml::closeElement( 'select' );
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000..9c56558
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,20 @@
+/*jshint node:true */
+module.exports = function ( grunt ) {
+       grunt.loadNpmTasks( 'grunt-banana-checker' );
+       grunt.loadNpmTasks( 'grunt-jsonlint' );
+
+       grunt.initConfig( {
+               banana: {
+                       all: 'i18n/'
+               },
+               jsonlint: {
+                       all: [
+                               '**/*.json',
+                               '!node_modules/**'
+                       ]
+               }
+       } );
+
+       grunt.registerTask( 'test', [ 'jsonlint', 'banana' ] );
+       grunt.registerTask( 'default', 'test' );
+};
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..4365e8a
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,12 @@
+{
+       "require-dev": {
+               "jakub-onderka/php-parallel-lint": "0.9",
+               "mediawiki/mediawiki-codesniffer": "0.4.0"
+       },
+       "scripts": {
+               "test": [
+                       "parallel-lint . --exclude vendor",
+                       "phpcs -p -s"
+               ]
+       }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..76e8a82
--- /dev/null
+++ b/package.json
@@ -0,0 +1,12 @@
+{
+  "private": true,
+  "scripts": {
+    "test": "grunt test"
+  },
+  "devDependencies": {
+    "grunt": "0.4.5",
+    "grunt-cli": "0.1.13",
+    "grunt-banana-checker": "0.2.2",
+    "grunt-jsonlint": "1.0.4"
+  }
+}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..d81a292
--- /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>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I353593e72e219bf9a1e8591bce1e1c0e6c16824b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AllTimeZones
Gerrit-Branch: master
Gerrit-Owner: Siebrand <siebr...@kitano.nl>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to