jenkins-bot has submitted this change and it was merged.
Change subject: Add srf.settings class
......................................................................
Add srf.settings class
* srf.settings.getList()
* srf.settings.get()
* Fix jsDuck docs
Change-Id: I6ede6a6872f9306607b5bcc2710f8a87fa26d1e1
---
M SemanticResultFormats.hooks.php
M resources/ext.srf.js
M tests/qunit/ext.srf.test.js
3 files changed, 166 insertions(+), 32 deletions(-)
Approvals:
Mwjames: Looks good to me, approved
jenkins-bot: Verified
diff --git a/SemanticResultFormats.hooks.php b/SemanticResultFormats.hooks.php
index 534ff3c..2bc1f63 100644
--- a/SemanticResultFormats.hooks.php
+++ b/SemanticResultFormats.hooks.php
@@ -152,10 +152,11 @@
*/
public static function onResourceLoaderGetConfigVars( &$vars ) {
- $vars['srf'] = array(
+ $vars['srf-config'] = array(
'version' => SRF_VERSION,
- 'options' => array(
- 'thumbsize' => $GLOBALS['wgThumbLimits']
+ 'settings' => array(
+ 'wgThumbLimits' => $GLOBALS['wgThumbLimits'],
+ 'srfgScriptPath' => $GLOBALS['srfgScriptPath'],
)
);
diff --git a/resources/ext.srf.js b/resources/ext.srf.js
index e7dfab7..9ec0b3d 100644
--- a/resources/ext.srf.js
+++ b/resources/ext.srf.js
@@ -1,45 +1,129 @@
/**
- * JavaScript for SRF namespace placeholder
- * @see http://www.semantic-mediawiki.org/wiki/Writing_result_printers
+ * This file is part of the Semantic Result Formats Extension
+ * @see https://semantic-mediawiki.org/wiki/Srf
*
- * @since 1.8
- * @release 0.2
+ * @section LICENSE
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA
*
* @file
+ *
+ * @since 1.9
* @ingroup SRF
*
- * @licence GNU GPL v2 or later
+ * @licence GNU GPL v2+
* @author Jeroen De Dauw <jeroendedauw at gmail dot com>
* @author mwjames
*/
-window.semanticFormats = new( function() {
+/*global console:true message:true */
- this.log = function( message ) {
+/**
+ * Declares global srf instance and namespace
+ *
+ * @class srf
+ */
+var instance = ( function ( $ ) {
+ 'use strict';
+
+ var instance = {};
+
+ instance.log = function( message ) {
if ( typeof mediaWiki === 'undefined' ) {
if ( typeof console !== 'undefined' ) {
- console.log( 'SRF: ' + message );
+ console.log( 'SRF: ', message );
}
+ } else {
+ return mediaWiki.log.call( mediaWiki.log, 'SRF: ',
message );
}
- else {
- return mediaWiki.log.call( mediaWiki.log, 'SRF: ' +
message );
- }
- }
+ };
- this.msg = function() {
+ instance.msg = function() {
if ( typeof mediaWiki === 'undefined' ) {
message = window.wgSRFMessages[arguments[0]];
for ( var i = arguments.length - 1; i > 0; i-- ) {
message = message.replace( '$' + i,
arguments[i] );
}
-
return message;
- }
- else {
+ } else {
return mediaWiki.msg.apply( mediaWiki.msg, arguments );
}
- }
-} )();
+ };
-// Alias
-window.srf = window.semanticFormats;
\ No newline at end of file
+ /**
+ * Declares utility namespace
+ */
+ instance.util = {};
+
+ /**
+ * Declares formats namespace
+ */
+ instance.formats = {};
+
+ /**
+ * Access settings array
+ *
+ * @since 1.9
+ *
+ * @return {mixed}
+ */
+ instance.settings = {
+
+ /**
+ * Returns list of available settings
+ *
+ * @since 1.9
+ *
+ * @return {Object}
+ */
+ getList: function() {
+ return mediaWiki.config.get( 'srf-config' ).settings;
+ },
+
+ /**
+ * Returns a specific settings value
+ *
+ * @since 1.9
+ *
+ * @param {string} key options to be selected
+ *
+ * @return {mixed}
+ */
+ get: function( key ) {
+ if( typeof key === 'string' ) {
+ return this.getList()[key];
+ }
+ return undefined;
+ }
+ };
+
+ /**
+ * Returns SRF version
+ *
+ * @since 1.9
+ *
+ * @return {string}
+ */
+ instance.version = function() {
+ return mediaWiki.config.get( 'srf-config' ).version;
+ };
+
+ // Alias
+ instance.Util = instance.util;
+
+ return instance;
+} )( jQuery );
+
+// Assign namespace
+window.srf = window.semanticFormats = instance;
\ No newline at end of file
diff --git a/tests/qunit/ext.srf.test.js b/tests/qunit/ext.srf.test.js
index 9947a4a..118699a 100644
--- a/tests/qunit/ext.srf.test.js
+++ b/tests/qunit/ext.srf.test.js
@@ -1,29 +1,78 @@
/**
- * QUnit tests
+ * This file is part of the Semantic Result Formats QUnit Suite
+ * @see https://www.semantic-mediawiki.org/wiki/QUnit
*
- * @since 1.9
+ * @section LICENSE
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA
*
* @file
- * @ingroup SRF
*
- * @licence GNU GPL v2 or later
+ * @since 1.9
+ * @ingroup SMW
+ *
+ * @licence GNU GPL v2+
* @author mwjames
+ */
+
+/**
+ * QUnit tests for the srf base class
+ *
*/
( function ( mw, srf ) {
'use strict';
QUnit.module( 'ext.srf', QUnit.newMwEnvironment() );
- var pass = 'Passes because ';
+ /**
+ * Test initialization and accessibility
+ *
+ * @since: 1.9
+ */
+ QUnit.test( 'init', 6, function ( assert ) {
+
+ assert.ok( srf instanceof Object, 'srf namespace and instance
was accessible' );
+ assert.equal( $.type( srf.log ), 'function', '.log() was
accessible' );
+ assert.equal( $.type( srf.msg ), 'function', '.msg() was
accessible' );
+ assert.equal( $.type( srf.settings.getList ), 'function',
'.settings.getList() was accessible' );
+ assert.equal( $.type( srf.settings.get ), 'function',
'.settings.get() was accessible' );
+ assert.equal( $.type( srf.version ), 'function', '.version()
was accessible' );
+
+ } );
/**
- * Instance testing
+ * Test settings function
*
- * @since 1.9
+ * @since: 1.9
*/
- QUnit.test( 'instance', 1, function ( assert ) {
+ QUnit.test( 'settings', 4, function ( assert ) {
- assert.ok( srf instanceof Object, pass + 'srf instance was
accessible' );
+ assert.equal( $.type( srf.settings.getList() ), 'object',
'.getList() returned a list of objects' );
+ assert.equal( $.type( srf.settings.get( 'srfgScriptPath' ) ),
'string', '.get( "srfgScriptPath" ) returned a value' );
+ assert.equal( srf.settings.get( 'lula' ), undefined, '.get(
"lula" ) returned undefined for an unknown key' );
+ assert.equal( srf.settings.get(), undefined, '.get() returned
undefined for an empty key' );
+
+ } );
+
+ /**
+ * Test version function
+ *
+ * @since: 1.9
+ */
+ QUnit.test( 'version', 1, function ( assert ) {
+
+ assert.equal( $.type( srf.version() ), 'string', '.version()
returned a string' );
} );
--
To view, visit https://gerrit.wikimedia.org/r/63230
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6ede6a6872f9306607b5bcc2710f8a87fa26d1e1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticResultFormats
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
Gerrit-Reviewer: Mwjames <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits