Index: trunk/extensions/InlineEditor/InlineEditor.class.php |
— | — | @@ -4,12 +4,16 @@ |
5 | 5 | * It handles hooks through static functions, and they can spawn an InlineEditor object using |
6 | 6 | * an article object, and then render like a normal page, or as JSON. Reason for this is to be |
7 | 7 | * able to pass this object to different hook functions. |
| 8 | + * |
| 9 | + * This file was modified by Dimitris Mitropoulos and Dimitris Meimaris (GRNET) |
| 10 | + * |
8 | 11 | */ |
9 | 12 | class InlineEditor { |
10 | 13 | private static $fallbackReason; /// < reason for not using the editor, used for showing a message |
11 | 14 | const REASON_BROWSER = 1; /// < reason is an incompatible browser |
12 | 15 | const REASON_ADVANCED = 2; /// < reason is editing an 'advanced' page, whatever that may be |
13 | 16 | |
| 17 | + private $section; /// < Section number to scroll to if the user chooses to edit a specific section |
14 | 18 | private $article; /// < Article object to edit |
15 | 19 | private $extendedEditPage; /// < ExtendedEditPage object we're using to handle editor logic |
16 | 20 | |
— | — | @@ -17,15 +21,9 @@ |
18 | 22 | * Main entry point, hooks into MediaWikiPerformAction. |
19 | 23 | * Checks whether or not to spawn the editor, and does so if necessary. |
20 | 24 | */ |
21 | | - public static function mediaWikiPerformAction( $output, $article, $title, $user, $request, $wiki ) { |
| 25 | + public static function mediaWikiPerformAction( $output, $article, $title, $user, $request, $wiki) { |
22 | 26 | global $wgHooks; |
23 | 27 | |
24 | | - // check if the editor could be used on this page, and if so, hide the [edit] links |
25 | | - if ( self::isValidBrowser() && !self::isAdvancedPage( $article, $title ) ) { |
26 | | - self::hideEditSection( $output ); |
27 | | - } |
28 | | - |
29 | | - |
30 | 28 | // return if the action is not 'edit' or if it's disabled |
31 | 29 | // @todo: FIXME: we don't want to break with older versions just yet, |
32 | 30 | // but do remove this when the time is there! |
— | — | @@ -47,11 +45,6 @@ |
48 | 46 | $wgHooks['EditPage::showEditForm:fields'][] = 'InlineEditor::showEditFormFields'; |
49 | 47 | return true; |
50 | 48 | } |
51 | | - |
52 | | - // for now, ignore section edits and just edit the whole page |
53 | | - unset( $_GET['section'] ); |
54 | | - unset( $_POST['section'] ); |
55 | | - $request->setVal( 'section', null ); |
56 | 49 | |
57 | 50 | // terminate if the browser is not supported |
58 | 51 | if ( !self::isValidBrowser() ) { |
— | — | @@ -72,6 +65,20 @@ |
73 | 66 | |
74 | 67 | // try to spawn the editor and render the page |
75 | 68 | $editor = new InlineEditor( $article ); |
| 69 | + |
| 70 | + // set the section to scroll to |
| 71 | + if( isset( $_GET['section'] ) ) { |
| 72 | + $editor->setSection( $_GET['section'] ); |
| 73 | + } |
| 74 | + elseif( isset( $_POST['section'] ) ) { |
| 75 | + $editor->setSection( $_POST['section'] ); |
| 76 | + } |
| 77 | + |
| 78 | + // unset the section variables so the entire page will be edited |
| 79 | + unset( $_GET['section'] ); |
| 80 | + unset( $_POST['section'] ); |
| 81 | + $request->setVal( 'section', null ); |
| 82 | + |
76 | 83 | if ( $editor->render( $output ) ) { |
77 | 84 | return false; |
78 | 85 | } |
— | — | @@ -167,15 +174,6 @@ |
168 | 175 | } |
169 | 176 | |
170 | 177 | /** |
171 | | - * Hide the [edit] links on the page by enabling a piece of CSS (instead of screwing with the parser cache). |
172 | | - * @param $output OutputPage |
173 | | - */ |
174 | | - public static function hideEditSection( &$output ) { |
175 | | - global $wgExtensionAssetsPath; |
176 | | - $output->addExtensionStyle( $wgExtensionAssetsPath . "/InlineEditor/HideEditSection.css?0" ); |
177 | | - } |
178 | | - |
179 | | - /** |
180 | 178 | * Add a 'fulleditor' hidden input field to the normal edit page |
181 | 179 | * @param $editpage EditPage |
182 | 180 | * @param $output OutputPage |
— | — | @@ -204,7 +202,7 @@ |
205 | 203 | * @param $output OutputPage |
206 | 204 | */ |
207 | 205 | public function render( &$output ) { |
208 | | - global $wgHooks, $wgRequest, $wgExtensionAssetsPath, $wgDisableOutputCompression; |
| 206 | + global $wgHooks, $wgRequest, $wgExtensionAssetsPath; |
209 | 207 | |
210 | 208 | // if the page is being saved, retrieve the wikitext from the JSON |
211 | 209 | if ( $wgRequest->wasPosted() ) { |
— | — | @@ -229,6 +227,10 @@ |
230 | 228 | $output->addScriptFile( $wgExtensionAssetsPath . "/InlineEditor/jquery.inlineEditor.js?0" ); |
231 | 229 | $output->addScriptFile( $wgExtensionAssetsPath . "/InlineEditor/jquery.inlineEditor.basicEditor.js?0" ); |
232 | 230 | $output->addScriptFile( $wgExtensionAssetsPath . "/InlineEditor/jquery-ui-effects-1.8.4.min.js?0" ); |
| 231 | + |
| 232 | + // include the required JS files for scrolling |
| 233 | + $output->addScriptFile( $wgExtensionAssetsPath . "/InlineEditor/jquery.sectionScroller.js?0" ); |
| 234 | + |
233 | 235 | $output->addExtensionStyle( $wgExtensionAssetsPath . "/InlineEditor/InlineEditor.css?0" ); |
234 | 236 | $output->addExtensionStyle( $wgExtensionAssetsPath . "/InlineEditor/BasicEditor.css?0" ); |
235 | 237 | |
— | — | @@ -241,14 +243,11 @@ |
242 | 244 | // add a large <div> around the marked wikitext to denote the editing position |
243 | 245 | $parserOutput = $text->getFullParserOutput(); |
244 | 246 | $parserOutput->setText( '<div id="editContent">' . $parserOutput->getText() . '</div>' ); |
245 | | - |
| 247 | + |
246 | 248 | // put the marked output into the page |
247 | 249 | $output->addParserOutput( $parserOutput ); |
248 | 250 | $output->setPageTitle( $parserOutput->getTitleText() ); |
249 | 251 | |
250 | | - // make sure that no compression is used, or the page might be corrupted |
251 | | - $wgDisableOutputCompression = false; |
252 | | - |
253 | 252 | // convert the text object into an initial state to send |
254 | 253 | $initial = InlineEditorText::initialState( $text ); |
255 | 254 | |
— | — | @@ -266,6 +265,16 @@ |
267 | 266 | jQuery.inlineEditor.init(); |
268 | 267 | } );' |
269 | 268 | ); |
| 269 | + |
| 270 | + // scroll to a section if needed |
| 271 | + $scrollAnchor = $this->getScrollAnchor( $parserOutput ); |
| 272 | + if( $scrollAnchor !== null ) { |
| 273 | + $output->addInlineScript( |
| 274 | + 'jQuery( document ).ready( function() { |
| 275 | + jQuery.sectionScroller.scrollToSection( "' . $scrollAnchor . '" ); |
| 276 | + } );' |
| 277 | + ); |
| 278 | + } |
270 | 279 | |
271 | 280 | // hook into SiteNoticeBefore to display the two boxes above the title |
272 | 281 | // @todo: fix this in core, make sure that anything can be inserted above the title, outside #siteNotice |
— | — | @@ -284,13 +293,41 @@ |
285 | 294 | public function getArticle() { |
286 | 295 | return $this->article; |
287 | 296 | } |
| 297 | + |
| 298 | + /** |
| 299 | + * Set the section number to scroll to |
| 300 | + * @param $section |
| 301 | + */ |
| 302 | + public function setSection( $section ) { |
| 303 | + $this->section = $section; |
| 304 | + } |
| 305 | + |
| 306 | + /** |
| 307 | + * Get an anchor to scroll to, or null |
| 308 | + * @param $parserOutput ParserOutput |
| 309 | + * @return string or null |
| 310 | + */ |
| 311 | + private function getScrollAnchor( $parserOutput ) { |
| 312 | + if( isset( $this->section ) ) { |
| 313 | + // retrieve the sections from the original wikimedia parser |
| 314 | + $sections = $parserOutput->getSections(); |
288 | 315 | |
| 316 | + // find the corresponding name of the section to scroll to |
| 317 | + foreach( $sections as $section ) { |
| 318 | + if( $section['index'] == $this->section ){ |
| 319 | + return $section['anchor']; |
| 320 | + } |
| 321 | + } |
| 322 | + } |
| 323 | + return null; |
| 324 | + } |
| 325 | + |
289 | 326 | /** |
290 | 327 | * Pass JSON into an InlineEditorText object and return combined JSON (HTML + sentence representation) |
291 | 328 | * @param $json string |
292 | 329 | * @return string |
293 | 330 | */ |
294 | | - public function preview ( $json ) { |
| 331 | + public function preview( $json ) { |
295 | 332 | // decode the JSON |
296 | 333 | $request = FormatJson::decode( $json, true ); |
297 | 334 | |
Index: trunk/extensions/InlineEditor/jquery.sectionScroller.js |
— | — | @@ -0,0 +1,14 @@ |
| 2 | +/* |
| 3 | +* This takes a section id as a parameter and then makes the browser scroll |
| 4 | +* to this section. |
| 5 | +*/ |
| 6 | + |
| 7 | +( function( $ ) { |
| 8 | + |
| 9 | +$.sectionScroller = { |
| 10 | + scrollToSection: function( id ) { |
| 11 | + $('html,body').animate( { scrollTop: $("#"+id).offset().top}, 'slow'); } |
| 12 | + }; |
| 13 | +} |
| 14 | + |
| 15 | +) ( jQuery ); |
Property changes on: trunk/extensions/InlineEditor/jquery.sectionScroller.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 16 | + native |
Index: trunk/extensions/InlineEditor/InlineEditor.php |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | $wgExtensionCredits['other'][] = array( |
23 | 23 | 'path' => __FILE__, |
24 | 24 | 'name' => 'InlineEditor', |
25 | | - 'author' => array( 'Jan Paul Posma' ), |
| 25 | + 'author' => array( 'Jan Paul Posma', 'Dimitris Meimaris', 'Dimitris Mitropoulos' ), |
26 | 26 | 'version' => '0.1.0', |
27 | 27 | 'url' => 'http://www.mediawiki.org/wiki/Extension:InlineEditor', |
28 | 28 | 'descriptionmsg' => 'inline-editor-desc', |