r82204 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82203‎ | r82204 | r82205 >
Date:00:05, 16 February 2011
Author:janpaul123
Status:deferred
Tags:
Comment:
Added section scrolling by GRNET developers.
Modified paths:
  • /trunk/extensions/InlineEditor/InlineEditor.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/InlineEditor.php (modified) (history)
  • /trunk/extensions/InlineEditor/jquery.sectionScroller.js (added) (history)

Diff [purge]

Index: trunk/extensions/InlineEditor/InlineEditor.class.php
@@ -4,12 +4,16 @@
55 * It handles hooks through static functions, and they can spawn an InlineEditor object using
66 * an article object, and then render like a normal page, or as JSON. Reason for this is to be
77 * able to pass this object to different hook functions.
 8+ *
 9+ * This file was modified by Dimitris Mitropoulos and Dimitris Meimaris (GRNET)
 10+ *
811 */
912 class InlineEditor {
1013 private static $fallbackReason; /// < reason for not using the editor, used for showing a message
1114 const REASON_BROWSER = 1; /// < reason is an incompatible browser
1215 const REASON_ADVANCED = 2; /// < reason is editing an 'advanced' page, whatever that may be
1316
 17+ private $section; /// < Section number to scroll to if the user chooses to edit a specific section
1418 private $article; /// < Article object to edit
1519 private $extendedEditPage; /// < ExtendedEditPage object we're using to handle editor logic
1620
@@ -17,15 +21,9 @@
1822 * Main entry point, hooks into MediaWikiPerformAction.
1923 * Checks whether or not to spawn the editor, and does so if necessary.
2024 */
21 - public static function mediaWikiPerformAction( $output, $article, $title, $user, $request, $wiki ) {
 25+ public static function mediaWikiPerformAction( $output, $article, $title, $user, $request, $wiki) {
2226 global $wgHooks;
2327
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 -
3028 // return if the action is not 'edit' or if it's disabled
3129 // @todo: FIXME: we don't want to break with older versions just yet,
3230 // but do remove this when the time is there!
@@ -47,11 +45,6 @@
4846 $wgHooks['EditPage::showEditForm:fields'][] = 'InlineEditor::showEditFormFields';
4947 return true;
5048 }
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 );
5649
5750 // terminate if the browser is not supported
5851 if ( !self::isValidBrowser() ) {
@@ -72,6 +65,20 @@
7366
7467 // try to spawn the editor and render the page
7568 $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+
7683 if ( $editor->render( $output ) ) {
7784 return false;
7885 }
@@ -167,15 +174,6 @@
168175 }
169176
170177 /**
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 - /**
180178 * Add a 'fulleditor' hidden input field to the normal edit page
181179 * @param $editpage EditPage
182180 * @param $output OutputPage
@@ -204,7 +202,7 @@
205203 * @param $output OutputPage
206204 */
207205 public function render( &$output ) {
208 - global $wgHooks, $wgRequest, $wgExtensionAssetsPath, $wgDisableOutputCompression;
 206+ global $wgHooks, $wgRequest, $wgExtensionAssetsPath;
209207
210208 // if the page is being saved, retrieve the wikitext from the JSON
211209 if ( $wgRequest->wasPosted() ) {
@@ -229,6 +227,10 @@
230228 $output->addScriptFile( $wgExtensionAssetsPath . "/InlineEditor/jquery.inlineEditor.js?0" );
231229 $output->addScriptFile( $wgExtensionAssetsPath . "/InlineEditor/jquery.inlineEditor.basicEditor.js?0" );
232230 $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+
233235 $output->addExtensionStyle( $wgExtensionAssetsPath . "/InlineEditor/InlineEditor.css?0" );
234236 $output->addExtensionStyle( $wgExtensionAssetsPath . "/InlineEditor/BasicEditor.css?0" );
235237
@@ -241,14 +243,11 @@
242244 // add a large <div> around the marked wikitext to denote the editing position
243245 $parserOutput = $text->getFullParserOutput();
244246 $parserOutput->setText( '<div id="editContent">' . $parserOutput->getText() . '</div>' );
245 -
 247+
246248 // put the marked output into the page
247249 $output->addParserOutput( $parserOutput );
248250 $output->setPageTitle( $parserOutput->getTitleText() );
249251
250 - // make sure that no compression is used, or the page might be corrupted
251 - $wgDisableOutputCompression = false;
252 -
253252 // convert the text object into an initial state to send
254253 $initial = InlineEditorText::initialState( $text );
255254
@@ -266,6 +265,16 @@
267266 jQuery.inlineEditor.init();
268267 } );'
269268 );
 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+ }
270279
271280 // hook into SiteNoticeBefore to display the two boxes above the title
272281 // @todo: fix this in core, make sure that anything can be inserted above the title, outside #siteNotice
@@ -284,13 +293,41 @@
285294 public function getArticle() {
286295 return $this->article;
287296 }
 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();
288315
 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+
289326 /**
290327 * Pass JSON into an InlineEditorText object and return combined JSON (HTML + sentence representation)
291328 * @param $json string
292329 * @return string
293330 */
294 - public function preview ( $json ) {
 331+ public function preview( $json ) {
295332 // decode the JSON
296333 $request = FormatJson::decode( $json, true );
297334
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
116 + native
Index: trunk/extensions/InlineEditor/InlineEditor.php
@@ -21,7 +21,7 @@
2222 $wgExtensionCredits['other'][] = array(
2323 'path' => __FILE__,
2424 'name' => 'InlineEditor',
25 - 'author' => array( 'Jan Paul Posma' ),
 25+ 'author' => array( 'Jan Paul Posma', 'Dimitris Meimaris', 'Dimitris Mitropoulos' ),
2626 'version' => '0.1.0',
2727 'url' => 'http://www.mediawiki.org/wiki/Extension:InlineEditor',
2828 'descriptionmsg' => 'inline-editor-desc',

Status & tagging log