jenkins-bot has submitted this change and it was merged.

Change subject: Add smw.dataItem.wikiPage.getText()
......................................................................


Add smw.dataItem.wikiPage.getText()

* wikiPage.getText() outputs text without hash fragment;in-page
objects such as subobjects (Foo#_QUERY9a665a578eb95c1) now are
displayed with its base page text (Foo)
* Fix some docs (JSDuck)
* Add tests (total of 74 tests)

Change-Id: I0a355ebd7ee03ab30467ef510ff97da34ac2877a
---
M resources/smw/data/ext.smw.dataItem.wikiPage.js
M resources/smw/ext.smw.js
M tests/qunit/smw/data/ext.smw.dataItem.wikiPage.test.js
3 files changed, 174 insertions(+), 73 deletions(-)

Approvals:
  Mwjames: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/resources/smw/data/ext.smw.dataItem.wikiPage.js 
b/resources/smw/data/ext.smw.dataItem.wikiPage.js
index 22b94a2..a425fd8 100644
--- a/resources/smw/data/ext.smw.dataItem.wikiPage.js
+++ b/resources/smw/data/ext.smw.dataItem.wikiPage.js
@@ -1,42 +1,64 @@
-/**
- * SMW wikiPage DataItem JavaScript representation
+/*!
+ * This file is part of the Semantic MediaWiki Extension
+ * @see https://semantic-mediawiki.org/
  *
- * @see SMW\DIWikiPage
+ * @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
  *
  * @since 1.9
  *
  * @file
+ *
  * @ingroup SMW
  *
- * @licence GNU GPL v2 or later
+ * @license GNU GPL v2+
  * @author mwjames
  */
 ( function( $, mw, smw ) {
        'use strict';
 
+       /**
+        * Helper method
+        * @ignore
+        */
        var html = mw.html;
 
        /**
-        * Inheritance class
+        * Inheritance class for the smw.dataItem constructor
         *
-        * @type object
+        * @since 1.9
+        *
+        * @class smw.dataItem
+        * @abstract
         */
        smw.dataItem = smw.dataItem || {};
 
        /**
-        * wikiPage constructor
+        * Initializes the constructor
         *
-        * @since  1.9
+        * @param {string} fulltext
+        * @param {string} fullurl
+        * @param {number} ns
+        * @param {boolean} exists
         *
-        * @param {String} fulltext
-        * @param {String} fullurl
-        * @param {Integer} namespace
-        * @return {Object} this
+        * @return {smw.dataItem.wikiPage} this
         */
-       var wikiPage = function ( fulltext, fullurl, namespace, exists ) {
+       var wikiPage = function ( fulltext, fullurl, ns, exists ) {
                this.fulltext  = fulltext !== ''&& fulltext !==  undefined ? 
fulltext : null;
                this.fullurl   = fullurl !== '' && fullurl !==  undefined ? 
fullurl : null;
-               this.namespace = namespace !==  undefined ? namespace : 0;
+               this.ns        = ns !==  undefined ? ns : 0;
                this.exists    = exists !==  undefined ? exists : true;
 
                // Get mw.Title inheritance
@@ -48,27 +70,24 @@
        };
 
        /**
-        * Constructor
+        * A class that includes methods to create a wikiPage dataItem 
representation
+        * in JavaScript that resembles the SMW\DIWikiPage object in PHP
         *
-        * @var Object
+        * @since 1.9
+        *
+        * @class
+        * @constructor
         */
-       smw.dataItem.wikiPage = function( fulltext, fullurl, namespace, exists 
) {
+       smw.dataItem.wikiPage = function( fulltext, fullurl, ns, exists ) {
                if ( $.type( fulltext ) === 'string' && $.type( fullurl ) === 
'string' ) {
-                       this.constructor( fulltext, fullurl, namespace, exists 
);
+                       this.constructor( fulltext, fullurl, ns, exists );
                } else {
                        throw new Error( 'smw.dataItem.wikiPage: fulltext, 
fullurl must be a string' );
                }
        };
 
-       /**
-        * Creates an object with methods related to the wikiPage dataItem
-        *
-        * @see SMW\DIWikiPage
-        *
-        * @since  1.9
-        *
-        * @type object
-        */
+       /* Public methods */
+
        var fn = {
 
                constructor: wikiPage,
@@ -85,10 +104,8 @@
                },
 
                /**
-                * Returns wikiPage text title
-                *
-                * Get full name in text form, like "File:Foo bar.jpg" due to 
fact
-                * that name is serialized in fulltext
+                * Returns wikiPage text title as full name like "File:Foo 
bar.jpg"
+                * due to fact that the name is serialized in fulltext
                 *
                 * @since  1.9
                 *
@@ -96,6 +113,17 @@
                 */
                getFullText: function() {
                        return this.fulltext;
+               },
+
+               /**
+                * Returns main part of the title without any fragment
+                *
+                * @since  1.9
+                *
+                * @return {string}
+                */
+               getText: function() {
+                       return this.fulltext && this.fulltext.split( '#' )[0];
                },
 
                /**
@@ -110,7 +138,7 @@
                },
 
                /**
-                * Returns mw.Title
+                * Returns mw.Title object
                 *
                 * @since  1.9
                 *
@@ -121,7 +149,7 @@
                },
 
                /**
-                * Returns wikiPage is a known entity or not
+                * Returns if the wikiPage is a known entity or not
                 *
                 * @since  1.9
                 *
@@ -132,14 +160,14 @@
                },
 
                /**
-                * Returns namespace
+                * Returns namespace id
                 *
                 * @since  1.9
                 *
-                * @return {string}
+                * @return {number}
                 */
-               getNamespace: function() {
-                       return this.namespace;
+               getNamespaceId: function() {
+                       return this.ns;
                },
 
                /**
@@ -154,9 +182,9 @@
                getHtml: function( linker ) {
                        if ( linker && this.fullurl !== null ){
                                var attributes = this.exists ? { 'href': 
this.fullurl } : { 'href': this.fullurl, 'class': 'new' };
-                               return html.element( 'a', attributes , 
this.fulltext );
+                               return html.element( 'a', attributes , 
this.getText() );
                        }
-                       return this.fulltext;
+                       return this.getText();
                }
        };
 
@@ -169,8 +197,7 @@
        // Assign methods
        smw.dataItem.wikiPage.prototype = fn;
 
-       // Extension
-       // If you need to extend methods just use
+       // For additional methods use
        // $.extend( smw.dataItem.wikiPage.prototype, { method: function (){ 
... } } );
 
 } )( jQuery, mediaWiki, semanticMediaWiki );
\ No newline at end of file
diff --git a/resources/smw/ext.smw.js b/resources/smw/ext.smw.js
index f166b56..8b8220e 100644
--- a/resources/smw/ext.smw.js
+++ b/resources/smw/ext.smw.js
@@ -1,4 +1,4 @@
-/**
+/*!
  * This file is part of the Semantic MediaWiki Extension
  * @see https://semantic-mediawiki.org/
  *
@@ -20,7 +20,6 @@
  * @since 1.8
  *
  * @file
- * @ignore
  *
  * @ingroup SMW
  *
diff --git a/tests/qunit/smw/data/ext.smw.dataItem.wikiPage.test.js 
b/tests/qunit/smw/data/ext.smw.dataItem.wikiPage.test.js
index 1fa7e56..08a358b 100644
--- a/tests/qunit/smw/data/ext.smw.dataItem.wikiPage.test.js
+++ b/tests/qunit/smw/data/ext.smw.dataItem.wikiPage.test.js
@@ -1,12 +1,30 @@
-/**
- * QUnit tests
+/*!
+ * This file is part of the Semantic MediaWiki QUnit test suite
+ * @see https://semantic-mediawiki.org/wiki/QUnit
+ *
+ * @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
  *
  * @since 1.9
  *
  * @file
- * @ingroup SMW
  *
- * @licence GNU GPL v2 or later
+ * @ingroup SMW
+ * @ingroup Test
+ *
+ * @licence GNU GPL v2+
  * @author mwjames
  */
 ( function ( $, mw, smw ) {
@@ -14,17 +32,48 @@
 
        QUnit.module( 'ext.smw.dataItem.wikiPage', QUnit.newMwEnvironment() );
 
-       var pass = 'Passes because ';
-
        // Data provider
        var testCases = [
-               { test: [ '', '', '' ], expected: [ null, null, 0 , null, true] 
} ,
-               { test: [ 'foo', '', '' ], expected: [ 'foo', null, 0, 'foo', 
true] },
-               { test: [ 'bar', '', 6 ], expected: [ 'bar', null, 6, 'bar', 
true ] },
-               { test: [ 'bar', '', 0, true ], expected: [ 'bar', null, 0, 
'bar', true ] },
-               { test: [ 'bar', '', 2, false ], expected: [ 'bar', null, 2, 
'bar', false ] },
-               { test: [ 'fooBar', 'http://fooBar', 0, false ], expected: [ 
'fooBar', 'http://fooBar', 0, '<a href=\"http://fooBar\"; 
class=\"new\">fooBar</a>', false ] },
-               { test: [ 'fooBar', 'http://fooBar', 0, true ], expected: [ 
'fooBar', 'http://fooBar', 0, '<a href=\"http://fooBar\";>fooBar</a>', true ] }
+               {
+                       test: [ '', '', '' ],
+                       expected: { 'name': null, 'text': null, 'uri': null, 
'ns': 0, 'html': null, 'known': true }
+               } ,
+               {
+                       test: [ 'foo', '', '' ],
+                       expected: { 'name': 'foo', 'text': 'foo', 'uri': null, 
'ns': 0, 'html': 'foo', 'known': true }
+               },
+               {
+                       test: [ 'bar', '', 6 ],
+                       expected: { 'name': 'bar', 'text': 'bar', 'uri': null, 
'ns': 6, 'html': 'bar', 'known': true }
+               },
+               {
+                       test: [ 'bar', '', 0, true ],
+                       expected: { 'name': 'bar', 'text': 'bar', 'uri': null, 
'ns': 0, 'html': 'bar', 'known': true }
+               },
+               {
+                       test: [ 'bar', '', 2, false ],
+                       expected: { 'name': 'bar', 'text': 'bar', 'uri': null, 
'ns': 2, 'html': 'bar', 'known': false }
+               },
+               {
+                       test: [ 'fooBar', 'http://fooBar', 0, false ],
+                       expected: { 'name': 'fooBar', 'text': 'fooBar', 'uri': 
'http://fooBar', 'ns': 0, 'html': '<a href=\"http://fooBar\"; 
class=\"new\">fooBar</a>', 'known': false }
+               },
+               {
+                       test: [ 'fooBar#_9a0c8abb8ef729b5c7', 
'http://fooBar#_9a0c8abb8ef729b5c7', 0, false ],
+                       expected: { 'name': 'fooBar#_9a0c8abb8ef729b5c7', 
'text': 'fooBar', 'uri': 'http://fooBar#_9a0c8abb8ef729b5c7', 'ns': 0, 'html': 
'<a href=\"http://fooBar#_9a0c8abb8ef729b5c7\"; class=\"new\">fooBar</a>', 
'known': false }
+               },
+               {
+                       test: [ 'fooBar', 'http://fooBar', 0, true ],
+                       expected: { 'name': 'fooBar', 'text': 'fooBar', 'uri': 
'http://fooBar', 'ns': 0, 'html': '<a href=\"http://fooBar\";>fooBar</a>', 
'known': true }
+               },
+               {
+                       test: [ 'Foo#_QUERY9a665a578eb95c1', 
'http://Foo#_QUERY9a665a578eb95c1', 0, true ],
+                       expected: { 'name': 'Foo#_QUERY9a665a578eb95c1', 
'text': 'Foo', 'uri': 'http://Foo#_QUERY9a665a578eb95c1', 'ns': 0, 'html': '<a 
href=\"http://Foo#_QUERY9a665a578eb95c1\";>Foo</a>', 'known': true }
+               },
+               {
+                       test: [ 'Foo#_QUERY#9a665a578eb95c1', 
'http://Foo#_QUERY#9a665a578eb95c1', 0, true ],
+                       expected: { 'name': 'Foo#_QUERY#9a665a578eb95c1', 
'text': 'Foo', 'uri': 'http://Foo#_QUERY#9a665a578eb95c1', 'ns': 0, 'html': '<a 
href=\"http://Foo#_QUERY#9a665a578eb95c1\";>Foo</a>', 'known': true }
+               }
        ];
 
        /**
@@ -35,7 +84,7 @@
        QUnit.test( 'instance', 1, function ( assert ) {
 
                var result = new smw.dataItem.wikiPage( 'foo', 'bar' );
-               assert.ok( result instanceof Object, pass + 'the 
smw.dataItem.wikiPage instance was accessible' );
+               assert.ok( result instanceof Object, 'the smw.dataItem.wikiPage 
instance was accessible' );
 
        } );
 
@@ -47,21 +96,36 @@
        QUnit.test( 'getDIType', 1, function ( assert ) {
 
                var result = new smw.dataItem.wikiPage( 'foo', 'bar' );
-               assert.equal( result.getDIType(), '_wpg', pass + 'returned 
_wpg' );
+               assert.equal( result.getDIType(), '_wpg', 'returned _wpg' );
 
        } );
 
        /**
-        * Test getName
+        * Test getPrefixedText
         *
         * @since: 1.9
         */
-       QUnit.test( 'getName', 7, function ( assert ) {
+       QUnit.test( 'getPrefixedText', 10, function ( assert ) {
                var result;
 
                $.map( testCases, function ( testCase ) {
                        result = new smw.dataItem.wikiPage( testCase.test[0], 
testCase.test[1], testCase.test[2] );
-                       assert.equal( result.getName(), testCase.expected[0] , 
pass + 'returned ' + testCase.expected[0]  );
+                       assert.equal( result.getPrefixedText(), 
testCase.expected.name , 'returned ' + testCase.expected.name  );
+               } );
+
+       } );
+
+       /**
+        * Test getText
+        *
+        * @since: 1.9
+        */
+       QUnit.test( 'getText', 10, function ( assert ) {
+               var result;
+
+               $.map( testCases, function ( testCase ) {
+                       result = new smw.dataItem.wikiPage( testCase.test[0], 
testCase.test[1], testCase.test[2] );
+                       assert.equal( result.getText(), testCase.expected.text 
, 'returned ' + testCase.expected.text  );
                } );
 
        } );
@@ -71,27 +135,27 @@
         *
         * @since: 1.9
         */
-       QUnit.test( 'getUri', 7, function ( assert ) {
+       QUnit.test( 'getUri', 10, function ( assert ) {
                var result;
 
                $.map( testCases, function ( testCase ) {
                        result = new smw.dataItem.wikiPage( testCase.test[0], 
testCase.test[1], testCase.test[2] );
-                       assert.equal( result.getUri(), testCase.expected[1] , 
pass + 'returned ' + testCase.expected[1]  );
+                       assert.equal( result.getUri(), testCase.expected.uri , 
'returned ' + testCase.expected.uri  );
                } );
 
        } );
 
        /**
-        * Test getNamespace
+        * Test getNamespaceId
         *
         * @since: 1.9
         */
-       QUnit.test( 'getNamespace', 7, function ( assert ) {
+       QUnit.test( 'getNamespaceId', 10, function ( assert ) {
                var result;
 
                $.map( testCases, function ( testCase ) {
                        result = new smw.dataItem.wikiPage( testCase.test[0], 
testCase.test[1], testCase.test[2] );
-                       assert.equal( result.getNamespace(), 
testCase.expected[2] , pass + 'returned ' + testCase.expected[2]  );
+                       assert.equal( result.getNamespaceId(), 
testCase.expected.ns , 'returned ' + testCase.expected.ns  );
                } );
 
        } );
@@ -101,12 +165,13 @@
         *
         * @since: 1.9
         */
-       QUnit.test( 'getTitle', 1, function ( assert ) {
+       QUnit.test( 'getTitle', 2, function ( assert ) {
 
                var wikiPage = new smw.dataItem.wikiPage( 'File:foo', 'bar' );
                var title = new mw.Title( 'File:foo' );
 
-               assert.deepEqual( wikiPage.getTitle(), title ,pass + 'returned 
a Title instance' );
+               assert.ok( wikiPage.getTitle() instanceof mw.Title, 
'.getTitle() returned a Title instance' );
+               assert.deepEqual( wikiPage.getTitle(), title, 'returned a Title 
instance' );
 
        } );
 
@@ -115,12 +180,12 @@
         *
         * @since: 1.9
         */
-       QUnit.test( 'isKnown', 7, function ( assert ) {
+       QUnit.test( 'isKnown', 10, function ( assert ) {
                var result;
 
                $.map( testCases, function ( testCase ) {
                        result = new smw.dataItem.wikiPage( testCase.test[0], 
testCase.test[1], testCase.test[2], testCase.test[3] );
-                       assert.equal( result.isKnown(), testCase.expected[4] , 
pass + 'returned ' + testCase.expected[4]  );
+                       assert.equal( result.isKnown(), 
testCase.expected.known, 'returned ' + testCase.expected.known  );
                } );
 
        } );
@@ -130,17 +195,27 @@
         *
         * @since: 1.9
         */
-       QUnit.test( 'getHtml', 14, function ( assert ) {
+       QUnit.test( 'getHtml( false )', 10, function ( assert ) {
                var result;
 
                $.map( testCases, function ( testCase ) {
                        result = new smw.dataItem.wikiPage( testCase.test[0], 
testCase.test[1], testCase.test[2] );
-                       assert.equal( result.getHtml(), testCase.expected[0] , 
pass + 'returned ' + testCase.expected[0]  );
+                       assert.equal( result.getHtml( false ), 
testCase.expected.text, 'returned ' + testCase.expected.text  );
                } );
+
+       } );
+
+       /**
+        * Test getHtml
+        *
+        * @since: 1.9
+        */
+       QUnit.test( 'getHtml( true )', 10, function ( assert ) {
+               var result;
 
                $.map( testCases, function ( testCase ) {
                        result = new smw.dataItem.wikiPage( testCase.test[0], 
testCase.test[1], testCase.test[2], testCase.test[3] );
-                       assert.equal( result.getHtml( true ), 
testCase.expected[3] , pass + 'returned ' + testCase.expected[3]  );
+                       assert.equal( result.getHtml( true ), 
testCase.expected.html, 'returned ' + testCase.expected.html  );
                } );
 
        } );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0a355ebd7ee03ab30467ef510ff97da34ac2877a
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
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

Reply via email to