X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMessage.php;h=57c6264dfa98e95aa1b7264dad7a6002af3d83ce;hb=3195d2ab7ff55e2633ddcfa86188f61f1fd26184;hp=74b4021ba896e6d25a886a64235e28fe23abbac3;hpb=91e3622c9257427d37592ba630a939a3971c1e48;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Message.php b/includes/Message.php index 74b4021ba8..57c6264dfa 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -356,6 +356,96 @@ class Message { return $this; } + /** + * Add parameters that are durations of time and will be passed through + * Language::formatDuration before substitution + * @since 1.22 + * @param Varargs: numeric parameters (or single argument that is array of numeric parameters) + * @return Message: $this + */ + public function durationParams( /*...*/ ) { + $params = func_get_args(); + if ( isset( $params[0] ) && is_array( $params[0] ) ) { + $params = $params[0]; + } + foreach ( $params as $param ) { + $this->parameters[] = self::durationParam( $param ); + } + return $this; + } + + /** + * Add parameters that are expiration times and will be passed through + * Language::formatExpiry before substitution + * @since 1.22 + * @param Varargs: numeric parameters (or single argument that is array of numeric parameters) + * @return Message: $this + */ + public function expiryParams( /*...*/ ) { + $params = func_get_args(); + if ( isset( $params[0] ) && is_array( $params[0] ) ) { + $params = $params[0]; + } + foreach ( $params as $param ) { + $this->parameters[] = self::expiryParam( $param ); + } + return $this; + } + + /** + * Add parameters that are time periods and will be passed through + * Language::formatTimePeriod before substitution + * @since 1.22 + * @param Varargs: numeric parameters (or single argument that is array of numeric parameters) + * @return Message: $this + */ + public function timeperiodParams( /*...*/ ) { + $params = func_get_args(); + if ( isset( $params[0] ) && is_array( $params[0] ) ) { + $params = $params[0]; + } + foreach ( $params as $param ) { + $this->parameters[] = self::timeperiodParam( $param ); + } + return $this; + } + + /** + * Add parameters that are file sizes and will be passed through + * Language::formatSize before substitution + * @since 1.22 + * @param Varargs: numeric parameters (or single argument that is array of numeric parameters) + * @return Message: $this + */ + public function sizeParams( /*...*/ ) { + $params = func_get_args(); + if ( isset( $params[0] ) && is_array( $params[0] ) ) { + $params = $params[0]; + } + foreach ( $params as $param ) { + $this->parameters[] = self::sizeParam( $param ); + } + return $this; + } + + /** + * Add parameters that are bitrates and will be passed through + * Language::formatBitrate before substitution + * @since 1.22 + * @param Varargs: numeric parameters (or single argument that is array of numeric parameters) + * @return Message: $this + */ + public function bitrateParams( /*...*/ ) { + $params = func_get_args(); + if ( isset( $params[0] ) && is_array( $params[0] ) ) { + $params = $params[0]; + } + foreach ( $params as $param ) { + $this->parameters[] = self::bitrateParam( $param ); + } + return $this; + } + /** * Set the language and the title from a context object * @since 1.19 @@ -423,7 +513,7 @@ class Message { * @since 1.20 */ public function setInterfaceMessageFlag( $value ) { - $this->interface = (bool) $value; + $this->interface = (bool)$value; return $this; } @@ -434,7 +524,7 @@ class Message { * @return Message: $this */ public function useDatabase( $value ) { - $this->useDatabase = (bool) $value; + $this->useDatabase = (bool)$value; return $this; } @@ -638,6 +728,51 @@ class Message { return array( 'num' => $value ); } + /** + * @since 1.22 + * @param $value + * @return array + */ + public static function durationParam( $value ) { + return array( 'duration' => $value ); + } + + /** + * @since 1.22 + * @param $value + * @return array + */ + public static function expiryParam( $value ) { + return array( 'expiry' => $value ); + } + + /** + * @since 1.22 + * @param $value + * @return array + */ + public static function timeperiodParam( $value ) { + return array( 'period' => $value ); + } + + /** + * @since 1.22 + * @param $value + * @return array + */ + public static function sizeParam( $value ) { + return array( 'size' => $value ); + } + + /** + * @since 1.22 + * @param $value + * @return array + */ + public static function bitrateParam( $value ) { + return array( 'bitrate' => $value ); + } + /** * Substitutes any parameters into the message text. * @since 1.17 @@ -664,20 +799,37 @@ class Message { * @return Tuple(type, value) */ protected function extractParam( $param ) { - if ( is_array( $param ) && isset( $param['raw'] ) ) { - return array( 'after', $param['raw'] ); - } elseif ( is_array( $param ) && isset( $param['num'] ) ) { - // Replace number params always in before step for now. - // No support for combined raw and num params - return array( 'before', $this->language->formatNum( $param['num'] ) ); - } elseif ( !is_array( $param ) ) { - return array( 'before', $param ); + if ( is_array( $param ) ) { + if ( isset( $param['raw'] ) ) { + return array( 'after', $param['raw'] ); + } elseif ( isset( $param['num'] ) ) { + // Replace number params always in before step for now. + // No support for combined raw and num params + return array( 'before', $this->language->formatNum( $param['num'] ) ); + } elseif ( isset( $param['duration'] ) ) { + return array( 'before', $this->language->formatDuration( $param['duration'] ) ); + } elseif ( isset( $param['expiry'] ) ) { + return array( 'before', $this->language->formatExpiry( $param['expiry'] ) ); + } elseif ( isset( $param['period'] ) ) { + return array( 'before', $this->language->formatTimePeriod( $param['period'] ) ); + } elseif ( isset( $param['size'] ) ) { + return array( 'before', $this->language->formatSize( $param['size'] ) ); + } elseif ( isset( $param['bitrate'] ) ) { + return array( 'before', $this->language->formatBitrate( $param['bitrate'] ) ); + } else { + trigger_error( + "Invalid message parameter: " . htmlspecialchars( serialize( $param ) ), + E_USER_WARNING + ); + return array( 'before', '[INVALID]' ); + } + } elseif ( $param instanceof Message ) { + // Message objects should not be before parameters because + // then they'll get double escaped. If the message needs to be + // escaped, it'll happen right here when we call toString(). + return array( 'after', $param->toString() ); } else { - trigger_error( - "Invalid message parameter: " . htmlspecialchars( serialize( $param ) ), - E_USER_WARNING - ); - return array( 'before', '[INVALID]' ); + return array( 'before', $param ); } }