r80949 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80948‎ | r80949 | r80950 >
Date:01:00, 25 January 2011
Author:nad
Status:deferred
Tags:
Comment:
allow record templates to appear anywhere in the text by keeping a basic {{type}} placeholder there
Modified paths:
  • /trunk/extensions/RecordAdmin/RecordAdmin.i18n.php (modified) (history)
  • /trunk/extensions/RecordAdmin/RecordAdmin.php (modified) (history)
  • /trunk/extensions/RecordAdmin/RecordAdmin_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php
@@ -69,33 +69,38 @@
7070 $offset = $brace['OFFSET'];
7171 $length = $brace['LENGTH'];
7272 $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 );
7474 }
7575 }
7676 }
7777 $count = count( $records );
7878
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
8080 if( $count > 0 ) {
8181
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 );
8485
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 );
8688
 89+ # Add a tab for each type with a form filled in with the parameters from its template call
8790 $jsFormsList = array();
8891 $tabset = "<div class=\"tabset\">";
8992 $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>";
9194 foreach( $records as $type => $record ) {
9295 $jsFormsList[] = "'$type'";
9396 $this->preProcessForm( $type );
9497 $this->examineForm();
95 - $this->populateForm( $this->valuesFromText( $record ) );
 98+ $values = $this->valuesFromText( $record );
 99+ $this->populateForm( $values );
96100 $tabset .= "<fieldset><legend>$type " . strtolower( wfMsg( 'recordadmin-properties' ) ) . "</legend>\n";
97101 $tabset .= "<form id=\"$type-form\" class=\"$type-record recordadmin\">$this->form</form>\n";
98102 $tabset .= "</fieldset>";
99103 }
 104+
100105 $tabset .= "</div>";
101106 $jsFormsList = join( ', ', $jsFormsList );
102107
@@ -155,17 +160,20 @@
156161 # Bail if no record data was posted
157162 if( count( $data ) == 0 ) return true;
158163
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
161165 foreach( $data as $type => $values ) {
162166 $this->preProcessForm( $type );
163167 $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+
165176 }
166177
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";
170178 return true;
171179 }
172180
@@ -595,7 +603,7 @@
596604 # Parse any brace structures
597605 global $wgTitle, $wgUser, $wgParser;
598606 $options = ParserOptions::newFromUser( $wgUser );
599 - $max = 25;
 607+ $max = 10;
600608 do {
601609 $braces = false;
602610 foreach( self::examineBraces( $this->form ) as $brace ) {
Index: trunk/extensions/RecordAdmin/RecordAdmin.i18n.php
@@ -54,7 +54,7 @@
5555 'recordadmin-export-csv' => 'CSV',
5656 'recordadmin-export-pdf' => 'PDF',
5757 '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.',
5959 'recordadmin-properties' => 'Properties',
6060 );
6161
Index: trunk/extensions/RecordAdmin/RecordAdmin.php
@@ -10,7 +10,7 @@
1111 * @author Siebrand Mazeland
1212 * @licence GNU General Public Licence 2.0 or later
1313 */
14 -define( 'RECORDADMIN_VERSION', '1.1.3, 2010-11-16' );
 14+define( 'RECORDADMIN_VERSION', '1.1.4, 2011-01-25' );
1515
1616 $dir = dirname( __FILE__ ) . '/';
1717 $wgExtensionMessagesFiles['RecordAdmin'] = $dir . 'RecordAdmin.i18n.php';

Status & tagging log