r40704 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40703‎ | r40704 | r40705 >
Date:17:10, 10 September 2008
Author:yaron
Status:old
Tags:
Comment:
Fixed bugs: unnecessary space at beginning of forms, and incorrect handling of
templates with spaces in their name
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc
@@ -158,7 +158,7 @@
159159 // remove the '<nowiki>' tags, leaving us with what we need
160160 global $sfgDisableWikiTextParsing;
161161 if (! $sfgDisableWikiTextParsing) {
162 - $form_def = "__NOEDITSECTION__ " . strtr($form_def, array('{{{' => '<nowiki>{{{', '}}}' => '}}}</nowiki>'));
 162+ $form_def = "__NOEDITSECTION__" . strtr($form_def, array('{{{' => '<nowiki>{{{', '}}}' => '}}}</nowiki>'));
163163 $wgParser->mOptions = new ParserOptions();
164164 $wgParser->mOptions->initialiseFromUser($wgUser);
165165 $form_def = $wgParser->parse($form_def, $this->mPageTitle, $wgParser->mOptions)->getText();
@@ -268,11 +268,9 @@
269269 // once in that page, and multiple values are allowed, repeat this
270270 // section
271271 $existing_template_text = null;
272 - // special template string for preg_match calls - includes a
273 - // regular expression, to allow matching of either spaces or
274 - // underlines in name
275 - $search_template_str = str_replace('/', '\/', $tif->template_name);
276 - $search_template_str = preg_replace('/[_| ]/', '[_| ]', $search_template_str);
 272+ // replace underlines with spaces in template name, to allow for
 273+ // searching on either
 274+ $search_template_str = str_replace('_', ' ', $tif->template_name);
277275 if ($source_is_page || $form_is_partial) {
278276 if ($allow_multiple) {
279277 // find instances of this template in the page -
@@ -282,7 +280,7 @@
283281 // there has to be a more efficient way to handle multiple
284282 // instances of templates, one that doesn't involve re-parsing
285283 // the same tags, but I don't know what it is.
286 - if (stripos($existing_page_content, '{{' . $search_template_str) !== false) {
 284+ if (stripos(str_replace('_', ' ', $existing_page_content), '{{' . $search_template_str) !== false) {
287285 $instance_num++;
288286 } else {
289287 $all_instances_printed = true;
@@ -290,7 +288,7 @@
291289 }
292290 // get the first instance of this template on the page being edited,
293291 // even if there are more
294 - if (($start_char = stripos($existing_page_content, '{{' . $search_template_str)) !== false) {
 292+ if (($start_char = stripos(str_replace('_', ' ', $existing_page_content), '{{' . $search_template_str)) !== false) {
295293 $fields_start_char = $start_char + 2 + strlen($search_template_str);
296294 // skip ahead to the first real character
297295 while (in_array($existing_page_content[$fields_start_char], array(' ', '\n', '|'))) {

Status & tagging log