mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ParserFunctions
synced 2024-11-15 11:59:54 +00:00
SFH_OBJECT_ARGS was added pre 1.12...
Kill ancient back compat, and code where unused
This commit is contained in:
parent
f4d9df85d5
commit
0b1347bdd2
Notes:
Sam Reed
2011-12-19 00:38:10 +00:00
|
@ -50,7 +50,7 @@ $wgPFUnitLanguageVariants = array(
|
|||
$wgExtensionCredits['parserhook'][] = array(
|
||||
'path' => __FILE__,
|
||||
'name' => 'ParserFunctions',
|
||||
'version' => '1.4.0',
|
||||
'version' => '1.4.1',
|
||||
'url' => 'https://www.mediawiki.org/wiki/Extension:ParserFunctions',
|
||||
'author' => array( 'Tim Starling', 'Robert Rohde', 'Ross McClure', 'Juraj Simlovic' ),
|
||||
'descriptionmsg' => 'pfunc_desc',
|
||||
|
@ -76,22 +76,13 @@ $wgHooks['ParserFirstCallInit'][] = 'wfRegisterParserFunctions';
|
|||
function wfRegisterParserFunctions( $parser ) {
|
||||
global $wgPFEnableStringFunctions, $wgPFEnableConvert;
|
||||
|
||||
if ( defined( get_class( $parser ) . '::SFH_OBJECT_ARGS' ) ) {
|
||||
// These functions accept DOM-style arguments
|
||||
$parser->setFunctionHook( 'if', 'ExtParserFunctions::ifObj', SFH_OBJECT_ARGS );
|
||||
$parser->setFunctionHook( 'ifeq', 'ExtParserFunctions::ifeqObj', SFH_OBJECT_ARGS );
|
||||
$parser->setFunctionHook( 'switch', 'ExtParserFunctions::switchObj', SFH_OBJECT_ARGS );
|
||||
$parser->setFunctionHook( 'ifexist', 'ExtParserFunctions::ifexistObj', SFH_OBJECT_ARGS );
|
||||
$parser->setFunctionHook( 'ifexpr', 'ExtParserFunctions::ifexprObj', SFH_OBJECT_ARGS );
|
||||
$parser->setFunctionHook( 'iferror', 'ExtParserFunctions::iferrorObj', SFH_OBJECT_ARGS );
|
||||
} else {
|
||||
$parser->setFunctionHook( 'if', 'ExtParserFunctions::ifHook' );
|
||||
$parser->setFunctionHook( 'ifeq', 'ExtParserFunctions::ifeq' );
|
||||
$parser->setFunctionHook( 'switch', 'ExtParserFunctions::switchHook' );
|
||||
$parser->setFunctionHook( 'ifexist', 'ExtParserFunctions::ifexist' );
|
||||
$parser->setFunctionHook( 'ifexpr', 'ExtParserFunctions::ifexpr' );
|
||||
$parser->setFunctionHook( 'iferror', 'ExtParserFunctions::iferror' );
|
||||
}
|
||||
// These functions accept DOM-style arguments
|
||||
$parser->setFunctionHook( 'if', 'ExtParserFunctions::ifObj', SFH_OBJECT_ARGS );
|
||||
$parser->setFunctionHook( 'ifeq', 'ExtParserFunctions::ifeqObj', SFH_OBJECT_ARGS );
|
||||
$parser->setFunctionHook( 'switch', 'ExtParserFunctions::switchObj', SFH_OBJECT_ARGS );
|
||||
$parser->setFunctionHook( 'ifexist', 'ExtParserFunctions::ifexistObj', SFH_OBJECT_ARGS );
|
||||
$parser->setFunctionHook( 'ifexpr', 'ExtParserFunctions::ifexprObj', SFH_OBJECT_ARGS );
|
||||
$parser->setFunctionHook( 'iferror', 'ExtParserFunctions::iferrorObj', SFH_OBJECT_ARGS );
|
||||
|
||||
$parser->setFunctionHook( 'expr', 'ExtParserFunctions::expr' );
|
||||
$parser->setFunctionHook( 'time', 'ExtParserFunctions::time' );
|
||||
|
|
|
@ -108,14 +108,6 @@ class ExtParserFunctions {
|
|||
return $result;
|
||||
}
|
||||
|
||||
public static function ifHook( $parser, $test = '', $then = '', $else = '' ) {
|
||||
if ( $test !== '' ) {
|
||||
return $then;
|
||||
} else {
|
||||
return $else;
|
||||
}
|
||||
}
|
||||
|
||||
public static function ifObj( $parser, $frame, $args ) {
|
||||
$test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
|
||||
if ( $test !== '' ) {
|
||||
|
@ -125,14 +117,6 @@ class ExtParserFunctions {
|
|||
}
|
||||
}
|
||||
|
||||
public static function ifeq( $parser, $left = '', $right = '', $then = '', $else = '' ) {
|
||||
if ( $left == $right ) {
|
||||
return $then;
|
||||
} else {
|
||||
return $else;
|
||||
}
|
||||
}
|
||||
|
||||
public static function ifeqObj( $parser, $frame, $args ) {
|
||||
$left = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
|
||||
$right = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
|
||||
|
@ -165,47 +149,7 @@ class ExtParserFunctions {
|
|||
}
|
||||
}
|
||||
|
||||
public static function switchHook( $parser /*,...*/ ) {
|
||||
$args = func_get_args();
|
||||
array_shift( $args );
|
||||
$primary = trim( array_shift( $args ) );
|
||||
$found = $defaultFound = false;
|
||||
$parts = null;
|
||||
$default = null;
|
||||
$mwDefault =& MagicWord::get( 'default' );
|
||||
foreach ( $args as $arg ) {
|
||||
$parts = array_map( 'trim', explode( '=', $arg, 2 ) );
|
||||
if ( count( $parts ) == 2 ) {
|
||||
# Found "="
|
||||
if ( $found || $parts[0] == $primary ) {
|
||||
# Found a match, return now
|
||||
return $parts[1];
|
||||
} elseif ( $defaultFound || $mwDefault->matchStartAndRemove( $parts[0] ) ) {
|
||||
$default = $parts[1];
|
||||
} # else wrong case, continue
|
||||
} elseif ( count( $parts ) == 1 ) {
|
||||
# Multiple input, single output
|
||||
# If the value matches, set a flag and continue
|
||||
if ( $parts[0] == $primary ) {
|
||||
$found = true;
|
||||
} elseif ( $mwDefault->matchStartAndRemove( $parts[0] ) ) {
|
||||
$defaultFound = true;
|
||||
}
|
||||
} # else RAM corruption due to cosmic ray?
|
||||
}
|
||||
# Default case
|
||||
# Check if the last item had no = sign, thus specifying the default case
|
||||
if ( count( $parts ) == 1 ) {
|
||||
return $parts[0];
|
||||
} elseif ( !is_null( $default ) ) {
|
||||
return $default;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param $parser Parser
|
||||
* @param $frame PPFrame
|
||||
* @param $args
|
||||
|
@ -348,10 +292,6 @@ class ExtParserFunctions {
|
|||
return $parser->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit;
|
||||
}
|
||||
|
||||
public static function ifexist( $parser, $title = '', $then = '', $else = '' ) {
|
||||
return self::ifexistCommon( $parser, false, $title, $then, $else );
|
||||
}
|
||||
|
||||
public static function ifexistCommon( $parser, $frame, $titletext = '', $then = '', $else = '' ) {
|
||||
global $wgContLang;
|
||||
$title = Title::newFromText( $titletext );
|
||||
|
|
Loading…
Reference in a new issue