r112001 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112000‎ | r112001 | r112002 >
Date:10:55, 21 February 2012
Author:nikerabbit
Status:ok
Tags:i18nreview 
Comment:
rebuild() was not dealing with recursion properly.
This lead to infinite loop, when there was no message index yet and translate workflow states:
* rebuild loads groups
* workflow state group adds missing messages when it loads message keys
* onSave hook gets run when those messages are credited
* the hooks wants to know which message the page corresponds to
* so it loads message index
* which is messing, so rebuild() gets called again...
Modified paths:
  • /trunk/extensions/Translate/utils/MessageIndex.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/MessageIndex.php
@@ -64,14 +64,22 @@
6565 abstract public function retrieve();
6666 abstract protected function store( array $array );
6767
68 - public function rebuild( /*bool*/ $scratch = false ) {
 68+ public function rebuild() {
 69+ static $recursion = 0;
 70+
 71+ if ( $recursion > 0 ) {
 72+ $msg = __METHOD__ . ': trying to recurse - building the index first time?';
 73+ STDERR( $msg );
 74+ wfDebug( "$msg\n" );
 75+ return array();
 76+ }
 77+ $recursion++;
 78+
 79+
6980 $groups = MessageGroups::singleton()->getGroups();
7081
7182 $new = $old = array();
72 - if ( !$scratch ) {
73 - // To avoid inifinite recursion
74 - $old = $this->retrieve();
75 - }
 83+ $old = $this->retrieve();
7684 $postponed = array();
7785
7886 STDOUT( "Working with ", 'main' );
@@ -96,6 +104,7 @@
97105
98106 $this->store( $new );
99107 $this->clearMessageGroupStats( $old, $new );
 108+ $recursion--;
100109 return $new;
101110 }
102111
@@ -196,7 +205,7 @@
197206 if ( file_exists( $file ) ) {
198207 return $this->index = unserialize( file_get_contents( $file ) );
199208 } else {
200 - return $this->index = $this->rebuild( 'empty' );
 209+ return $this->index = $this->rebuild();
201210 }
202211 }
203212
@@ -232,7 +241,7 @@
233242 if ( is_array( $data ) ) {
234243 return $this->index = $data;
235244 } else {
236 - return $this->index = $this->rebuild( 'empty' );
 245+ return $this->index = $this->rebuild();
237246 }
238247 }
239248

Sign-offs

UserFlagDate
Siebrandtested12:25, 21 February 2012

Status & tagging log