r73354 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73353‎ | r73354 | r73355 >
Date:00:11, 20 September 2010
Author:nad
Status:deferred
Tags:
Comment:
change page edit so that any templates that have forms are removed and rendered in their own form instead of in the wikitext
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
@@ -52,39 +52,49 @@
5353 */
5454 function onEditPage( $editPage ) {
5555 global $wgOut;
56 - $type = false;
57 - if( $type ) {
58 - $this->preProcessForm( $type );
59 - $this->examineForm();
60 - $this->populateForm( array() );
61 - $editPage->editFormTextTop = "<form class=\"{$type}-record recordadmin\">$this->form</form>";
6256
63 - # Add the forms from QS:default and RA::templates to divs
64 - # - since the forms are being rendered here they should include values (from current state then preload)
65 - # - since these are added, they should be removed from the text at this point not in JS
66 -
67 - # Add the JS that converts the divs into a single form
68 - $wgOut->addScript( "<script>
69 - var forms = document.getElementById('ra-editforms');
70 - var form = document.getElementById('editform');
71 - for( i in forms) {
72 - form.innerHTML = form.innerHTML + '<fieldset>' + i.innerHTML + '</fieldset>';
 57+ # Extract each of the top-level template calls in the content that have associated forms
 58+ # - note multiple records are now allowed in an article, but only one of each type
 59+ $records = array();
 60+ $content = $editPage->getContent();
 61+ foreach( self::examineBraces( $content ) as $brace ) {
 62+ if( $brace['DEPTH'] == 2 ) {
 63+ $name = $brace['NAME'];
 64+ $form = Title::newFromText( $name, NS_FORM );
 65+ if( $form->exists() ) {
 66+ $offset = $brace['OFFSET'];
 67+ $length = $brace['LENGTH'];
 68+ $records[$name] = substr( $content, $offset, $length );
 69+ $content = substr_replace( $content, str_repeat( "\x07", $length ), $offset, $length );
7370 }
74 - </script>");
75 -
76 - # Allow tabset to execute if exists
77 -
78 - # NOTE: The form now submits all the data in one go so no need to rebuild into wikitext
79 - # - but therefore the onsave hook is needed to build the wikitext at that point instead
 71+ }
8072 }
 73+
 74+ # If any were found, remove them from the textbox and render their forms instead
 75+ if( count( $records ) > 0 ) {
 76+ $editPage->textbox1 = str_replace( "\x07", "", $content );
 77+ foreach( $records as $type => $record ) {
 78+ $this->preProcessForm( $type );
 79+ $this->examineForm();
 80+ $this->populateForm( $this->valuesFromText( $record ) );
 81+ $editPage->editFormTextTop = "<form class=\"{$type}-record recordadmin\">$this->form</form>";
 82+ }
 83+
 84+ # TODO: JS needs to be added so that the record form's values are posted with the edit form submission
 85+
 86+ }
 87+
8188 return true;
8289 }
8390
8491
8592 /**
86 - * Incorprate any posted form data into the article wikitext before saving
 93+ * Incorprate any posted record form's data into the article wikitext before saving
8794 */
8895 function onArticleSave( &$article, &$user, &$text ) {
 96+
 97+ # TODO
 98+
8999 return true;
90100 }
91101
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.0.1, 2010-09-20' );
 14+define( 'RECORDADMIN_VERSION', '1.0.2, 2010-09-20' );
1515
1616 $dir = dirname( __FILE__ ) . '/';
1717 $wgExtensionMessagesFiles['RecordAdmin'] = $dir . 'RecordAdmin.i18n.php';

Status & tagging log