r64902 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64901‎ | r64902 | r64903 >
Date:21:12, 10 April 2010
Author:nad
Status:deferred
Tags:
Comment:
trap bad form title
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
@@ -646,32 +646,34 @@
647647 $this->formClass = strtolower( $type ) . '-record recordadmin';
648648 $this->formAtts = '';
649649 $title = Title::newFromText( $type, NS_FORM );
650 - if ( $title->exists() ) {
 650+ if ( is_object( $title ) {
 651+ if ( $title->exists() ) {
651652
652 - # Get the form content
653 - $form = new Article( $title );
654 - $form = $form->getContent();
655 -
656 - # Extract form's class and other attributes (except method and action)
657 - if ( preg_match( "|<form\s*([^>]+)\s*>.+</form>|is", $form, $atts )) {
658 - if ( preg_match( "|class\s*=\s*[\"'](.+?)['\"]|", $atts[1], $m ) ) $this->formClass .= ' ' . $m[1];
659 - $this->formAtts = ' ' . trim( preg_replace( "/(class|action|method)\s*=\s*[\"'](.*?)['\"]/", "", $atts[1] ) );
 653+ # Get the form content
 654+ $form = new Article( $title );
 655+ $form = $form->getContent();
 656+
 657+ # Extract form's class and other attributes (except method and action)
 658+ if ( preg_match( "|<form\s*([^>]+)\s*>.+</form>|is", $form, $atts )) {
 659+ if ( preg_match( "|class\s*=\s*[\"'](.+?)['\"]|", $atts[1], $m ) ) $this->formClass .= ' ' . $m[1];
 660+ $this->formAtts = ' ' . trim( preg_replace( "/(class|action|method)\s*=\s*[\"'](.*?)['\"]/", "", $atts[1] ) );
 661+ }
 662+
 663+ # Process content
 664+ $form = preg_replace( '#<input.+?type=[\'"]?submit["\']?.+?/(input| *)>#i', '', $form ); # remove submits
 665+ $form = preg_replace( '#^.+?<form.*?>#is', '', $form ); # remove up to and including form open
 666+ $form = preg_replace( '#</form>.+?$#is', '', $form ); # remove form close and everything after
 667+ $form = preg_replace( '#name\s*=\s*([\'"])(.*?)\\1#is', 'name="ra_$2"', $form ); # prefix input names with ra_
 668+ $form = preg_replace( '#(<select.+?>)\s*(?!<option/>)#is', '$1<option selected/>', $form ); # ensure all select lists have default blank
660669 }
661 -
662 - # Process content
663 - $form = preg_replace( '#<input.+?type=[\'"]?submit["\']?.+?/(input| *)>#i', '', $form ); # remove submits
664 - $form = preg_replace( '#^.+?<form.*?>#is', '', $form ); # remove up to and including form open
665 - $form = preg_replace( '#</form>.+?$#is', '', $form ); # remove form close and everything after
666 - $form = preg_replace( '#name\s*=\s*([\'"])(.*?)\\1#is', 'name="ra_$2"', $form ); # prefix input names with ra_
667 - $form = preg_replace( '#(<select.+?>)\s*(?!<option/>)#is', '$1<option selected/>', $form ); # ensure all select lists have default blank
668 - }
669 - else {
 670+ else {
670671
671 - # Create a red link to the form if it doesn't exist
672 - $form = '<b>' . wfMsg( 'recordadmin-noform', $type ) . '</b>'
673 - . '<br /><a href="' . $title->getLocalURL( 'action=edit' )
674 - . '">(' . wfMsg( 'recordadmin-createlink' ) . ')</a><br />';
675 - }
 672+ # Create a red link to the form if it doesn't exist
 673+ $form = '<b>' . wfMsg( 'recordadmin-noform', $type ) . '</b>'
 674+ . '<br /><a href="' . $title->getLocalURL( 'action=edit' )
 675+ . '">(' . wfMsg( 'recordadmin-createlink' ) . ')</a><br />';
 676+ }
 677+ } else $form = '';
676678 $this->form = $form;
677679 }
678680
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.11.9, 2010-03-31' );
 15+define( 'RECORDADMIN_VERSION', '0.11.10, 2010-04-11' );
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