r70609 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70608‎ | r70609 | r70610 >
Date:23:52, 6 August 2010
Author:kaldari
Status:ok
Tags:
Comment:
adding campaign status indication, beginnings of banner component insertion
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.i18n.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialNoticeTemplate.php (modified) (history)
  • /trunk/extensions/CentralNotice/arrow.png (deleted) (history)
  • /trunk/extensions/CentralNotice/centralnotice.css (modified) (history)
  • /trunk/extensions/CentralNotice/centralnotice.js (added) (history)
  • /trunk/extensions/CentralNotice/down-arrow.png (added) (history)
  • /trunk/extensions/CentralNotice/up-arrow.png (added) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/arrow.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -31,6 +31,9 @@
3232 // Add style file to the output headers
3333 $wgOut->addExtensionStyle( "$wgScriptPath/extensions/CentralNotice/centralnotice.css" );
3434
 35+ // Add script file to the output headers
 36+ $wgOut->addScriptFile( "$wgScriptPath/extensions/CentralNotice/centralnotice.js" );
 37+
3538 // Check permissions
3639 $this->editable = $wgUser->isAllowed( 'centralnotice-admin' );
3740
@@ -287,12 +290,15 @@
288291 return $notices;
289292 }
290293
291 - function tableRow( $fields, $element = 'td' ) {
 294+ /**
 295+ * Build a table row. Needed since Xml::buildTableRow escapes all HTML.
 296+ */
 297+ function tableRow( $fields, $element = 'td', $attribs = array() ) {
292298 $cells = array();
293299 foreach ( $fields as $field ) {
294300 $cells[] = Xml::tags( $element, array(), $field );
295301 }
296 - return Xml::tags( 'tr', array(), implode( "\n", $cells ) ) . "\n";
 302+ return Xml::tags( 'tr', $attribs, implode( "\n", $cells ) ) . "\n";
297303 }
298304
299305 function dateSelector( $prefix, $timestamp = null ) {
@@ -516,8 +522,14 @@
517523 $fields[] = Xml::check( 'removeNotices[]', false,
518524 array( 'value' => $row->not_name ) );
519525 }
520 -
521 - $htmlOut .= $this->tableRow( $fields );
 526+
 527+ // If campaign is currently active, set special class on table row.
 528+ $attribs = array();
 529+ if ( wfTimestamp() > wfTimestamp( TS_UNIX , $row->not_start ) && wfTimestamp() < wfTimestamp( TS_UNIX , $row->not_end ) && $row->not_enabled == '1' ) {
 530+ $attribs = array( 'class' => 'cn-active-campaign' );
 531+ }
 532+
 533+ $htmlOut .= $this->tableRow( $fields, 'td', $attribs );
522534 }
523535 // End table of campaigns
524536 $htmlOut .= Xml::closeElement( 'table' );
@@ -1328,26 +1340,7 @@
13291341 foreach( $languages as $code => $name ) {
13301342 $options .= Xml::option( "$code - $name", $code, in_array( $code, $selected ) ) . "\n";
13311343 }
1332 - $htmlOut = "
1333 -<script type=\"text/javascript\">
1334 -function selectLanguages(selectAll) {
1335 - var selectBox = document.getElementById(\"project_languages[]\");
1336 - var firstSelect = selectBox.options.length - 1;
1337 - for (var i = firstSelect; i >= 0; i--) {
1338 - selectBox.options[i].selected = selectAll;
1339 - }
1340 -}
1341 -function top10Languages() {
1342 - var selectBox = document.getElementById(\"project_languages[]\");
1343 - var top10 = new Array('en','de','fr','it','pt','ja','es','pl','ru','nl');
1344 - for (var i = 0; i < selectBox.options.length; i++) {
1345 - var lang = selectBox.options[i].value;
1346 - if (top10.toString().indexOf(lang)!==-1) {
1347 - selectBox.options[i].selected = true;
1348 - }
1349 - }
1350 -}
1351 -</script>";
 1344+ $htmlOut = '';
13521345 if ( $this->editable ) {
13531346 $htmlOut .= Xml::tags( 'select',
13541347 array( 'multiple' => 'multiple', 'size' => 4, 'id' => 'project_languages[]', 'name' => 'project_languages[]' ),
@@ -1355,7 +1348,7 @@
13561349 );
13571350 $htmlOut .= Xml::tags( 'div',
13581351 array( 'style' => 'margin-top: 0.2em;' ),
1359 - '<img src="'.$scriptPath.'/arrow.png" style="vertical-align:baseline;"/>' . wfMsg( 'centralnotice-select' ) . ': <a href="#" onclick="selectLanguages(true);return false;">' . wfMsg( 'powersearch-toggleall' ) . '</a>, <a href="#" onclick="selectLanguages(false);return false;">' . wfMsg( 'powersearch-togglenone' ) . '</a>, <a href="#" onclick="top10Languages();return false;">' . wfMsg( 'centralnotice-top-ten-languages' ) . '</a>'
 1352+ '<img src="'.$scriptPath.'/up-arrow.png" style="vertical-align:baseline;"/>' . wfMsg( 'centralnotice-select' ) . ': <a href="#" onclick="selectLanguages(true);return false;">' . wfMsg( 'powersearch-toggleall' ) . '</a>, <a href="#" onclick="selectLanguages(false);return false;">' . wfMsg( 'powersearch-togglenone' ) . '</a>, <a href="#" onclick="top10Languages();return false;">' . wfMsg( 'centralnotice-top-ten-languages' ) . '</a>'
13601353 );
13611354 } else {
13621355 $htmlOut .= Xml::tags( 'select',
Index: trunk/extensions/CentralNotice/centralnotice.css
@@ -28,6 +28,9 @@
2929 #preferences fieldset.prefsection div.cn-error {
3030 margin:0;
3131 }
 32+#preferences table tr.cn-active-campaign {
 33+ background-color: #ddffdd;
 34+}
3235 #preferences div.cn-buttons {
3336 padding:1em;
3437 }
Index: trunk/extensions/CentralNotice/down-arrow.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: trunk/extensions/CentralNotice/down-arrow.png
___________________________________________________________________
Added: svn:mime-type
3538 + application/octet-stream
Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php
@@ -105,6 +105,9 @@
106106 'centralnotice-donate-button' => 'Donate button',
107107 'centralnotice-expanded-banner' => 'Expanded banner',
108108 'centralnotice-collapsed-banner' => 'Collapsed banner',
 109+ 'centralnotice-banner-type' => 'Banner type',
 110+ 'centralnotice-banner-hidable' => 'Static/Hidable',
 111+ 'centralnotice-banner-collapsable' => 'Collapsable',
109112
110113 'right-centralnotice-admin' => 'Manage central notices',
111114 'right-centralnotice-translate' => 'Translate central notices',
Index: trunk/extensions/CentralNotice/up-arrow.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: trunk/extensions/CentralNotice/up-arrow.png
___________________________________________________________________
Added: svn:mime-type
112115 + application/octet-stream
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php
@@ -26,6 +26,9 @@
2727
2828 // Add style file to the output headers
2929 $wgOut->addExtensionStyle( "$wgScriptPath/extensions/CentralNotice/centralnotice.css" );
 30+
 31+ // Add script file to the output headers
 32+ $wgOut->addScriptFile( "$wgScriptPath/extensions/CentralNotice/centralnotice.js" );
3033
3134 // Check permissions
3235 $this->editable = $wgUser->isAllowed( 'centralnotice-admin' );
@@ -179,7 +182,8 @@
180183 * Show "Add a banner" interface
181184 */
182185 function showAdd() {
183 - global $wgOut, $wgUser;
 186+ global $wgOut, $wgUser, $wgScriptPath;
 187+ $scriptPath = "$wgScriptPath/extensions/CentralNotice";
184188
185189 // Build HTML
186190 $htmlOut = '';
@@ -188,17 +192,15 @@
189193 $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-add-template' ) );
190194 $htmlOut .= Xml::hidden( 'wpMethod', 'addTemplate' );
191195 $htmlOut .= Xml::tags( 'p', null,
192 - Xml::inputLabel(
193 - wfMsg( 'centralnotice-template-name' ) . ":",
194 - 'templateName',
195 - 'templateName',
196 - 25
197 - )
 196+ Xml::inputLabel( wfMsg( 'centralnotice-template-name' ) . ":", 'templateName', 'templateName', 25 )
198197 );
199198 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-template' ) );
200 - $htmlOut .= Xml::tags( 'p', null,
201 - Xml::textarea( 'templateBody', '', 60, 20 )
 199+ $htmlOut .= wfMsg( 'centralnotice-edit-template-summary' );
 200+ $htmlOut .= Xml::tags( 'div',
 201+ array( 'style' => 'margin-bottom: 0.2em;' ),
 202+ '<img src="'.$scriptPath.'/down-arrow.png" style="vertical-align:baseline;"/>' . wfMsg( 'centralnotice-insert' ) . ': <a href="#" onclick="insertButton(\'hide\');return false;">' . wfMsg( 'centralnotice-hide-button' ) . '</a>, <a href="#" onclick="insertButton(\'translate\');return false;">' . wfMsg( 'centralnotice-translate-button' ) . '</a>'
202203 );
 204+ $htmlOut .= Xml::textarea( 'templateBody', '', 60, 20 );
203205 $htmlOut .= Xml::closeElement( 'fieldset' );
204206 $htmlOut .= Xml::hidden( 'authtoken', $wgUser->editToken() );
205207
Index: trunk/extensions/CentralNotice/centralnotice.js
@@ -0,0 +1,43 @@
 2+function selectLanguages(selectAll) {
 3+ var selectBox = document.getElementById('project_languages[]');
 4+ var firstSelect = selectBox.options.length - 1;
 5+ for (var i = firstSelect; i >= 0; i--) {
 6+ selectBox.options[i].selected = selectAll;
 7+ }
 8+}
 9+function top10Languages() {
 10+ var selectBox = document.getElementById('project_languages[]');
 11+ var top10 = new Array('en','de','fr','it','pt','ja','es','pl','ru','nl');
 12+ for (var i = 0; i < selectBox.options.length; i++) {
 13+ var lang = selectBox.options[i].value;
 14+ if (top10.toString().indexOf(lang)!==-1) {
 15+ selectBox.options[i].selected = true;
 16+ }
 17+ }
 18+}
 19+function insertButton( buttonType ) {
 20+ var bannerField = document.getElementById('templateBody');
 21+ switch( buttonType ) {
 22+ case 'translate':
 23+ var buttonValue = '[<a href="http://meta.wikimedia.org/wiki/CentralNotice">{{int:centralnotice-shared-help-translate}}</a>]';
 24+ break;
 25+ case 'hide':
 26+ var buttonValue = '[<a href="#" onclick="toggleNotice();return false">{{int:centralnotice-shared-hide}}</a>]';
 27+ break;
 28+ }
 29+ if (document.selection) {
 30+ // IE support
 31+ bannerField.focus();
 32+ sel = document.selection.createRange();
 33+ sel.text = buttonValue;
 34+ } else if (bannerField.selectionStart || bannerField.selectionStart == '0') {
 35+ // Mozilla support
 36+ var startPos = bannerField.selectionStart;
 37+ var endPos = bannerField.selectionEnd;
 38+ bannerField.value = bannerField.value.substring(0, startPos)
 39+ + buttonValue
 40+ + bannerField.value.substring(endPos, bannerField.value.length);
 41+ } else {
 42+ bannerField.value += buttonValue;
 43+ }
 44+}
\ No newline at end of file

Status & tagging log