Index: trunk/extensions/InlineEditor/InlineEditor.class.php |
— | — | @@ -12,6 +12,7 @@ |
13 | 13 | const REASON_ADVANCED = 2; /// < reason is editing an 'advanced' page, whatever that may be |
14 | 14 | |
15 | 15 | private $section; /// < Section number to scroll to if the user chooses to edit a specific section |
| 16 | + private $editWarning; /// < boolean that shows if the editWarning message of the Vector Extension is enabled |
16 | 17 | private $article; /// < Article object to edit |
17 | 18 | private $extendedEditPage; /// < ExtendedEditPage object we're using to handle editor logic |
18 | 19 | |
— | — | @@ -70,6 +71,9 @@ |
71 | 72 | unset( $_GET['section'] ); |
72 | 73 | unset( $_POST['section'] ); |
73 | 74 | $request->setVal( 'section', null ); |
| 75 | + |
| 76 | + // set a warning when leaving the page if necessary |
| 77 | + $editor->setEditWarning( $user->getOption( 'useeditwarning' ) == 1 ); |
74 | 78 | |
75 | 79 | if ( $editor->render( $output ) ) { |
76 | 80 | return false; |
— | — | @@ -230,6 +234,7 @@ |
231 | 235 | $this->renderScripts( $output ); |
232 | 236 | $this->renderInitialState( $output, $text ); |
233 | 237 | $this->renderScroll( $output, $parserOutput ); |
| 238 | + $this->renderEditWarning( $output ); |
234 | 239 | |
235 | 240 | // hook into SiteNoticeBefore to display the two boxes above the title |
236 | 241 | // @todo: fix this in core, make sure that anything can be inserted above the title, outside #siteNotice |
— | — | @@ -258,6 +263,14 @@ |
259 | 264 | } |
260 | 265 | |
261 | 266 | /** |
| 267 | + * Set whether or not to use the editWarning utility of the Vector Extension |
| 268 | + * @param $value Boolean |
| 269 | + */ |
| 270 | + public function setEditWarning( $value ) { |
| 271 | + $this->editWarning = $value; |
| 272 | + } |
| 273 | + |
| 274 | + /** |
262 | 275 | * Add the preference in the user preferences |
263 | 276 | * @param $user |
264 | 277 | * @param $preferences |
— | — | @@ -332,6 +345,22 @@ |
333 | 346 | } |
334 | 347 | |
335 | 348 | /** |
| 349 | + * Render the edit warning script |
| 350 | + * |
| 351 | + * @param $output OutputPage |
| 352 | + * @param $parserOutput ParserOutput |
| 353 | + */ |
| 354 | + private function renderEditWarning( $output ) { |
| 355 | + if ( $this->editWarning ) { |
| 356 | + $output->addInlineScript( |
| 357 | + 'jQuery( document ).ready( function() { |
| 358 | + jQuery.inlineEditor.enableEditWarning(); |
| 359 | + } );' |
| 360 | + ); |
| 361 | + } |
| 362 | + } |
| 363 | + |
| 364 | + /** |
336 | 365 | * Get an anchor to scroll to, or null |
337 | 366 | * @param $parserOutput ParserOutput |
338 | 367 | * @return string or null |
Index: trunk/extensions/InlineEditor/InlineEditorText.class.php |
— | — | @@ -59,9 +59,9 @@ |
60 | 60 | |
61 | 61 | if( $this->changedNode != $this->root ) { |
62 | 62 | $markedWiki = $this->changedNode->render(); |
63 | | - if( wfRunHooks( 'InlineEditorPartialBeforeParse', array( $markedWiki ) ) ) { |
| 63 | + if( wfRunHooks( 'InlineEditorPartialBeforeParse', array( &$markedWiki ) ) ) { |
64 | 64 | $output = $this->parse( $markedWiki ); |
65 | | - if( wfRunHooks( 'InlineEditorPartialAfterParse', array( $output ) ) ) { |
| 65 | + if( wfRunHooks( 'InlineEditorPartialAfterParse', array( &$output ) ) ) { |
66 | 66 | return array( 'id' => $this->changedNode->getId(), 'html' => $output->getText() ); |
67 | 67 | } |
68 | 68 | } |
Index: trunk/extensions/InlineEditor/jquery.inlineEditor.js |
— | — | @@ -5,9 +5,10 @@ |
6 | 6 | ( function( $ ) { $.inlineEditor = { |
7 | 7 | editors: {}, |
8 | 8 | |
9 | | - states: [], |
10 | | - currentState: 0, |
11 | | - lastState: 0, |
| 9 | + states: [], // history of all the states (HTML and original wikitexts) |
| 10 | + currentState: 0, // state that is currently viewed |
| 11 | + lastState: 0, // last state in the history |
| 12 | + publishing: false, // whether or not currently publishing |
12 | 13 | |
13 | 14 | /** |
14 | 15 | * Adds the initial state from the current HTML and a wiki string. |
— | — | @@ -160,7 +161,9 @@ |
161 | 162 | /** |
162 | 163 | * Submit event, adds the json to the hidden field |
163 | 164 | */ |
164 | | - submit: function( event ) { |
| 165 | + submit: function( event ) { |
| 166 | + $.inlineEditor.publishing = true; |
| 167 | + |
165 | 168 | // get the wikitext from the state as it's currently on the screen |
166 | 169 | var data = { |
167 | 170 | 'object': $.inlineEditor.states[$.inlineEditor.currentState].object |
— | — | @@ -178,6 +181,16 @@ |
179 | 182 | $( '#editForm' ).submit(); |
180 | 183 | }, |
181 | 184 | |
| 185 | + warningMessage: function( ) { |
| 186 | + if ( $.inlineEditor.lastState > 0 && !$.inlineEditor.publishing ) { |
| 187 | + return mediaWiki.msg( 'vector-editwarning-warning' ); |
| 188 | + } |
| 189 | + }, |
| 190 | + |
| 191 | + enableEditWarning: function( ) { |
| 192 | + window.onbeforeunload = $.inlineEditor.warningMessage; |
| 193 | + }, |
| 194 | + |
182 | 195 | /** |
183 | 196 | * Initializes the editor. |
184 | 197 | */ |