MediaWiki r1425 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r1424‎ | r1425 (on ViewVC)‎ | r1426 >
Date:13:52, 3 July 2003
Author:timstarling
Status:old
Tags:
Comment:
Misc. dynamic date fixes and improvements
Modified paths:

Diff [purge]

Index: trunk/phase3/languages/Language.php
@@ -25,7 +25,8 @@
2626 "contextlines" => 5, "contextchars" => 50,
2727 "skin" => 0, "math" => 1, "rcdays" => 7, "rclimit" => 50,
2828 "highlightbroken" => 1, "stubthreshold" => 0,
29 - "previewontop" => 1, "editsection"=>1, "showtoc"=>1
 29+ "previewontop" => 1, "editsection"=>1, "showtoc"=>1,
 30+ "date" => 0
3031 );
3132
3233 /* private */ $wgQuickbarSettingsEn = array(
@@ -1225,8 +1226,8 @@
12261227
12271228 if ( $adj ) { $ts = $this->userAdjust( $ts ); }
12281229
1229 - $datePreference = $wgUser->getOption('date');
1230 - if ( $datePrefernce == 0 ) {
 1230+ $datePreference = $wgUser->getOption( 'date' );
 1231+ if ( $datePreference == 0 ) {
12311232 $datePreference = $wgAmericanDates ? 1 : 2;
12321233 }
12331234
@@ -1259,7 +1260,7 @@
12601261
12611262 function timeanddate( $ts, $adj = false )
12621263 {
1263 - return $this->time( $ts, $adj ) . " " . $this->date( $ts, $adj );
 1264+ return $this->time( $ts, $adj ) . ", " . $this->date( $ts, $adj );
12641265 }
12651266
12661267 function rfc1123( $ts )
@@ -1370,55 +1371,69 @@
13711372
13721373 function replaceDates( $text )
13731374 {
1374 - global $wgUser;
 1375+ global $wgUser, $wgInputEncoding;
13751376
13761377 # Setup
13771378
1378 - $datePreference = $wgUser->getOption('date');
 1379+ $datePreference = $wgUser->getOption( 'date' );
 1380+
13791381 static $monthNames = "", $rxDM, $rxMD, $rxY, $rxDMY, $rxYMD, $rxMDY, $rxYMD;
13801382 if ( $monthNames == "" ) {
13811383 $monthNames = $this->getMonthRegex();
1382 - $rxDM = '\[\[(\d{1,2})[ _](' . $monthNames . ')]](?![a-z])';
1383 - $rxMD = '\[\[(' . $monthNames . ')[ _](\d{1,2})]](?![a-z])';
1384 - $rxY = '\[\[(\d{1,4}([ _]BC|))]](?![a-z])';
13851384
1386 - $rxDMY = "/{$rxDM} *, *{$rxY}/i";
1387 - $rxYDM = "/{$rxY} *, *{$rxDM}/i";
1388 - $rxMDY = "/{$rxMD} *, *{$rxY}/i";
1389 - $rxYMD = "/{$rxY} *, *{$rxMD}/i";
 1385+ # Attempt at UTF-8 support, untested at the moment
 1386+ if ( $wgInputEncoding == 'UTF-8' ) {
 1387+ $regexTrail = '(?![a-z])/iu';
 1388+ } else {
 1389+ $regexTrail = '(?![a-z])/i';
 1390+ }
 1391+
 1392+ # Partial regular expressions
 1393+ $prxDM = '\[\[(\d{1,2})[ _](' . $monthNames . ')]]';
 1394+ $prxMD = '\[\[(' . $monthNames . ')[ _](\d{1,2})]]';
 1395+ $prxY = '\[\[(\d{1,4}([ _]BC|))]]';
 1396+
 1397+ # Real regular expressions
 1398+ $rxDMY = "/{$prxDM} *,? *{$prxY}{$regexTrail}";
 1399+ $rxYDM = "/{$prxY} *,? *{$prxDM}{$regexTrail}";
 1400+ $rxMDY = "/{$prxMD} *,? *{$prxY}{$regexTrail}";
 1401+ $rxYMD = "/{$prxY} *,? *{$prxMD}{$regexTrail}";
 1402+ $rxDM = "/{$prxDM}{$regexTrail}";
 1403+ $rxMD = "/{$prxMD}{$regexTrail}";
 1404+ $rxY = "/{$prxY}{$regexTrail}";
13901405 }
13911406
13921407 # Do replacements
13931408 # TODO: month capitalisation?
13941409 if ( $datePreference == 0 ) {
13951410 # no preference
1396 - $text = preg_replace( $rxDMY, '[[$2 $1|$1 $2]], [[$3]]', $text);
 1411+ $text = preg_replace( $rxDMY, '[[$2 $1|$1 $2]] [[$3]]', $text);
13971412 $text = preg_replace( $rxYDM, '[[$1]] [[$4 $3]]', $text);
13981413 $text = preg_replace( $rxMDY, '[[$1 $2]], [[$3]]', $text);
13991414 $text = preg_replace( $rxYMD, '[[$1]] [[$3 $4]]', $text);
1400 - $text = preg_replace ( "/$rxDM/i", '[[$2 $1|$1 $2]]', $text);
 1415+ $text = preg_replace ( $rxDM, '[[$2 $1|$1 $2]]', $text);
14011416 } else if ( $datePreference == 1 ) {
14021417 # MDY preferred
14031418 $text = preg_replace( $rxDMY, '[[$2 $1]], [[$3]]', $text);
14041419 $text = preg_replace( $rxYDM, '[[$4 $3]], [[$1]]', $text);
14051420 $text = preg_replace( $rxMDY, '[[$1 $2]], [[$3]]', $text);
14061421 $text = preg_replace( $rxYMD, '[[$3 $4]], [[$1]]', $text);
1407 - $text = preg_replace ( "/$rxDM/i", '[[$2 $1]]', $text);
 1422+ $text = preg_replace ( $rxDM, '[[$2 $1]]', $text);
14081423 } else if ( $datePreference == 2 ) {
14091424 # DMY preferred
1410 - $text = preg_replace( $rxDMY, '[[$2 $1|$1 $2]], [[$3]]', $text);
1411 - $text = preg_replace( $rxYDM, '[[$4 $3|$3 $4]], [[$1]]', $text);
1412 - $text = preg_replace( $rxMDY, '[[$1 $2|$2 $1]], [[$3]]', $text);
1413 - $text = preg_replace( $rxYMD, '[[$3 $4|$4 $3]], [[$1]]', $text);
1414 - $text = preg_replace ( "/$rxDM/i", '[[$2 $1|$1 $2]]', $text);
1415 - $text = preg_replace ( "/$rxMD/i", '[[$1 $2|$2 $1]]', $text);
 1425+ $text = preg_replace( $rxDMY, '[[$2 $1|$1 $2]] [[$3]]', $text);
 1426+ $text = preg_replace( $rxYDM, '[[$4 $3|$3 $4]] [[$1]]', $text);
 1427+ $text = preg_replace( $rxMDY, '[[$1 $2|$2 $1]] [[$3]]', $text);
 1428+ $text = preg_replace( $rxYMD, '[[$3 $4|$4 $3]] [[$1]]', $text);
 1429+ $text = preg_replace ( $rxDM, '[[$2 $1|$1 $2]]', $text);
 1430+ $text = preg_replace ( $rxMD, '[[$1 $2|$2 $1]]', $text);
14161431 } else if ( $datePreference == 3 ) {
14171432 # YMD preferred
14181433 $text = preg_replace( $rxDMY, '[[$3]] [[$2 $1]]', $text);
14191434 $text = preg_replace( $rxYDM, '[[$1]] [[$4 $3]]', $text);
14201435 $text = preg_replace( $rxMDY, '[[$3]] [[$1 $2]]', $text);
14211436 $text = preg_replace( $rxYMD, '[[$1]] [[$3 $4]]', $text);
1422 - $text = preg_replace ( "/$rxDM/i", '[[$2 $1]]', $text);
 1437+ $text = preg_replace ( $rxDM, '[[$2 $1]]', $text);
14231438 }
14241439 return $text;
14251440 }

Status & tagging log

  • 21:41, 11 October 2010 Reedy (Talk | contribs) changed the status of r1425 [removed: new added: old]
Personal tools
Namespaces

Variants
Views
Actions
Navigation
Support
Download
Development
Communication
Toolbox