Subramanya Sastry has uploaded a new change for review.

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


Change subject: Dont Merge: Some comments and minor fixes to use/address.
......................................................................

Dont Merge: Some comments and minor fixes to use/address.

* Not to be merged.

Change-Id: Ic37efcb22c09bb28cf18fd6c4ad6d2cf4b2ee878
---
M js/lib/mediawiki.DOMPostProcessor.js
1 file changed, 25 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Parsoid 
refs/changes/90/50190/1

diff --git a/js/lib/mediawiki.DOMPostProcessor.js 
b/js/lib/mediawiki.DOMPostProcessor.js
index 34b419c..bee108d 100644
--- a/js/lib/mediawiki.DOMPostProcessor.js
+++ b/js/lib/mediawiki.DOMPostProcessor.js
@@ -117,6 +117,14 @@
 DOMTraverser.prototype.traverse = function ( node ) {
        var ix, child, childDT, children = node.childNodes;
 
+       // SSS: This is buggy.
+       //
+       // If the handlers modify 'node' or 'child' either by
+       // deleting child or adding nodes before/after it, then
+       // this code processes deleted nodes, or skips over
+       // newly added nodes (which may be the right thing to do
+       // in some cases but is it always without any additional
+       // info about what the handlers do?)
        for ( ix = 0; children && ix < children.length; ix++ ) {
                child = children[ix];
                this.callHandlers( child );
@@ -2063,12 +2071,12 @@
        var baseAbout = null,
                regex = env.conf.wiki.linkPrefixRegex;
 
-       if ( node !== null && DU.isTplElementNode( env, node ) ) {
-               baseAbout = node.getAttribute( 'about' );
-       }
-
        if ( !regex ) {
                return null;
+       }
+
+       if ( node !== null && DU.isTplElementNode( env, node ) ) {
+               baseAbout = node.getAttribute( 'about' );
        }
 
        node = node === null ? node : node.previousSibling;
@@ -2082,12 +2090,12 @@
        var baseAbout = null,
                regex = env.conf.wiki.linkTrailRegex;
 
-       if ( node !== null && DU.isTplElementNode( env, node ) ) {
-               baseAbout = node.getAttribute( 'about' );
-       }
-
        if ( !regex ) {
                return null;
+       }
+
+       if ( node !== null && DU.isTplElementNode( env, node ) ) {
+               baseAbout = node.getAttribute( 'about' );
        }
 
        node = node === null ? node : node.nextSibling;
@@ -2098,14 +2106,14 @@
  * Abstraction of both link-prefix and link-trail searches.
  */
 function searchForNeighbour( env, goForward, regex, node, baseAbout ) {
-       var value, matches, document,
+       var value, matches,
+               document = node ? node.ownerDocument : null,
                nextNode = goForward ? 'nextSibling' : 'previousSibling',
                innerNode = goForward ? 'firstChild' : 'lastChild',
                getInnerNeighbour = goForward ? getLinkTrail : getLinkPrefix,
                result = { content: [], src: '' };
 
        while ( node !== null ) {
-               document = node.ownerDocument;
 
                if ( node.nodeType === node.TEXT_NODE ) {
                        matches = node.nodeValue.match( regex );
@@ -2114,8 +2122,9 @@
                                value.src = matches[0];
                                if ( value.src === node.nodeValue ) {
                                        value.content = node;
+                                       // FIXME: Dont you want to delete node 
in this case?
                                } else {
-                                       value.content = 
document.createTextNode( matches[0] );
+                                       value.content = 
document.createTextNode( value.src );
                                        node.parentNode.replaceChild( 
document.createTextNode( node.nodeValue.replace( regex, '' ) ), node );
                                }
                        } else {
@@ -2161,7 +2170,8 @@
 function handleLinkNeighbours( env, node ) {
        var ix, prefix = getLinkPrefix( env, node ),
                trail = getLinkTrail( env, node ),
-               dp = Util.getJSONAttribute( node, 'data-parsoid', {} );
+               dp = Util.getJSONAttribute( node, 'data-parsoid', {} ),
+               updated = true;
 
        if ( node.getAttribute( 'rel' ) !== 'mw:WikiLink' ) {
                return;
@@ -2172,6 +2182,7 @@
                        node.insertBefore( prefix.content[ix], node.firstChild 
);
                }
                if ( prefix.src.length > 0 ) {
+                       updated = true;
                        dp.prefix = prefix.src;
                        if (dp.dsr) {
                                dp.dsr[0] -= prefix.src.length;
@@ -2185,6 +2196,7 @@
                        node.appendChild( trail.content[ix] );
                }
                if ( trail.src.length > 0 ) {
+                       updated = true;
                        dp.tail = trail.src;
                        if (dp.dsr) {
                                dp.dsr[1] += trail.src.length;
@@ -2193,7 +2205,7 @@
                }
        }
 
-       if ( trail !== null || prefix !== null ) {
+       if (updated) {
                node.setAttribute( 'data-parsoid', JSON.stringify( dp ) );
        }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic37efcb22c09bb28cf18fd6c4ad6d2cf4b2ee878
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>

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

Reply via email to