* @ingroup SpecialPage
*/
+use Wikimedia\Timestamp\TimestampException;
+
/**
* A special page that lists log entries
*
// 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
--- /dev/null
+<?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 );
+ }
+
+}