mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ParserFunctions
synced 2024-11-15 11:59:54 +00:00
Minor documentation additions
Change-Id: I876de41b2c81d93df34ee2a8222aff6dc8176aae
This commit is contained in:
parent
8d2534bc77
commit
fdd7c091bd
19
Convert.php
19
Convert.php
|
@ -5,6 +5,10 @@ if ( !defined( 'MEDIAWIKI' ) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConvertError extends MWException {
|
class ConvertError extends MWException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $msg string
|
||||||
|
*/
|
||||||
public function __construct( $msg /*...*/ ) {
|
public function __construct( $msg /*...*/ ) {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
array_shift( $args );
|
array_shift( $args );
|
||||||
|
@ -203,7 +207,8 @@ class ConvertParser {
|
||||||
/**
|
/**
|
||||||
* Find the unit at the end of the string and load $this->sourceUnit with an appropriate
|
* Find the unit at the end of the string and load $this->sourceUnit with an appropriate
|
||||||
* ConvertUnit, or throw an exception if the unit is unrecognised.
|
* ConvertUnit, or throw an exception if the unit is unrecognised.
|
||||||
* @param $string
|
* @param $string string
|
||||||
|
* @throws ConvertError
|
||||||
*/
|
*/
|
||||||
protected function deduceSourceUnit( $string ){
|
protected function deduceSourceUnit( $string ){
|
||||||
# Get the unit from the end of the string
|
# Get the unit from the end of the string
|
||||||
|
@ -407,9 +412,10 @@ class ConvertDimension {
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param $var ConvertDimension|Int a dimension constant or existing unit
|
* @param $var ConvertDimension|Int a dimension constant or existing unit
|
||||||
* @param $var2 ConvertDimension|Int optionally another dimension constant for a compound unit $var/$var2
|
* @param $var2 ConvertDimension|Int|null optionally another dimension constant for a compound unit $var/$var2
|
||||||
|
* @throws ConvertError
|
||||||
*/
|
*/
|
||||||
public function __construct( $var, $var2=null ){
|
public function __construct( $var, $var2 = null ){
|
||||||
static $legalDimensionsFlip;
|
static $legalDimensionsFlip;
|
||||||
|
|
||||||
if( is_string( $var ) ){
|
if( is_string( $var ) ){
|
||||||
|
@ -707,6 +713,7 @@ class ConvertUnit {
|
||||||
/**
|
/**
|
||||||
* Parse a raw unit string, and populate member variables
|
* Parse a raw unit string, and populate member variables
|
||||||
* @param $rawUnit String
|
* @param $rawUnit String
|
||||||
|
* @throws ConvertError
|
||||||
*/
|
*/
|
||||||
protected function parseUnit( $rawUnit ){
|
protected function parseUnit( $rawUnit ){
|
||||||
|
|
||||||
|
@ -721,7 +728,7 @@ class ConvertUnit {
|
||||||
array_map( 'trim', $parts );
|
array_map( 'trim', $parts );
|
||||||
if( count( $parts ) == 1 ){
|
if( count( $parts ) == 1 ){
|
||||||
# Single unit
|
# Single unit
|
||||||
foreach( self::$units as $dimension => $units ){
|
foreach( self::$units as $units ){
|
||||||
foreach( $units as $unit => $data ){
|
foreach( $units as $unit => $data ){
|
||||||
if( $rawUnit == $unit
|
if( $rawUnit == $unit
|
||||||
|| ( !$data[2] && preg_match( "/^({$data[1]})$/u", $parts[0] ) )
|
|| ( !$data[2] && preg_match( "/^({$data[1]})$/u", $parts[0] ) )
|
||||||
|
@ -770,7 +777,7 @@ class ConvertUnit {
|
||||||
/**
|
/**
|
||||||
* Get the mathematical factor which will convert a measurement in this unit into a
|
* Get the mathematical factor which will convert a measurement in this unit into a
|
||||||
* measurement in the SI base unit for the dimension
|
* measurement in the SI base unit for the dimension
|
||||||
* @return double
|
* @return number double
|
||||||
*/
|
*/
|
||||||
public function getConversion(){
|
public function getConversion(){
|
||||||
return $this->conversion * $this->getPrefixConversion();
|
return $this->conversion * $this->getPrefixConversion();
|
||||||
|
@ -778,7 +785,7 @@ class ConvertUnit {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the conversion factor associated with the prefix(es) in the unit
|
* Get the conversion factor associated with the prefix(es) in the unit
|
||||||
* @return double
|
* @return number double
|
||||||
*/
|
*/
|
||||||
public function getPrefixConversion(){
|
public function getPrefixConversion(){
|
||||||
if( !$this->prefix ){
|
if( !$this->prefix ){
|
||||||
|
|
5
Expr.php
5
Expr.php
|
@ -47,6 +47,10 @@ define( 'EXPR_POW', 35 );
|
||||||
define( 'EXPR_PI', 36 );
|
define( 'EXPR_PI', 36 );
|
||||||
|
|
||||||
class ExprError extends MWException {
|
class ExprError extends MWException {
|
||||||
|
/**
|
||||||
|
* @param $msg string
|
||||||
|
* @param $parameter string
|
||||||
|
*/
|
||||||
public function __construct( $msg, $parameter = '' ) {
|
public function __construct( $msg, $parameter = '' ) {
|
||||||
$this->message = '<strong class="error">' . wfMsgForContent( "pfunc_expr_$msg", htmlspecialchars( $parameter ) ) . '</strong>';
|
$this->message = '<strong class="error">' . wfMsgForContent( "pfunc_expr_$msg", htmlspecialchars( $parameter ) ) . '</strong>';
|
||||||
}
|
}
|
||||||
|
@ -158,6 +162,7 @@ class ExprParser {
|
||||||
* http://montcs.bloomu.edu/~bobmon/Information/RPN/infix2rpn.shtml
|
* http://montcs.bloomu.edu/~bobmon/Information/RPN/infix2rpn.shtml
|
||||||
* It's essentially the same as Dijkstra's shunting yard algorithm.
|
* It's essentially the same as Dijkstra's shunting yard algorithm.
|
||||||
* @param $expr string
|
* @param $expr string
|
||||||
|
* @throws ExprError
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function doExpression( $expr ) {
|
function doExpression( $expr ) {
|
||||||
|
|
|
@ -372,7 +372,7 @@ class ExtParserFunctions {
|
||||||
* since their existence can be checked without
|
* since their existence can be checked without
|
||||||
* accessing the database.
|
* accessing the database.
|
||||||
*/
|
*/
|
||||||
return SpecialPage::exists( $title->getDBkey() ) ? $then : $else;
|
return SpecialPageFactory::exists( $title->getDBkey() ) ? $then : $else;
|
||||||
} elseif ( $title->isExternal() ) {
|
} elseif ( $title->isExternal() ) {
|
||||||
/* Can't check the existence of pages on other sites,
|
/* Can't check the existence of pages on other sites,
|
||||||
* so just return $else. Makes a sort of sense, since
|
* so just return $else. Makes a sort of sense, since
|
||||||
|
@ -524,7 +524,7 @@ class ExtParserFunctions {
|
||||||
* Obtain a specified number of slash-separated parts of a title,
|
* Obtain a specified number of slash-separated parts of a title,
|
||||||
* e.g. {{#titleparts:Hello/World|1}} => "Hello"
|
* e.g. {{#titleparts:Hello/World|1}} => "Hello"
|
||||||
*
|
*
|
||||||
* @param $parser Parent parser
|
* @param $parser Parser Parent parser
|
||||||
* @param $title string Title to split
|
* @param $title string Title to split
|
||||||
* @param $parts int Number of parts to keep
|
* @param $parts int Number of parts to keep
|
||||||
* @param $offset int Offset starting at 1
|
* @param $offset int Offset starting at 1
|
||||||
|
@ -626,7 +626,7 @@ class ExtParserFunctions {
|
||||||
* Note: If the needle is not found, empty string is returned.
|
* Note: If the needle is not found, empty string is returned.
|
||||||
* @param $parser Parser
|
* @param $parser Parser
|
||||||
* @param $inStr string
|
* @param $inStr string
|
||||||
* @param $inNeedle int
|
* @param $inNeedle int|string
|
||||||
* @param $inOffset int
|
* @param $inOffset int
|
||||||
* @return int|string
|
* @return int|string
|
||||||
*/
|
*/
|
||||||
|
@ -660,7 +660,7 @@ class ExtParserFunctions {
|
||||||
* Note: If the needle is not found, -1 is returned.
|
* Note: If the needle is not found, -1 is returned.
|
||||||
* @param $parser Parser
|
* @param $parser Parser
|
||||||
* @param $inStr string
|
* @param $inStr string
|
||||||
* @param $inNeedle int
|
* @param $inNeedle int|string
|
||||||
* @return int|string
|
* @return int|string
|
||||||
*/
|
*/
|
||||||
public static function runRPos ( $parser, $inStr = '', $inNeedle = '' ) {
|
public static function runRPos ( $parser, $inStr = '', $inNeedle = '' ) {
|
||||||
|
|
Loading…
Reference in a new issue