r54993 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54992‎ | r54993 | r54994 >
Date:04:29, 14 August 2009
Author:nad
Status:deferred
Tags:
Comment:
make html regex's case insensitive
Modified paths:
  • /trunk/extensions/RecordAdmin/RecordAdmin.php (modified) (history)
  • /trunk/extensions/RecordAdmin/RecordAdmin_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php
@@ -419,17 +419,17 @@
420420 $form = $form->getContent();
421421
422422 # Extract form's class and other attributes (except method and action)
423 - if ( preg_match( "|<form\s*([^>]+)\s*>.+</form>|s", $form, $atts )) {
 423+ if ( preg_match( "|<form\s*([^>]+)\s*>.+</form>|is", $form, $atts )) {
424424 if ( preg_match( "|class\s*=\s*[\"'](.+?)['\"]|", $atts[1], $m ) ) $this->formClass .= ' ' . $m[1];
425425 $this->formAtts = ' ' . trim( preg_replace( "/(class|action|method)\s*=\s*[\"'](.*?)['\"]/", "", $atts[1] ) );
426426 }
427427
428428 # Process content
429 - $form = preg_replace( '#<input.+?type=[\'"]?submit["\']?.+?/(input| *)>#', '', $form ); # remove submits
430 - $form = preg_replace( '#^.+?<form.*?>#s', '', $form ); # remove up to and including form open
431 - $form = preg_replace( '#</form>.+?$#s', '', $form ); # remove form close and everything after
432 - $form = preg_replace( '#name\s*=\s*([\'"])(.*?)\\1#s', 'name="ra_$2"', $form ); # prefix input names with ra_
433 - $form = preg_replace( '#(<select.+?>)\s*(?!<option/>)#s', '$1<option selected/>', $form ); # ensure all select lists have default blank
 429+ $form = preg_replace( '#<input.+?type=[\'"]?submit["\']?.+?/(input| *)>#i', '', $form ); # remove submits
 430+ $form = preg_replace( '#^.+?<form.*?>#is', '', $form ); # remove up to and including form open
 431+ $form = preg_replace( '#</form>.+?$#is', '', $form ); # remove form close and everything after
 432+ $form = preg_replace( '#name\s*=\s*([\'"])(.*?)\\1#is', 'name="ra_$2"', $form ); # prefix input names with ra_
 433+ $form = preg_replace( '#(<select.+?>)\s*(?!<option/>)#is', '$1<option selected/>', $form ); # ensure all select lists have default blank
434434 }
435435 else {
436436
@@ -456,7 +456,7 @@
457457 foreach( $this->types as $k => $type ) {
458458
459459 # Get this input element's html text and position and length
460 - preg_match( "|<([a-zA-Z]+)[^<]+?name=\"ra_$k\\[?\\]?\".*?>(.*?</\\1>)?|s", $this->form, $m, PREG_OFFSET_CAPTURE );
 460+ preg_match( "|<([a-z]+)[^<]+?name=\"ra_$k\\[?\\]?\".*?>(.*?</\\1>)?|is", $this->form, $m, PREG_OFFSET_CAPTURE );
461461 list( $html, $pos ) = $m[0];
462462 $len = strlen( $html );
463463
@@ -465,27 +465,27 @@
466466 $v = isset( $values[$k] ) ? $values[$k] : '';
467467 switch ( $type ) {
468468 case 'text':
469 - $html = preg_replace( "|value\s*=\s*\".*?\"|", "", $html );
 469+ $html = preg_replace( "|value\s*=\s*\".*?\"|i", "", $html );
470470 if ( $v ) $html = preg_replace( "|(/?>)$|", " value=\"$v\" $1", $html );
471471 break;
472472 case 'bool':
473 - $html = preg_replace( "|checked|", "", $html );
 473+ $html = preg_replace( "|checked|i", "", $html );
474474 if ( $v ) $html = preg_replace( "|(/?>)$|", " checked $1", $html );
475475 break;
476476 case 'list':
477477 $html = preg_replace_callback("|\{\{.+\}\}|s", array($this, 'parsePart'), $html); # parse any braces
478478 #if ( empty( $this->record ) )
479 - $html = preg_replace( "|(<option[^<>]*) selected|", "$1", $html ); # remove the currently selected option
 479+ $html = preg_replace( "|(<option[^<>]*) selected|i", "$1", $html ); # remove the currently selected option
480480 if ( $v ) {
481481 foreach( split( "\n", $v ) as $v ) {
482 - $html = preg_match( "|<option[^>]+value\s*=|s", $html )
483 - ? preg_replace( "|(<option)([^>]+value\s*=\s*[\"']{$v}['\"])|s", "$1 selected$2", $html )
484 - : preg_replace( "|(<option[^>]*)(?=>$v</option>)|s", "$1 selected", $html );
 482+ $html = preg_match( "|<option[^>]+value\s*=|is", $html )
 483+ ? preg_replace( "|(<option)([^>]+value\s*=\s*[\"']{$v}['\"])|is", "$1 selected$2", $html )
 484+ : preg_replace( "|(<option[^>]*)(?=>$v</option>)|is", "$1 selected", $html );
485485 }
486486 }
487487 break;
488488 case 'blob':
489 - $html = preg_replace( "|>.*?(?=</textarea>)|s", ">$v", $html );
 489+ $html = preg_replace( "|>.*?(?=</textarea>)|is", ">$v", $html );
490490 break;
491491 }
492492
@@ -501,7 +501,7 @@
502502 global $wgUser, $wgParser;
503503 $options = ParserOptions::newFromUser( $wgUser );
504504 $html = $wgParser->parse($part[0], $this->title, $options, true, true )->getText();
505 - return preg_match("|(<option.+</option>)|s", $html, $m) ? $m[1] : '';
 505+ return preg_match("|(<option.+</option>)|is", $html, $m) ? $m[1] : '';
506506 }
507507
508508 /**
@@ -510,10 +510,10 @@
511511 */
512512 function examineForm() {
513513 $this->types = array();
514 - preg_match_all( "|<([a-zA-Z]+)[^<]+?name=\"ra_(.+?)\\[?\\]?\".*?>|", $this->form, $m );
 514+ preg_match_all( "|<([a-z]+)[^<]+?name=\"ra_(.+?)\\[?\\]?\".*?>|i", $this->form, $m );
515515 foreach ( $m[2] as $i => $k ) {
516516 $tag = $m[1][$i];
517 - $type = preg_match( "|type\s*=\s*\"(.+?)\"|", $m[0][$i], $n ) ? $n[1] : '';
 517+ $type = preg_match( "|type\s*=\s*\"(.+?)\"|i", $m[0][$i], $n ) ? $n[1] : '';
518518 switch ( $tag ) {
519519 case 'input':
520520 switch ( $type ) {
@@ -672,7 +672,7 @@
673673 $template = false;
674674 $count = false;
675675 foreach ( func_get_args() as $arg ) if ( !is_object( $arg ) ) {
676 - if ( preg_match( "/^(.+?)\\s*=\\s*(.+)$/", $arg, $match ) ) {
 676+ if ( preg_match( "|^(.+?)\s*=\s*(.+)$|i", $arg, $match ) ) {
677677 list( , $k, $v ) = $match;
678678 if ( $k == 'title' ) $title = $v;
679679 elseif ( $k == 'name' ) $name = $v;
@@ -700,7 +700,7 @@
701701 $parser->mOutput->mCacheTime = -1;
702702 $regexp = '';
703703 foreach ( func_get_args() as $arg ) if ( !is_object( $arg ) ) {
704 - if ( preg_match( "/^(.+?)\\s*=\\s*(.+)$/", $arg, $match ) ) {
 704+ if ( preg_match( "|^(.+?)\s*=\s*(.+)$|", $arg, $match ) ) {
705705 list( , $k, $v ) = $match;
706706 if ( $k == 'type' ) $type = $v;
707707 elseif ( $k == 'record' ) $record = $v;
Index: trunk/extensions/RecordAdmin/RecordAdmin.php
@@ -11,7 +11,7 @@
1212 * @licence GNU General Public Licence 2.0 or later
1313 */
1414
15 -define( 'RECORDADMIN_VERSION', '0.8.4, 2009-08-06' );
 15+define( 'RECORDADMIN_VERSION', '0.8.5, 2009-08-14' );
1616
1717 $wgRecordAdminUseNamespaces = false; # Whether record articles should be in a namespace of the same name as their type
1818 $wgRecordAdminCategory = 'Records'; # Category containing record types

Status & tagging log