r48566 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48565‎ | r48566 | r48567 >
Date:03:06, 19 March 2009
Author:nad
Status:deferred
Tags:
Comment:
use form's attributes if it has any
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
@@ -4,12 +4,14 @@
55 */
66 class SpecialRecordAdmin extends SpecialPage {
77
8 - var $form = '';
9 - var $type = '';
10 - var $types = array();
11 - var $orderby = '';
12 - var $desc = false;
13 - var $guid = '';
 8+ var $form = '';
 9+ var $formClass = '';
 10+ var $formAtts = '';
 11+ var $type = '';
 12+ var $types = array();
 13+ var $orderBy = '';
 14+ var $desc = false;
 15+ var $guid = '';
1416
1517 function __construct() {
1618 # Name to use for creating a new record either via RecordAdmin or a public form
@@ -30,6 +32,7 @@
3133 $record = $wgRequest->getText( 'wpRecord' );
3234 $invert = $wgRequest->getText( 'wpInvert' );
3335 $title = $this->title = Title::makeTitle( NS_SPECIAL, 'RecordAdmin' );
 36+ $action = $title->getLocalURL( 'action=submit' );
3437 $wpTitle = trim( $wgRequest->getText( 'wpTitle' ) );
3538
3639 if ( $type && $wgRecordAdminUseNamespaces ) {
@@ -61,11 +64,7 @@
6265
6366 # If no type selected, render form for record types and create record-type
6467 if ( empty( $type ) ) {
65 - $wgOut->addHTML( Xml::element(
66 - 'form',
67 - array( 'class' => 'recordadmin', 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ),
68 - null
69 - ) );
 68+ $wgOut->addHTML( Xml::element( 'form', array( 'class' => 'recordadmin', 'action' => $action, 'method' => 'post' ), null ) );
7069 $wgOut->addWikiText( "<div class='visualClear'></div>\n==" . wfMsg( 'recordadmin-select' ) . "==\n" );
7170
7271 # Get titles in $wgRecordAdminCategory and build option list
@@ -134,9 +133,7 @@
135134 $this->populateForm( $posted );
136135
137136 # Render the form
138 - $wgOut->addHTML(
139 - Xml::element( 'form', array( 'class' => strtolower( $type ) . '-record recordadmin', 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ), null )
140 - );
 137+ $wgOut->addHTML( "<form class=\"{$this->formClass}\"{$this->formAtts} action=\"$action\" method=\"POST\">" );
141138 $wgOut->addWikiText( "==" . wfMsg( 'recordadmin-create', $type ) . "==\n" );
142139 $wgOut->addHTML(
143140 '<b>' . wfMsg( 'recordadmin-recordid' ) . '</b>&nbsp;' . Xml::element( 'input', array( 'name' => 'wpTitle', 'size' => 30, 'value' => $wpTitle ) )
@@ -202,7 +199,7 @@
203200 $this->populateForm( substr( $text, $braces['OFFSET'], $braces['LENGTH'] ) );
204201
205202 # Render the form
206 - $wgOut->addHTML( Xml::element( 'form', array( 'class' => 'recordadmin', 'action' => $title->getLocalURL( 'action=submit' ), 'method' => 'post' ), null ) );
 203+ $wgOut->addHTML( "<form class=\"{$this->formClass}\"{$this->formAtts} action=\"$action\" method=\"POST\">" );
207204 $wgOut->addHTML( $this->form );
208205 $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpType', 'value' => $type ) ) );
209206 $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpRecord', 'value' => $record ) ) );
@@ -276,7 +273,7 @@
277274
278275 # Sort the records according to "orderby" parameter
279276 if ( $this->desc = eregi( ' +desc *$', $orderby ) ) $orderby = eregi_replace( ' +desc *$', '', $orderby );
280 - $this->orderby = $orderby;
 277+ $this->orderBy = $orderby;
281278 usort( $records, array( $this, 'sortCallback' ) );
282279
283280 return $records;
@@ -286,9 +283,9 @@
287284 * Compares to arrays by column
288285 */
289286 function sortCallback( $row1, $row2 ) {
290 - if ( !isset( $row1[$this->orderby] ) || !isset( $row1[$this->orderby] ) ) return 0;
291 - if ( $row1[$this->orderby] == $row2[$this->orderby] ) return 0;
292 - $cmp = $row1[$this->orderby] > $row2[$this->orderby] ? 1 : -1;
 287+ if ( !isset( $row1[$this->orderBy] ) || !isset( $row1[$this->orderBy] ) ) return 0;
 288+ if ( $row1[$this->orderBy] == $row2[$this->orderBy] ) return 0;
 289+ $cmp = $row1[$this->orderBy] > $row2[$this->orderBy] ? 1 : -1;
293290 return $this->desc ? -$cmp : $cmp;
294291 }
295292
@@ -364,13 +361,26 @@
365362 * Read in and prepare the form (for use as a search filter) for passed record type
366363 * - we're using the record's own form as a filter for searching for records
367364 * - extract only the content from between the form tags and remove any submit inputs
 365+ * - also record the forms attributes and class if any
368366 */
369367 function preProcessForm( $type ) {
370368 $this->type = $type;
 369+ $this->formClass = strtolower( $type ) . '-record recordadmin';
 370+ $this->formAtts = '';
371371 $title = Title::newFromText( $type, NS_FORM );
372372 if ( $title->exists() ) {
 373+
 374+ # Get the form content
373375 $form = new Article( $title );
374376 $form = $form->getContent();
 377+
 378+ # Extract form's class and other attributes (except method and action)
 379+ if ( preg_match( "|<form\s*([^>]+)\s*>.+</form>|s", $form, $atts )) {
 380+ if ( preg_match( "|class\s*=\s*[\"'](.+?)['\"]|", $atts[1], $m ) ) $this->formClass .= ' ' . $m[1];
 381+ $this->formAtts = ' ' . trim( preg_replace( "/(class|action|method)\s*=\s*[\"'](.*?)['\"]/", "", $atts[1] ) );
 382+ }
 383+
 384+ # Process content
375385 $form = preg_replace( '#<input.+?type=[\'"]?submit["\']?.+?/(input| *)>#', '', $form ); # remove submits
376386 $form = preg_replace( '#^.+?<form.*?>#s', '', $form ); # remove up to and including form open
377387 $form = preg_replace( '#</form>.+?$#s', '', $form ); # remove form close and everything after
@@ -384,6 +394,7 @@
385395 . '">(' . wfMsg( 'recordadmin-createlink' ) . ')</a><br />';
386396 }
387397 $this->form = $form;
 398+ print $this->formAtts;
388399 }
389400
390401
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.5.8, 2009-03-19' );
 15+define( 'RECORDADMIN_VERSION', '0.5.9, 2009-03-19' );
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