Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php |
— | — | @@ -52,39 +52,49 @@ |
53 | 53 | */ |
54 | 54 | function onEditPage( $editPage ) { |
55 | 55 | 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>"; |
62 | 56 | |
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 ); |
73 | 70 | } |
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 | + } |
80 | 72 | } |
| 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 | + |
81 | 88 | return true; |
82 | 89 | } |
83 | 90 | |
84 | 91 | |
85 | 92 | /** |
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 |
87 | 94 | */ |
88 | 95 | function onArticleSave( &$article, &$user, &$text ) { |
| 96 | + |
| 97 | + # TODO |
| 98 | + |
89 | 99 | return true; |
90 | 100 | } |
91 | 101 | |
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.0.1, 2010-09-20' ); |
| 14 | +define( 'RECORDADMIN_VERSION', '1.0.2, 2010-09-20' ); |
15 | 15 | |
16 | 16 | $dir = dirname( __FILE__ ) . '/'; |
17 | 17 | $wgExtensionMessagesFiles['RecordAdmin'] = $dir . 'RecordAdmin.i18n.php'; |