r93801 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93800‎ | r93801 | r93802 >
Date:07:02, 3 August 2011
Author:nad
Status:deferred
Tags:
Comment:
make JS loading work witj 1.17 addModules but maintain backward campatibility with pre 1.17
Modified paths:
  • /trunk/extensions/RecordAdmin/RecordAdmin.php (modified) (history)
  • /trunk/extensions/RecordAdmin/RecordAdmin_body.php (modified) (history)
  • /trunk/extensions/RecordAdmin/recordadmin.js (added) (history)

Diff [purge]

Index: trunk/extensions/RecordAdmin/recordadmin.js
@@ -0,0 +1,25 @@
 2+window.raRecordForms = function () {
 3+ for( i = 0; i < window.forms.length; i++ ) {
 4+ var type = forms[i];
 5+ var form = document.getElementById( type + '-form' );
 6+ var tags = [ 'input', 'select', 'textarea' ];
 7+ for( j = 0; j < tags.length; j++ ) {
 8+ var inputs = form.getElementsByTagName( tags[j] );
 9+ for( k = 0; k < inputs.length; k++ ) {
 10+ var input = jQuery( inputs[k] );
 11+ if( input.attr('type') != 'checkbox' || input.attr('checked') ) {
 12+ var multi = input.val();
 13+ if( typeof( multi ) == 'object' ) multi = multi.join('\\n');
 14+ var key = type + ':' + inputs[k].getAttribute('name');
 15+ var hidden = jQuery( document.createElement( 'input' ) );
 16+ hidden.attr( 'name', key );
 17+ hidden.attr( 'type', 'hidden' );
 18+ hidden.val( multi );
 19+ jQuery( '#editform' ).append( hidden );
 20+ }
 21+ }
 22+ }
 23+ }
 24+};
 25+
 26+jQuery( '#editform' ).attr( 'onsubmit', 'raRecordForms()' );
Index: trunk/extensions/RecordAdmin/RecordAdmin_body.php
@@ -108,36 +108,20 @@
109109 $editPage->editFormTextTop = $tabset;
110110
111111 # JS to add an onSubmit method that adds the record forms contents to hidden values in the edit form
112 - $wgOut->addScript( "<script type='$wgJsMimeType'>
113 - function raRecordForms() {
114 - var forms = [ $jsFormsList ];
115 - for( i = 0; i < forms.length; i++ ) {
116 - var type = forms[i];
117 - var form = document.getElementById( type + '-form' );
118 - var tags = [ 'input', 'select', 'textarea' ];
119 - for( j = 0; j < tags.length; j++ ) {
120 - var inputs = form.getElementsByTagName( tags[j] );
121 - for( k = 0; k < inputs.length; k++ ) {
122 - var input = jQuery( inputs[k] );
123 - if( input.attr('type') != 'checkbox' || input.attr('checked') ) {
124 - var multi = input.val();
125 - if( typeof( multi ) == 'object' ) multi = multi.join('\\n');
126 - var key = type + ':' + inputs[k].getAttribute('name');
127 - var hidden = jQuery( document.createElement( 'input' ) );
128 - hidden.attr( 'name', key );
129 - hidden.attr( 'type', 'hidden' );
130 - hidden.val( multi );
131 - jQuery( '#editform' ).append( hidden );
132 - }
133 - }
134 - }
 112+ if( is_callable( array( $wgOut, 'addModules' ) ) ) {
 113+ $wgOut->addModules( 'ext.recordadmin' );
 114+ } else {
 115+ global $wgRecordAdminExtPath;
 116+ $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"$wgRecordAdminExtPath/recordadmin.js\"></script>" );
 117+ $wgOut->addScript( "<script type=\"$wgJsMimeType\">
 118+ function raAddRecordFormSubmit() {
 119+ jQuery( '#editform' ).attr( 'onsubmit', 'raRecordForms()' );
135120 }
136 - }
137 - function raAddToSubmit() {
138 - jQuery( '#editform' ).attr( 'onsubmit', 'raRecordForms()' );
139 - }
140 - addOnloadHook( raAddToSubmit );
141 - </script>" );
 121+ addOnloadHook( raAddRecordFormSubmit );</script>"
 122+ );
 123+ }
 124+ $wgOut->addScript( "<script type=\"$wgJsMimeType\">var forms = [ $jsFormsList ];</script>" );
 125+
142126 }
143127
144128
Index: trunk/extensions/RecordAdmin/RecordAdmin.php
@@ -10,8 +10,10 @@
1111 * @author Siebrand Mazeland
1212 * @licence GNU General Public Licence 2.0 or later
1313 */
14 -define( 'RECORDADMIN_VERSION', '1.2.10, 2011-08-01' );
 14+define( 'RECORDADMIN_VERSION', '1.3.0, 2011-08-03' );
1515
 16+$wgRecordAdminExtPath = preg_replace( "|^.*(/extensions/.*$)|", "$wgScriptPath$1", dirname( __FILE__ ) );
 17+
1618 $dir = dirname( __FILE__ ) . '/';
1719 $wgExtensionMessagesFiles['RecordAdmin'] = $dir . 'RecordAdmin.i18n.php';
1820 $wgExtensionAliasesFiles['RecordAdmin'] = $dir . 'RecordAdmin.alias.php';
@@ -35,7 +37,16 @@
3638
3739 $wgExtensionFunctions[] = 'wfSetupRecordAdmin';
3840 function wfSetupRecordAdmin() {
39 - global $wgRecordAdmin;
 41+ global $wgRecordAdmin, $wgResourceModules, $wgRecordAdminExtPath;
 42+
 43+ $wgResourceModules['ext.recordadmin'] = array(
 44+ 'scripts' => array( 'recordadmin.js' ),
 45+ 'styles' => array(),
 46+ 'dependencies' => array( 'jquery' ),
 47+ 'localBasePath' => dirname( __FILE__ ),
 48+ 'remoteExtPath' => $wgRecordAdminExtPath
 49+ );
 50+
4051 $wgRecordAdmin = new RecordAdmin();
4152 }
4253

Status & tagging log