package votorola.s.gwt.pollwiki; // Copyright 2012-2013, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import com.google.gwt.core.client.*; import com.google.gwt.regexp.shared.RegExp; import com.google.gwt.user.client.Window; import java.util.regex.*; import votorola.a.position.*; import votorola.a.voter.*; import votorola.a.web.gwt.*; import votorola.g.*; import votorola.g.web.gwt.*; import votorola.s.gwt.mediawiki.*; import votorola.s.gwt.stage.*; /** The GWT entry module for embedding the Crossforum Theatre {@linkplain * votorola.s.gwt.stage.Stage stage} in pollwiki pages. An instance of this class is * automatically constructed and invoked per module definition PollwikiIn.gwt.xml. * It constructs a {@linkplain votorola.s.gwt.stage.StageV stage view} and ordinarily * inserts it as the first child of the body element, as detailed for * MediaWikiIn.{@linkplain MediaWikiIn#insertStageVTop(JavaScriptObject) * insertStageVTop}. To install it add the following to pollwiki page * MediaWiki:Common.js:
  // Crossforum Theatre stage.
  *  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  *  // module.css and gwt.js must load before boot script nocache.js
  *  // http://reluk.ca/project/votorola/_/javadoc/votorola/s/gwt/pollwiki/PollwikiIn.html
  *
  *    if( $.client.profile().name != 'msie' ) // all but IE [1]
  *    {
  *        var context = '{@linkplain App#getServletContextLocation() CONTEXT}';
  *        document.write( "<link href='" + context // [2]
  *          + "/mediawiki/module.css' rel='stylesheet' type='text/css'/>" );
  *        document.write( "<script src='" + context // [3]
  *          + "/w/publicConfig/gwt.js' type='text/javascript'></script>" );
  *        document.write( "<script src='" + context // [3]
  *          + "/votorola.s.gwt.pollwiki.PollwikiIn/votorola.s.gwt.pollwiki.PollwikiIn.nocache.js'"
  *          + " type='text/javascript'></script>" );
  *    }
  *
  *  //
  *  // NOTES
  *  //
  *  //   [1] IE excluded by conditional compilation in MediaWiki 16 and earlier, thus:
  *  //
  *  //          /*@cc_on @if( false ) @*/
  *  //          /*@end @*/
  *  //
  *  //       And by JQuery in MediaWiki 17 and later, thus:
  *  //
  *  //          if( $.client.profile().name != 'msie' )
  *  //
  *  //   [2] For MediaWiki 16 and earlier, would ordinarily use: importStylesheetURI( URL )
  *  //       For MediaWiki 17 and later: mw.loader.load( URL, 'text/css' )
  *  //       http://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_%28users%29
  *  //
  *  //       But instead write to ensure CSS link element precedes script element, else layout
  *  //       may be unstable: http://mail.zelea.com/list/votorola/2012-November/001540.html
  *  //
  *  //   [3] Scripts might instead be inject asynchronously using MediaWiki's mw.loader or
  *  //       importScriptURI.  We are no longer using the old cross-site linker ('xs') that
  *  //       writes to the document.  But asynchronous injection has not been tested yet.
  *  //
* * *

Working examples

*/ public final class PollwikiIn extends TheatreInitializer0 implements EntryPointS { // - E n t r y - P o i n t ------------------------------------------------------------ public final void onModuleLoad() { MediaWikiIn.insertStageVTop( (JavaScriptObject)WindowX.js()._get("voGWTConfig") ); EntryPointS.U.schedule( PollwikiIn.this ); EntryPointS.U.execute(); // because all modules are now loaded Stage.i().addInitializer( PollwikiIn.this ); // auto-removed // Set username. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - final JavaScriptObject window = WindowX.js(); final String wgUserName = window._get( "wgUserName" ); if( wgUserName != null && !wgUserName.equals("null") ) { // IDPair.toInternetAddress( wgUserName ); // test for proper mailish username //// that is too difficult to emulate under GWT. Only admin logs in under //// non-username anyway, and only rarely. Should be OK. // App.setUsername( IDPair.normalUsername( wgUserName )); //// always canonical, Mailish Username extension's login guarantees it App.setUsername( wgUserName ); } } // - S c h e d u l e r . S c h e d u l e d - C o m m a n d ---------------------------- public void execute() { StageV.i().initEmbeddedDisplay(); } // - T h e a t r e - I n i t i a l i z e r -------------------------------------------- public @Override void initFrom( final Stage stage, boolean _isReferencePending ) { initAbsolutes( stage, /*isRestore*/true ); } public @Override void initTo( final Stage stage ) { initAbsolutes( stage, /*isRestore*/false ); } public @Override void initTo( final Stage stage, TheatrePage _referrer ) { initAbsolutes( stage, /*isRestore*/false ); } //// P r i v a t e /////////////////////////////////////////////////////////////////////// /** Effects initialization that is absolutely required, whether the stage is being * restored (initFrom) or not (initTo). */ private void initAbsolutes( final Stage stage, final boolean isRestore ) { // Set default stage properties to match page. Page categories are editable so // their values may differ from those originally set and stored and now restored. final JavaScriptObject window = WindowX.js(); final JsArrayString categories = window._get( "wgCategories" ); PageType pageType = PageType.other; // till proven otherwise if( categories != null ) for( int c = categories.length() - 1; c >= 0; --c ) { final String cat = categories.get( c ); if( "Position".equals(cat) || "Pipe".equals(cat) || cat.endsWith(" pipe") ) // Component pipe, Office pipe, Supercomponent pipe, etc. { pageType = PageType.position; break; } else if( "Poll".equals( cat )) { pageType = PageType.poll; break; } } if( pageType == PageType.poll ) { final String pageName = window._get( "wgPageName" ); Stage.setDefaultPollName( pageName ); } else if( "User".equals( window._get( "wgCanonicalNamespace" ))) { final String pageName = window._get( "wgPageName" ); if( pageName != null ) { if( pageType == PageType.position ) { if( isRestore && stage.getDefaultActorName() != null && stage.getDefaultPollName() != null ) return; // save match time, stored values should be correct final PositionID position = App.i().pollwiki().identifyAsPosition( pageName ); if( position != null ) { Stage.setDefaultActorName( position.personName() ); Stage.setDefaultPollName( position.pollName() ); } } else // other user page { if( isRestore && stage.getDefaultActorName() != null && stage.getDefaultPollName() == null ) return; // save match time, stored values should be correct Stage.setDefaultPollName( null ); final MatchResult m = MediaWiki.parsePageNameS( pageName ); if( m != null ) { Stage.setDefaultActorName( IDPair.normalUsername( m.group( 2 ))); } } } } } // ==================================================================================== private static enum PageType { other, poll, position } }