r72575 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72574‎ | r72575 | r72576 >
Date:06:38, 8 September 2010
Author:siebrand
Status:ok (Comments)
Tags:
Comment:
* run stylize.php
* L10n tweaks
* newline at end of file
* i18n FIXME added
Modified paths:
  • /trunk/extensions/InlineEditor/ExtendedEditPage.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/FullEditor/FullEditor.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/FullEditor/FullEditor.i18n.php (modified) (history)
  • /trunk/extensions/InlineEditor/FullEditor/FullEditor.php (modified) (history)
  • /trunk/extensions/InlineEditor/InlineEditor.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/InlineEditor.i18n.php (modified) (history)
  • /trunk/extensions/InlineEditor/InlineEditor.php (modified) (history)
  • /trunk/extensions/InlineEditor/InlineEditorPiece.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/InlineEditorPreviousMarking.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/InlineEditorText.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/ListEditor/ListEditor.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/ListEditor/ListEditor.i18n.php (modified) (history)
  • /trunk/extensions/InlineEditor/ListEditor/ListEditor.php (modified) (history)
  • /trunk/extensions/InlineEditor/MediaEditor/MediaEditor.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/MediaEditor/MediaEditor.i18n.php (modified) (history)
  • /trunk/extensions/InlineEditor/MediaEditor/MediaEditor.php (modified) (history)
  • /trunk/extensions/InlineEditor/ReferenceEditor/ReferenceEditor.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/ReferenceEditor/ReferenceEditor.i18n.php (modified) (history)
  • /trunk/extensions/InlineEditor/ReferenceEditor/ReferenceEditor.php (modified) (history)
  • /trunk/extensions/InlineEditor/SentenceEditor/SentenceDetection/ISentenceDetection.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/SentenceEditor/SentenceDetection/SentenceDetectionBasic.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/SentenceEditor/SentenceEditor.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/SentenceEditor/SentenceEditor.i18n.php (modified) (history)
  • /trunk/extensions/InlineEditor/SentenceEditor/SentenceEditor.php (modified) (history)
  • /trunk/extensions/InlineEditor/TemplateEditor/TemplateEditor.class.php (modified) (history)
  • /trunk/extensions/InlineEditor/TemplateEditor/TemplateEditor.i18n.php (modified) (history)
  • /trunk/extensions/InlineEditor/TemplateEditor/TemplateEditor.php (modified) (history)

Diff [purge]

Index: trunk/extensions/InlineEditor/InlineEditor.class.php
@@ -6,63 +6,63 @@
77 * able to pass this object to different hook functions.
88 */
99 class InlineEditor {
10 - private static $fallbackReason; ///< reason for not using the editor, used for showing a message
11 - const REASON_BROWSER = 1; ///< reason is an incompatible browser
12 - const REASON_ADVANCED = 2; ///< reason is editing an 'advanced' page, whatever that may be
13 -
14 - private $article; ///< Article object to edit
15 - private $editModes; ///< array of different edit modes, see addEditMode()
16 - private $extendedEditPage; ///< ExtendedEditPage object we're using to handle editor logic
17 -
 10+ private static $fallbackReason; /// < reason for not using the editor, used for showing a message
 11+ const REASON_BROWSER = 1; /// < reason is an incompatible browser
 12+ const REASON_ADVANCED = 2; /// < reason is editing an 'advanced' page, whatever that may be
 13+
 14+ private $article; /// < Article object to edit
 15+ private $editModes; /// < array of different edit modes, see addEditMode()
 16+ private $extendedEditPage; /// < ExtendedEditPage object we're using to handle editor logic
 17+
1818 /**
1919 * Main entry point, hooks into MediaWikiPerformAction.
2020 * Checks whether or not to spawn the editor, and does so if nessicary.
2121 */
2222 public static function mediaWikiPerformAction( $output, $article, $title, $user, $request, $wiki ) {
2323 global $wgHooks;
24 -
 24+
2525 // the action of the page, i.e. 'view' or 'edit'
2626 $action = $wiki->getVal( 'Action' );
27 -
 27+
2828 // check if the editor could be used on this page, and if so, hide the [edit] links
2929 if ( self::isValidBrowser() && !self::isAdvancedPage( $article, $title ) ) {
3030 self::hideEditSection( $output );
3131 }
32 -
 32+
3333 // return if the action is not 'edit' or if it's disabled
34 - if( $action != 'edit' || in_array( $action, $wiki->getVal( 'DisabledActions', array() ) ) )
 34+ if ( $action != 'edit' || in_array( $action, $wiki->getVal( 'DisabledActions', array() ) ) )
3535 {
3636 return true;
3737 }
38 -
 38+
3939 // check if the 'fulleditor' parameter is set either in GET or POST
4040 if ( $request->getCheck( 'fulleditor' ) ) {
4141 // hook into the edit page to inject the hidden 'fulleditor' input field again
4242 $wgHooks['EditPage::showEditForm:fields'][] = 'InlineEditor::showEditFormFields';
4343 return true;
4444 }
45 -
 45+
4646 // terminate if the browser is not supported
47 - if( !self::isValidBrowser() ) {
 47+ if ( !self::isValidBrowser() ) {
4848 self::$fallbackReason = self::REASON_BROWSER;
4949 return true;
5050 }
51 -
 51+
5252 // terminate if we consider this page 'advanced'
53 - if( self::isAdvancedPage( $article, $title ) ) {
 53+ if ( self::isAdvancedPage( $article, $title ) ) {
5454 self::$fallbackReason = self::REASON_ADVANCED;
5555 return true;
5656 }
57 -
 57+
5858 // start the session if needed
59 - if( session_id() == '' ) {
 59+ if ( session_id() == '' ) {
6060 wfSetupSession();
6161 }
62 -
 62+
6363 // try to spawn the editor and render the page
6464 $editor = new InlineEditor( $article );
65 - if( $editor->render( $output ) ) {
66 - return false;
 65+ if ( $editor->render( $output ) ) {
 66+ return false;
6767 }
6868 else {
6969 // if rendering fails for some reason, terminate and show the advanced page notice
@@ -70,19 +70,19 @@
7171 return true;
7272 }
7373 }
74 -
 74+
7575 /**
7676 * Hooks into EditPage::showEditForm:initial. Shows a message if there is a fallback reason set.
77 - * @param $editPage EditPage
 77+ * @param $editPage EditPage
7878 */
7979 public static function showEditForm( &$editPage ) {
8080 global $wgExtensionAssetsPath, $wgOut, $wgRequest;
81 -
 81+
8282 // check for a fallback reason
83 - if( isset( self::$fallbackReason ) ) {
 83+ if ( isset( self::$fallbackReason ) ) {
8484 // add the style for fallback message
8585 $wgOut->addExtensionStyle( $wgExtensionAssetsPath . "/InlineEditor/EditForm.css?0" );
86 -
 86+
8787 // show the appropriate message at the top of the page
8888 switch( self::$fallbackReason ) {
8989 case self::REASON_BROWSER:
@@ -93,19 +93,19 @@
9494 break;
9595 }
9696 }
97 -
 97+
9898 return true;
9999 }
100 -
 100+
101101 /**
102102 * Prepends a fallback message at the top of the page.
103103 * @param $html String with correct HTML
104104 */
105105 private static function prependFallbackMessage( $html ) {
106106 global $wgOut;
107 - $wgOut->prependHTML( '<div class="inlineEditorMessage">' . $html . '</div>');
 107+ $wgOut->prependHTML( '<div class="inlineEditorMessage">' . $html . '</div>' );
108108 }
109 -
 109+
110110 /**
111111 * Checks if the browser is supported.
112112 * This function is borrowed from EditPage::checkUnicodeCompliantBrowser().
@@ -118,13 +118,13 @@
119119 }
120120 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
121121 foreach ( $wgInlineEditorBrowserBlacklist as $browser ) {
122 - if ( preg_match($browser, $currentbrowser) ) {
 122+ if ( preg_match( $browser, $currentbrowser ) ) {
123123 return false;
124124 }
125125 }
126126 return true;
127127 }
128 -
 128+
129129 /**
130130 * Check if the page is 'advanced'. For now, that means it has to be in an allowed namespace.
131131 * @param $article Article
@@ -133,13 +133,13 @@
134134 */
135135 private static function isAdvancedPage( &$article, &$title ) {
136136 global $wgInlineEditorAllowedNamespaces;
137 - if( !empty( $wgInlineEditorAllowedNamespaces )
 137+ if ( !empty( $wgInlineEditorAllowedNamespaces )
138138 && !in_array( $title->getNamespace(), $wgInlineEditorAllowedNamespaces ) ) {
139139 return true;
140140 }
141141 return false;
142142 }
143 -
 143+
144144 /**
145145 * Entry point for the 'Preview' function through Ajax.
146146 * No real point in securing this, as nothing is actually saved.
@@ -150,11 +150,11 @@
151151 public static function ajaxPreview( $json, $pageName ) {
152152 $title = Title::newFromText( $pageName );
153153 $article = Article::newFromId( $title->getArticleId() );
154 -
 154+
155155 $editor = new InlineEditor( $article );
156156 return $editor->preview( $json );
157157 }
158 -
 158+
159159 /**
160160 * Hide the [edit] links on the page by enabling a piece of CSS (instead of screwing with the parser cache).
161161 * @param $output OutputPage
@@ -163,7 +163,7 @@
164164 global $wgExtensionAssetsPath;
165165 $output->addExtensionStyle( $wgExtensionAssetsPath . "/InlineEditor/HideEditSection.css?0" );
166166 }
167 -
 167+
168168 /**
169169 * Add a 'fulleditor' hidden input field to the normal edit page
170170 * @param $editpage EditPage
@@ -171,11 +171,11 @@
172172 */
173173 public static function showEditFormFields( &$editpage, &$output ) {
174174 $output->addHTML(
175 - HTML::rawElement( 'input', array( 'name' => 'fulleditor', 'type' => 'hidden', 'value' => '1' ))
 175+ HTML::rawElement( 'input', array( 'name' => 'fulleditor', 'type' => 'hidden', 'value' => '1' ) )
176176 );
177177 return true;
178178 }
179 -
 179+
180180 /**
181181 * Constructor which takes only an Article object
182182 * @param $article Article
@@ -184,7 +184,7 @@
185185 $this->article = $article;
186186 $editmodes = array();
187187 }
188 -
 188+
189189 /**
190190 * Render the editor.
191191 * Spawns an ExtendedEditPage which is an EditPage with some specific logic for this editor.
@@ -195,43 +195,43 @@
196196 */
197197 public function render( &$output ) {
198198 global $wgParser, $wgHooks, $wgRequest, $wgExtensionAssetsPath;
199 -
 199+
200200 // create an InlineEditorText object which generates the HTML and JSON for the editor
201201 $text = new InlineEditorText( $this->article );
202 -
 202+
203203 // if the page is being saved, retrieve the wikitext from the JSON
204 - if( $wgRequest->wasPosted() ) {
 204+ if ( $wgRequest->wasPosted() ) {
205205 $text->loadFromJson( $wgRequest->getVal( 'json' ) );
206206 $wgRequest->setVal( 'wpTextbox1', $text->getWikiOriginal() );
207207 }
208 -
 208+
209209 // try to init, or else return false, which will spawn an 'advanced page' notice
210210 $this->extendedEditPage = new ExtendedEditPage( $this->article );
211 - if( $this->extendedEditPage->initInlineEditor() ) {
 211+ if ( $this->extendedEditPage->initInlineEditor() ) {
212212 // IMPORTANT: if the page was being saved, the script has been terminated by now!!
213 -
 213+
214214 // include the required JS and CSS files
215215 $output->includeJQuery();
216216 $output->addScriptFile( $wgExtensionAssetsPath . "/InlineEditor/jquery.inlineEditor.js?0" );
217217 $output->addScriptFile( $wgExtensionAssetsPath . "/InlineEditor/jquery.inlineEditor.basicEditor.js?0" );
218218 $output->addScriptFile( $wgExtensionAssetsPath . "/InlineEditor/jquery-ui-effects-1.8.4.min.js?0" );
219219 $output->addExtensionStyle( $wgExtensionAssetsPath . "/InlineEditor/InlineEditor.css?0" );
220 -
 220+
221221 // have the different kind of editors register themselves
222222 wfRunHooks( 'InlineEditorDefineEditors', array( &$this, &$output ) );
223 -
 223+
224224 // load the wikitext into the InlineEditorText object
225225 $text->loadFromWikiText( $this->extendedEditPage->getWikiText() );
226 -
 226+
227227 // add a large <div> around the marked wikitext to denote the editing position
228228 $parserOutput = $text->getParserOutputMarked();
229229 $parserOutput->setText( '<div id="editContent">' . $parserOutput->getText() . '</div>' );
230 -
 230+
231231 // put the marked output into the page
232232 $output->addParserOutput( $parserOutput );
233 -
 233+
234234 // add the different edit modes and initial JSON state in Javascript, and finally init the editor
235 - $output->addInlineScript(
 235+ $output->addInlineScript(
236236 'jQuery( document ).ready( function() {
237237 jQuery.inlineEditor.editModes = ["' . implode( '","', array_keys( $this->editModes ) ) . '"];
238238 jQuery.inlineEditor.currentMode = "' . reset( $this->editModes ) . '";
@@ -239,7 +239,7 @@
240240 jQuery.inlineEditor.init();
241241 } );'
242242 );
243 -
 243+
244244 // hook into SiteNoticeBefore to display the two boxes above the title
245245 // @todo: fix this in core, make sure that anything can be inserted above the title, outside #siteNotice
246246 $wgHooks['SiteNoticeBefore'][] = array( $this, 'siteNoticeBefore' );
@@ -249,7 +249,7 @@
250250 return false;
251251 }
252252 }
253 -
 253+
254254 /**
255255 * Get the Article being edited
256256 * @return Article
@@ -257,7 +257,7 @@
258258 public function getArticle() {
259259 return $this->article;
260260 }
261 -
 261+
262262 /**
263263 * Pass JSON into an InlineEditorText object and return combined JSON (HTML + sentence representation)
264264 * @param $json String
@@ -268,23 +268,23 @@
269269 $text->loadFromJson( $json );
270270 return $text->getCombinedJson();
271271 }
272 -
 272+
273273 /**
274 - * Hooks into SiteNoticeBefore. Renders the edit interface above the title of the page.
 274+ * Hooks into SiteNoticeBefore. Renders the edit interface above the title of the page.
275275 * @param $siteNotice String
276276 */
277277 public function siteNoticeBefore( &$siteNotice ) {
278278 $siteNotice = $this->renderEditBox() . $this->renderEditModes();
279279 return false;
280280 }
281 -
 281+
282282 /**
283283 * Add an edit mode to the list.
284284 * @param $name String Name to be used in id-fields
285285 * @param $caption String Name to be displayed
286286 * @param $description String Description to be displayed when the mode is selected (*escaped* HTML only!)
287287 */
288 - public function addEditMode($name, $caption, $description) {
 288+ public function addEditMode( $name, $caption, $description ) {
289289 $this->editModes[$name] = array(
290290 'radioid' => 'radio-' . $name,
291291 'descriptionid' => 'description-' . $name,
@@ -292,19 +292,19 @@
293293 'description' => $description
294294 );
295295 }
296 -
 296+
297297 /**
298298 * Generates "Edit box" (the first one)
299299 * This looks like this:
300300 * <div class="editbox">
301301 * inline-editor-editbox-top
302302 * <hr/>
303 - *
 303+ *
304304 * inline-editor-editbox-changes-question
305305 * <input class="summary" name="summary" />
306306 * <div class="example">inline-editor-editbox-changes-example</div>
307307 * <hr/>
308 - *
 308+ *
309309 * <div class="side">
310310 * inline-editor-editbox-publish-notice
311311 * <div class="terms">inline-editor-editbox-publish-terms</div>
@@ -315,31 +315,33 @@
316316 private function renderEditBox() {
317317 $top = wfMsgExt( 'inline-editor-editbox-top', 'parseinline' );
318318 $top .= '<hr/>';
319 -
 319+
320320 $summary = wfMsgExt( 'inline-editor-editbox-changes-question', 'parseinline' );
321 - $summary .= Html::input( 'wpSummary', $this->extendedEditPage->getSummary(),
 321+ $summary .= Html::input( 'wpSummary', $this->extendedEditPage->getSummary(),
322322 'text', array( 'class' => 'summary', 'maxlength' => 250 ) );
323 - $summary .= Html::rawElement( 'div', array( 'class' => 'example' ),
 323+ $summary .= Html::rawElement( 'div', array( 'class' => 'example' ),
324324 wfMsgExt( 'inline-editor-editbox-changes-example', 'parseinline' ) );
325325 $summary .= '<hr/>';
326 -
327 - $terms = Html::rawElement( 'div', array( 'class' => 'terms' ),
328 - wfMsgExt( 'inline-editor-editbox-publish-terms', 'parseinline', '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' ) );
329 - $publish = Html::rawElement( 'div', array( 'class' => 'side' ),
330 - wfMsgExt( 'inline-editor-editbox-publish-notice', 'parseinline' ) . $terms );
 326+
 327+ $terms = Html::rawElement( 'div', array( 'class' => 'terms' ),
 328+ // @todo FIXME: Create a link to content language copyrightpage with plain content
 329+ // link description.
 330+ wfMsgExt( 'inline-editor-editbox-publish-terms', 'parseinline', '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' ) );
 331+ $publish = Html::rawElement( 'div', array( 'class' => 'side' ),
 332+ wfMsgExt( 'inline-editor-editbox-publish-notice', 'parseinline' ) . $terms );
331333 $publish .= Html::rawElement( 'a', array( 'id' => 'publish', 'href' => '#' ),
332334 wfMsgExt( 'inline-editor-editbox-publish-caption', 'parseinline' ) );
333 - $publish .= HTML::rawElement( 'input', array( 'id' => 'json', 'name' => 'json', 'type' => 'hidden' ));
334 -
335 - $form = Html::rawElement( 'form', array(
 335+ $publish .= HTML::rawElement( 'input', array( 'id' => 'json', 'name' => 'json', 'type' => 'hidden' ) );
 336+
 337+ $form = Html::rawElement( 'form', array(
336338 'id' => 'editForm',
337339 'method' => 'POST',
338340 'action' => $this->extendedEditPage->getSubmitUrl() ), $top . $summary . $publish );
339 -
340 -
 341+
 342+
341343 return Html::rawElement( 'div', array( 'class' => 'editbox' ), $form );
342344 }
343 -
 345+
344346 /**
345347 * Generates "Edit mode" box (the second one)
346348 * This looks like this:
@@ -359,43 +361,43 @@
360362 * @return string HTML
361363 */
362364 private function renderEditModes() {
363 - if (!isset($this->editModes)) return '';
364 -
365 - $header = Html::rawElement( 'div', array( 'class' => 'radio title' ),
 365+ if ( !isset( $this->editModes ) ) return '';
 366+
 367+ $header = Html::rawElement( 'div', array( 'class' => 'radio title' ),
366368 wfMsgExt( 'inline-editor-editmodes-caption', 'parseinline' ) );
367 -
 369+
368370 $descriptions = '';
369371 $first = true;
370 - foreach( $this->editModes as $editmode ) {
 372+ foreach ( $this->editModes as $editmode ) {
371373 $inputOptions = array( 'id' => $editmode['radioid'], 'class' => 'optionMode' );
372 - if ($first) {
 374+ if ( $first ) {
373375 $inputOptions['checked'] = 'checked';
374376 $first = false;
375377 }
376378 $input = Html::input( 'optionMode', '', 'radio', $inputOptions );
377 - $label = Html::rawElement('label', array( 'for' => $editmode['radioid'] ), $editmode['caption'] );
378 -
 379+ $label = Html::rawElement( 'label', array( 'for' => $editmode['radioid'] ), $editmode['caption'] );
 380+
379381 $header .= Html::rawElement( 'div', array( 'class' => 'radio' ), $input . $label );
380 -
381 - $descriptions .= Html::rawElement('div', array( 'class' => 'descriptionInner', 'id' => $editmode['descriptionid']),
 382+
 383+ $descriptions .= Html::rawElement( 'div', array( 'class' => 'descriptionInner', 'id' => $editmode['descriptionid'] ),
382384 $editmode['description'] );
383385 }
384 -
 386+
385387 $header .= Html::rawElement( 'div', array( 'class' => 'button' ),
386388 Html::rawElement( 'a', array( 'id' => 'redo', 'href' => '#' ),
387389 wfMsgExt( 'inline-editor-editmodes-redo', 'parseinline' ) )
388390 );
389391 $header .= Html::rawElement( 'div', array( 'class' => 'button' ),
390392 Html::rawElement( 'a', array( 'id' => 'undo', 'href' => '#' ),
391 - wfMsgExt( 'inline-editor-editmodes-undo', 'parseinline' ) )
 393+ wfMsgExt( 'inline-editor-editmodes-undo', 'parseinline' ) )
392394 );
393395 $header .= Html::rawElement( 'div', array( 'class' => 'button' ),
394396 Html::rawElement( 'div', array( 'id' => 'editCounter', 'href' => '#' ), '#0' )
395397 );
396 -
 398+
397399 return Html::rawElement( 'div', array( 'class' => 'editmode' ),
398400 Html::rawElement( 'div', array( 'class' => 'header' ), $header )
399401 . Html::rawElement( 'div', array( 'class' => 'descriptionOuter' ), $descriptions )
400402 );
401403 }
402 -}
\ No newline at end of file
 404+}
Index: trunk/extensions/InlineEditor/ListEditor/ListEditor.i18n.php
@@ -15,10 +15,8 @@
1616 'list-editor-desc' => 'Adds the "Lists" edit mode for the InlineEditor',
1717
1818 'list-editor-editmode-caption' => "Lists",
19 - 'list-editor-editmode-description' => "
20 -Lists work like shown below.
21 -You can also make a new list by going in any other mode, like the '''Text''' mode,
22 -and add a list like the one below.
 19+ 'list-editor-editmode-description' => "Lists work like shown below.
 20+You can also make a new list by going in any other mode, like the '''Text''' mode, and add a list like the one below.
2321
2422 {| width=\"100%\" style=\"background-color: inherit\"
2523 ! Code
@@ -38,6 +36,5 @@
3937 *** deeper levels
4038 |}
4139
42 -[http://meta.wikimedia.org/wiki/Help:List More information]
43 - ",
44 -);
\ No newline at end of file
 40+[http://meta.wikimedia.org/wiki/Help:List More information]",
 41+);
Index: trunk/extensions/InlineEditor/ListEditor/ListEditor.php
@@ -38,4 +38,4 @@
3939 $wgHooks['InlineEditorDefineEditors'][] = 'ListEditor::defineEditors';
4040
4141 // i18n messages
42 -$wgExtensionMessagesFiles['ListEditor'] = $dir . 'ListEditor.i18n.php';
\ No newline at end of file
 42+$wgExtensionMessagesFiles['ListEditor'] = $dir . 'ListEditor.i18n.php';
Index: trunk/extensions/InlineEditor/ListEditor/ListEditor.class.php
@@ -1,9 +1,9 @@
22 <?php
 3+
34 /**
4 - * Simple editor for lists.
 5+ * Simple editor for lists.
56 */
67 class ListEditor {
7 -
88 /**
99 * This function hooks into InlineEditorMark and marks the media.
1010 * @param $inlineEditorText InlineEditorText
@@ -11,23 +11,23 @@
1212 public static function mark( &$inlineEditorText ) {
1313 // get the original wikitext
1414 $text = $inlineEditorText->getWikiOriginal();
15 -
 15+
1616 $matches = array();
1717 preg_match_all( '/(\n|^)(([*#;:].*(\n|$))+)/', $text, $matches, PREG_OFFSET_CAPTURE );
18 -
19 - foreach( $matches[2] as $match ) {
 18+
 19+ foreach ( $matches[2] as $match ) {
2020 $start = $match[1];
2121 $end = $start + strlen( $match[0] );
22 -
 22+
2323 // do not include the trailing newline
24 - if( substr( $match[0], -1) == "\n" ) $end--;
25 -
 24+ if ( substr( $match[0], -1 ) == "\n" ) $end--;
 25+
2626 $inlineEditorText->addPiece( new InlineEditorPiece( $start, $end, 'listEditorElement', false ) );
2727 }
28 -
 28+
2929 return true;
3030 }
31 -
 31+
3232 /**
3333 * Hooks into InlineEditorDefineEditors. Adds the option to to the list and adds CSS and JS files
3434 * @param $editor InlineEditor
@@ -35,16 +35,16 @@
3636 */
3737 public static function defineEditors( &$editor, &$output ) {
3838 global $wgExtensionAssetsPath;
39 -
 39+
4040 $editor->addEditMode(
41 - 'listEditor',
42 - wfMsgExt( 'list-editor-editmode-caption', 'parseinline' ),
43 - wfMsgExt( 'list-editor-editmode-description','parseinline' )
 41+ 'listEditor',
 42+ wfMsgExt( 'list-editor-editmode-caption', 'parseinline' ),
 43+ wfMsgExt( 'list-editor-editmode-description', 'parseinline' )
4444 );
45 -
46 - $output->addExtensionStyle( "$wgExtensionAssetsPath/InlineEditor/ListEditor/ListEditor.css?0");
 45+
 46+ $output->addExtensionStyle( "$wgExtensionAssetsPath/InlineEditor/ListEditor/ListEditor.css?0" );
4747 $output->addScriptFile( "$wgExtensionAssetsPath/InlineEditor/ListEditor/jquery.inlineEditor.editors.listEditor.js?0" );
48 -
 48+
4949 return true;
5050 }
51 -}
\ No newline at end of file
 51+}
Index: trunk/extensions/InlineEditor/TemplateEditor/TemplateEditor.i18n.php
@@ -15,11 +15,8 @@
1616 'template-editor-desc' => 'Adds the "Template" edit mode for the InlineEditor',
1717
1818 'template-editor-editmode-caption' => "Templates",
19 - 'template-editor-editmode-description' => "
20 -Templates are used to show the same thing on multiple pages.
21 -To fully understand templates, you should read documentation
22 -found online.
 19+ 'template-editor-editmode-description' => "Templates are used to show the same thing on multiple pages.
 20+To fully understand templates, you should read documentation found online.
2321
24 -[http://www.mediawiki.org/wiki/Help:Templates More information]
25 -",
26 -);
\ No newline at end of file
 22+[http://www.mediawiki.org/wiki/Help:Templates More information].",
 23+);
Index: trunk/extensions/InlineEditor/TemplateEditor/TemplateEditor.php
@@ -38,4 +38,4 @@
3939 $wgHooks['InlineEditorDefineEditors'][] = 'TemplateEditor::defineEditors';
4040
4141 // i18n messages
42 -$wgExtensionMessagesFiles['TemplateEditor'] = $dir . 'TemplateEditor.i18n.php';
\ No newline at end of file
 42+$wgExtensionMessagesFiles['TemplateEditor'] = $dir . 'TemplateEditor.i18n.php';
Index: trunk/extensions/InlineEditor/TemplateEditor/TemplateEditor.class.php
@@ -1,9 +1,9 @@
22 <?php
 3+
34 /**
4 - * Simple editor for templates.
 5+ * Simple editor for templates.
56 */
67 class TemplateEditor {
7 -
88 /**
99 * This function hooks into InlineEditorMark and marks the media.
1010 * @param $inlineEditorText InlineEditorText
@@ -11,19 +11,19 @@
1212 public static function mark( &$inlineEditorText ) {
1313 // get the original wikitext
1414 $text = $inlineEditorText->getWikiOriginal();
15 -
 15+
1616 $matches = array();
17 - preg_match_all('/^(\{\{.*?\}\})/ms', $text, $matches, PREG_OFFSET_CAPTURE);
18 -
19 - foreach( $matches[0] as $match ) {
 17+ preg_match_all( '/^(\{\{.*?\}\})/ms', $text, $matches, PREG_OFFSET_CAPTURE );
 18+
 19+ foreach ( $matches[0] as $match ) {
2020 $start = $match[1];
2121 $end = $start + strlen( $match[0] );
2222 $inlineEditorText->addPiece( new InlineEditorPiece( $start, $end, 'templateEditorElement templateEditorElementNotEditing', false ) );
2323 }
24 -
 24+
2525 return true;
2626 }
27 -
 27+
2828 /**
2929 * Hooks into InlineEditorDefineEditors. Adds the option to to the list and adds CSS and JS files
3030 * @param $editor InlineEditor
@@ -31,16 +31,16 @@
3232 */
3333 public static function defineEditors( &$editor, &$output ) {
3434 global $wgExtensionAssetsPath;
35 -
 35+
3636 $editor->addEditMode(
37 - 'templateEditor',
38 - wfMsgExt( 'template-editor-editmode-caption', 'parseinline' ),
39 - wfMsgExt( 'template-editor-editmode-description','parseinline' )
 37+ 'templateEditor',
 38+ wfMsgExt( 'template-editor-editmode-caption', 'parseinline' ),
 39+ wfMsgExt( 'template-editor-editmode-description', 'parseinline' )
4040 );
41 -
42 - $output->addExtensionStyle( "$wgExtensionAssetsPath/InlineEditor/TemplateEditor/TemplateEditor.css?0");
 41+
 42+ $output->addExtensionStyle( "$wgExtensionAssetsPath/InlineEditor/TemplateEditor/TemplateEditor.css?0" );
4343 $output->addScriptFile( "$wgExtensionAssetsPath/InlineEditor/TemplateEditor/jquery.inlineEditor.editors.templateEditor.js?0" );
44 -
 44+
4545 return true;
4646 }
47 -}
\ No newline at end of file
 47+}
Index: trunk/extensions/InlineEditor/InlineEditorText.class.php
@@ -3,19 +3,19 @@
44 /**
55 * Stores wikitext, pieces and previous markings, and generates HTML and JSON from them.
66 * Can import wikitext and previous markings from JSON and from an original article.
7 - *
 7+ *
88 * Computation path is as follows:
9 - *
 9+ *
1010 * First time editing the page:
1111 * wikitext from article => adding of new pieces => generating HTML (using parser) and JSON array
12 - *
 12+ *
1313 * Previewing the page:
1414 * JSON array with pieces + last edit diff => adding of new pieces
1515 * => computing overlap of pieces with previous markings => generating HTML (using parser) and JSON array
1616 * => generating combined JSON array
1717 *
1818 * Saving the page:
19 - * JSON array with pieces => new wikitext
 19+ * JSON array with pieces => new wikitext
2020 *
2121 */
2222 class InlineEditorText {
@@ -27,7 +27,7 @@
2828 private $article;
2929 private $pieces;
3030 private $previousMarkings;
31 -
 31+
3232 /**
3333 * @param $article Article The article to work with.
3434 */
@@ -36,7 +36,7 @@
3737 $this->pieces = array();
3838 $this->previousMarkings = array();
3939 }
40 -
 40+
4141 /**
4242 * Load the original wikitext from $wikiText.
4343 * @param $wikiText String
@@ -45,53 +45,53 @@
4646 $this->reset();
4747 $this->wikiOriginal = $wikiText;
4848 }
49 -
 49+
5050 /**
5151 * Get the original wikitext.
5252 * @return String Original wikitext
5353 */
5454 public function getWikiOriginal() {
55 - return $this->wikiOriginal;
 55+ return $this->wikiOriginal;
5656 }
57 -
 57+
5858 /**
5959 * Get the HTML with <span> and <div> markings.
6060 * @return String HTML
6161 */
6262 public function getParserOutputMarked() {
63 - if( !isset( $this->parserOutputMarked ) ) $this->process();
64 - return $this->parserOutputMarked;
 63+ if ( !isset( $this->parserOutputMarked ) ) $this->process();
 64+ return $this->parserOutputMarked;
6565 }
66 -
 66+
6767 /**
6868 * Get JSON representation of the wikitext and markings.
6969 * @return String JSON
7070 */
7171 public function getWikiJson() {
72 - if( !isset( $this->wikiJsonText ) ) $this->toJsonText();
73 - return $this->wikiJsonText;
 72+ if ( !isset( $this->wikiJsonText ) ) $this->toJsonText();
 73+ return $this->wikiJsonText;
7474 }
75 -
 75+
7676 /**
7777 * Get a combined JSON representation of the wikitext with markings, and marked HTML.
7878 * @return String JSON with HTML in it
7979 */
8080 public function getCombinedJson() {
81 - if( !isset( $this->combinedJson ) ) $this->toCombinedJson();
 81+ if ( !isset( $this->combinedJson ) ) $this->toCombinedJson();
8282 return $this->combinedJson;
8383 }
84 -
 84+
8585 /**
86 - * Add a marking piece to the list of pieces. To be called by the different edit modes.
 86+ * Add a marking piece to the list of pieces. To be called by the different edit modes.
8787 * @param $piece InlineEditorPiece
8888 */
8989 public function addPiece( InlineEditorPiece $piece ) {
90 - if( isset( $this->pieces[$piece->getStart()] ) ) return;
91 - if( !$piece->isValid() ) return;
92 -
 90+ if ( isset( $this->pieces[$piece->getStart()] ) ) return;
 91+ if ( !$piece->isValid() ) return;
 92+
9393 $this->pieces[$piece->getStart()] = $piece;
9494 }
95 -
 95+
9696 /**
9797 * Reset the object.
9898 */
@@ -104,7 +104,7 @@
105105 $this->pieces = array();
106106 $this->previousMarkings = array();
107107 }
108 -
 108+
109109 /**
110110 * Load original wikitext and previous markings from JSON
111111 * @param $json String JSON string from the client side editor
@@ -112,74 +112,74 @@
113113 public function loadFromJson( $json ) {
114114 // first of all, reset the object
115115 $this->reset();
116 -
 116+
117117 // decode the JSON to an associative array
118118 $input = FormatJson::decode( $json, true );
119 -
 119+
120120 // if the 'lastEdit' attribute is set, this contains the edit the user made
121121 // the original text is kept intact, but we don't need it, so just overwrite it with the new text
122 - if( isset($input['lastEdit']) ) {
 122+ if ( isset( $input['lastEdit'] ) ) {
123123 $input['originalWiki']['locations'][$input['lastEdit']['id']]['text'] = $input['lastEdit']['text'];
124124 }
125 -
 125+
126126 // convert the 'locations' array (by id) to the $pieces array (by position)
127127 $pieces = array();
128 - foreach( $input['originalWiki']['locations'] as $id => $piece ) {
 128+ foreach ( $input['originalWiki']['locations'] as $id => $piece ) {
129129 $piece['id'] = $id;
130130 $pieces[$piece['pos']] = $piece;
131131 }
132 -
 132+
133133 // sort the $pieces array by position
134 - ksort($pieces);
135 -
 134+ ksort( $pieces );
 135+
136136 // init loop variables
137137 $text = ''; // reconstructed wikitext
138138 $lastPos = 0; // position in the text of the previous piece
139139 $offset = 0; // total amount of wikitext *inside* pieces so far
140 -
 140+
141141 // iterate on all pieces
142 - foreach( $pieces as $pos => $piece) {
 142+ foreach ( $pieces as $pos => $piece ) {
143143 // calculate the length of the piece
144144 $length = strlen( $piece['text'] );
145 -
 145+
146146 // add the wikitext between the previous piece and this piece
147147 $text .= substr( $input['originalWiki']['text'], $lastPos, $pos - $lastPos );
148 -
 148+
149149 // add the wikitext of the piece itself
150150 $text .= $piece['text'];
151 -
 151+
152152 // if this piece was last edited or marked before, add it to previousMarkings
153 - if( ( isset( $input['lastEdit'] ) && $input['lastEdit']['id'] == $piece['id'] )
154 - || $piece['edited'] )
 153+ if ( ( isset( $input['lastEdit'] ) && $input['lastEdit']['id'] == $piece['id'] )
 154+ || $piece['edited'] )
155155 {
156156 // because these positions are within the text *with* the pieces included,
157157 // the position has to be offsetted by exactly the total length of pieces so far
158158 $previousStart = $pos + $offset;
159159 $previousMarking = new InlineEditorPreviousMarking( $previousStart, $previousStart + $length );
160160 $previousMarking->setEdited( true );
161 -
162 - if( isset( $input['lastEdit'] ) && $input['lastEdit']['id'] == $piece['id'] ) {
 161+
 162+ if ( isset( $input['lastEdit'] ) && $input['lastEdit']['id'] == $piece['id'] ) {
163163 $previousMarking->setLastEdit( true );
164164 }
165 -
 165+
166166 // last sanity check before adding the marking
167 - if( $previousMarking->isValid() ) {
 167+ if ( $previousMarking->isValid() ) {
168168 $this->previousMarkings[$previousStart] = $previousMarking;
169169 }
170170 }
171 -
 171+
172172 // set variables for next round
173 - $lastPos = $pos;
174 - $offset += $length;
 173+ $lastPos = $pos;
 174+ $offset += $length;
175175 }
176 -
 176+
177177 // add the text after the last piece
178178 $text .= substr( $input['originalWiki']['text'], $lastPos );
179 -
 179+
180180 // store it as the original wikitext
181181 $this->wikiOriginal = $text;
182182 }
183 -
 183+
184184 /**
185185 * Encodes the wikiJsonArray to a JSON string and stores it.
186186 */
@@ -187,41 +187,41 @@
188188 if ( !isset( $this->wikiJsonArray ) ) $this->process();
189189 $this->wikiJsonText = FormatJson::encode( $this->wikiJsonArray );
190190 }
191 -
 191+
192192 /**
193193 * Encodes both the wikiJsonArray and the parserOutputMarked to a JSON string and stores it.
194194 */
195195 private function toCombinedJson() {
196196 if ( !isset( $this->wikiJsonArray ) || !isset( $this->parserOutputMarked ) ) $this->process();
197 -
198 - $combined = array('html' => $this->parserOutputMarked->getText(), 'wiki' => $this->wikiJsonArray);
 197+
 198+ $combined = array( 'html' => $this->parserOutputMarked->getText(), 'wiki' => $this->wikiJsonArray );
199199 $this->combinedJson = FormatJson::encode( $combined );
200200 }
201 -
 201+
202202 /**
203203 * Calls the InlineEditorMark hook to have pieces added, and calculates the JSON and marked HTML.
204204 */
205205 private function process() {
206206 global $wgParser;
207 -
 207+
208208 // make sure the pieces are added by the edit modes
209209 wfRunHooks( 'InlineEditorMark', array( &$this ) );
210 -
 210+
211211 // init the basic variables
212212 $last = 0; // end position of the last piece in the original wikitext
213213 $offset = 0; // total amount of wikitext *inside* pieces so far
214214 $wikiMarked = ''; // marked wikitext to run through the parser
215215 $jsonText = ''; // wikitext in JSON, which has the pieces *removed*
216216 $jsonLocations = array(); // pieces with positions where to insert them in $jsonText
217 -
 217+
218218 // sort the pieces by start position
219219 ksort( $this->pieces );
220 -
 220+
221221 // make sure the 'edited' and 'lastEdit' properties on pieces are correctly set
222222 $this->applyPreviousMarkings();
223 -
 223+
224224 // iterate on all pieces
225 - foreach( $this->pieces as $start => $piece ) {
 225+ foreach ( $this->pieces as $start => $piece ) {
226226 // do not allow overlap of pieces, so only take those with the lowest
227227 // starting position
228228 if ( $start < $last ) {
@@ -230,24 +230,24 @@
231231 else {
232232 // get the end and calculate the length of the current piece
233233 $end = $piece->getEnd();
234 - $length = $end-$start;
235 -
 234+ $length = $end -$start;
 235+
236236 // get the text between last piece and this piece
237 - $prePieceText = substr($this->wikiOriginal, $last, $start-$last);
238 -
 237+ $prePieceText = substr( $this->wikiOriginal, $last, $start -$last );
 238+
239239 // get the text of the piece itself
240 - $pieceText = substr($this->wikiOriginal, $start, $length);
241 -
 240+ $pieceText = substr( $this->wikiOriginal, $start, $length );
 241+
242242 // add the text between last piece and this piece, followed by
243243 // the text of the piece surrounded by markings
244 - $wikiMarked .= $prePieceText
245 - . $piece->renderStartMarking()
 244+ $wikiMarked .= $prePieceText
 245+ . $piece->renderStartMarking()
246246 . $pieceText
247247 . $piece->renderEndMarking();
248 -
 248+
249249 // only add the text between pieces to the JSON text
250250 $jsonText .= $prePieceText;
251 -
 251+
252252 // add the piece and position in $jsonText to the list of locations
253253 // note that because we're taking out exactly the length of text within pieces,
254254 // we can subtract this number from the start position of the piece, to obtain
@@ -255,89 +255,89 @@
256256 $jsonLocations[$piece->getId()] = array(
257257 'text' => $pieceText,
258258 'pos' => $start - $offset,
259 - 'edited' => ($piece->getEdited() ? '1' : '0')
 259+ 'edited' => ( $piece->getEdited() ? '1' : '0' )
260260 );
261 -
 261+
262262 // set variables for the next round
263263 $offset += $length;
264264 $last = $end;
265265 }
266266 }
267 -
 267+
268268 // get the text after the last piece and add it to both variables
269 - $postPieceText = substr($this->wikiOriginal, $last);
 269+ $postPieceText = substr( $this->wikiOriginal, $last );
270270 $wikiMarked .= $postPieceText;
271271 $jsonText .= $postPieceText;
272 -
 272+
273273 // store the JSON text and locations
274274 $this->wikiJsonArray = array( 'text' => $jsonText, 'locations' => $jsonLocations );
275 -
 275+
276276 // get the same parser options as usual, but remove [edit] links
277277 $parserOptions = clone $this->article->getParserOptions();
278278 $parserOptions->setEditSection( false );
279 -
 279+
280280 // run $wikiMarked through the parser and store the result
281 - $this->parserOutputMarked = $wgParser->parse( $wikiMarked, $this->article->getTitle(),
 281+ $this->parserOutputMarked = $wgParser->parse( $wikiMarked, $this->article->getTitle(),
282282 $parserOptions, true, true, $this->article->getRevIdFetched() );
283283 }
284 -
 284+
285285 /**
286286 * Checks if pieces have overlap with previous markings and marks them again with
287287 * 'edited' or 'lastEdit'.
288 - *
 288+ *
289289 * A piece can have overlap with multiple previous markings, but not with many. To
290290 * avoid checking all pieces against all markings, a smarter algorithm is employed.
291 - *
292 - * When both the pieces are sorted (*precondition*) and the previous markings are
 291+ *
 292+ * When both the pieces are sorted (*precondition*) and the previous markings are
293293 * sorted (which is done in the function), both arrays can be walked. For the array of
294294 * previous markings we define a $firstId and $lastId. The end of the first previous marking
295 - * has to be at least on or past the start of the current piece. The start of the last
 295+ * has to be at least on or past the start of the current piece. The start of the last
296296 * previous marking has to be at least past the end of the current piece. This way we can
297297 * increment $firstId and $lastId until this is true, and we have a smaller window to
298298 * check.
299 - *
 299+ *
300300 * @return unknown_type
301301 */
302302 private function applyPreviousMarkings() {
303303 // if there are no previous markings there is no point in checking
304 - if( empty( $this->previousMarkings ) ) return;
305 -
 304+ if ( empty( $this->previousMarkings ) ) return;
 305+
306306 // start both at the beginning
307307 $firstId = 0;
308308 $lastId = 0;
309 -
 309+
310310 // sort based on start position
311311 ksort( $this->previousMarkings );
312 -
 312+
313313 // use an array with as keys 0, 1, 2, etc.
314314 $previous = array_values( $this->previousMarkings );
315 -
 315+
316316 // interate over all pieces
317 - foreach( $this->pieces as $start => $piece ) {
 317+ foreach ( $this->pieces as $start => $piece ) {
318318 $end = $piece->getEnd();
319 -
 319+
320320 // move the pointer of the first previous marking so it overlaps with the piece
321 - while( isset( $previous[$firstId] ) && $previous[$firstId]->getEnd() < $start ) {
 321+ while ( isset( $previous[$firstId] ) && $previous[$firstId]->getEnd() < $start ) {
322322 $firstId++;
323323 }
324 -
 324+
325325 // if the pointer to the first previous marking has gone too far, there is nothing
326326 // to check for anymore: we're done
327 - if( !isset( $previous[$firstId] ) ) return;
328 -
 327+ if ( !isset( $previous[$firstId] ) ) return;
 328+
329329 // move the pointer of the last previous marking so it just doesn't overlap
330 - while( isset( $previous[$lastId] ) && $previous[$lastId]->getStart() <= $end ) {
 330+ while ( isset( $previous[$lastId] ) && $previous[$lastId]->getStart() <= $end ) {
331331 $lastId++;
332332 }
333 -
 333+
334334 // check the (small) window of previous markings for overlap
335 - for( $i = $firstId; $i < $lastId; $i++ ) {
 335+ for ( $i = $firstId; $i < $lastId; $i++ ) {
336336 // this should always be true, but check anyway!
337 - if( $previous[$i]->inMarking( $piece ) ) {
338 - if( $previous[$i]->getEdited() ) $piece->setEdited( true );
339 - if( $previous[$i]->getLastEdit() ) $piece->setLastEdit( true );
 337+ if ( $previous[$i]->inMarking( $piece ) ) {
 338+ if ( $previous[$i]->getEdited() ) $piece->setEdited( true );
 339+ if ( $previous[$i]->getLastEdit() ) $piece->setLastEdit( true );
340340 }
341341 }
342342 }
343343 }
344 -}
\ No newline at end of file
 344+}
Index: trunk/extensions/InlineEditor/InlineEditorPiece.class.php
@@ -4,16 +4,16 @@
55 * Denotes the start and end of an editiable piece in the wikitext, along with some properties.
66 */
77 class InlineEditorPiece {
8 - private static $lastId = 0; ///< counter which is used to generate unique ids
9 -
10 - private $start; ///< start position of the piece in the wikitext
11 - private $end; ///< end position of the piece in the wikitext
12 - private $class; ///< class(es) attached to the piece, usually identifies the edit mode
13 - private $inline; ///< whether or not the piece is inline (span) or not (div)
14 - private $id; ///< unique id of this piece
15 - private $edited; ///< boolean whether or not (part of) the piece has been edited before
16 - private $lastEdit; ///< boolean whether or not (part of) the piece was in the last edit
17 -
 8+ private static $lastId = 0; /// < counter which is used to generate unique ids
 9+
 10+ private $start; /// < start position of the piece in the wikitext
 11+ private $end; /// < end position of the piece in the wikitext
 12+ private $class; /// < class(es) attached to the piece, usually identifies the edit mode
 13+ private $inline; /// < whether or not the piece is inline (span) or not (div)
 14+ private $id; /// < unique id of this piece
 15+ private $edited; /// < boolean whether or not (part of) the piece has been edited before
 16+ private $lastEdit; /// < boolean whether or not (part of) the piece was in the last edit
 17+
1818 // getter functions for most private variables
1919 public function getStart() { return $this->start; }
2020 public function getEnd() { return $this->end; }
@@ -21,28 +21,28 @@
2222 public function getId() { return $this->id; }
2323 public function getEdited() { return $this->edited; }
2424 public function getLastEdit() { return $this->lastEdit; }
25 -
 25+
2626 // setter functions for edited and lastEdit, as these are not set by the different editors,
2727 // but by InlineEditorText
2828 public function setEdited( $val ) { $this->edited = $val; }
2929 public function setLastEdit( $val ) { $this->lastEdit = $val; }
30 -
 30+
3131 /**
3232 * @param $start Integer Start of the piece, offset in number of characters from the begin of the wikitext
3333 * @param $end Integer End of the piece, offset in number of characters from the begin of the wikitext
3434 * @param $class String Class(es) the piece should be labeled with
3535 * @param $inline Boolean Whether the piece is inline (span) or not (div), a div also adds newlines
3636 */
37 - function __construct($start, $end, $class, $inline) {
 37+ function __construct( $start, $end, $class, $inline ) {
3838 $this->start = $start;
3939 $this->end = $end;
4040 $this->class = $class;
4141 $this->inline = $inline;
4242 $this->id = self::uniqueId();
4343 $this->edited = false;
44 - $this->lastEdit = false;
 44+ $this->lastEdit = false;
4545 }
46 -
 46+
4747 /**
4848 * Render the open tag, depending on $this->inline this is a <span> or a <div>.
4949 * @return String HTML
@@ -51,7 +51,7 @@
5252 $attribs = array( 'class' => $this->getFullClass(), 'id' => $this->id );
5353 return HTML::openElement( $this->getElement(), $attribs ) . $this->getNewline();
5454 }
55 -
 55+
5656 /**
5757 * Render the close tag.
5858 * @return String HTML
@@ -59,7 +59,7 @@
6060 public function renderEndMarking() {
6161 return $this->getNewline() . '</' . $this->getElement() . '>';
6262 }
63 -
 63+
6464 /**
6565 * Simple check to prevent invalid values.
6666 * @return boolean
@@ -67,15 +67,15 @@
6868 public function isValid() {
6969 return $this->end > $this->start;
7070 }
71 -
 71+
7272 /**
73 - * Get the class that should be rendered, this may include 'edited' and 'lastEdit' for highlighting.
 73+ * Get the class that should be rendered, this may include 'edited' and 'lastEdit' for highlighting.
7474 * @return String All the classes
7575 */
7676 private function getFullClass() {
77 - return $this->class . ($this->edited ? ' edited' : '') . ($this->lastEdit ? ' lastEdit' : '');
 77+ return $this->class . ( $this->edited ? ' edited' : '' ) . ( $this->lastEdit ? ' lastEdit' : '' );
7878 }
79 -
 79+
8080 /**
8181 * Get the element name based on $this->inline.
8282 * @return String Element name
@@ -83,7 +83,7 @@
8484 private function getElement() {
8585 return $this->inline ? 'span' : 'div';
8686 }
87 -
 87+
8888 /**
8989 * Get a newline or not based on $this->inline.
9090 * @return String Empty string or single newline character
@@ -91,7 +91,7 @@
9292 private function getNewline() {
9393 return $this->inline ? '' : "\n";
9494 }
95 -
 95+
9696 /**
9797 * Get a unique id by using self::$lastId and incrementing it.
9898 * @return String
@@ -99,4 +99,4 @@
100100 private static function uniqueId() {
101101 return 'inline-editor-' . self::$lastId++;
102102 }
103 -}
\ No newline at end of file
 103+}
Index: trunk/extensions/InlineEditor/InlineEditorPreviousMarking.class.php
@@ -4,11 +4,11 @@
55 * Denotes the start and end of previously edited pieces in the wikitext.
66 */
77 class InlineEditorPreviousMarking {
8 - private $start; ///< start position of the piece in the wikitext
9 - private $end; ///< end position of the piece in the wikitext
10 - private $edited; ///< boolean whether or not (part of) the piece has been edited before
11 - private $lastEdit; ///< boolean whether or not (part of) the piece was in the last edit
12 -
 8+ private $start; /// < start position of the piece in the wikitext
 9+ private $end; /// < end position of the piece in the wikitext
 10+ private $edited; /// < boolean whether or not (part of) the piece has been edited before
 11+ private $lastEdit; /// < boolean whether or not (part of) the piece was in the last edit
 12+
1313 // getters and setters for the private variables
1414 public function getStart() { return $this->start; }
1515 public function getEnd() { return $this->end; }
@@ -16,16 +16,16 @@
1717 public function getLastEdit() { return $this->lastEdit; }
1818 public function setEdited( $val ) { $this->edited = $val; }
1919 public function setLastEdit( $val ) { $this->lastEdit = $val; }
20 -
 20+
2121 /**
2222 * @param $start Integer Start of the piece, offset in number of characters from the begin of the wikitext
2323 * @param $end Integer End of the piece, offset in number of characters from the begin of the wikitext
2424 */
25 - function __construct($start, $end) {
 25+ function __construct( $start, $end ) {
2626 $this->start = $start;
2727 $this->end = $end;
2828 }
29 -
 29+
3030 /**
3131 * Checks if an InlineEditorPiece overlaps *or touches* with this marking.
3232 * @param $piece InlineEditorPiece
@@ -34,9 +34,9 @@
3535 public function inMarking( InlineEditorPiece $piece ) {
3636 $start = $piece->getStart();
3737 $end = $piece->getEnd();
38 - return ($start >= $this->start && $start <= $this->end) || ($end >= $this->start && $end <= $this->end);
 38+ return ( $start >= $this->start && $start <= $this->end ) || ( $end >= $this->start && $end <= $this->end );
3939 }
40 -
 40+
4141 /**
4242 * Simple check to prevent invalid values.
4343 * @return boolean
@@ -44,4 +44,4 @@
4545 public function isValid() {
4646 return $this->end > $this->start;
4747 }
48 -}
\ No newline at end of file
 48+}
Index: trunk/extensions/InlineEditor/MediaEditor/MediaEditor.class.php
@@ -1,9 +1,9 @@
22 <?php
 3+
34 /**
4 - * Simple editor for media (images, video, sound).
 5+ * Simple editor for media (images, video, sound).
56 */
67 class MediaEditor {
7 -
88 /**
99 * This function hooks into InlineEditorMark and marks the media.
1010 * @param $inlineEditorText InlineEditorText
@@ -11,33 +11,33 @@
1212 public static function mark( &$inlineEditorText ) {
1313 // get the original wikitext
1414 $text = $inlineEditorText->getWikiOriginal();
15 -
 15+
1616 $matches = array();
1717 preg_match_all( '/^\s*(\[\[(.*:.*)\]\])\s*$/m', $text, $matches, PREG_OFFSET_CAPTURE );
18 -
19 - foreach( $matches[1] as $id => $match ) {
 18+
 19+ foreach ( $matches[1] as $id => $match ) {
2020 $link = $matches[2][$id][0];
21 - $firstPipe = strpos($link, '|');
22 - if( $firstPipe !== false ) {
 21+ $firstPipe = strpos( $link, '|' );
 22+ if ( $firstPipe !== false ) {
2323 $url = substr( $link, 0, $firstPipe );
2424 }
2525 else {
2626 $url = $link;
2727 }
28 -
 28+
2929 $title = Title::newFromText( $url );
3030 $namespace = $title->getNamespace();
31 -
32 - if( $namespace == NS_FILE ) {
 31+
 32+ if ( $namespace == NS_FILE ) {
3333 $start = $match[1];
3434 $end = $start + strlen( $match[0] );
3535 $inlineEditorText->addPiece( new InlineEditorPiece( $start, $end, 'mediaEditorElement', false ) );
3636 }
3737 }
38 -
 38+
3939 return true;
4040 }
41 -
 41+
4242 /**
4343 * Hooks into InlineEditorDefineEditors. Adds the option to to the list and adds CSS and JS files
4444 * @param $editor InlineEditor
@@ -45,16 +45,16 @@
4646 */
4747 public static function defineEditors( &$editor, &$output ) {
4848 global $wgExtensionAssetsPath;
49 -
 49+
5050 $editor->addEditMode(
51 - 'mediaEditor',
52 - wfMsgExt( 'media-editor-editmode-caption', 'parseinline' ),
53 - wfMsgExt( 'media-editor-editmode-description','parseinline' )
 51+ 'mediaEditor',
 52+ wfMsgExt( 'media-editor-editmode-caption', 'parseinline' ),
 53+ wfMsgExt( 'media-editor-editmode-description', 'parseinline' )
5454 );
55 -
56 - $output->addExtensionStyle( "$wgExtensionAssetsPath/InlineEditor/MediaEditor/MediaEditor.css?0");
 55+
 56+ $output->addExtensionStyle( "$wgExtensionAssetsPath/InlineEditor/MediaEditor/MediaEditor.css?0" );
5757 $output->addScriptFile( "$wgExtensionAssetsPath/InlineEditor/MediaEditor/jquery.inlineEditor.editors.mediaEditor.js?0" );
58 -
 58+
5959 return true;
6060 }
61 -}
\ No newline at end of file
 61+}
Index: trunk/extensions/InlineEditor/MediaEditor/MediaEditor.i18n.php
@@ -15,12 +15,10 @@
1616 'media-editor-desc' => 'Adds the "Media" edit mode for the InlineEditor',
1717
1818 'media-editor-editmode-caption' => "Media",
19 - 'media-editor-editmode-description' => "
20 -You can edit media like images, video and sound using this mode.
 19+ 'media-editor-editmode-description' => "You can edit media like images, video and sound using this mode.
2120 Sometimes templates are used to display images, in which case you have to use the '''Template''' mode.
2221
2322 :<code><nowiki>[[File:Example.jpg|thumb|An example file]]</nowiki></code>
2423
25 -[http://en.wikipedia.org/wiki/Help:Files More information]
26 -",
27 -);
\ No newline at end of file
 24+[http://en.wikipedia.org/wiki/Help:Files More information].",
 25+);
Index: trunk/extensions/InlineEditor/MediaEditor/MediaEditor.php
@@ -38,4 +38,4 @@
3939 $wgHooks['InlineEditorDefineEditors'][] = 'MediaEditor::defineEditors';
4040
4141 // i18n messages
42 -$wgExtensionMessagesFiles['MediaEditor'] = $dir . 'MediaEditor.i18n.php';
\ No newline at end of file
 42+$wgExtensionMessagesFiles['MediaEditor'] = $dir . 'MediaEditor.i18n.php';
Index: trunk/extensions/InlineEditor/InlineEditor.i18n.php
@@ -14,16 +14,18 @@
1515 $messages['en'] = array(
1616 'inline-editor-desc' => 'Provides an alternative editor which is easier to use',
1717
18 - 'inline-editor-editbox-top' => "'''Awesome, you're editing {{SITENAME}}!'''<br/>You can edit the article below, by clicking on <span class=\"highlightExample\">blue elements</span> in the article.",
 18+ 'inline-editor-editbox-top' => "'''Awesome, you are editing {{SITENAME}}!'''<br />You can edit the article below, by clicking on <span class=\"highlightExample\">blue elements</span> in the page.",
1919 'inline-editor-editbox-changes-question' => "Can you briefly describe the changes you're making?",
2020 'inline-editor-editbox-changes-example' => 'For example: "Fixed spelling mistake", "Corrected facts", "Wrote a new paragraph", etc.',
21 - 'inline-editor-editbox-publish-notice' => "When you're done, don't forget to publish the page!",
22 - //'inline-editor-editbox-publish-terms' => 'When you click "Publish", you agree to the [http://wikimediafoundation.org/wiki/Terms_of_Use Terms of Use]. This means that you agree to share your contributions under a free license.',
23 - 'inline-editor-editbox-publish-terms' => 'When you click "Publish", you agree with our copyright policy. See $1 for more information.',
 21+ 'inline-editor-editbox-publish-notice' => "When you are done, do not forget to publish the page!",
 22+ // 'inline-editor-editbox-publish-terms' => 'When you click "Publish", you agree to the [http://wikimediafoundation.org/wiki/Terms_of_Use Terms of Use]. This means that you agree to share your contributions under a free license.',
 23+ 'inline-editor-editbox-publish-terms' => 'When you click "Publish", you agree with our copyright policy.
 24+See $1 for more information.',
2425 'inline-editor-editbox-publish-caption' => 'Publish',
2526 'inline-editor-editmodes-caption' => 'Edit mode:',
2627 'inline-editor-redirect-browser' => 'The new editing interface is not supported by your browser.',
27 - 'inline-editor-redirect-advanced' => "Editing this page is considered '''advanced''' use of Wikipedia. You can only use the '''full editor''' for this page.",
 28+ 'inline-editor-redirect-advanced' => "Editing this page is considered '''advanced''' use of MediaWiki.
 29+You can only use the '''full editor''' for this page.",
2830 'inline-editor-editmodes-undo' => 'Undo',
2931 'inline-editor-editmodes-redo' => 'Redo',
30 -);
\ No newline at end of file
 32+);
Index: trunk/extensions/InlineEditor/ExtendedEditPage.class.php
@@ -1,11 +1,11 @@
22 <?php
33 /**
4 - * This is basically an EditPage with some specific functions for the InlineEditor. This
 4+ * This is basically an EditPage with some specific functions for the InlineEditor. This
55 * allows retrieval of wikitext, summary and a submit URL, and handles when to fall back
6 - * to the full/traditional editor.
 6+ * to the full/traditional editor.
77 */
88 class ExtendedEditPage extends EditPage {
9 -
 9+
1010 /**
1111 * Inits the edit page for the InlineEditor.
1212 * This is largely a copy-paste from EditPage::edit(), with some specific changes.
@@ -13,18 +13,18 @@
1414 public function initInlineEditor() {
1515 global $wgRequest, $wgOut;
1616 $this->importFormData( $wgRequest );
17 -
18 - if( !empty( $this->section ) ) return false;
19 -
 17+
 18+ if ( !empty( $this->section ) ) return false;
 19+
2020 // @todo: refactor this piece in EditPage.php to (a) different function(s)
2121 // so that this is not an ugly copy-paste
22 -
 22+
2323 if ( wfReadOnly() && $this->save ) {
2424 // Force preview
2525 $this->save = false;
2626 $this->preview = true;
2727 }
28 -
 28+
2929 $permErrors = $this->getEditPermissionErrors();
3030 if ( $permErrors ) {
3131 wfDebug( __METHOD__ . ": User can't edit\n" );
@@ -47,7 +47,7 @@
4848 }
4949 }
5050 }
51 -
 51+
5252 // If they used redlink=1 and the page exists, redirect to the main article
5353 if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle->exists() ) {
5454 $wgOut->redirect( $this->mTitle->getFullURL() );
@@ -59,18 +59,18 @@
6060 $this->isCssSubpage = $this->mTitle->isCssSubpage();
6161 $this->isJsSubpage = $this->mTitle->isJsSubpage();
6262 $this->isValidCssJsSubpage = $this->mTitle->isValidCssJsSubpage();
63 -
 63+
6464 // catch the HTML that the intro throws
6565 // if anything is thrown, fall back to the normal editor
6666 $wgOut->clearHTML();
6767 if ( $this->formtype == 'initial' || $this->firsttime ) {
6868 $this->showIntro();
69 - if( $wgOut->getHTML() != '' ) {
 69+ if ( $wgOut->getHTML() != '' ) {
7070 $wgOut->clearHTML();
7171 return false;
7272 }
7373 }
74 -
 74+
7575 if ( 'initial' == $this->formtype || 'preview' == $this->formtype || $this->firsttime ) {
7676 if ( $this->initialiseForm() !== false ) {
7777 return true;
@@ -82,7 +82,7 @@
8383 elseif ( 'save' == $this->formtype ) {
8484 // attemptSave does a redirect *itself* when it's succesful!
8585 $this->attemptSave();
86 - if( $this->isConflict ) {
 86+ if ( $this->isConflict ) {
8787 return false;
8888 }
8989 else {
@@ -93,7 +93,7 @@
9494 return false;
9595 }
9696 }
97 -
 97+
9898 /**
9999 * Get the wikitext to render the page from
100100 * @return String
@@ -101,7 +101,7 @@
102102 public function getWikiText() {
103103 return $this->textbox1;
104104 }
105 -
 105+
106106 /**
107107 * Get the summary to show in the input field
108108 * @return String
@@ -109,7 +109,7 @@
110110 public function getSummary() {
111111 return $this->summary;
112112 }
113 -
 113+
114114 /**
115115 * Get the URL to submit to, with some options in the URL that are usually hidden fields
116116 * @return String
@@ -122,11 +122,11 @@
123123 'wpEdittime' => $this->edittime,
124124 'wpStarttime' => $this->starttime
125125 );
126 -
127 - if( $this->scrolltop ) $options['wpScrolltop'] = 1;
128 - if( $this->minoredit ) $options['wpMinorEdit'] = 1;
129 - if( $this->watchthis ) $options['wpWatchthis'] = 1;
130 -
 126+
 127+ if ( $this->scrolltop ) $options['wpScrolltop'] = 1;
 128+ if ( $this->minoredit ) $options['wpMinorEdit'] = 1;
 129+ if ( $this->watchthis ) $options['wpWatchthis'] = 1;
 130+
131131 return $this->mTitle->getLocalURL( $options );
132132 }
133 -}
\ No newline at end of file
 133+}
Index: trunk/extensions/InlineEditor/ReferenceEditor/ReferenceEditor.class.php
@@ -1,9 +1,9 @@
22 <?php
 3+
34 /**
4 - * Simple editor for references.
 5+ * Simple editor for references.
56 */
67 class ReferenceEditor {
7 -
88 /**
99 * This function hooks into InlineEditorMark and marks the references.
1010 * @param $inlineEditorText InlineEditorText
@@ -11,19 +11,19 @@
1212 public static function mark( &$inlineEditorText ) {
1313 // get the original wikitext
1414 $text = $inlineEditorText->getWikiOriginal();
15 -
 15+
1616 $matches = array();
1717 preg_match_all( '/<ref[^\/]*?>.*?<\/ref>|<ref.*?\/>/is', $text, $matches, PREG_OFFSET_CAPTURE );
18 -
19 - foreach( $matches[0] as $match ) {
 18+
 19+ foreach ( $matches[0] as $match ) {
2020 $start = $match[1];
2121 $end = $start + strlen( $match[0] );
2222 $inlineEditorText->addPiece( new InlineEditorPiece( $start, $end, 'referenceEditorElement', true ) );
2323 }
24 -
 24+
2525 return true;
2626 }
27 -
 27+
2828 /**
2929 * Hooks into InlineEditorDefineEditors. Adds the option to to the list and adds CSS and JS files
3030 * @param $editor InlineEditor
@@ -31,16 +31,16 @@
3232 */
3333 public static function defineEditors( &$editor, &$output ) {
3434 global $wgExtensionAssetsPath;
35 -
 35+
3636 $editor->addEditMode(
37 - 'referenceEditor',
38 - wfMsgExt( 'reference-editor-editmode-caption', 'parseinline' ),
39 - wfMsgExt( 'reference-editor-editmode-description','parseinline' )
 37+ 'referenceEditor',
 38+ wfMsgExt( 'reference-editor-editmode-caption', 'parseinline' ),
 39+ wfMsgExt( 'reference-editor-editmode-description', 'parseinline' )
4040 );
41 -
42 - $output->addExtensionStyle( "$wgExtensionAssetsPath/InlineEditor/ReferenceEditor/ReferenceEditor.css?0");
 41+
 42+ $output->addExtensionStyle( "$wgExtensionAssetsPath/InlineEditor/ReferenceEditor/ReferenceEditor.css?0" );
4343 $output->addScriptFile( "$wgExtensionAssetsPath/InlineEditor/ReferenceEditor/jquery.inlineEditor.editors.referenceEditor.js?0" );
44 -
 44+
4545 return true;
4646 }
47 -}
\ No newline at end of file
 47+}
Index: trunk/extensions/InlineEditor/ReferenceEditor/ReferenceEditor.i18n.php
@@ -15,12 +15,10 @@
1616 'reference-editor-desc' => 'Adds the "References" edit mode for the InlineEditor',
1717
1818 'reference-editor-editmode-caption' => "References",
19 - 'reference-editor-editmode-description' => "
20 -References are placed after a piece of text.
 19+ 'reference-editor-editmode-description' => "References are placed after a piece of text.
2120 You can edit them in this mode, and add new references in the '''Text''' mode.
2221
2322 :<code><nowiki>According to scientists, the Sun is pretty big. <ref>E. Miller, The Sun, (New York: Academic Press, 2005), 23-5.</ref></nowiki></code>
2423
25 -[http://www.mediawiki.org/wiki/Extension:Cite/Cite.php More information]
26 -",
27 -);
\ No newline at end of file
 24+[http://www.mediawiki.org/wiki/Extension:Cite/Cite.php More information].",
 25+);
Index: trunk/extensions/InlineEditor/ReferenceEditor/ReferenceEditor.php
@@ -38,4 +38,4 @@
3939 $wgHooks['InlineEditorDefineEditors'][] = 'ReferenceEditor::defineEditors';
4040
4141 // i18n messages
42 -$wgExtensionMessagesFiles['ReferenceEditor'] = $dir . 'ReferenceEditor.i18n.php';
\ No newline at end of file
 42+$wgExtensionMessagesFiles['ReferenceEditor'] = $dir . 'ReferenceEditor.i18n.php';
Index: trunk/extensions/InlineEditor/FullEditor/FullEditor.php
@@ -37,4 +37,4 @@
3838 $wgHooks['InlineEditorDefineEditors'][] = 'FullEditor::defineEditors';
3939
4040 // i18n messages
41 -$wgExtensionMessagesFiles['FullEditor'] = $dir . 'FullEditor.i18n.php';
\ No newline at end of file
 41+$wgExtensionMessagesFiles['FullEditor'] = $dir . 'FullEditor.i18n.php';
Index: trunk/extensions/InlineEditor/FullEditor/FullEditor.class.php
@@ -1,17 +1,18 @@
22 <?php
 3+
34 /**
45 * This 'editor' just shows some description with a link to the full/traditional editor.
56 */
67 class FullEditor {
78 public static function defineEditors( &$editor, &$output ) {
89 $editor->addEditMode(
9 - 'FullEditor',
10 - wfMsgExt( 'fulleditor-editmode-caption', 'parseinline' ),
 10+ 'FullEditor',
 11+ wfMsgExt( 'fulleditor-editmode-caption', 'parseinline' ),
1112 wfMsgExt( 'fulleditor-editmode-description', 'parseinline' )
12 - . '<br/><a class="fulleditor" href="' . $editor->getArticle()->getTitle()->getLocalURL( 'action=edit&fulleditor=1' ) . '">'
 13+ . '<br /><a class="fulleditor" href="' . $editor->getArticle()->getTitle()->getLocalURL( 'action=edit&fulleditor=1' ) . '">'
1314 . wfMsgExt( 'fulleditor-editmode-description-link', 'parseinline' )
1415 . '</a>'
1516 );
1617 return true;
1718 }
18 -}
\ No newline at end of file
 19+}
Index: trunk/extensions/InlineEditor/FullEditor/FullEditor.i18n.php
@@ -15,9 +15,8 @@
1616 'fulleditor-desc' => 'Provides a link to the full editor for the InlineEditor',
1717
1818 'fulleditor-editmode-caption' => 'Full editor',
19 - 'fulleditor-editmode-description' => "
20 -If you want full control over the page, you can use the full editor.
 19+ 'fulleditor-editmode-description' => "If you want full control over the page, you can use the full editor.
2120 With this editor you can edit the [http://en.wikipedia.org/wiki/Help:Wiki_markup Wiki markup] directly.
22 -The editor is also more complex to use, but to have full control of editing Wikipedia, that's worth it!",
23 - 'fulleditor-editmode-description-link' => 'Use the full editor &raquo;',
24 -);
\ No newline at end of file
 21+The editor is also more complex to use, but to have full control of editing this wikis, may be worth it!",
 22+ 'fulleditor-editmode-description-link' => 'Use the full editor »',
 23+);
Index: trunk/extensions/InlineEditor/SentenceEditor/SentenceEditor.i18n.php
@@ -16,27 +16,23 @@
1717
1818 'sentence-editor-editmode-caption' => "Text",
1919 /*
20 - 'sentence-editor-editmode-description' => "
21 -There are a few [http://en.wikipedia.org/wiki/Wikipedia:Simplified_ruleset guidelines] for editing an article:<br/>
 20+ 'sentence-editor-editmode-description' => "There are a few [http://en.wikipedia.org/wiki/Wikipedia:Simplified_ruleset guidelines] for editing an article:<br/>
2221 * Write what you think is best for the article, or as we say here: [http://en.wikipedia.org/wiki/Wikipedia:Be_bold be bold when updating pages]! If you feel that a rule prevents you from improving Wikipedia, [http://en.wikipedia.org/wiki/Wikipedia:Ignore_all_rules ignore it].
2322 * [http://en.wikipedia.org/wiki/Wikipedia:What_Wikipedia_is_not Wikipedia is an encyclopedia.] Someone else should be able to [http://en.wikipedia.org/wiki/Wikipedia:Verifiability verify] what you've written, for example in books or online.
24 -* Write from a [http://en.wikipedia.org/wiki/Wikipedia:Neutral_point_of_view neutral point of view], and use your [http://en.wikipedia.org/wiki/Wikipedia:Copyrights own words].
25 - ",
 23+* Write from a [http://en.wikipedia.org/wiki/Wikipedia:Neutral_point_of_view neutral point of view], and use your [http://en.wikipedia.org/wiki/Wikipedia:Copyrights own words].",
2624 */
27 - 'sentence-editor-editmode-description' => "
28 -Edit sentences by clicking on them. You can use wiki syntax to format the text. Some examples:
 25+ 'sentence-editor-editmode-description' => "Edit sentences by clicking on them. You can use wiki syntax to format the text. Some examples:
2926 {| width=\"100%\" style=\"background-color: inherit\"
3027 ! Code
3128 ! Output
3229 |-
3330 | <code><nowiki>Here's a link to the [[Main Page]].</nowiki></code>
34 -| Here's a link to the [[Main Page]].
 31+| Here is a link to the [[Main Page]].
3532 |-
3633 | <code><nowiki>This is ''italic text'' and this is '''bold text'''.</nowiki></code>
3734 | This is ''italic text'' and this is '''bold text'''.
38 -|-
 35+|-
3936 | <code><nowiki>[http://meta.wikimedia.org/wiki/Help:Editing More information]</nowiki></code>
4037 | [http://meta.wikimedia.org/wiki/Help:Editing More information]
41 -|}
42 - ",
43 -);
\ No newline at end of file
 38+|}",
 39+);
Index: trunk/extensions/InlineEditor/SentenceEditor/SentenceEditor.php
@@ -43,4 +43,4 @@
4444 $wgExtensionMessagesFiles['SentenceEditor'] = $dir . 'SentenceEditor.i18n.php';
4545
4646 // default settings
47 -$wgSentenceEditorDetectionDefault = 'SentenceDetectionBasic';
\ No newline at end of file
 47+$wgSentenceEditorDetectionDefault = 'SentenceDetectionBasic';
Index: trunk/extensions/InlineEditor/SentenceEditor/SentenceDetection/SentenceDetectionBasic.class.php
@@ -1,36 +1,37 @@
22 <?php
 3+
34 /**
45 * Basic implementation of sentence splitting. Not recommended for actual use, but does the job
56 * for a simple demo.
67 */
78 class SentenceDetectionBasic implements ISentenceDetection {
89 private $wikiTexts;
9 -
 10+
1011 function __construct() {
1112 $this->wikiTexts = array();
1213 }
13 -
 14+
1415 public function addWikiText( $text, $offset ) {
1516 $this->wikiTexts[] = array( 'text' => $text, 'offset' => $offset );
1617 }
17 -
 18+
1819 public function addPiecesToText( InlineEditorText &$inlineEditorText, $class, $inline ) {
1920 $pieces = array();
20 - foreach( $this->wikiTexts as $wikiText ) {
21 - $sentences = preg_split( "/(?<!\..|\...|\....)([\?\!\.]+)\s(?!.\.|..\.|...\.)/u", $wikiText['text'], -1,
 21+ foreach ( $this->wikiTexts as $wikiText ) {
 22+ $sentences = preg_split( "/(?<!\..|\...|\....)([\?\!\.]+)\s(?!.\.|..\.|...\.)/u", $wikiText['text'], -1,
2223 PREG_SPLIT_OFFSET_CAPTURE | PREG_SPLIT_DELIM_CAPTURE );
23 -
24 - foreach( $sentences as $index => $sentence ) {
25 - if( $index % 2 == 0 ) {
26 - if( isset( $sentences[$index+1] ) ) {
27 - $sentence[0] .= $sentences[$index+1][0];
 24+
 25+ foreach ( $sentences as $index => $sentence ) {
 26+ if ( $index % 2 == 0 ) {
 27+ if ( isset( $sentences[$index + 1] ) ) {
 28+ $sentence[0] .= $sentences[$index + 1][0];
2829 }
2930 $start = $wikiText['offset'] + $sentence[1];
30 - $end = $start + strlen( $sentence[0] );
 31+ $end = $start + strlen( $sentence[0] );
3132 $inlineEditorText->addPiece( new InlineEditorPiece( $start, $end, $class, $inline ) );
3233 }
3334 }
3435 }
3536 return $pieces;
3637 }
37 -}
\ No newline at end of file
 38+}
Index: trunk/extensions/InlineEditor/SentenceEditor/SentenceDetection/ISentenceDetection.class.php
@@ -1,18 +1,19 @@
22 <?php
 3+
34 /**
45 * This interface defines what a sentence detector should be able to do, which is
56 * adding portions of wikitext and adding the detected sentences as pieces to an
6 - * InlineEditorText object.
 7+ * InlineEditorText object.
78 */
89 interface ISentenceDetection {
910 /**
1011 * Add a bit of wikitext to the object. The wikitext has to be split in sentences while
11 - * remembering the position of each sentence.
 12+ * remembering the position of each sentence.
1213 * @param $text String
1314 * @param $position Integer
1415 */
1516 public function addWikiText( $text, $position );
16 -
 17+
1718 /**
1819 * All the sentences and their offsets have to be added as pieces to $inlineEditorText.
1920 * @param $inlineEditorText InlineEditorText Object the pieces should be added to
@@ -20,4 +21,4 @@
2122 * @param $inline Boolean whether the pieces are inline or not
2223 */
2324 public function addPiecesToText( InlineEditorText &$inlineEditorText, $class, $inline );
24 -}
\ No newline at end of file
 25+}
Index: trunk/extensions/InlineEditor/SentenceEditor/SentenceEditor.class.php
@@ -1,48 +1,48 @@
22 <?php
 3+
34 /**
45 * This editor allows for editing individual sentences. It strips the wikitext from
5 - * things that are too hard to edit, and leaves the splitting of sentences to a
6 - * class that implements the interface ISentenceDetection.
7 - *
 6+ * things that are too hard to edit, and leaves the splitting of sentences to a
 7+ * class that implements the interface ISentenceDetection.
 8+ *
89 * It's very much possible to create an extension that inherits from this class to
910 * do the detection another way, i.e. without the preprocessing and splitting.
1011 */
1112 class SentenceEditor {
12 -
1313 /**
1414 * This function hooks into InlineEditorMark and marks the sentences.
1515 * @param $inlineEditorText InlineEditorText
1616 */
1717 public static function mark( &$inlineEditorText ) {
1818 global $wgSentenceEditorDetectionDefault;
19 -
 19+
2020 // get the original wikitext
2121 $text = $inlineEditorText->getWikiOriginal();
22 -
 22+
2323 // preprocess the text by replacing everything difficult by spaces
2424 $text = self::preprocess( $text );
25 -
 25+
2626 // split what's left into sensible blocks of text
2727 $split = self::split( $text );
28 -
 28+
2929 // get the default detection class and make it able for extensions to alter it
3030 $detectionClass = $wgSentenceEditorDetectionDefault;
3131 wfRunHooks( 'SentenceEditorDetectionClass', array( &$detectionClass ) );
32 -
 32+
3333 // spawn the detection class and add the texts and position
3434 $detection = new $detectionClass();
35 - foreach( $split as $wikiText ) {
 35+ foreach ( $split as $wikiText ) {
3636 // $wikiText[0] is the text, $wikiText[1] is the position of that text
3737 $detection->addWikiText( $wikiText[0], $wikiText[1] );
3838 }
39 -
 39+
4040 // have the detection class add the pieces to the InlineEditorText object,
4141 // class 'sentenceEditorElement', inline elements
4242 $detection->addPiecesToText( $inlineEditorText, 'sentenceEditorElement', true );
43 -
 43+
4444 return true;
4545 }
46 -
 46+
4747 /**
4848 * Hooks into InlineEditorDefineEditors. Adds the option to to the list and adds CSS and JS files
4949 * @param $editor InlineEditor
@@ -50,21 +50,21 @@
5151 */
5252 public static function defineEditors( &$editor, &$output ) {
5353 global $wgExtensionAssetsPath;
54 -
 54+
5555 $editor->addEditMode(
56 - 'sentenceEditor',
57 - wfMsgExt( 'sentence-editor-editmode-caption', 'parseinline' ),
58 - wfMsgExt( 'sentence-editor-editmode-description','parseinline' )
 56+ 'sentenceEditor',
 57+ wfMsgExt( 'sentence-editor-editmode-caption', 'parseinline' ),
 58+ wfMsgExt( 'sentence-editor-editmode-description', 'parseinline' )
5959 );
60 -
61 - $output->addExtensionStyle( "$wgExtensionAssetsPath/InlineEditor/SentenceEditor/SentenceEditor.css?0");
 60+
 61+ $output->addExtensionStyle( "$wgExtensionAssetsPath/InlineEditor/SentenceEditor/SentenceEditor.css?0" );
6262 $output->addScriptFile( "$wgExtensionAssetsPath/InlineEditor/SentenceEditor/jquery.inlineEditor.editors.sentenceEditor.js?0" );
6363 $output->addScriptFile( "$wgExtensionAssetsPath/InlineEditor/SentenceEditor/jquery.textWidth.js?0" );
6464 $output->addScriptFile( "$wgExtensionAssetsPath/InlineEditor/SentenceEditor/jquery.elastic.js?0" );
65 -
 65+
6666 return true;
6767 }
68 -
 68+
6969 /**
7070 * Replaces all occurences of unsupported wikitext by spaces. This is to make sure the
7171 * positions of what's left are still the same as those in the original wikitext
@@ -73,40 +73,40 @@
7474 */
7575 protected static function preprocess( $wikitext ) {
7676 $patterns = array();
77 -
 77+
7878 // remove references
7979 $patterns[] = '/(<ref[^>\/]*>.*?<\/ref>)/is';
80 -
 80+
8181 // remove references like <ref/>
8282 $patterns[] = '/(<ref.*?\/>)/i';
83 -
 83+
8484 // remove templates starting at the beginning of a line (or with whitespace)
8585 $patterns[] = '/^\s*(\{\{.*?\}\})/ms';
86 -
 86+
8787 // remove tables
8888 $patterns[] = '/(\{\|.*?\|\})/';
89 -
 89+
9090 // remove links with : in it
9191 $patterns[] = '/(\[\[[^:\[\]]*:[^:\[\]]*\]\])/';
92 -
 92+
9393 // remove headings
9494 $patterns[] = '/^(=+[^=]*=+)\s*$/m';
95 -
 95+
9696 // remove lists, indents, things like that
9797 $patterns[] = '/^[\*#:;](.*)$/m';
98 -
 98+
9999 return preg_replace_callback( $patterns, 'SentenceEditor::makeSpaces', $wikitext );
100100 }
101 -
 101+
102102 /**
103103 * Function used by preprocess() to replace matches with spaces
104104 * @param $matches array
105105 * @return String
106106 */
107107 protected static function makeSpaces ( $matches ) {
108 - return str_repeat( ' ', strlen($matches[0]) );
 108+ return str_repeat( ' ', strlen( $matches[0] ) );
109109 }
110 -
 110+
111111 /**
112112 * Splits the wikitext into pieces of actual text. A split is forced where there are
113113 * two spaces or a newline. This way, it's possible to have the users define the sentences.
@@ -116,12 +116,12 @@
117117 protected static function split( $wikitext ) {
118118 // split where there are at least two spaces, or a newline, or the beginning of the text
119119 $splits = preg_split( '/\s\s+|\n\s*|^/', $wikitext, -1, PREG_SPLIT_OFFSET_CAPTURE );
120 -
 120+
121121 // remove small occurences
122 - foreach( $splits as $index => $split ) {
123 - if( strlen( $split[0] ) < 2 ) unset( $splits[$index] );
 122+ foreach ( $splits as $index => $split ) {
 123+ if ( strlen( $split[0] ) < 2 ) unset( $splits[$index] );
124124 }
125 -
 125+
126126 return $splits;
127127 }
128 -}
\ No newline at end of file
 128+}
Index: trunk/extensions/InlineEditor/InlineEditor.php
@@ -9,7 +9,7 @@
1010 *
1111 * Usage: Include the following line in your LocalSettings.php
1212 * require_once( "$IP/extensions/InlineEditor.php" );
13 - *
 13+ *
1414 * To enable all provided editors, add this in your LocalSettings.php:
1515 * require_once( "$IP/extensions/InlineEditor/InlineEditor.php" );
1616 * require_once( "$IP/extensions/InlineEditor/SentenceEditor/SentenceEditor.php" );
@@ -37,7 +37,7 @@
3838 );
3939
4040 // current directory including trailing slash
41 -$dir = dirname(__FILE__) . '/';
 41+$dir = dirname( __FILE__ ) . '/';
4242
4343 // add autoload classes
4444 $wgAutoloadClasses['InlineEditor'] = $dir . 'InlineEditor.class.php';
@@ -58,4 +58,4 @@
5959
6060 // default options
6161 $wgInlineEditorBrowserBlacklist = $wgBrowserBlackList;
62 -$wgInlineEditorAllowedNamespaces = array( NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK );
\ No newline at end of file
 62+$wgInlineEditorAllowedNamespaces = array( NS_MAIN, NS_TALK, NS_USER, NS_USER_TALK );

Comments

#Comment by JanPaul123 (talk | contribs)   22:39, 12 September 2010

Thanks for fixing a few things from r72458!

Status & tagging log