Index: trunk/extensions/InlineEditor/InlineEditor.class.php |
— | — | @@ -45,13 +45,7 @@ |
46 | 46 | self::$fallbackReason = self::REASON_BROWSER; |
47 | 47 | return true; |
48 | 48 | } |
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 | + |
56 | 50 | // start the session if needed |
57 | 51 | if ( session_id() == '' ) { |
58 | 52 | wfSetupSession(); |
— | — | @@ -82,6 +76,10 @@ |
83 | 77 | else { |
84 | 78 | // if rendering fails for some reason, terminate and show the advanced page notice |
85 | 79 | self::$fallbackReason = self::REASON_ADVANCED; |
| 80 | + |
| 81 | + // don't leave traces of HTML behind |
| 82 | + $output->clearHTML(); |
| 83 | + |
86 | 84 | return true; |
87 | 85 | } |
88 | 86 | } |
— | — | @@ -139,22 +137,21 @@ |
140 | 138 | } |
141 | 139 | return true; |
142 | 140 | } |
143 | | - |
| 141 | + |
144 | 142 | /** |
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 |
149 | 146 | */ |
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; |
157 | 154 | } |
158 | | - |
| 155 | + |
159 | 156 | /** |
160 | 157 | * Entry point for the 'Preview' function through ajax. |
161 | 158 | * No real point in securing this, as nothing is actually saved. |
— | — | @@ -219,6 +216,9 @@ |
220 | 217 | |
221 | 218 | // have the different kind of editors register themselves |
222 | 219 | 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 ); |
223 | 223 | |
224 | 224 | // load the wikitext into the InlineEditorText object |
225 | 225 | $text->loadFromWikiText( $this->extendedEditPage->getWikiText() ); |
— | — | @@ -281,18 +281,16 @@ |
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
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 |
288 | 287 | */ |
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; |
297 | 295 | } |
298 | 296 | |
299 | 297 | /** |
Index: trunk/extensions/InlineEditor/InlineEditorText.class.php |
— | — | @@ -14,13 +14,14 @@ |
15 | 15 | * in the text), the entire page is re-rendered |
16 | 16 | */ |
17 | 17 | 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 |
25 | 26 | |
26 | 27 | /** |
27 | 28 | * @param $article Article The article to work with. |
— | — | @@ -28,6 +29,7 @@ |
29 | 30 | public function __construct( Article $article ) { |
30 | 31 | $this->article = $article; |
31 | 32 | $this->wikiOriginal = ''; |
| 33 | + $this->disableMarking = false; |
32 | 34 | } |
33 | 35 | |
34 | 36 | /** |
— | — | @@ -47,6 +49,13 @@ |
48 | 50 | } |
49 | 51 | |
50 | 52 | /** |
| 53 | + * Set or unset the disabling of marking |
| 54 | + */ |
| 55 | + public function setDisableMarking( $value ) { |
| 56 | + $this->disableMarking = $value; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
51 | 60 | * Try to get a partial rendering of the page based on which part of the page has been edited. |
52 | 61 | * Before and after partial rendering hooks are called (InlineEditorPartialBeforeParse and |
53 | 62 | * InlineEditorPartialAfterParse), to have the ability to terminate in the case something in |
— | — | @@ -185,8 +194,13 @@ |
186 | 195 | // abort if we already did markings |
187 | 196 | if( isset( $this->markings ) ) return; |
188 | 197 | |
| 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 | + |
189 | 204 | // have the extensions mark the wikitext |
190 | | - $this->markings = array(); |
191 | 205 | wfRunHooks( 'InlineEditorMark', array( &$this ) ); |
192 | 206 | |
193 | 207 | // sort the markings while preserving the keys (ids) |
— | — | @@ -437,9 +451,10 @@ |
438 | 452 | */ |
439 | 453 | public function serialize() { |
440 | 454 | 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() |
444 | 459 | ) ) ); |
445 | 460 | } |
446 | 461 | |
— | — | @@ -448,8 +463,9 @@ |
449 | 464 | */ |
450 | 465 | public function unserialize( $string ) { |
451 | 466 | $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']; |
454 | 470 | InlineEditorMarking::setUniqueIdState( $data['uniqueIdState'] ); |
455 | 471 | } |
456 | 472 | |