User:NeilK/hackpad.js

// Script to include a remote editor (such as Hackpad) and receive the posted message back

// On all wiki pages // Create an editing button that will invoke hackpad // Pass in hackpad invocation URL //  uniqueID 'net:' + canonical URL + rev  -- to identify session //  title                                  -- so they can join sessions //  username                               -- so they can id the user in the interface //  eventPostback                          -- event we will listen for, to get article text via postMessage

// ... how does WYSIFTW do this

// Save the thing

( function( $, mw ) {    // change this if your wiki's domain name is not available on the public internet    var domainNamespace = 'PUBLIC';    var configurations = {        hackpad: {             name: 'hackpad',            tabTitle: 'HackPad',            editorUrl: 'http://hackpad.com/..'        },        test: {            name: 'test',            tabTitle: 'TestRemoteEditor',            editorUrl: 'http://www.brevity.org/test/wikieditor.pl'        }    };

mw.remoteEditor = function( editorName ) { if ( typeof configurations[editorName] === undefined ) { alert( "don't have config for the remote editor: " + editorName ); return; }       $.extend( this, configurations[editorName] ); this.createTab; this.canonicalUrl = mw.config.get( 'wgServer' ) + mw.config.get( 'wgScript' ) + '?' + $.param( {                    'title': mw.config.get( 'wgPageName' )                 } ); this.$form = $( 'form#editform' ); if ( this.isOurEditPage ) { this.launchEditor; }   };    mw.remoteEditor.prototype = { launchEditor: function { this.$form.hide; debugger; var form = this.$form.get(0); var pageTitle = mw.config.get( 'wgPageName' ); var sessionId = $.map( [ domainNamespace, this.canonicalUrl, form.baseRevId.value ], encodeURIComponent ).join( ':' ); var iframeUrl = this.editorConfig.url + '?' + $.param( {               sessionId: sessionId,                title: mw.config.get( 'wgPageName' ),                user: mw.config.get( 'wgUsername' ),                text: form.wpTextbox1.value            } ); this.$iframe = $( ' ' ).attr( { src: iframeUrl } ); this.listenForEdit;

this.$form.prepend( this.$iframe ); console.log( "launch the editor: " + this.name ); },       listenForEdit: function { },

isOurEditPage: function { // wish we had mw.Uri.js           return mw.config.get( 'wgAction' ) === 'edit' &&                    window.location.href.indexOf( 'editor=' + this.name ) !== -1; },       createTab: function { // could be better done with mw.Uri.js + this.canonicalUrl var editUrl = mw.config.get( 'wgServer' ) + mw.config.get( 'wgScript' ) + '?'                + $.param( {                     'title': mw.config.get( 'wgPageName' ),                     'action': 'edit',                     'editor': this.name }                 ); $( '#p-views ul' ).prepend(                $( '' ).append( $(' ').append(                         $('' )                            .attr( { href: editUrl } )                            .html( this.tabTitle )                    ) )           );        }    }; } )( jQuery, mediaWiki );

var editor = new mw.remoteEditor( 'test' );