Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php |
— | — | @@ -69,33 +69,38 @@ |
70 | 70 | $offset = $brace['OFFSET']; |
71 | 71 | $length = $brace['LENGTH']; |
72 | 72 | $records[$name] = substr( $content, $offset, $length ); |
73 | | - $content = substr_replace( $content, str_repeat( "\x07", $length ), $offset, $length ); |
| 73 | + $content = substr_replace( $content, "\x07$name" . str_repeat( "\x07", $length - strlen( $name ) - 1 ), $offset, $length ); |
74 | 74 | } |
75 | 75 | } |
76 | 76 | } |
77 | 77 | $count = count( $records ); |
78 | 78 | |
79 | | - # If any were found, remove them from the textbox and render their forms instead |
| 79 | + # If any were found, replace them with a simple {{type}} placeholder in the textarea |
80 | 80 | if( $count > 0 ) { |
81 | 81 | |
82 | | - # Add the prefs JS for the tabset |
83 | | - #$wgOut->addScript( "<script src=\"$wgStylePath/common/prefs.js\"></script>" ); |
| 82 | + # Strip noincludes if any, they will be put back later |
| 83 | + $content = preg_replace( "|<noinclude>\s*\x07|", "\x07", $content ); |
| 84 | + $content = preg_replace( "|(\x07+)\s*</noinclude>|", "$1", $content ); |
84 | 85 | |
85 | | - $editPage->textbox1 = preg_replace( "|(<noinclude>)?\s*\x07+\s*(</noinclude>)?|", "", $content ); |
| 86 | + # Replace the template calls with the simple {{type}} placeholder |
| 87 | + $editPage->textbox1 = preg_replace( "|\x07([^\x07]+)\x07+|", '{{$1}}', $content ); |
86 | 88 | |
| 89 | + # Add a tab for each type with a form filled in with the parameters from its template call |
87 | 90 | $jsFormsList = array(); |
88 | 91 | $tabset = "<div class=\"tabset\">"; |
89 | 92 | $tabset .= "<fieldset><legend>" . wfMsg( 'recordadmin-properties' ) . "</legend>"; |
90 | | - $tabset .= wfMsg( 'recordadmin-edit-info' ) . "</fieldset>"; |
| 93 | + $tabset .= wfMsg( 'recordadmin-edit-info', $wgRequest->appendQuery( 'nora=1' ) ) . "</fieldset>"; |
91 | 94 | foreach( $records as $type => $record ) { |
92 | 95 | $jsFormsList[] = "'$type'"; |
93 | 96 | $this->preProcessForm( $type ); |
94 | 97 | $this->examineForm(); |
95 | | - $this->populateForm( $this->valuesFromText( $record ) ); |
| 98 | + $values = $this->valuesFromText( $record ); |
| 99 | + $this->populateForm( $values ); |
96 | 100 | $tabset .= "<fieldset><legend>$type " . strtolower( wfMsg( 'recordadmin-properties' ) ) . "</legend>\n"; |
97 | 101 | $tabset .= "<form id=\"$type-form\" class=\"$type-record recordadmin\">$this->form</form>\n"; |
98 | 102 | $tabset .= "</fieldset>"; |
99 | 103 | } |
| 104 | + |
100 | 105 | $tabset .= "</div>"; |
101 | 106 | $jsFormsList = join( ', ', $jsFormsList ); |
102 | 107 | |
— | — | @@ -155,17 +160,20 @@ |
156 | 161 | # Bail if no record data was posted |
157 | 162 | if( count( $data ) == 0 ) return true; |
158 | 163 | |
159 | | - # Build the template syntax for the posted record data |
160 | | - $templates = ''; |
| 164 | + # Build the template syntax for each record and replace the current template or prepend if none |
161 | 165 | foreach( $data as $type => $values ) { |
162 | 166 | $this->preProcessForm( $type ); |
163 | 167 | $this->examineForm(); |
164 | | - $templates .= $this->valuesToText( $type, $values ) . "\n"; |
| 168 | + $template = "<noinclude>" . $this->valuesToText( $type, $values ) . "</noinclude>"; |
| 169 | + |
| 170 | + # Replace any instance of the template in the text with the new parameters |
| 171 | + $text = preg_replace( "|\{\{$type\}\}|", $template, $text, -1, $count ); |
| 172 | + |
| 173 | + # If there were no matches, prepend it (either its newly added, or is a prepended one) |
| 174 | + if( $count == 0) $text = "$template\n$text"; |
| 175 | + |
165 | 176 | } |
166 | 177 | |
167 | | - # Prepend the template syntax to the posted wikitext (which had them removed by onEditPage) |
168 | | - # - wrap them in noincludes as these should never show in enbeded articles |
169 | | - $text = "<noinclude>$templates</noinclude>$text"; |
170 | 178 | return true; |
171 | 179 | } |
172 | 180 | |
— | — | @@ -595,7 +603,7 @@ |
596 | 604 | # Parse any brace structures |
597 | 605 | global $wgTitle, $wgUser, $wgParser; |
598 | 606 | $options = ParserOptions::newFromUser( $wgUser ); |
599 | | - $max = 25; |
| 607 | + $max = 10; |
600 | 608 | do { |
601 | 609 | $braces = false; |
602 | 610 | foreach( self::examineBraces( $this->form ) as $brace ) { |
Index: trunk/extensions/RecordAdmin/RecordAdmin.i18n.php |
— | — | @@ -54,7 +54,7 @@ |
55 | 55 | 'recordadmin-export-csv' => 'CSV', |
56 | 56 | 'recordadmin-export-pdf' => 'PDF', |
57 | 57 | 'recordadmin-notset' => 'No "$1"', |
58 | | - 'recordadmin-edit-info' => 'This page contains templates which have their own forms which you can fill in from this tab-set', |
| 58 | + 'recordadmin-edit-info' => 'This page contains templates which have their own forms that you can fill in from this tab-set.<br />Click <a href="$1">here</a> to use the normal MediaWiki edit functionality without template forms.', |
59 | 59 | 'recordadmin-properties' => 'Properties', |
60 | 60 | ); |
61 | 61 | |
Index: trunk/extensions/RecordAdmin/RecordAdmin.php |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | * @author Siebrand Mazeland |
12 | 12 | * @licence GNU General Public Licence 2.0 or later |
13 | 13 | */ |
14 | | -define( 'RECORDADMIN_VERSION', '1.1.3, 2010-11-16' ); |
| 14 | +define( 'RECORDADMIN_VERSION', '1.1.4, 2011-01-25' ); |
15 | 15 | |
16 | 16 | $dir = dirname( __FILE__ ) . '/'; |
17 | 17 | $wgExtensionMessagesFiles['RecordAdmin'] = $dir . 'RecordAdmin.i18n.php'; |