http://www.mediawiki.org/wiki/Special:Code/MediaWiki/70609
Revision: 70609 Author: kaldari Date: 2010-08-06 23:52:29 +0000 (Fri, 06 Aug 2010) Log Message: ----------- adding campaign status indication, beginnings of banner component insertion Modified Paths: -------------- trunk/extensions/CentralNotice/CentralNotice.i18n.php trunk/extensions/CentralNotice/SpecialCentralNotice.php trunk/extensions/CentralNotice/SpecialNoticeTemplate.php trunk/extensions/CentralNotice/centralnotice.css Added Paths: ----------- trunk/extensions/CentralNotice/centralnotice.js trunk/extensions/CentralNotice/down-arrow.png trunk/extensions/CentralNotice/up-arrow.png Removed Paths: ------------- trunk/extensions/CentralNotice/arrow.png Modified: trunk/extensions/CentralNotice/CentralNotice.i18n.php =================================================================== --- trunk/extensions/CentralNotice/CentralNotice.i18n.php 2010-08-06 23:44:00 UTC (rev 70608) +++ trunk/extensions/CentralNotice/CentralNotice.i18n.php 2010-08-06 23:52:29 UTC (rev 70609) @@ -105,6 +105,9 @@ 'centralnotice-donate-button' => 'Donate button', 'centralnotice-expanded-banner' => 'Expanded banner', 'centralnotice-collapsed-banner' => 'Collapsed banner', + 'centralnotice-banner-type' => 'Banner type', + 'centralnotice-banner-hidable' => 'Static/Hidable', + 'centralnotice-banner-collapsable' => 'Collapsable', 'right-centralnotice-admin' => 'Manage central notices', 'right-centralnotice-translate' => 'Translate central notices', Modified: trunk/extensions/CentralNotice/SpecialCentralNotice.php =================================================================== --- trunk/extensions/CentralNotice/SpecialCentralNotice.php 2010-08-06 23:44:00 UTC (rev 70608) +++ trunk/extensions/CentralNotice/SpecialCentralNotice.php 2010-08-06 23:52:29 UTC (rev 70609) @@ -31,6 +31,9 @@ // Add style file to the output headers $wgOut->addExtensionStyle( "$wgScriptPath/extensions/CentralNotice/centralnotice.css" ); + // Add script file to the output headers + $wgOut->addScriptFile( "$wgScriptPath/extensions/CentralNotice/centralnotice.js" ); + // Check permissions $this->editable = $wgUser->isAllowed( 'centralnotice-admin' ); @@ -287,12 +290,15 @@ return $notices; } - function tableRow( $fields, $element = 'td' ) { + /** + * Build a table row. Needed since Xml::buildTableRow escapes all HTML. + */ + function tableRow( $fields, $element = 'td', $attribs = array() ) { $cells = array(); foreach ( $fields as $field ) { $cells[] = Xml::tags( $element, array(), $field ); } - return Xml::tags( 'tr', array(), implode( "\n", $cells ) ) . "\n"; + return Xml::tags( 'tr', $attribs, implode( "\n", $cells ) ) . "\n"; } function dateSelector( $prefix, $timestamp = null ) { @@ -516,8 +522,14 @@ $fields[] = Xml::check( 'removeNotices[]', false, array( 'value' => $row->not_name ) ); } - - $htmlOut .= $this->tableRow( $fields ); + + // If campaign is currently active, set special class on table row. + $attribs = array(); + if ( wfTimestamp() > wfTimestamp( TS_UNIX , $row->not_start ) && wfTimestamp() < wfTimestamp( TS_UNIX , $row->not_end ) && $row->not_enabled == '1' ) { + $attribs = array( 'class' => 'cn-active-campaign' ); + } + + $htmlOut .= $this->tableRow( $fields, 'td', $attribs ); } // End table of campaigns $htmlOut .= Xml::closeElement( 'table' ); @@ -1328,26 +1340,7 @@ foreach( $languages as $code => $name ) { $options .= Xml::option( "$code - $name", $code, in_array( $code, $selected ) ) . "\n"; } - $htmlOut = " -<script type=\"text/javascript\"> -function selectLanguages(selectAll) { - var selectBox = document.getElementById(\"project_languages[]\"); - var firstSelect = selectBox.options.length - 1; - for (var i = firstSelect; i >= 0; i--) { - selectBox.options[i].selected = selectAll; - } -} -function top10Languages() { - var selectBox = document.getElementById(\"project_languages[]\"); - var top10 = new Array('en','de','fr','it','pt','ja','es','pl','ru','nl'); - for (var i = 0; i < selectBox.options.length; i++) { - var lang = selectBox.options[i].value; - if (top10.toString().indexOf(lang)!==-1) { - selectBox.options[i].selected = true; - } - } -} -</script>"; + $htmlOut = ''; if ( $this->editable ) { $htmlOut .= Xml::tags( 'select', array( 'multiple' => 'multiple', 'size' => 4, 'id' => 'project_languages[]', 'name' => 'project_languages[]' ), @@ -1355,7 +1348,7 @@ ); $htmlOut .= Xml::tags( 'div', array( 'style' => 'margin-top: 0.2em;' ), - '<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>' + '<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>' ); } else { $htmlOut .= Xml::tags( 'select', Modified: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php =================================================================== --- trunk/extensions/CentralNotice/SpecialNoticeTemplate.php 2010-08-06 23:44:00 UTC (rev 70608) +++ trunk/extensions/CentralNotice/SpecialNoticeTemplate.php 2010-08-06 23:52:29 UTC (rev 70609) @@ -26,6 +26,9 @@ // Add style file to the output headers $wgOut->addExtensionStyle( "$wgScriptPath/extensions/CentralNotice/centralnotice.css" ); + + // Add script file to the output headers + $wgOut->addScriptFile( "$wgScriptPath/extensions/CentralNotice/centralnotice.js" ); // Check permissions $this->editable = $wgUser->isAllowed( 'centralnotice-admin' ); @@ -179,7 +182,8 @@ * Show "Add a banner" interface */ function showAdd() { - global $wgOut, $wgUser; + global $wgOut, $wgUser, $wgScriptPath; + $scriptPath = "$wgScriptPath/extensions/CentralNotice"; // Build HTML $htmlOut = ''; @@ -188,17 +192,15 @@ $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-add-template' ) ); $htmlOut .= Xml::hidden( 'wpMethod', 'addTemplate' ); $htmlOut .= Xml::tags( 'p', null, - Xml::inputLabel( - wfMsg( 'centralnotice-template-name' ) . ":", - 'templateName', - 'templateName', - 25 - ) + Xml::inputLabel( wfMsg( 'centralnotice-template-name' ) . ":", 'templateName', 'templateName', 25 ) ); $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-template' ) ); - $htmlOut .= Xml::tags( 'p', null, - Xml::textarea( 'templateBody', '', 60, 20 ) + $htmlOut .= wfMsg( 'centralnotice-edit-template-summary' ); + $htmlOut .= Xml::tags( 'div', + array( 'style' => 'margin-bottom: 0.2em;' ), + '<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>' ); + $htmlOut .= Xml::textarea( 'templateBody', '', 60, 20 ); $htmlOut .= Xml::closeElement( 'fieldset' ); $htmlOut .= Xml::hidden( 'authtoken', $wgUser->editToken() ); Deleted: trunk/extensions/CentralNotice/arrow.png =================================================================== (Binary files differ) Modified: trunk/extensions/CentralNotice/centralnotice.css =================================================================== --- trunk/extensions/CentralNotice/centralnotice.css 2010-08-06 23:44:00 UTC (rev 70608) +++ trunk/extensions/CentralNotice/centralnotice.css 2010-08-06 23:52:29 UTC (rev 70609) @@ -28,6 +28,9 @@ #preferences fieldset.prefsection div.cn-error { margin:0; } +#preferences table tr.cn-active-campaign { + background-color: #ddffdd; +} #preferences div.cn-buttons { padding:1em; } Added: trunk/extensions/CentralNotice/centralnotice.js =================================================================== --- trunk/extensions/CentralNotice/centralnotice.js (rev 0) +++ trunk/extensions/CentralNotice/centralnotice.js 2010-08-06 23:52:29 UTC (rev 70609) @@ -0,0 +1,43 @@ +function selectLanguages(selectAll) { + var selectBox = document.getElementById('project_languages[]'); + var firstSelect = selectBox.options.length - 1; + for (var i = firstSelect; i >= 0; i--) { + selectBox.options[i].selected = selectAll; + } +} +function top10Languages() { + var selectBox = document.getElementById('project_languages[]'); + var top10 = new Array('en','de','fr','it','pt','ja','es','pl','ru','nl'); + for (var i = 0; i < selectBox.options.length; i++) { + var lang = selectBox.options[i].value; + if (top10.toString().indexOf(lang)!==-1) { + selectBox.options[i].selected = true; + } + } +} +function insertButton( buttonType ) { + var bannerField = document.getElementById('templateBody'); + switch( buttonType ) { + case 'translate': + var buttonValue = '[<a href="http://meta.wikimedia.org/wiki/CentralNotice">{{int:centralnotice-shared-help-translate}}</a>]'; + break; + case 'hide': + var buttonValue = '[<a href="#" onclick="toggleNotice();return false">{{int:centralnotice-shared-hide}}</a>]'; + break; + } + if (document.selection) { + // IE support + bannerField.focus(); + sel = document.selection.createRange(); + sel.text = buttonValue; + } else if (bannerField.selectionStart || bannerField.selectionStart == '0') { + // Mozilla support + var startPos = bannerField.selectionStart; + var endPos = bannerField.selectionEnd; + bannerField.value = bannerField.value.substring(0, startPos) + + buttonValue + + bannerField.value.substring(endPos, bannerField.value.length); + } else { + bannerField.value += buttonValue; + } +} \ No newline at end of file Added: trunk/extensions/CentralNotice/down-arrow.png =================================================================== (Binary files differ) Property changes on: trunk/extensions/CentralNotice/down-arrow.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/extensions/CentralNotice/up-arrow.png =================================================================== (Binary files differ) Property changes on: trunk/extensions/CentralNotice/up-arrow.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs