Luis Felipe Schenone has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/174934

Change subject: Initial commit
......................................................................

Initial commit

Change-Id: I0755fe91fafc613a3e643ecc17264df8feac0ec8
---
A .gitignore
A MsInsert.body.php
A MsInsert.i18n.php
A MsInsert.js
A MsInsert.php
A README.md
A i18n/de.json
A i18n/en.json
A i18n/es.json
A i18n/qqq.json
10 files changed, 276 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MsInsert 
refs/changes/34/174934/1

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..496ee2c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.DS_Store
\ No newline at end of file
diff --git a/MsInsert.body.php b/MsInsert.body.php
new file mode 100644
index 0000000..9e7524d
--- /dev/null
+++ b/MsInsert.body.php
@@ -0,0 +1,24 @@
+<?php
+
+class MsInsert {
+
+       static function start() {
+               global $wgOut, $wgTemplates;
+
+               $wgOut->addModules( 'ext.MsInsert' );
+
+               $templates = array();
+               foreach ( $wgTemplates as $key => $template ) {
+                       $title = Title::newFromText( htmlentities( $template ) 
);
+                       $title2 = Title::newFromText( $template );
+                       if ( $title and $title->exists() ) {
+                               $templates[] = htmlentities( $template );
+                       } elseif ( $title2 and $title2->exists() ) {
+                               $templates[] = $template;
+                       }
+               }
+               $templates = json_encode( $templates );
+               $wgOut->addScript( "<script>var msi_templates = 
JSON.parse('$templates');</script>" );
+               return true;
+       }
+}
\ No newline at end of file
diff --git a/MsInsert.i18n.php b/MsInsert.i18n.php
new file mode 100644
index 0000000..b64e7a0
--- /dev/null
+++ b/MsInsert.i18n.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * This is a backwards-compatibility shim, generated by:
+ * 
https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php
+ *
+ * Beginning with MediaWiki 1.23, translation strings are stored in json files,
+ * and the EXTENSION.i18n.php file only exists to provide compatibility with
+ * older releases of MediaWiki. For more information about this migration, see:
+ * https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format
+ *
+ * This shim maintains compatibility back to MediaWiki 1.17.
+ */
+$messages = array();
+if ( !function_exists( 'wfJsonI18nShim9bfcb6d3a88a9ce0' ) ) {
+       function wfJsonI18nShim9bfcb6d3a88a9ce0( $cache, $code, &$cachedData ) {
+               $codeSequence = array_merge( array( $code ), 
$cachedData['fallbackSequence'] );
+               foreach ( $codeSequence as $csCode ) {
+                       $fileName = dirname( __FILE__ ) . 
"/extensions/MsInsert/i18n/$csCode.json";
+                       if ( is_readable( $fileName ) ) {
+                               $data = FormatJson::decode( file_get_contents( 
$fileName ), true );
+                               foreach ( array_keys( $data ) as $key ) {
+                                       if ( $key === '' || $key[0] === '@' ) {
+                                               unset( $data[$key] );
+                                       }
+                               }
+                               $cachedData['messages'] = array_merge( $data, 
$cachedData['messages'] );
+                       }
+
+                       $cachedData['deps'][] = new FileDependency( $fileName );
+               }
+               return true;
+       }
+
+       $GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 
'wfJsonI18nShim9bfcb6d3a88a9ce0';
+}
\ No newline at end of file
diff --git a/MsInsert.js b/MsInsert.js
new file mode 100755
index 0000000..e19f412
--- /dev/null
+++ b/MsInsert.js
@@ -0,0 +1,121 @@
+if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
+       mw.loader.using( 'user.options', function () {
+               if ( mw.user.options.get( 'usebetatoolbar' ) && 
mw.user.options.get( 'showtoolbar' ) ) {
+                       mw.loader.using( 'ext.wikiEditor.toolbar', 
msi_modifyToolbar1 );
+               } else {
+                       msi_modifyToolbar2();
+               }
+       });
+}
+
+function msi_modifyToolbar1() {
+       var dropdownMenu = $( '<select/>' ).attr( 'id', 'msi-select' ).css( 
'margin', '4px' ).change( function () {
+               var selection = this.options[ this.selectedIndex ].value;
+               msi_templateSelect( selection );
+       });
+       dropdownMenu.append( '<option value="0">' + mw.msg( 
'msi-insert-template' ) + '</option>' );
+       for ( var i = 0; i < msi_templates.length; i++ ) {
+               dropdownMenu.append( '<option value="' + ( i + 1 ) + '">' + 
msi_templates[ i ] + '</option>' );
+       }
+       $( '#editform' ).find( '.group-insert' ).append( dropdownMenu );
+}
+
+function msi_modifyToolbar2() {
+       var dropdownMenu = $( '<select/>' ).attr( 'id', 'msi-select' ).change( 
function () {
+               var selection = this.options[ this.selectedIndex ].value;
+               msi_templateSelect( selection );
+       });
+       dropdownMenu.append( '<option value="0">' + mw.msg( 
'msi-insert-template' ) + '</option>' );
+       for ( var i = 0; i < msi_templates.length; i++ ) {
+               dropdownMenu.append( '<option value="' + ( i + 1 ) + '">' + 
msi_templates[ i ] + '</option>' );
+       }
+       $( '#toolbar' ).append( dropdownMenu );
+}
+
+function msi_templateSelect( i ) {
+       if ( i === 0 ) {
+               return false;
+       }
+       var api = new mw.Api();
+       api.get({
+               'format': 'json',
+               'action': 'query',
+               'titles': msi_templates[ i - 1 ],
+               'prop': 'revisions',
+               'rvprop': 'content'
+       }).done ( function ( data ) {
+               if ( data.hasOwnProperty( 'query' ) && 
data.query.hasOwnProperty( 'pages' ) ) {
+                       //Extract the content from the JSON wrappers
+                       var pages = data.query.pages;
+                       for ( i in pages ) {
+                               var content = pages[ i ].revisions['0']['*'];
+                       }
+                       msi_templateInsert( content, '\n', '\n' );
+                       $( '#msi-select option[value="0"]').prop( 'selected', 
true );
+               }
+       });
+}
+
+function msi_templateInsert( inhalt, tagOpen, tagClose ) {
+       this.editor = document.getElementById( 'wpTextbox1' );
+       var sampleText = inhalt;
+       var isSample = false;
+
+       if ( document.selection && document.selection.createRange ) {
+               if ( document.documentElement && 
document.documentElement.scrollTop ) {
+                       var windowScroll = document.documentElement.scrollTop
+               } else if ( document.body ) {
+                       var windowScroll = document.body.scrollTop;
+               }
+
+               // Get current selection
+               this.editor.focus();
+               var range = document.selection.createRange();
+               var selectedText = range.text;
+
+               // Insert tags
+               msi_checkSelectedText();
+               range.text = tagOpen + selectedText + tagClose;
+
+               // Restore window scroll position
+               if ( document.documentElement && 
document.documentElement.scrollTop ) {
+                       document.documentElement.scrollTop = windowScroll
+               } else if ( document.body ) {
+                       document.body.scrollTop = windowScroll;
+               }
+       } else if ( this.editor.selectionStart || this.editor.selectionStart == 
'0' ) { // Mozilla
+               // Save textarea scroll position
+               var textScroll = this.editor.scrollTop;
+
+               // Get current selection
+               this.editor.focus();
+
+               var selectionStart = this.editor.selectionStart;
+               var selectionEnd = this.editor.selectionEnd;
+               var selectedText = this.editor.value.substring( selectionStart, 
selectionEnd );
+
+               // Insert tags
+               msi_checkSelectedText();
+               this.editor.value = this.editor.value.substring( 0, 
selectionStart ) + tagOpen + selectedText + tagClose + 
this.editor.value.substring( selectionEnd, this.editor.value.length );
+
+               // Set new selection
+               if ( isSample ) {
+                       this.editor.selectionStart = selectionStart + 
tagOpen.length + selectedText.length;
+                       this.editor.selectionEnd = selectionStart + 
tagOpen.length + selectedText.length;
+               } else {
+                       this.editor.selectionStart = this.editor.selectionStart;
+                       this.editor.selectionEnd = this.editor.selectionStart;
+               }
+               this.editor.scrollTop = textScroll;
+       }
+
+       function msi_checkSelectedText() {
+               if ( !selectedText ) {
+                       selectedText = sampleText;
+                       isSample = true;
+               } else if ( selectedText.charAt( selectedText.length - 1 ) === 
' ' ) { // Exclude ending space char
+                       selectedText = selectedText.substring( 0, 
selectedText.length - 1 );
+                       tagClose += ' ';
+               }
+       }
+}
\ No newline at end of file
diff --git a/MsInsert.php b/MsInsert.php
new file mode 100755
index 0000000..5f9b36d
--- /dev/null
+++ b/MsInsert.php
@@ -0,0 +1,29 @@
+<?php
+
+$wgExtensionCredits['other'][] = array(
+       'name' => 'MsInsert',
+       'url' => 'https://www.mediawiki.org/wiki/Extension:MsInsert',
+       'version' => '3.0',
+       'descriptionmsg' => 'msi-desc',
+       'license-name' => 'GPLv2+',
+       'author' => array( '[mailto:[email protected] Martin Schwindl]', 
'[mailto:[email protected] Martin Keyler]', 
'[https://www.mediawiki.org/wiki/User:Luis_Felipe_Schenone Luis Felipe 
Schenone]' ),
+);
+
+$wgResourceModules['ext.MsInsert'] = array(
+       'scripts' => 'MsInsert.js',
+       'messages' => array(
+               'msi-insert-template',
+       ),
+       'localBasePath' => __DIR__,
+       'remoteExtPath' => 'MsInsert',
+);
+
+$wgAutoloadClasses['MsInsert'] = __DIR__ . '/MsInsert.body.php';
+
+$wgExtensionMessagesFiles['MsInsert'] = __DIR__ . '/MsInsert.i18n.php';
+$wgMessagesDirs['MsInsert'] = __DIR__ . '/i18n';
+
+$wgHooks['EditPage::showEditForm:initial'][] = 'MsInsert::start';
+
+// Default configuration
+$wgTemplates = array();
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100755
index 0000000..24fb399
--- /dev/null
+++ b/README.md
@@ -0,0 +1,30 @@
+MsInsert
+========
+
+The MsInsert extension adds a dropdown menu to the editor, that allows you to 
insert into the textarea the content of any wiki page listed in the dropdown 
menu.
+
+Installation
+------------
+To install MsInsert, add the following to your LocalSettings.php:
+
+require_once "$IP/extensions/MsInsert/MsInsert.php";
+
+Configuration
+-------------
+To add a page to the dropdown menu, add it to the $wgTemplates array in your 
LocalSettings.php, like so:
+
+$wgTemplates = array( 'Template:Test', 'Main Page', 'Talk:Main Page' );
+
+Or alternatively:
+
+$wgTemplates[] = 'Template:Test';
+$wgTemplates[] = 'Main Page';
+$wgTemplates[] = 'Talk:Main Page';
+
+If the page does not exist yet, then it will not be added to the dropdown 
menu, even if it's listed in the $wgTemplates array. By default, the array is 
empty.
+
+Credits
+-------
+* Developed and coded by Martin Schwindl ([email protected])
+* Idea, project management and bug fixing by Martin Keyler 
([email protected])
+* Updated, debugged and enhanced by Luis Felipe Schenone ([email protected])
\ No newline at end of file
diff --git a/i18n/de.json b/i18n/de.json
new file mode 100644
index 0000000..4913d7e
--- /dev/null
+++ b/i18n/de.json
@@ -0,0 +1,9 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Luis Felipe Schenone"
+               ]
+       },
+       "msi-desc": "Per Dropdown koennen bestimmte Seiten als Vorlage in den 
Editor geladen werden",
+       "msi-insert-template": "Vorlage einfügen"
+}
diff --git a/i18n/en.json b/i18n/en.json
new file mode 100644
index 0000000..e149c35
--- /dev/null
+++ b/i18n/en.json
@@ -0,0 +1,9 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Luis Felipe Schenone"
+               ]
+       },
+       "msi-desc": "Adds a dropdown menu for inserting into the editor the 
content of certain pages",
+       "msi-insert-template": "Insert a template"
+}
diff --git a/i18n/es.json b/i18n/es.json
new file mode 100644
index 0000000..dd800f2
--- /dev/null
+++ b/i18n/es.json
@@ -0,0 +1,9 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Luis Felipe Schenone"
+               ]
+       },
+       "msi-desc": "Agrega un menu para insertar al editor el contenido de 
ciertas páginas",
+       "msi-insert-template": "Insertar una plantilla"
+}
diff --git a/i18n/qqq.json b/i18n/qqq.json
new file mode 100644
index 0000000..641584d
--- /dev/null
+++ b/i18n/qqq.json
@@ -0,0 +1,9 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Luis Felipe Schenone"
+               ]
+       },
+       "msi-desc": 
"{{desc|name=MsInsert|url=https://www.mediawiki.org/wiki/Extension:MsInsert}}";,
+       "msi-select-template": "Text of the default option of the dropdown 
menu",
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/174934
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0755fe91fafc613a3e643ecc17264df8feac0ec8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MsInsert
Gerrit-Branch: master
Gerrit-Owner: Luis Felipe Schenone <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to