r76407 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76406‎ | r76407 | r76408 >
Date:19:51, 9 November 2010
Author:yaron
Status:deferred
Tags:
Comment:
Added handling for new 'random' sub-param within "page name=" param in {{{info}}}
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_FormEdit.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_FormEdit.php
@@ -49,6 +49,11 @@
5050 return $text;
5151 }
5252
 53+ static function makeRandomNumber() {
 54+ srand( time() );
 55+ return rand() % 1000000;
 56+ }
 57+
5358 static function printForm( $form_name, $target_name, $alt_forms = array() ) {
5459 global $wgOut, $wgRequest, $wgScriptPath, $sfgScriptPath, $sfgFormPrinter;
5560
@@ -177,15 +182,22 @@
178183 $target_name = $wgParser->recursiveTagParse( $target_name );
179184
180185 if ( strpos( $target_name, '{num' ) ) {
 186+ $title_number = "";
 187+ $isRandom = false;
181188 // get unique number start value
182189 // from target name; if it's not
183190 // there, or it's not a positive
184191 // number, start it out as blank
185192 preg_match( '/{num.*start[_]*=[_]*([^;]*).*}/', $target_name, $matches );
186193 if ( count( $matches ) == 2 && is_numeric( $matches[1] ) && $matches[1] >= 0 ) {
 194+ // the "start" value"
187195 $title_number = $matches[1];
188196 } 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+ }
190202 }
191203 // cycle through numbers for
192204 // this tag until we find one
@@ -193,11 +205,18 @@
194206 // title
195207 do {
196208 $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+ }
197216 // if title number is blank,
198217 // change it to 2; otherwise,
199218 // increment it, and if necessary
200219 // pad it with leading 0s as well
201 - if ( $title_number == "" ) {
 220+ elseif ( $title_number == "" ) {
202221 $title_number = 2;
203222 } else {
204223 $title_number = str_pad( $title_number + 1, strlen( $title_number ), '0', STR_PAD_LEFT );

Status & tagging log