Merge "Remove unnecesary else blocks"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 24 Sep 2018 16:37:55 +0000 (16:37 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 24 Sep 2018 16:37:55 +0000 (16:37 +0000)
includes/specials/SpecialLog.php
maintenance/resources/foreign-resources.yaml
tests/phpunit/includes/Storage/RevisionStoreDbTestBase.php
tests/phpunit/includes/specials/SpecialLogTest.php [new file with mode: 0644]

index d700c39..54afde1 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup SpecialPage
  */
 
+use Wikimedia\Timestamp\TimestampException;
+
 /**
  * A special page that lists log entries
  *
@@ -63,10 +65,18 @@ class SpecialLog extends SpecialPage {
                // Set date values
                $dateString = $this->getRequest()->getVal( 'wpdate' );
                if ( !empty( $dateString ) ) {
-                       $dateStamp = MWTimestamp::getInstance( $dateString . ' 00:00:00' );
-                       $opts->setValue( 'year', (int)$dateStamp->format( 'Y' ) );
-                       $opts->setValue( 'month', (int)$dateStamp->format( 'm' ) );
-                       $opts->setValue( 'day', (int)$dateStamp->format( 'd' ) );
+                       try {
+                               $dateStamp = MWTimestamp::getInstance( $dateString . ' 00:00:00' );
+                       } catch ( TimestampException $e ) {
+                               // If users provide an invalid date, silently ignore it
+                               // instead of letting an exception bubble up (T201411)
+                               $dateStamp = false;
+                       }
+                       if ( $dateStamp ) {
+                               $opts->setValue( 'year', (int)$dateStamp->format( 'Y' ) );
+                               $opts->setValue( 'month', (int)$dateStamp->format( 'm' ) );
+                               $opts->setValue( 'day', (int)$dateStamp->format( 'd' ) );
+                       }
                }
 
                # Don't let the user get stuck with a certain date
index 1070d71..ae45ab8 100644 (file)
@@ -67,6 +67,11 @@ jquery:
   integrity: sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=
   dest: jquery.js
 
+jquery.cookie:
+  type: file
+  src: https://raw.githubusercontent.com/carhartl/jquery-cookie/v1.3.1/jquery.cookie.js
+  integrity: sha384-Xxq63E9KDgzUJ6WPNPqVeOtRIwZyx6y9DzEwY2u6LYKSnWrjSoGtWSKmTindYBf2
+
 mustache:
   type: multi-file
   files:
index 910cdc4..5497d98 100644 (file)
@@ -65,10 +65,6 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
         */
        abstract protected function getMcrTablesToReset();
 
-       public function needsDB() {
-               return true;
-       }
-
        public function setUp() {
                parent::setUp();
                $this->tablesUsed[] = 'archive';
diff --git a/tests/phpunit/includes/specials/SpecialLogTest.php b/tests/phpunit/includes/specials/SpecialLogTest.php
new file mode 100644 (file)
index 0000000..d66280e
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+/**
+ * @license GPL-2.0-or-later
+ * @author Legoktm
+ */
+
+/**
+ * @covers SpecialLog
+ */
+class SpecialLogTest extends SpecialPageTestBase {
+
+       /**
+        * Returns a new instance of the special page under test.
+        *
+        * @return SpecialPage
+        */
+       protected function newSpecialPage() {
+               return new SpecialLog();
+       }
+
+       /**
+        * Verify that no exception was thrown for an invalid date
+        * @see T201411
+        */
+       public function testInvalidDate() {
+               list( $html, ) = $this->executeSpecialPage(
+                       '',
+                       // There is no 13th month
+                       new FauxRequest( [ 'wpdate' => '2018-13-01' ] ),
+                       'qqx'
+               );
+               $this->assertContains( '(log-summary)', $html );
+       }
+
+}