r106616 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106615‎ | r106616 | r106617 >
Date:00:38, 19 December 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
SFH_OBJECT_ARGS was added pre 1.12...

Kill ancient back compat, and code where unused
Modified paths:
  • /trunk/extensions/ParserFunctions/ParserFunctions.php (modified) (history)
  • /trunk/extensions/ParserFunctions/ParserFunctions_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ParserFunctions/ParserFunctions_body.php
@@ -108,14 +108,6 @@
109109 return $result;
110110 }
111111
112 - public static function ifHook( $parser, $test = '', $then = '', $else = '' ) {
113 - if ( $test !== '' ) {
114 - return $then;
115 - } else {
116 - return $else;
117 - }
118 - }
119 -
120112 public static function ifObj( $parser, $frame, $args ) {
121113 $test = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
122114 if ( $test !== '' ) {
@@ -125,14 +117,6 @@
126118 }
127119 }
128120
129 - public static function ifeq( $parser, $left = '', $right = '', $then = '', $else = '' ) {
130 - if ( $left == $right ) {
131 - return $then;
132 - } else {
133 - return $else;
134 - }
135 - }
136 -
137121 public static function ifeqObj( $parser, $frame, $args ) {
138122 $left = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : '';
139123 $right = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : '';
@@ -165,47 +149,7 @@
166150 }
167151 }
168152
169 - public static function switchHook( $parser /*,...*/ ) {
170 - $args = func_get_args();
171 - array_shift( $args );
172 - $primary = trim( array_shift( $args ) );
173 - $found = $defaultFound = false;
174 - $parts = null;
175 - $default = null;
176 - $mwDefault =& MagicWord::get( 'default' );
177 - foreach ( $args as $arg ) {
178 - $parts = array_map( 'trim', explode( '=', $arg, 2 ) );
179 - if ( count( $parts ) == 2 ) {
180 - # Found "="
181 - if ( $found || $parts[0] == $primary ) {
182 - # Found a match, return now
183 - return $parts[1];
184 - } elseif ( $defaultFound || $mwDefault->matchStartAndRemove( $parts[0] ) ) {
185 - $default = $parts[1];
186 - } # else wrong case, continue
187 - } elseif ( count( $parts ) == 1 ) {
188 - # Multiple input, single output
189 - # If the value matches, set a flag and continue
190 - if ( $parts[0] == $primary ) {
191 - $found = true;
192 - } elseif ( $mwDefault->matchStartAndRemove( $parts[0] ) ) {
193 - $defaultFound = true;
194 - }
195 - } # else RAM corruption due to cosmic ray?
196 - }
197 - # Default case
198 - # Check if the last item had no = sign, thus specifying the default case
199 - if ( count( $parts ) == 1 ) {
200 - return $parts[0];
201 - } elseif ( !is_null( $default ) ) {
202 - return $default;
203 - } else {
204 - return '';
205 - }
206 - }
207 -
208153 /**
209 - * @static
210154 * @param $parser Parser
211155 * @param $frame PPFrame
212156 * @param $args
@@ -348,10 +292,6 @@
349293 return $parser->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit;
350294 }
351295
352 - public static function ifexist( $parser, $title = '', $then = '', $else = '' ) {
353 - return self::ifexistCommon( $parser, false, $title, $then, $else );
354 - }
355 -
356296 public static function ifexistCommon( $parser, $frame, $titletext = '', $then = '', $else = '' ) {
357297 global $wgContLang;
358298 $title = Title::newFromText( $titletext );
Index: trunk/extensions/ParserFunctions/ParserFunctions.php
@@ -50,7 +50,7 @@
5151 $wgExtensionCredits['parserhook'][] = array(
5252 'path' => __FILE__,
5353 'name' => 'ParserFunctions',
54 - 'version' => '1.4.0',
 54+ 'version' => '1.4.1',
5555 'url' => 'https://www.mediawiki.org/wiki/Extension:ParserFunctions',
5656 'author' => array( 'Tim Starling', 'Robert Rohde', 'Ross McClure', 'Juraj Simlovic' ),
5757 'descriptionmsg' => 'pfunc_desc',
@@ -76,22 +76,13 @@
7777 function wfRegisterParserFunctions( $parser ) {
7878 global $wgPFEnableStringFunctions, $wgPFEnableConvert;
7979
80 - if ( defined( get_class( $parser ) . '::SFH_OBJECT_ARGS' ) ) {
81 - // These functions accept DOM-style arguments
82 - $parser->setFunctionHook( 'if', 'ExtParserFunctions::ifObj', SFH_OBJECT_ARGS );
83 - $parser->setFunctionHook( 'ifeq', 'ExtParserFunctions::ifeqObj', SFH_OBJECT_ARGS );
84 - $parser->setFunctionHook( 'switch', 'ExtParserFunctions::switchObj', SFH_OBJECT_ARGS );
85 - $parser->setFunctionHook( 'ifexist', 'ExtParserFunctions::ifexistObj', SFH_OBJECT_ARGS );
86 - $parser->setFunctionHook( 'ifexpr', 'ExtParserFunctions::ifexprObj', SFH_OBJECT_ARGS );
87 - $parser->setFunctionHook( 'iferror', 'ExtParserFunctions::iferrorObj', SFH_OBJECT_ARGS );
88 - } else {
89 - $parser->setFunctionHook( 'if', 'ExtParserFunctions::ifHook' );
90 - $parser->setFunctionHook( 'ifeq', 'ExtParserFunctions::ifeq' );
91 - $parser->setFunctionHook( 'switch', 'ExtParserFunctions::switchHook' );
92 - $parser->setFunctionHook( 'ifexist', 'ExtParserFunctions::ifexist' );
93 - $parser->setFunctionHook( 'ifexpr', 'ExtParserFunctions::ifexpr' );
94 - $parser->setFunctionHook( 'iferror', 'ExtParserFunctions::iferror' );
95 - }
 80+ // These functions accept DOM-style arguments
 81+ $parser->setFunctionHook( 'if', 'ExtParserFunctions::ifObj', SFH_OBJECT_ARGS );
 82+ $parser->setFunctionHook( 'ifeq', 'ExtParserFunctions::ifeqObj', SFH_OBJECT_ARGS );
 83+ $parser->setFunctionHook( 'switch', 'ExtParserFunctions::switchObj', SFH_OBJECT_ARGS );
 84+ $parser->setFunctionHook( 'ifexist', 'ExtParserFunctions::ifexistObj', SFH_OBJECT_ARGS );
 85+ $parser->setFunctionHook( 'ifexpr', 'ExtParserFunctions::ifexprObj', SFH_OBJECT_ARGS );
 86+ $parser->setFunctionHook( 'iferror', 'ExtParserFunctions::iferrorObj', SFH_OBJECT_ARGS );
9687
9788 $parser->setFunctionHook( 'expr', 'ExtParserFunctions::expr' );
9889 $parser->setFunctionHook( 'time', 'ExtParserFunctions::time' );

Comments

#Comment by Nikerabbit (talk | contribs)   07:50, 19 December 2011

ifexpr and iferror functions?

#Comment by Reedy (talk | contribs)   19:05, 19 December 2011

What about them? Why didn't I delete them?

If that's the case, it's because they are called otherwise, most likely via their fooObj brethren, and I wasn't going to the extent of refactoring to fold in the methods, but it could be done sometime

#Comment by Nikerabbit (talk | contribs)   19:37, 19 December 2011

Okay.

Status & tagging log