package votorola.s.gwt.mediawiki; // Copyright 2012-2014, 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.JavaScriptObject; import com.google.gwt.dom.client.*; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.RootPanel; import votorola.a.voter.*; import votorola.a.web.gwt.*; import votorola.g.web.gwt.*; import votorola.s.gwt.stage.*; /** The GWT entry module for embedding the Crossforum Theatre {@linkplain * votorola.s.gwt.stage.Stage stage} in MediaWiki pages. An instance of this class is * automatically constructed and invoked per module definition MediaWikiIn.gwt.xml. * *

Configuration

* *

The following configuration properties are specific to this entry module. These * are properties of global JavaScript object {@linkplain GWTConfig window.voGWTConfig}. * The short name (SHORT) of each is fully qualified as * "window.voGWTConfig.s_gwt_mediawiki_SHORT".

* * * * * * * * * * * * * * * * * *
Short nameFormValueDefault
toTopbooleanSpecify true for {@linkplain #insertStageVTop(JavaScriptObject) top * insertion} of the stage. Otherwise the stage is placed as for * remote drafting.false
* *

Injection

* *

Injection embeds the stage in a web page. Common patterns of injection are * documented in the sections below.

* *

Universal injection

* * This constructs a {@linkplain votorola.s.gwt.stage.StageV stage view} and ordinarily * inserts it as the first child of the body element on every page, as detailed for * {@linkplain #insertStageVTop(JavaScriptObject) insertStageVTop}. To install it, add * the following to pollwiki page MediaWiki:Common.js or your * personal script/user script, * substituting the correct value for CONTEXT:
  *
  *  // Crossforum Theatre stage.
  *  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  *  // module.css and gwt.js must load before boot script nocache.js
  *  // http://reluk.ca/project/votorola/_/javadoc/votorola/s/gwt/mediawiki/MediaWikiIn.html
  *
  *    if( $.client.profile().name != 'msie' ) // all but IE [1]
  *    {
  *        voInject = function()  // implicitly declared so deletable below
  *        {
  *            if( !window.voGWTConfig ) voGWTConfig = {};
  *            else if( window.voGWTConfig.s_gwt_mediawiki_isInjected ) return;
  *              // guard against double injection by both admin and user scripts
  *
  *            window.voGWTConfig.s_gwt_mediawiki_isInjected = true;
  *            window.voGWTConfig.s_gwt_mediawiki_toTop = true;
  *            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.mediawiki.MediaWikiIn/votorola.s.gwt.mediawiki.MediaWikiIn.nocache.js'"
  *              + " type='text/javascript'></script>" );
  *        }
  *        voInject();
  *        delete voInject; // clean up
  *    }
  *
  *  //
  *  // 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 injected 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.
  *  //
* *

Selective injection for remote drafting

* * This will ordinarily inject the stage only in remote draft pages. It locates * <ELEMENT id='bodyContent'/> and inserts a newly * constructed {@linkplain StageV stage view} as its first child, which will normally * render just beneath the tabs and other navigation controls of the wiki (or if * ELEMENT cannot be located, then it defaults to {@linkplain * #insertStageVTop(JavaScriptObject) top insertion}). To install it add the following * to MediaWiki:Common.js or your * personal script/user script, * substituting the correct value for CONTEXT:
  *
  *  // Crossforum Theatre stage for remote drafting.
  *  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  *  // module.css and gwt.js must load before boot script nocache.js
  *  // http://reluk.ca/project/votorola/_/javadoc/votorola/s/gwt/mediawiki/MediaWikiIn.html
  *
  *    if( $.client.profile().name != 'msie' ) // all but IE [1]
  *    {
  *        voInject = function()  // implicitly declared so deletable below
  *        {
  *            var toInject = false;
  *            for( var c = wgCategories.length - 1; c >=0; --c )
  *            {
  *                var category = wgCategories[c];
  *                if( category == 'Remote draft' )
  *                {
  *                    toInject = true; // inject regardless for a remote draft page
  *                    break;
  *                }
  *            }
  *            if( toInject )
  *            {
  *                if( !window.voGWTConfig ) voGWTConfig = {};
  *                else if( window.voGWTConfig.s_gwt_mediawiki_isInjected ) return;
  *                  // guard against double injection by both admin and user scripts
  *
  *                window.voGWTConfig.s_gwt_mediawiki_isInjected = true;
  *                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.mediawiki.MediaWikiIn/votorola.s.gwt.mediawiki.MediaWikiIn.nocache.js'"
  *                  + " type='text/javascript'></script>" );
  *            }
  *        }
  *        voInject();
  *        delete voInject; // clean up
  *    }
  *
  *  //
  *  // NOTES
  *  //
  *  //   (same as farther above)
  *  //
* *

As mentioned, this will ordinarily inject the stage only in remote draft pages. * You may create such pages with the help of the template provided * in the working examples farther below.

* *

Note that the username of the logged in Votorola/Outcast user is not currently * detectable in MediaWiki pages external to the pollwiki. This means that user-oriented * links such as "my draft" in the {@linkplain votorola.s.gwt.stage.link.LinkTrackV link * track} will not be properly disabled when they are redundant, e.g. when "my draft" is * already being shown.

* *

Working examples

* * The only site deploying this entry module (at time of writing) is Metagov, which * deploys it in non-standard fashion via its plug-in framework. See: */ public final @GWTConfig class MediaWikiIn extends TheatreInitializer0 implements EntryPointS { /** Constructs a {@linkplain StageV stage view} and ordinarily inserts it as the first * child of the body element. Alternatively the page author may specify the * insertion point as {@linkplain StageIn#insertStageV() documented for StageIn}. */ public static void insertStageVTop( final JavaScriptObject voGWTConfig ) { StageIn.insertStageV(); final Document doc = Document.get(); // Adjust styling to accomodate stage, which may affect layout. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - final Element gW; if( "monobook".equals( WindowX.js()._get("skin") )) { gW = doc.getElementById( "globalWrapper" ); if( gW == null ) { Window.alert( "unable to layout stage, no element ID 'globalWrapper'" ); return; } } else // might be vector, which removes that element, so create our own { gW = doc.createDivElement(); final Element stageV = doc.getElementById( "StageV-top" ); final Element body = doc.getBody(); for( Node node = body.getFirstChild(); node != null; ) { final Node next = node.getNextSibling(); move: { if( Element.is( node )) { final Element e = node.cast(); if( e.equals( stageV )) break move; // leave this above gW final String id = e.getId(); if( id.equals("mgSwitchPopperSensor") || id.equals("mgSwitchWindow") ) break move; // leave these above gW } gW.appendChild( node ); } node = next; } body.appendChild( gW ); } // The stage view element is now assured of being on top, followed by gW which // contains all other content. Next make gW a containing block by giving it a // relative postition. This ensures that all of MediaWiki's positioned elements // (#pLogo and such) are situated relative to gW, and therefore sit properly // beneath the stage instead of overlapping it. gW.getStyle().setPosition( Style.Position.RELATIVE ); } // - E n t r y - P o i n t ------------------------------------------------------------ public void onModuleLoad() { final JavaScriptObject voGWTConfig = WindowX.js()._get( "voGWTConfig" ); if( voGWTConfig._getBoolean( "s_gwt_mediawiki_toTop" )) insertStageVTop( voGWTConfig ); else { // Expect the wiki in this case to inject the stage script in some pages only, // so place the stage beneath the wiki's own nav controls, thus keeping those // controls in a steady position across all pages, staged or not. final RootPanel parent = RootPanel.get( "bodyContent" ); if( parent != null ) parent.insert( new StageV( /*toDisplay*/true ), 0 ); // toDisplay because stabilization not yet implemented for this kind of embedding else insertStageVTop( voGWTConfig ); // fallback } // - - - EntryPointS.U.schedule( MediaWikiIn.this ); EntryPointS.U.execute(); // because all modules are now loaded } // - 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(); Stage.i().addInitializer( MediaWikiIn.this ); // auto-removed } // - T h e a t r e - I n i t i a l i z e r -------------------------------------------- public @Override void initFrom( final Stage s, boolean _rPending ) { initAbsolutes( s ); } public @Override void initTo( final Stage s ) { initAbsolutes( s ); } public @Override void initTo( final Stage s, TheatrePage _r ) { initAbsolutes( s ); } //// 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 ) { // Set default properties from voDraft markers. The markers are editable so their // values may differ from those originally set and stored and now restored. final Document doc = Document.get(); Element marker; marker = doc.getElementById( "voDraft-poll" ); if( marker != null ) Stage.setDefaultPollName( marker.getTitle() ); marker = doc.getElementById( "voDraft-author" ); if( marker != null ) { Stage.setDefaultActorName( IDPair.normalUsername( marker.getTitle() )); } } }