r111632 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111631‎ | r111632 | r111633 >
Date:12:01, 16 February 2012
Author:maxsem
Status:ok
Tags:
Comment:
Avoid static variables to make the formatter useable more than once per request
Modified paths:
  • /trunk/extensions/MobileFrontend/MobileFormatter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFormatter.php
@@ -276,13 +276,11 @@
277277 */
278278 private function headingTransformCallbackWML( $matches ) {
279279 wfProfileIn( __METHOD__ );
280 - static $headings = 0;
281 - ++$headings;
 280+ $this->headings++;
282281
283282 $base = self::WML_SECTION_SEPARATOR .
284 - "<h2 class='section_heading' id='section_{$headings}'>{$matches[2]}</h2>";
 283+ "<h2 class='section_heading' id='section_{$this->headings}'>{$this->matches[2]}</h2>";
285284
286 - $this->headings = $headings;
287285 wfProfileOut( __METHOD__ );
288286 return $base;
289287 }
@@ -299,40 +297,39 @@
300298
301299 $headlineId = ( isset( $headlineMatches[1] ) ) ? $headlineMatches[1] : '';
302300
303 - static $headings = 0;
304301 $show = $this->msg( 'mobile-frontend-show-button' );
305302 $hide = $this->msg( 'mobile-frontend-hide-button' );
306303 $backToTop = $this->msg( 'mobile-frontend-back-to-top-of-section' );
307 - ++$headings;
 304+ $this->headings++;
308305 // Back to top link
309306 $base = Html::openElement( 'div',
310 - array( 'id' => 'anchor_' . intval( $headings - 1 ),
 307+ array( 'id' => 'anchor_' . intval( $this->headings - 1 ),
311308 'class' => 'section_anchors', )
312309 ) .
313310 Html::rawElement( 'a',
314 - array( 'href' => '#section_' . intval( $headings - 1 ),
 311+ array( 'href' => '#section_' . intval( $this->headings - 1 ),
315312 'class' => 'back_to_top' ),
316313 '&#8593;' . $backToTop ) .
317314 Html::closeElement( 'div' );
318315 // generate the HTML we are going to inject
319316 $buttons = Html::element( 'button',
320317 array( 'class' => 'section_heading show',
321 - 'section_id' => $headings ),
 318+ 'section_id' => $this->headings ),
322319 $show ) .
323320 Html::element( 'button',
324321 array( 'class' => 'section_heading hide',
325 - 'section_id' => $headings ),
 322+ 'section_id' => $this->headings ),
326323 $hide );
327324 if ( $this->expandableSections ) {
328 - $h2OnClick = 'javascript:wm_toggle_section(' . $headings . ');';
 325+ $h2OnClick = 'javascript:wm_toggle_section(' . $this->headings . ');';
329326 $base .= Html::openElement( 'h2',
330327 array( 'class' => 'section_heading',
331 - 'id' => 'section_' . $headings,
 328+ 'id' => 'section_' . $this->headings,
332329 'onclick' => $h2OnClick ) );
333330 } else {
334331 $base .= Html::openElement( 'h2',
335332 array( 'class' => 'section_heading',
336 - 'id' => 'section_' . $headings ) );
 333+ 'id' => 'section_' . $this->headings ) );
337334 }
338335 $base .= $buttons .
339336 Html::rawElement( 'span',
@@ -341,14 +338,13 @@
342339 Html::closeElement( 'h2' ) .
343340 Html::openElement( 'div',
344341 array( 'class' => 'content_block',
345 - 'id' => 'content_' . $headings ) );
 342+ 'id' => 'content_' . $this->headings ) );
346343
347 - if ( $headings > 1 ) {
 344+ if ( $this->headings > 1 ) {
348345 // Close it up here
349346 $base = Html::closeElement( 'div' ) . $base;
350347 }
351348
352 - $this->headings = $headings;
353349 wfProfileOut( __METHOD__ );
354350 return $base;
355351 }

Status & tagging log