dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Make most of DateFormatter private
[lhc/web/wiklou.git]
/
includes
/
parser
/
DateFormatter.php
diff --git
a/includes/parser/DateFormatter.php
b/includes/parser/DateFormatter.php
index
edb9ff1
..
08e3c77
100644
(file)
--- a/
includes/parser/DateFormatter.php
+++ b/
includes/parser/DateFormatter.php
@@
-27,13
+27,19
@@
* @ingroup Parser
*/
class DateFormatter {
* @ingroup Parser
*/
class DateFormatter {
- p
ublic
$mSource, $mTarget;
- p
ublic $monthNames = '', $rxDM, $rxMD, $rxDMY, $rxYDM, $rxMDY, $rxYMD
;
+ p
rivate
$mSource, $mTarget;
+ p
rivate $monthNames = ''
;
- p
ublic $regexes, $pDays, $pMonths, $pYear
s;
- p
ublic
$rules, $xMonths, $preferences;
+ p
rivate $regexe
s;
+ p
rivate
$rules, $xMonths, $preferences;
- protected $lang, $mLinked;
+ private $lang, $mLinked;
+
+ /** @var string[] */
+ private $keys;
+
+ /** @var string[] */
+ private $targets;
const ALL = -1;
const NONE = 0;
const ALL = -1;
const NONE = 0;
@@
-108,13
+114,13
@@
class DateFormatter {
$this->rules[self::ALL][self::DM] = self::DM;
$this->rules[self::NONE][self::ISO2] = self::ISO1;
$this->rules[self::ALL][self::DM] = self::DM;
$this->rules[self::NONE][self::ISO2] = self::ISO1;
- $this->preferences =
array(
+ $this->preferences =
[
'default' => self::NONE,
'dmy' => self::DMY,
'mdy' => self::MDY,
'ymd' => self::YMD,
'ISO 8601' => self::ISO1,
'default' => self::NONE,
'dmy' => self::DMY,
'mdy' => self::MDY,
'ymd' => self::YMD,
'ISO 8601' => self::ISO1,
-
)
;
+
]
;
}
/**
}
/**
@@
-151,7
+157,7
@@
class DateFormatter {
*
* @return string
*/
*
* @return string
*/
- public function reformat( $preference, $text, $options =
array( 'linked' )
) {
+ public function reformat( $preference, $text, $options =
[ 'linked' ]
) {
$linked = in_array( 'linked', $options );
$match_whole = in_array( 'match-whole', $options );
$linked = in_array( 'linked', $options );
$match_whole = in_array( 'match-whole', $options );
@@
-179,7
+185,7
@@
class DateFormatter {
// Horrible hack
if ( !$linked ) {
// Horrible hack
if ( !$linked ) {
- $regex = str_replace(
array( '\[\[', '\]\]' )
, '', $regex );
+ $regex = str_replace(
[ '\[\[', '\]\]' ]
, '', $regex );
}
if ( $match_whole ) {
}
if ( $match_whole ) {
@@
-191,24
+197,26
@@
class DateFormatter {
// Another horrible hack
$this->mLinked = $linked;
// Another horrible hack
$this->mLinked = $linked;
- $text = preg_replace_callback( $regex,
array( &$this, 'replace' )
, $text );
+ $text = preg_replace_callback( $regex,
[ &$this, 'replace' ]
, $text );
unset( $this->mLinked );
}
return $text;
}
/**
unset( $this->mLinked );
}
return $text;
}
/**
+ * Regexp replacement callback
+ *
* @param array $matches
* @return string
*/
* @param array $matches
* @return string
*/
- p
ublic
function replace( $matches ) {
+ p
rivate
function replace( $matches ) {
# Extract information from $matches
$linked = true;
if ( isset( $this->mLinked ) ) {
$linked = $this->mLinked;
}
# Extract information from $matches
$linked = true;
if ( isset( $this->mLinked ) ) {
$linked = $this->mLinked;
}
- $bits =
array()
;
+ $bits =
[]
;
$key = $this->keys[$this->mSource];
$keyLength = strlen( $key );
for ( $p = 0; $p < $keyLength; $p++ ) {
$key = $this->keys[$this->mSource];
$keyLength = strlen( $key );
for ( $p = 0; $p < $keyLength; $p++ ) {
@@
-217,22
+225,24
@@
class DateFormatter {
}
}
}
}
- return $this->formatDate( $bits, $linked );
+ return $this->formatDate( $bits, $
matches[0], $
linked );
}
/**
* @param array $bits
}
/**
* @param array $bits
+ * @param string $orig Original input string, to be returned
+ * on formatting failure.
* @param bool $link
* @return string
*/
* @param bool $link
* @return string
*/
- p
ublic function formatDate( $bits
, $link = true ) {
+ p
rivate function formatDate( $bits, $orig
, $link = true ) {
$format = $this->targets[$this->mTarget];
if ( !$link ) {
// strip piped links
$format = preg_replace( '/\[\[[^|]+\|([^\]]+)\]\]/', '$1', $format );
// strip remaining links
$format = $this->targets[$this->mTarget];
if ( !$link ) {
// strip piped links
$format = preg_replace( '/\[\[[^|]+\|([^\]]+)\]\]/', '$1', $format );
// strip remaining links
- $format = str_replace(
array( '[[', ']]' )
, '', $format );
+ $format = str_replace(
[ '[[', ']]' ]
, '', $format );
}
# Construct new date
}
# Construct new date
@@
-300,11
+310,12
@@
class DateFormatter {
}
}
if ( $fail ) {
}
}
if ( $fail ) {
- /** @todo FIXME: $matches doesn't exist here, what's expected? */
- $text = $matches[0];
+ // This occurs when parsing a date with day or month outside the bounds
+ // of possibilities.
+ $text = $orig;
}
}
- $isoBits =
array()
;
+ $isoBits =
[]
;
if ( isset( $bits['y'] ) ) {
$isoBits[] = $bits['y'];
}
if ( isset( $bits['y'] ) ) {
$isoBits[] = $bits['y'];
}
@@
-314,7
+325,7
@@
class DateFormatter {
// Output is not strictly HTML (it's wikitext), but <span> is whitelisted.
$text = Html::rawElement( 'span',
// Output is not strictly HTML (it's wikitext), but <span> is whitelisted.
$text = Html::rawElement( 'span',
-
array( 'class' => 'mw-formatted-date', 'title' => $isoDate )
, $text );
+
[ 'class' => 'mw-formatted-date', 'title' => $isoDate ]
, $text );
return $text;
}
return $text;
}
@@
-323,8
+334,8
@@
class DateFormatter {
* Return a regex that can be used to find month names in string
* @return string regex to find the months with
*/
* Return a regex that can be used to find month names in string
* @return string regex to find the months with
*/
- p
ublic
function getMonthRegex() {
- $names =
array()
;
+ p
rivate
function getMonthRegex() {
+ $names =
[]
;
for ( $i = 1; $i <= 12; $i++ ) {
$names[] = $this->lang->getMonthName( $i );
$names[] = $this->lang->getMonthAbbreviation( $i );
for ( $i = 1; $i <= 12; $i++ ) {
$names[] = $this->lang->getMonthName( $i );
$names[] = $this->lang->getMonthAbbreviation( $i );
@@
-337,7
+348,7
@@
class DateFormatter {
* @param string $monthName Month name
* @return string ISO month name
*/
* @param string $monthName Month name
* @return string ISO month name
*/
- p
ublic
function makeIsoMonth( $monthName ) {
+ p
rivate
function makeIsoMonth( $monthName ) {
$n = $this->xMonths[$this->lang->lc( $monthName )];
return sprintf( '%02d', $n );
}
$n = $this->xMonths[$this->lang->lc( $monthName )];
return sprintf( '%02d', $n );
}
@@
-347,7
+358,7
@@
class DateFormatter {
* @param string $year Year name
* @return string ISO year name
*/
* @param string $year Year name
* @return string ISO year name
*/
- p
ublic
function makeIsoYear( $year ) {
+ p
rivate
function makeIsoYear( $year ) {
# Assumes the year is in a nice format, as enforced by the regex
if ( substr( $year, -2 ) == 'BC' ) {
$num = intval( substr( $year, 0, -3 ) ) - 1;
# Assumes the year is in a nice format, as enforced by the regex
if ( substr( $year, -2 ) == 'BC' ) {
$num = intval( substr( $year, 0, -3 ) ) - 1;
@@
-366,7
+377,7
@@
class DateFormatter {
* @return int|string int representing year number in case of AD dates, or string containing
* year number and 'BC' at the end otherwise.
*/
* @return int|string int representing year number in case of AD dates, or string containing
* year number and 'BC' at the end otherwise.
*/
- p
ublic
function makeNormalYear( $iso ) {
+ p
rivate
function makeNormalYear( $iso ) {
if ( $iso[0] == '-' ) {
$text = ( intval( substr( $iso, 1 ) ) + 1 ) . ' BC';
} else {
if ( $iso[0] == '-' ) {
$text = ( intval( substr( $iso, 1 ) ) + 1 ) . ' BC';
} else {