r83211 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83210‎ | r83211 | r83212 >
Date:11:27, 4 March 2011
Author:janpaul123
Status:deferred
Tags:
Comment:
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 (modified) (history)
  • /trunk/extensions/InlineEditor/InlineEditorText.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/jquery.inlineEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/InlineEditor/InlineEditor.class.php
@@ -12,6 +12,7 @@
1313 const REASON_ADVANCED = 2; /// < reason is editing an 'advanced' page, whatever that may be
1414
1515 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
1617 private $article; /// < Article object to edit
1718 private $extendedEditPage; /// < ExtendedEditPage object we're using to handle editor logic
1819
@@ -70,6 +71,9 @@
7172 unset( $_GET['section'] );
7273 unset( $_POST['section'] );
7374 $request->setVal( 'section', null );
 75+
 76+ // set a warning when leaving the page if necessary
 77+ $editor->setEditWarning( $user->getOption( 'useeditwarning' ) == 1 );
7478
7579 if ( $editor->render( $output ) ) {
7680 return false;
@@ -230,6 +234,7 @@
231235 $this->renderScripts( $output );
232236 $this->renderInitialState( $output, $text );
233237 $this->renderScroll( $output, $parserOutput );
 238+ $this->renderEditWarning( $output );
234239
235240 // hook into SiteNoticeBefore to display the two boxes above the title
236241 // @todo: fix this in core, make sure that anything can be inserted above the title, outside #siteNotice
@@ -258,6 +263,14 @@
259264 }
260265
261266 /**
 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+ /**
262275 * Add the preference in the user preferences
263276 * @param $user
264277 * @param $preferences
@@ -332,6 +345,22 @@
333346 }
334347
335348 /**
 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+ /**
336365 * Get an anchor to scroll to, or null
337366 * @param $parserOutput ParserOutput
338367 * @return string or null
Index: trunk/extensions/InlineEditor/InlineEditorText.class.php
@@ -59,9 +59,9 @@
6060
6161 if( $this->changedNode != $this->root ) {
6262 $markedWiki = $this->changedNode->render();
63 - if( wfRunHooks( 'InlineEditorPartialBeforeParse', array( $markedWiki ) ) ) {
 63+ if( wfRunHooks( 'InlineEditorPartialBeforeParse', array( &$markedWiki ) ) ) {
6464 $output = $this->parse( $markedWiki );
65 - if( wfRunHooks( 'InlineEditorPartialAfterParse', array( $output ) ) ) {
 65+ if( wfRunHooks( 'InlineEditorPartialAfterParse', array( &$output ) ) ) {
6666 return array( 'id' => $this->changedNode->getId(), 'html' => $output->getText() );
6767 }
6868 }
Index: trunk/extensions/InlineEditor/jquery.inlineEditor.js
@@ -5,9 +5,10 @@
66 ( function( $ ) { $.inlineEditor = {
77 editors: {},
88
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
1213
1314 /**
1415 * Adds the initial state from the current HTML and a wiki string.
@@ -160,7 +161,9 @@
161162 /**
162163 * Submit event, adds the json to the hidden field
163164 */
164 - submit: function( event ) {
 165+ submit: function( event ) {
 166+ $.inlineEditor.publishing = true;
 167+
165168 // get the wikitext from the state as it's currently on the screen
166169 var data = {
167170 'object': $.inlineEditor.states[$.inlineEditor.currentState].object
@@ -178,6 +181,16 @@
179182 $( '#editForm' ).submit();
180183 },
181184
 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+
182195 /**
183196 * Initializes the editor.
184197 */

Status & tagging log