Index: trunk/extensions/SemanticForms/specials/SF_FormEdit.php |
— | — | @@ -49,6 +49,11 @@ |
50 | 50 | return $text; |
51 | 51 | } |
52 | 52 | |
| 53 | + static function makeRandomNumber() { |
| 54 | + srand( time() ); |
| 55 | + return rand() % 1000000; |
| 56 | + } |
| 57 | + |
53 | 58 | static function printForm( $form_name, $target_name, $alt_forms = array() ) { |
54 | 59 | global $wgOut, $wgRequest, $wgScriptPath, $sfgScriptPath, $sfgFormPrinter; |
55 | 60 | |
— | — | @@ -177,15 +182,22 @@ |
178 | 183 | $target_name = $wgParser->recursiveTagParse( $target_name ); |
179 | 184 | |
180 | 185 | if ( strpos( $target_name, '{num' ) ) { |
| 186 | + $title_number = ""; |
| 187 | + $isRandom = false; |
181 | 188 | // get unique number start value |
182 | 189 | // from target name; if it's not |
183 | 190 | // there, or it's not a positive |
184 | 191 | // number, start it out as blank |
185 | 192 | preg_match( '/{num.*start[_]*=[_]*([^;]*).*}/', $target_name, $matches ); |
186 | 193 | if ( count( $matches ) == 2 && is_numeric( $matches[1] ) && $matches[1] >= 0 ) { |
| 194 | + // the "start" value" |
187 | 195 | $title_number = $matches[1]; |
188 | 196 | } else { |
189 | | - $title_number = ""; |
| 197 | + // random number |
| 198 | + if ( preg_match( '/{num;random}/', $target_name, $matches ) ) { |
| 199 | + $isRandom = true; |
| 200 | + $title_number = self::makeRandomNumber(); |
| 201 | + } |
190 | 202 | } |
191 | 203 | // cycle through numbers for |
192 | 204 | // this tag until we find one |
— | — | @@ -193,11 +205,18 @@ |
194 | 206 | // title |
195 | 207 | do { |
196 | 208 | $target_title = Title::newFromText( preg_replace( '/{num.*}/', $title_number, $target_name ) ); |
| 209 | + // create another title |
| 210 | + // number in case we |
| 211 | + // need it for the |
| 212 | + // next loop |
| 213 | + if ( $isRandom ) { |
| 214 | + $title_number = self::makeRandomNumber(); |
| 215 | + } |
197 | 216 | // if title number is blank, |
198 | 217 | // change it to 2; otherwise, |
199 | 218 | // increment it, and if necessary |
200 | 219 | // pad it with leading 0s as well |
201 | | - if ( $title_number == "" ) { |
| 220 | + elseif ( $title_number == "" ) { |
202 | 221 | $title_number = 2; |
203 | 222 | } else { |
204 | 223 | $title_number = str_pad( $title_number + 1, strlen( $title_number ), '0', STR_PAD_LEFT ); |