http://www.mediawiki.org/wiki/Special:Code/MediaWiki/83211

Revision: 83211
Author:   janpaul123
Date:     2011-03-04 11:27:18 +0000 (Fri, 04 Mar 2011)
Log Message:
-----------
Fixes bug 27388, and should fix a bug with some hooks being run incorrectly on 
some installations.

Modified Paths:
--------------
    trunk/extensions/InlineEditor/InlineEditor.class.php
    trunk/extensions/InlineEditor/InlineEditorText.class.php
    trunk/extensions/InlineEditor/jquery.inlineEditor.js

Modified: trunk/extensions/InlineEditor/InlineEditor.class.php
===================================================================
--- trunk/extensions/InlineEditor/InlineEditor.class.php        2011-03-04 
07:41:07 UTC (rev 83210)
+++ trunk/extensions/InlineEditor/InlineEditor.class.php        2011-03-04 
11:27:18 UTC (rev 83211)
@@ -12,6 +12,7 @@
        const REASON_ADVANCED = 2;      /// < reason is editing an 'advanced' 
page, whatever that may be
 
        private $section;                               /// < Section number to 
scroll to if the user chooses to edit a specific section
+       private $editWarning;           /// < boolean that shows if the 
editWarning message of the Vector Extension is enabled
        private $article;               /// < Article object to edit
        private $extendedEditPage;      /// < ExtendedEditPage object we're 
using to handle editor logic
 
@@ -70,6 +71,9 @@
                unset( $_GET['section'] );
                unset( $_POST['section'] );
                $request->setVal( 'section', null );
+               
+               // set a warning when leaving the page if necessary
+               $editor->setEditWarning( $user->getOption( 'useeditwarning' ) 
== 1 );
 
                if ( $editor->render( $output ) ) {
                        return false;
@@ -230,6 +234,7 @@
                        $this->renderScripts( $output );
                        $this->renderInitialState( $output, $text );
                        $this->renderScroll( $output, $parserOutput );
+                       $this->renderEditWarning( $output );
                        
                        // hook into SiteNoticeBefore to display the two boxes 
above the title
                        // @todo: fix this in core, make sure that anything can 
be inserted above the title, outside #siteNotice
@@ -258,6 +263,14 @@
        }
        
        /**
+        * Set whether or not to use the editWarning utility of the Vector 
Extension
+        * @param $value Boolean
+        */
+       public function setEditWarning( $value ) {
+               $this->editWarning = $value;
+       }
+       
+       /**
         * Add the preference in the user preferences
         * @param $user
         * @param $preferences
@@ -332,6 +345,22 @@
        }
        
        /**
+        * Render the edit warning script
+        *
+        * @param $output OutputPage
+        * @param $parserOutput ParserOutput
+        */
+       private function renderEditWarning( $output ) {
+               if ( $this->editWarning ) {
+                       $output->addInlineScript(
+                               'jQuery( document ).ready( function() {
+                                       jQuery.inlineEditor.enableEditWarning();
+                               } );'
+                       );      
+               }
+       }
+       
+       /**
         * Get an anchor to scroll to, or null
         * @param $parserOutput ParserOutput
         * @return string or null

Modified: trunk/extensions/InlineEditor/InlineEditorText.class.php
===================================================================
--- trunk/extensions/InlineEditor/InlineEditorText.class.php    2011-03-04 
07:41:07 UTC (rev 83210)
+++ trunk/extensions/InlineEditor/InlineEditorText.class.php    2011-03-04 
11:27:18 UTC (rev 83211)
@@ -59,9 +59,9 @@
                
                if( $this->changedNode != $this->root ) {
                        $markedWiki = $this->changedNode->render();
-                       if( wfRunHooks( 'InlineEditorPartialBeforeParse', 
array( $markedWiki ) ) ) {
+                       if( wfRunHooks( 'InlineEditorPartialBeforeParse', 
array( &$markedWiki ) ) ) {
                                $output = $this->parse( $markedWiki );
-                               if( wfRunHooks( 
'InlineEditorPartialAfterParse', array( $output ) ) ) {
+                               if( wfRunHooks( 
'InlineEditorPartialAfterParse', array( &$output ) ) ) {
                                        return array( 'id' => 
$this->changedNode->getId(), 'html' => $output->getText() );
                                }
                        }

Modified: trunk/extensions/InlineEditor/jquery.inlineEditor.js
===================================================================
--- trunk/extensions/InlineEditor/jquery.inlineEditor.js        2011-03-04 
07:41:07 UTC (rev 83210)
+++ trunk/extensions/InlineEditor/jquery.inlineEditor.js        2011-03-04 
11:27:18 UTC (rev 83211)
@@ -5,9 +5,10 @@
 ( function( $ ) { $.inlineEditor = {
        editors: {},
        
-       states: [],
-       currentState: 0,
-       lastState: 0,
+       states: [], // history of all the states (HTML and original wikitexts)
+       currentState: 0, // state that is currently viewed
+       lastState: 0, // last state in the history
+       publishing: false, // whether or not currently publishing
        
        /**
         * Adds the initial state from the current HTML and a wiki string.
@@ -160,7 +161,9 @@
        /**
         * Submit event, adds the json to the hidden field
         */
-       submit: function( event ) {             
+       submit: function( event ) {
+               $.inlineEditor.publishing = true;
+               
                // get the wikitext from the state as it's currently on the 
screen
                var data = {
                                'object': 
$.inlineEditor.states[$.inlineEditor.currentState].object
@@ -178,6 +181,16 @@
                $( '#editForm' ).submit();
        },
        
+       warningMessage: function( ) {   
+               if ( $.inlineEditor.lastState > 0 && !$.inlineEditor.publishing 
) {
+                       return mediaWiki.msg( 'vector-editwarning-warning' );
+               }
+       },
+       
+       enableEditWarning: function( ) {
+               window.onbeforeunload = $.inlineEditor.warningMessage;
+       },
+       
        /**
         * Initializes the editor.
         */


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to