r74119 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74118‎ | r74119 | r74120 >
Date:22:45, 1 October 2010
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
alert for document.write issue
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.i18n.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialNoticeTemplate.php (modified) (history)
  • /trunk/extensions/CentralNotice/centralnotice.js (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php
@@ -132,6 +132,7 @@
133133 'centralnotice-no-allocation' => 'No banners allocated.',
134134 'centralnotice-allocation-description' => 'Banner allocation for $1.$2 in $3:',
135135 '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.",
136137
137138 'right-centralnotice-admin' => 'Manage central notices',
138139 'right-centralnotice-translate' => 'Translate central notices',
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php
@@ -25,6 +25,12 @@
2626 // Add style file to the output headers
2727 $wgOut->addExtensionStyle( "$wgScriptPath/extensions/CentralNotice/centralnotice.css" );
2828
 29+ // Add localized script error messages
 30+ $scriptVars = array(
 31+ 'documentWriteError' => wfMsg( 'centralnotice-documentwrite-error' )
 32+ );
 33+ $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) );
 34+
2935 // Add script file to the output headers
3036 $wgOut->addScriptFile( "$wgScriptPath/extensions/CentralNotice/centralnotice.js" );
3137
@@ -213,7 +219,7 @@
214220 // Build HTML
215221 $htmlOut = '';
216222 $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)' ) );
218224 $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-add-template' ) );
219225 $htmlOut .= Xml::hidden( 'wpMethod', 'addTemplate' );
220226 $htmlOut .= Xml::tags( 'p', null,
@@ -461,7 +467,7 @@
462468
463469 // Show edit form
464470 if ( $this->editable ) {
465 - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
 471+ $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post', 'onsubmit' => 'return validateBannerForm(this)' ) );
466472 $htmlOut .= Xml::hidden( 'wpMethod', 'editTemplate' );
467473 }
468474
Index: trunk/extensions/CentralNotice/centralnotice.js
@@ -1,4 +1,4 @@
2 -function selectLanguages(selectAll) {
 2+function selectLanguages( selectAll ) {
33 var selectBox = document.getElementById('project_languages[]');
44 var firstSelect = selectBox.options.length - 1;
55 for (var i = firstSelect; i >= 0; i--) {
@@ -46,6 +46,18 @@
4747 }
4848 bannerField.focus();
4949 }
 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+}
5062 // Handle revealing the geoMultiSelector when the geotargetted checkbox is checked
5163 ( function( $ ) {
5264 $(document).ready(function() {

Comments

#Comment by TheDJ (talk | contribs)   14:46, 2 October 2010

This will also trigger on document.writeln() btw. Also something that should probably be avoided, but not currently documented in this code.

#Comment by Kaldari (talk | contribs)   18:21, 2 October 2010

Yes, I wanted to trigger on both. I guess I should mention writeln in the alert as well.

Status & tagging log