Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php |
— | — | @@ -132,6 +132,7 @@ |
133 | 133 | 'centralnotice-no-allocation' => 'No banners allocated.', |
134 | 134 | 'centralnotice-allocation-description' => 'Banner allocation for $1.$2 in $3:', |
135 | 135 | 'centralnotice-percentage' => 'Percentage', |
| 136 | + 'centralnotice-documentwrite-error' => "document.write() cannot be used within a banner.\nSee http://meta.wikimedia.org/wiki/Help:CentralNotice for more information.", |
136 | 137 | |
137 | 138 | 'right-centralnotice-admin' => 'Manage central notices', |
138 | 139 | 'right-centralnotice-translate' => 'Translate central notices', |
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php |
— | — | @@ -25,6 +25,12 @@ |
26 | 26 | // Add style file to the output headers |
27 | 27 | $wgOut->addExtensionStyle( "$wgScriptPath/extensions/CentralNotice/centralnotice.css" ); |
28 | 28 | |
| 29 | + // Add localized script error messages |
| 30 | + $scriptVars = array( |
| 31 | + 'documentWriteError' => wfMsg( 'centralnotice-documentwrite-error' ) |
| 32 | + ); |
| 33 | + $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) ); |
| 34 | + |
29 | 35 | // Add script file to the output headers |
30 | 36 | $wgOut->addScriptFile( "$wgScriptPath/extensions/CentralNotice/centralnotice.js" ); |
31 | 37 | |
— | — | @@ -213,7 +219,7 @@ |
214 | 220 | // Build HTML |
215 | 221 | $htmlOut = ''; |
216 | 222 | $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) ); |
217 | | - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
| 223 | + $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post', 'onsubmit' => 'return validateBannerForm(this)' ) ); |
218 | 224 | $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-add-template' ) ); |
219 | 225 | $htmlOut .= Xml::hidden( 'wpMethod', 'addTemplate' ); |
220 | 226 | $htmlOut .= Xml::tags( 'p', null, |
— | — | @@ -461,7 +467,7 @@ |
462 | 468 | |
463 | 469 | // Show edit form |
464 | 470 | if ( $this->editable ) { |
465 | | - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
| 471 | + $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post', 'onsubmit' => 'return validateBannerForm(this)' ) ); |
466 | 472 | $htmlOut .= Xml::hidden( 'wpMethod', 'editTemplate' ); |
467 | 473 | } |
468 | 474 | |
Index: trunk/extensions/CentralNotice/centralnotice.js |
— | — | @@ -1,4 +1,4 @@ |
2 | | -function selectLanguages(selectAll) { |
| 2 | +function selectLanguages( selectAll ) { |
3 | 3 | var selectBox = document.getElementById('project_languages[]'); |
4 | 4 | var firstSelect = selectBox.options.length - 1; |
5 | 5 | for (var i = firstSelect; i >= 0; i--) { |
— | — | @@ -46,6 +46,18 @@ |
47 | 47 | } |
48 | 48 | bannerField.focus(); |
49 | 49 | } |
| 50 | +function validateBannerForm( form ) { |
| 51 | + var output = ''; |
| 52 | + var pos = form.templateBody.value.indexOf("document.write"); |
| 53 | + if( pos > -1 ) { |
| 54 | + output += documentWriteError + '\n'; |
| 55 | + } |
| 56 | + if( output ) { |
| 57 | + alert( output ); |
| 58 | + return false; |
| 59 | + } |
| 60 | + return true; |
| 61 | +} |
50 | 62 | // Handle revealing the geoMultiSelector when the geotargetted checkbox is checked |
51 | 63 | ( function( $ ) { |
52 | 64 | $(document).ready(function() { |