From ef66daf320b086de3a1413bfebf5256da55cbe52 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Mon, 9 Mar 2009 23:51:58 +0000 Subject: [PATCH] Surround dynamic dates with a . Bug 17785. --- RELEASE-NOTES | 2 ++ includes/parser/DateFormatter.php | 31 ++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2b69d16677..50efcf495b 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -136,6 +136,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN name of the last user to edit the page * LinkerMakeExternalLink now has an $attribs parameter for link attributes and a $linkType parameter for the type of external link being made +* (bug 17785) Dynamic dates surrounded with a tag, fixing sortable tables with + dynamic dates. === Bug fixes in 1.15 === * (bug 16968) Special:Upload no longer throws useless warnings. diff --git a/includes/parser/DateFormatter.php b/includes/parser/DateFormatter.php index a699ef7098..814c9ac2b6 100644 --- a/includes/parser/DateFormatter.php +++ b/includes/parser/DateFormatter.php @@ -155,12 +155,22 @@ class DateFormatter $bits[$key{$p}] = $matches[$p+1]; } } - + + return $this->formatDate( $bits ); + } + + function formatDate( $bits ) { $format = $this->targets[$this->mTarget]; # Construct new date $text = ''; $fail = false; + + // Pre-generate y/Y stuff because we need the year for the title. + if ( !isset( $bits['y'] ) ) + $bits['y'] = $this->makeIsoYear( $bits['Y'] ); + if ( !isset( $bits['Y'] ) ) + $bits['Y'] = $this->makeNormalYear( $bits['y'] ); for ( $p=0; $p < strlen( $format ); $p++ ) { $char = $format{$p}; @@ -185,11 +195,7 @@ class DateFormatter } break; case 'y': # ISO year - if ( !isset( $bits['y'] ) ) { - $text .= $this->makeIsoYear( $bits['Y'] ); - } else { - $text .= $bits['y']; - } + $text .= $bits['y']; break; case 'j': # ordinary day of month if ( !isset($bits['j']) ) { @@ -212,11 +218,7 @@ class DateFormatter } break; case 'Y': # ordinary (optional BC) year - if ( !isset( $bits['Y'] ) ) { - $text .= $this->makeNormalYear( $bits['y'] ); - } else { - $text .= $bits['Y']; - } + $text .= $bits['Y']; break; default: $text .= $char; @@ -225,6 +227,13 @@ class DateFormatter if ( $fail ) { $text = $matches[0]; } + + $isoDate = $bits['y'].$bits['m'].$bits['d']; + + // Output is not strictly HTML (it's wikitext), but is whitelisted. + $text = Xml::tags( 'span', + array( 'class' => 'mw-formatted-date', 'title' => $isoDate ), $text ); + return $text; } -- 2.20.1