r79597 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79596‎ | r79597 | r79598 >
Date:21:03, 4 January 2011
Author:krinkle
Status:deferred
Tags:
Comment:
adding initial version of ext.translate.langstats module
Modified paths:
  • /trunk/extensions/Translate/SpecialLanguageStats.php (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/js/translate.langstats.css (added) (history)
  • /trunk/extensions/Translate/js/translate.langstats.js (added) (history)

Diff [purge]

Index: trunk/extensions/Translate/SpecialLanguageStats.php
@@ -31,6 +31,9 @@
3232 $this->setHeaders();
3333 $this->outputHeader();
3434
 35+ if ( MW_SUPPORTS_RESOURCE_MODULES ) {
 36+ $wgOut->addModules( 'ext.translate.langstats' );
 37+ }
3538 $wgOut->addExtensionStyle( TranslateUtils::assetPath( 'Translate.css' ) );
3639
3740 // no UI when including()
Index: trunk/extensions/Translate/js/translate.langstats.css
@@ -0,0 +1,17 @@
 2+.mw-sp-langstats-toggleall {
 3+ text-align: right;
 4+}
 5+
 6+.mw-sp-langstats-toggle {
 7+ float: right;
 8+}
 9+
 10+.mw-sp-langstats-collapser,
 11+.mw-sp-langstats-collapser a {
 12+ cursor: n-resize;
 13+}
 14+
 15+.mw-sp-langstats-expander,
 16+.mw-sp-langstats-expander a {
 17+ cursor: s-resize;
 18+}
\ No newline at end of file
Property changes on: trunk/extensions/Translate/js/translate.langstats.css
___________________________________________________________________
Added: svn:eol-style
119 + native
Index: trunk/extensions/Translate/js/translate.langstats.js
@@ -0,0 +1,75 @@
 2+/**
 3+ * Collapsing script for Special:LanguageStats in MediaWiki Extension:Translate
 4+ * @author Krinkle <krinklemail (at) gmail (dot) com>
 5+ * @created January 3, 2011
 6+ * @license GPL v2, CC-BY-SA-3.0
 7+ */
 8+var MSGexpand = 'expand', MSGcollapse = 'collapse', MSGexpandall = 'expand all', MSGcollapseall = 'collapse all';
 9+jQuery( document ).ready( function() {
 10+ if ( mw.config.get( 'wgPageName' ) == 'Special:LanguageStats' ) {
 11+
 12+ var $translateTable = $( '.mw-sp-translate-table' ),
 13+ $metaRows = $( 'tr[data-ismeta=1]', $translateTable );
 14+
 15+ // Only do stuff if there are any meta group rows on this pages
 16+ if ( $metaRows.size() ) {
 17+
 18+ var $allChildRows = $( 'tr[data-parentgroups]', $translateTable ),
 19+ $toggleAllButton = $( '<span class="mw-sp-langstats-expander">[<a href="#" onclick="return false;">' + MSGexpandall + '</a>]</span>' ).click( function() {
 20+ var $el = $( this ),
 21+ $allToggles = $( '.mw-sp-langstats-toggle', $translateTable );
 22+ // Switch the state and toggle the rows
 23+ // and update the local toggles too
 24+ if ( $el.hasClass( 'mw-sp-langstats-expander' ) ) {
 25+ $allChildRows.fadeIn();
 26+ $el.add( $allToggles ).removeClass( 'mw-sp-langstats-expander' ).addClass( 'mw-sp-langstats-collapser' )
 27+ $el.find( '> a' ).text( MSGcollapseall );
 28+ $allToggles.find( '> a' ).text( MSGcollapse );
 29+ } else {
 30+ $allChildRows.fadeOut();
 31+ $el.add( $allToggles ).addClass( 'mw-sp-langstats-expander' ).removeClass( 'mw-sp-langstats-collapser' )
 32+ $el.find( '> a' ).text( MSGexpandall );
 33+ $allToggles.find( '> a' ).text( MSGexpand );
 34+ }
 35+ } );
 36+
 37+ // Initially hide them
 38+ $allChildRows.hide();
 39+
 40+ // Add the toggle-all button above the table
 41+ $( '<p class="mw-sp-langstats-toggleall"></p>' ).append( $toggleAllButton ).insertBefore( $translateTable );
 42+
 43+ $metaRows.each( function() {
 44+ // Get info and cache selectors
 45+ var $thisGroup = $(this),
 46+ thisGroupId = $thisGroup.attr( 'data-groupid' ),
 47+ $thisChildRows = $( 'tr[data-parentgroups~="' + thisGroupId + '"]', $translateTable );
 48+
 49+ // Only do the collapse stuff if this Meta-group actually has children on this page
 50+ if ( $thisChildRows.size() ) {
 51+
 52+ // Build toggle link
 53+ var $toggler = $( '<span class="mw-sp-langstats-toggle mw-sp-langstats-expander">[<a href="#" onclick="return false;">' + MSGexpand + '</a>]</span>' ).click( function() {
 54+ var $el = $( this );
 55+ // Switch the state and toggle the rows
 56+ if ( $el.hasClass( 'mw-sp-langstats-expander' ) ) {
 57+ $thisChildRows.fadeIn();
 58+ $el.removeClass( 'mw-sp-langstats-expander' ).addClass( 'mw-sp-langstats-collapser' )
 59+ .find( '> a' ).text( MSGcollapse );
 60+ } else {
 61+ $thisChildRows.fadeOut();
 62+ $el.addClass( 'mw-sp-langstats-expander' ).removeClass( 'mw-sp-langstats-collapser' )
 63+ .find( '> a' ).text( MSGexpand );
 64+ }
 65+ } );
 66+
 67+ // Add the toggle link to the first cell of the meta group table-row
 68+ $thisGroup.find( ' > td:first' ).append( $toggler );
 69+ }
 70+ } );
 71+ }
 72+ }
 73+} );
 74+// @TODO: Create the following messages "translate-expand-all" (new), "translate-collapse-all" (new), "translate-expand" ({{Identical|collapsible-expand}}) and "translate-collapse" ({{Identical|collapsible-collapse}})
 75+// @TODO: Load this script via ResourceLoader and pass the those 4 messages
 76+// @TODO: Replace hardcoded messages with mw.msg('');
\ No newline at end of file
Property changes on: trunk/extensions/Translate/js/translate.langstats.js
___________________________________________________________________
Added: svn:eol-style
177 + native
Index: trunk/extensions/Translate/Translate.php
@@ -125,6 +125,12 @@
126126 'localBasePath' => dirname( __FILE__ ),
127127 'remoteExtPath' => 'Translate'
128128 );
 129+$wgResourceModules['ext.translate.langstats'] = array(
 130+ 'scripts' => 'js/translate.langstats.js',
 131+ 'styles' => 'js/translate.langstats.css',
 132+ 'localBasePath' => dirname( __FILE__ ),
 133+ 'remoteExtPath' => 'Translate',
 134+);
129135
130136 /** @endcond */
131137

Follow-up revisions

RevisionCommit summaryAuthorDate
r79603- No longer needed if-check...krinkle21:45, 4 January 2011

Status & tagging log