r83242 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83241‎ | r83242 | r83243 >
Date:20:39, 4 March 2011
Author:janpaul123
Status:deferred
Tags:
Comment:
Fixes bug 27169.
Modified paths:
  • /trunk/extensions/InlineEditor/InlineEditor.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/InlineEditorText.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/InlineEditor/InlineEditor.class.php
@@ -45,13 +45,7 @@
4646 self::$fallbackReason = self::REASON_BROWSER;
4747 return true;
4848 }
49 -
50 - // terminate if we consider this page 'advanced'
51 - if ( self::isAdvancedPage( $article, $title ) ) {
52 - self::$fallbackReason = self::REASON_ADVANCED;
53 - return true;
54 - }
55 -
 49+
5650 // start the session if needed
5751 if ( session_id() == '' ) {
5852 wfSetupSession();
@@ -82,6 +76,10 @@
8377 else {
8478 // if rendering fails for some reason, terminate and show the advanced page notice
8579 self::$fallbackReason = self::REASON_ADVANCED;
 80+
 81+ // don't leave traces of HTML behind
 82+ $output->clearHTML();
 83+
8684 return true;
8785 }
8886 }
@@ -139,22 +137,21 @@
140138 }
141139 return true;
142140 }
143 -
 141+
144142 /**
145 - * Check if the page is 'advanced'. For now, that means it has to be in an allowed namespace.
146 - * @param $article Article
147 - * @param $title Title
148 - * @return bool
 143+ * Add the preference in the user preferences with the GetPreferences hook.
 144+ * @param $user
 145+ * @param $preferences
149146 */
150 - private static function isAdvancedPage( &$article, &$title ) {
151 - global $wgInlineEditorAllowedNamespaces;
152 - if ( !empty( $wgInlineEditorAllowedNamespaces )
153 - && !in_array( $title->getNamespace(), $wgInlineEditorAllowedNamespaces ) ) {
154 - return true;
155 - }
156 - return false;
 147+ public static function getPreferences( $user, &$preferences ) {
 148+ $preferences['inline-editor-enabled'] = array(
 149+ 'type' => 'check',
 150+ 'section' => 'editing/labs',
 151+ 'label-message' => 'inline-editor-enable-preference',
 152+ );
 153+ return true;
157154 }
158 -
 155+
159156 /**
160157 * Entry point for the 'Preview' function through ajax.
161158 * No real point in securing this, as nothing is actually saved.
@@ -219,6 +216,9 @@
220217
221218 // have the different kind of editors register themselves
222219 wfRunHooks( 'InlineEditorDefineEditors', array( &$this, &$output ) );
 220+
 221+ // don't do any marking if this is an advanced page
 222+ if( $this->isAdvancedPage() ) $text->setDisableMarking( true );
223223
224224 // load the wikitext into the InlineEditorText object
225225 $text->loadFromWikiText( $this->extendedEditPage->getWikiText() );
@@ -281,18 +281,16 @@
282282 }
283283
284284 /**
285 - * Add the preference in the user preferences
286 - * @param $user
287 - * @param $preferences
 285+ * Check if the page is 'advanced'. For now, that means it has to be in an allowed namespace.
 286+ * @return bool
288287 */
289 -
290 - public static function getPreferences( $user, &$preferences ) {
291 - $preferences['inline-editor-enabled'] = array(
292 - 'type' => 'check',
293 - 'section' => 'editing/labs',
294 - 'label-message' => 'inline-editor-enable-preference',
295 - );
296 - return true;
 288+ private function isAdvancedPage() {
 289+ global $wgInlineEditorAllowedNamespaces;
 290+ if ( !empty( $wgInlineEditorAllowedNamespaces )
 291+ && !in_array( $this->article->getTitle()->getNamespace(), $wgInlineEditorAllowedNamespaces ) ) {
 292+ return true;
 293+ }
 294+ return false;
297295 }
298296
299297 /**
Index: trunk/extensions/InlineEditor/InlineEditorText.class.php
@@ -14,13 +14,14 @@
1515 * in the text), the entire page is re-rendered
1616 */
1717 class InlineEditorText implements Serializable {
18 - private $wikiOriginal; /// < original wikitext of the article
19 - private $article; /// < article object for parsing
20 - private $markings; /// < array of InlineEditorMarking objects
21 - private $previous; /// < array of InlineEditorMarking objects before this edit
22 - private $editedPiece; /// < InlineEditorMarking object to describe the range where edits occurred
23 - private $changedNode; /// < Node which should be rendered when doing a partial rendering
24 - private $root; /// < Root of the tree where the markings are arranged in
 18+ private $wikiOriginal; /// < original wikitext of the article
 19+ private $article; /// < article object for parsing
 20+ private $markings; /// < array of InlineEditorMarking objects
 21+ private $previous; /// < array of InlineEditorMarking objects before this edit
 22+ private $editedPiece; /// < InlineEditorMarking object to describe the range where edits occurred
 23+ private $changedNode; /// < Node which should be rendered when doing a partial rendering
 24+ private $root; /// < Root of the tree where the markings are arranged in
 25+ private $disableMarking; /// < Disable the marking process entirely, e.g. for dealing with complex pages
2526
2627 /**
2728 * @param $article Article The article to work with.
@@ -28,6 +29,7 @@
2930 public function __construct( Article $article ) {
3031 $this->article = $article;
3132 $this->wikiOriginal = '';
 33+ $this->disableMarking = false;
3234 }
3335
3436 /**
@@ -47,6 +49,13 @@
4850 }
4951
5052 /**
 53+ * Set or unset the disabling of marking
 54+ */
 55+ public function setDisableMarking( $value ) {
 56+ $this->disableMarking = $value;
 57+ }
 58+
 59+ /**
5160 * Try to get a partial rendering of the page based on which part of the page has been edited.
5261 * Before and after partial rendering hooks are called (InlineEditorPartialBeforeParse and
5362 * InlineEditorPartialAfterParse), to have the ability to terminate in the case something in
@@ -185,8 +194,13 @@
186195 // abort if we already did markings
187196 if( isset( $this->markings ) ) return;
188197
 198+ // initialise markings array
 199+ $this->markings = array();
 200+
 201+ // if marking is disabled, we want to terminate here
 202+ if( $this->disableMarking ) return;
 203+
189204 // have the extensions mark the wikitext
190 - $this->markings = array();
191205 wfRunHooks( 'InlineEditorMark', array( &$this ) );
192206
193207 // sort the markings while preserving the keys (ids)
@@ -437,9 +451,10 @@
438452 */
439453 public function serialize() {
440454 return base64_encode( serialize( array(
441 - 'wikiOriginal' => $this->wikiOriginal,
442 - 'markings' => $this->markings,
443 - 'uniqueIdState' => InlineEditorMarking::getUniqueIdState()
 455+ 'disableMarking' => $this->disableMarking,
 456+ 'wikiOriginal' => $this->wikiOriginal,
 457+ 'markings' => $this->markings,
 458+ 'uniqueIdState' => InlineEditorMarking::getUniqueIdState()
444459 ) ) );
445460 }
446461
@@ -448,8 +463,9 @@
449464 */
450465 public function unserialize( $string ) {
451466 $data = unserialize( base64_decode( $string ) );
452 - $this->wikiOriginal = $data['wikiOriginal'];
453 - $this->markings = $data['markings'];
 467+ $this->disableMarking = $data['disableMarking'];
 468+ $this->wikiOriginal = $data['wikiOriginal'];
 469+ $this->markings = $data['markings'];
454470 InlineEditorMarking::setUniqueIdState( $data['uniqueIdState'] );
455471 }
456472

Status & tagging log