jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/334027 )
Change subject: Initial commit
......................................................................
Initial commit
Change-Id: Ic3c26955a2941afcc03927799ed0df0a0d6d2c76
---
A .eslintrc.json
A .gitignore
A Gruntfile.js
A README.md
A ShowMe.class.php
A ShowMe.hooks.php
A ShowMe.php
A composer.json
A extension.json
A i18n/en.json
A i18n/qqq.json
A modules/ext.showMe.js
A package.json
A phpcs.xml
14 files changed, 293 insertions(+), 0 deletions(-)
Approvals:
jenkins-bot: Verified
tosfos: Looks good to me, approved
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..4843240
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,10 @@
+{
+ "extends": "wikimedia",
+ "env": {
+ "browser": true,
+ "jquery": true
+ },
+ "globals": {
+ "mediaWiki": false
+ }
+}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..59a2a36
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+.*.swp
+*~
+/.project
+/composer.lock
+/vendor
+/node_modules
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000..c30a729
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,29 @@
+/* eslint-env node */
+module.exports = function ( grunt ) {
+ grunt.loadNpmTasks( 'grunt-eslint' );
+ grunt.loadNpmTasks( 'grunt-jsonlint' );
+ grunt.loadNpmTasks( 'grunt-banana-checker' );
+
+ grunt.initConfig( {
+ eslint: {
+ all: [
+ '*.js',
+ '**/*.js',
+ '!node_modules/**'
+ ]
+ },
+ banana: {
+ all: 'i18n/'
+ },
+ jsonlint: {
+ all: [
+ '**/*.json',
+ '!node_modules/**',
+ '!vendor/**'
+ ]
+ }
+ } );
+
+ grunt.registerTask( 'test', [ 'eslint', 'jsonlint', 'banana' ] );
+ grunt.registerTask( 'default', 'test' );
+};
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4f59de1
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+This is a MediaWiki extension. Find the docs
[https://www.mediawiki.org/wiki/Extension:ShowMe here].
diff --git a/ShowMe.class.php b/ShowMe.class.php
new file mode 100644
index 0000000..45b2a06
--- /dev/null
+++ b/ShowMe.class.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ *
+ * @author Ike Hecht <[email protected]>
+ */
+class ShowMe {
+ private $type;
+ private $name;
+ private $options;
+ static protected $num = 0;
+
+ /**
+ *
+ * @param string $type The type of input field, currently must be
'dropdown'
+ * @param string $name The name and ID to be assigned to the input field
+ * @param array $options Use the form label => value
+ * @param ParserOutput $out
+ */
+ function __construct( $type, $name, array $options, ParserOutput $out )
{
+ $this->type = $type;
+ $this->name = $name;
+ $this->options = $options;
+
+ // Add this $name to he array of ShowMe field IDs that exist on
this page
+ $configVars = $out->getJsConfigVars();
+ $configVars['wgShowMeDropdownIDs'][] = $name;
+ $out->addJsConfigVars( 'wgShowMeDropdownIDs',
$configVars['wgShowMeDropdownIDs'] );
+ }
+
+ /**
+ * Get the output HTML
+ *
+ * @return string
+ */
+ public function getHTML() {
+ // Theoretically, other types may be added in the future, such
as radio buttons.
+ if ( $this->type == 'dropdown' ) {
+ return $this->getDropdownHTML();
+ }
+ // invalid type
+ return ''; // Throw error?
+ }
+
+ /**
+ * Get the output HTML for a dropdown
+ *
+ * @return string
+ */
+ protected function getDropdownHTML() {
+ $select = new XmlSelect( $this->name, $this->name );
+ $select->addOptions( $this->options );
+ return $select->getHTML();
+ }
+}
diff --git a/ShowMe.hooks.php b/ShowMe.hooks.php
new file mode 100644
index 0000000..4109ced
--- /dev/null
+++ b/ShowMe.hooks.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Hooks for ShowMe extension
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+class ShowMeHooks {
+
+ /**
+ *
+ * @param Parser $parser
+ * @return bool
+ */
+ public static function onParserFirstCallInit( Parser &$parser ) {
+ $parser->setHook( 'showme', [ __CLASS__, 'showMeRender' ] );
+ return true;
+ }
+
+ /**
+ *
+ * @staticvar int $num
+ * @param string $input
+ * @param array $args
+ * @param Parser $parser
+ * @param PPFrame $frame
+ * @return string Output HTML
+ */
+ public static function showMeRender( $input, array $args, Parser
$parser, PPFrame $frame ) {
+ $parser->getOutput()->addModuleScripts( 'ext.showMe' );
+
+ $options = [];
+ $lines = StringUtils::explode( "\n", $input );
+ foreach ( $lines as $line ) {
+ $bits = StringUtils::explodeMarkup( '|', $line );
+ if ( count( $bits ) < 2 ) {
+ continue;
+ // throw error instead?
+ }
+ $options[$bits[0]] = $bits[1];
+ }
+
+ // If the user supplied an ID, use it. Otherwise, generate one.
+ if ( isset( $args['name'] ) ) {
+ $name = $args['name'];
+ } else {
+ static $num = 0;
+ // Add a num to the HTML ID in case there is more than
one ShowMe field on this page.
+ // Iterate after getting num.
+ $name = 'showme-dropdown' . '-' . $num++;
+ }
+
+ $showMe = new ShowMe( 'dropdown', $name, $options,
$parser->getOutput() );
+ return $showMe->getHTML();
+ }
+}
diff --git a/ShowMe.php b/ShowMe.php
new file mode 100644
index 0000000..3d48c85
--- /dev/null
+++ b/ShowMe.php
@@ -0,0 +1,15 @@
+<?php
+
+if ( function_exists( 'wfLoadExtension' ) ) {
+ wfLoadExtension( 'ShowMe' );
+ // Keep i18n globals so mergeMessageFileList.php doesn't break
+ $wgMessagesDirs['ShowMe'] = __DIR__ . '/i18n';
+ $wgExtensionMessagesFiles['ShowMeAlias'] = __DIR__ .
'/ShowMe.i18n.alias.php';
+ wfWarn(
+ 'Deprecated PHP entry point used for ShowMe extension. Please
use wfLoadExtension ' .
+ 'instead, see
https://www.mediawiki.org/wiki/Extension_registration for more details.'
+ );
+ return true;
+} else {
+ die( 'This version of the ShowMe extension requires MediaWiki 1.25+' );
+}
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..98d41d9
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,13 @@
+{
+ "require-dev": {
+ "jakub-onderka/php-parallel-lint": "0.9.2",
+ "mediawiki/mediawiki-codesniffer": "0.7.2"
+ },
+ "scripts": {
+ "fix": "phpcbf",
+ "test": [
+ "parallel-lint . --exclude vendor",
+ "phpcs -p -s"
+ ]
+ }
+}
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..2ad264b
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,41 @@
+{
+ "name": "ShowMe",
+ "version": "0.0.1",
+ "author": [
+ "Ike Hecht"
+ ],
+ "url": "https://www.mediawiki.org/wiki/Extension:ShowMe",
+ "descriptionmsg": "showme-desc",
+ "license-name": "GPL-2.0+",
+ "type": "parserhook",
+ "requires": {
+ "MediaWiki": ">= 1.25.0"
+ },
+ "AutoloadClasses": {
+ "ShowMe": "ShowMe.class.php",
+ "ShowMeHooks": "ShowMe.hooks.php"
+ },
+ "Hooks": {
+ "ParserFirstCallInit": [
+ "ShowMeHooks::onParserFirstCallInit"
+ ]
+ },
+ "MessagesDirs": {
+ "ShowMe": [
+ "i18n"
+ ]
+ },
+ "ResourceModules": {
+ "ext.showMe": {
+ "scripts": [
+ "modules/ext.showMe.js"
+ ],
+ "position": "bottom"
+ }
+ },
+ "ResourceFileModulePaths": {
+ "localBasePath": "",
+ "remoteExtPath": "ShowMe"
+ },
+ "manifest_version": 1
+}
diff --git a/i18n/en.json b/i18n/en.json
new file mode 100644
index 0000000..db650ef
--- /dev/null
+++ b/i18n/en.json
@@ -0,0 +1,8 @@
+{
+ "@metadata": {
+ "authors": [
+ "tosfos"
+ ]
+ },
+ "showme-desc": "Shows or hides selected elements on the page"
+}
diff --git a/i18n/qqq.json b/i18n/qqq.json
new file mode 100644
index 0000000..87ff7fc
--- /dev/null
+++ b/i18n/qqq.json
@@ -0,0 +1,8 @@
+{
+ "@metadata": {
+ "authors": [
+ "tosfos"
+ ]
+ },
+ "showme-desc":
"{{desc|name=ShowMe|url=https://www.mediawiki.org/wiki/Extension:ShowMe}}"
+}
diff --git a/modules/ext.showMe.js b/modules/ext.showMe.js
new file mode 100644
index 0000000..611469a
--- /dev/null
+++ b/modules/ext.showMe.js
@@ -0,0 +1,30 @@
+( function ( mw, $ ) {
+ var i, dropdowns = mw.config.get( 'wgShowMeDropdownIDs' );
+
+ function showMe( id ) {
+ var dropdown, options, i;
+ dropdown = document.getElementById( id );
+ if ( dropdown === null ) {
+ return;
+ } else {
+ options = dropdown.options;
+ }
+ $( '#mw-content-text .' + options[ 0 ].value ).show();
+ for ( i = 1; i < options.length; i++ ) {
+ $( '#mw-content-text .' + options[ i ].value ).hide();
+ }
+ $( '#mw-content-text #' + id ).change( function () {
+ for ( i = 0; i < options.length; i++ ) {
+ if ( options[ i ].value === this.value ) {
+ $( '#mw-content-text .' + this.value
).show();
+ } else {
+ $( '#mw-content-text .' + options[ i
].value ).hide();
+ }
+ }
+ } );
+ }
+
+ for ( i = 0; i < dropdowns.length; i++ ) {
+ showMe( dropdowns[ i ] );
+ }
+}( mediaWiki, jQuery ) );
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..e7a5f92
--- /dev/null
+++ b/package.json
@@ -0,0 +1,13 @@
+{
+ "private": true,
+ "scripts": {
+ "test": "grunt test"
+ },
+ "devDependencies": {
+ "grunt": "1.0.1",
+ "grunt-banana-checker": "0.5.0",
+ "grunt-eslint": "19.0.0",
+ "eslint-config-wikimedia": "0.3.0",
+ "grunt-jsonlint": "1.1.0"
+ }
+}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..d81a292
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<ruleset>
+ <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
+ <file>.</file>
+ <arg name="extensions" value="php,php5,inc"/>
+ <arg name="encoding" value="utf8"/>
+ <exclude-pattern>vendor</exclude-pattern>
+</ruleset>
--
To view, visit https://gerrit.wikimedia.org/r/334027
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic3c26955a2941afcc03927799ed0df0a0d6d2c76
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/ShowMe
Gerrit-Branch: master
Gerrit-Owner: tosfos <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
Gerrit-Reviewer: tosfos <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits