Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php |
— | — | @@ -4,12 +4,14 @@ |
5 | 5 | */ |
6 | 6 | class SpecialRecordAdmin extends SpecialPage { |
7 | 7 | |
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 = ''; |
14 | 16 | |
15 | 17 | function __construct() { |
16 | 18 | # Name to use for creating a new record either via RecordAdmin or a public form |
— | — | @@ -30,6 +32,7 @@ |
31 | 33 | $record = $wgRequest->getText( 'wpRecord' ); |
32 | 34 | $invert = $wgRequest->getText( 'wpInvert' ); |
33 | 35 | $title = $this->title = Title::makeTitle( NS_SPECIAL, 'RecordAdmin' ); |
| 36 | + $action = $title->getLocalURL( 'action=submit' ); |
34 | 37 | $wpTitle = trim( $wgRequest->getText( 'wpTitle' ) ); |
35 | 38 | |
36 | 39 | if ( $type && $wgRecordAdminUseNamespaces ) { |
— | — | @@ -61,11 +64,7 @@ |
62 | 65 | |
63 | 66 | # If no type selected, render form for record types and create record-type |
64 | 67 | 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 ) ); |
70 | 69 | $wgOut->addWikiText( "<div class='visualClear'></div>\n==" . wfMsg( 'recordadmin-select' ) . "==\n" ); |
71 | 70 | |
72 | 71 | # Get titles in $wgRecordAdminCategory and build option list |
— | — | @@ -134,9 +133,7 @@ |
135 | 134 | $this->populateForm( $posted ); |
136 | 135 | |
137 | 136 | # 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\">" ); |
141 | 138 | $wgOut->addWikiText( "==" . wfMsg( 'recordadmin-create', $type ) . "==\n" ); |
142 | 139 | $wgOut->addHTML( |
143 | 140 | '<b>' . wfMsg( 'recordadmin-recordid' ) . '</b> ' . Xml::element( 'input', array( 'name' => 'wpTitle', 'size' => 30, 'value' => $wpTitle ) ) |
— | — | @@ -202,7 +199,7 @@ |
203 | 200 | $this->populateForm( substr( $text, $braces['OFFSET'], $braces['LENGTH'] ) ); |
204 | 201 | |
205 | 202 | # 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\">" ); |
207 | 204 | $wgOut->addHTML( $this->form ); |
208 | 205 | $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpType', 'value' => $type ) ) ); |
209 | 206 | $wgOut->addHTML( Xml::element( 'input', array( 'type' => 'hidden', 'name' => 'wpRecord', 'value' => $record ) ) ); |
— | — | @@ -276,7 +273,7 @@ |
277 | 274 | |
278 | 275 | # Sort the records according to "orderby" parameter |
279 | 276 | if ( $this->desc = eregi( ' +desc *$', $orderby ) ) $orderby = eregi_replace( ' +desc *$', '', $orderby ); |
280 | | - $this->orderby = $orderby; |
| 277 | + $this->orderBy = $orderby; |
281 | 278 | usort( $records, array( $this, 'sortCallback' ) ); |
282 | 279 | |
283 | 280 | return $records; |
— | — | @@ -286,9 +283,9 @@ |
287 | 284 | * Compares to arrays by column |
288 | 285 | */ |
289 | 286 | 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; |
293 | 290 | return $this->desc ? -$cmp : $cmp; |
294 | 291 | } |
295 | 292 | |
— | — | @@ -364,13 +361,26 @@ |
365 | 362 | * Read in and prepare the form (for use as a search filter) for passed record type |
366 | 363 | * - we're using the record's own form as a filter for searching for records |
367 | 364 | * - extract only the content from between the form tags and remove any submit inputs |
| 365 | + * - also record the forms attributes and class if any |
368 | 366 | */ |
369 | 367 | function preProcessForm( $type ) { |
370 | 368 | $this->type = $type; |
| 369 | + $this->formClass = strtolower( $type ) . '-record recordadmin'; |
| 370 | + $this->formAtts = ''; |
371 | 371 | $title = Title::newFromText( $type, NS_FORM ); |
372 | 372 | if ( $title->exists() ) { |
| 373 | + |
| 374 | + # Get the form content |
373 | 375 | $form = new Article( $title ); |
374 | 376 | $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 |
375 | 385 | $form = preg_replace( '#<input.+?type=[\'"]?submit["\']?.+?/(input| *)>#', '', $form ); # remove submits |
376 | 386 | $form = preg_replace( '#^.+?<form.*?>#s', '', $form ); # remove up to and including form open |
377 | 387 | $form = preg_replace( '#</form>.+?$#s', '', $form ); # remove form close and everything after |
— | — | @@ -384,6 +394,7 @@ |
385 | 395 | . '">(' . wfMsg( 'recordadmin-createlink' ) . ')</a><br />'; |
386 | 396 | } |
387 | 397 | $this->form = $form; |
| 398 | + print $this->formAtts; |
388 | 399 | } |
389 | 400 | |
390 | 401 | |
Index: trunk/extensions/RecordAdmin/RecordAdmin.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @licence GNU General Public Licence 2.0 or later |
13 | 13 | */ |
14 | 14 | |
15 | | -define( 'RECORDADMIN_VERSION', '0.5.8, 2009-03-19' ); |
| 15 | +define( 'RECORDADMIN_VERSION', '0.5.9, 2009-03-19' ); |
16 | 16 | |
17 | 17 | $wgRecordAdminUseNamespaces = false; # Whether record articles should be in a namespace of the same name as their type |
18 | 18 | $wgRecordAdminCategory = 'Records'; # Category containing record types |