jenkins-bot has submitted this change and it was merged.
Change subject: Cleanup: Removed support for old-style templated attributes.
......................................................................
Cleanup: Removed support for old-style templated attributes.
* We've been generating data-mw style templated attrs. for a while
and production cache has also been cleared a few times since then.
So, no need to carry around code cruft anymore.
Change-Id: I4e0dbcce2064857dd96de8d90bf90beea817e25f
---
M js/lib/mediawiki.DOMUtils.js
M js/lib/mediawiki.WikitextSerializer.js
M js/lib/mediawiki.parser.defines.js
3 files changed, 34 insertions(+), 174 deletions(-)
Approvals:
GWicke: Looks good to me, approved
jenkins-bot: Verified
diff --git a/js/lib/mediawiki.DOMUtils.js b/js/lib/mediawiki.DOMUtils.js
index 2d33570..467ac6e 100644
--- a/js/lib/mediawiki.DOMUtils.js
+++ b/js/lib/mediawiki.DOMUtils.js
@@ -294,37 +294,18 @@
*
* @param {Node} node
* @param {string} name
- * @param {Object} tplAttrs
* @returns {Object}
* @returns {Mixed} return.value
* @returns {boolean} return.modified If the value of the attribute
changed since we parsed the wikitext
* @returns {boolean} return.fromsrc Whether we got the value from
source-based roundtripping
*/
- getAttributeShadowInfo: function ( node, name, tplAttrs ) {
+ getAttributeShadowInfo: function ( node, name ) {
this.getDataParsoid( node );
if ( !this.isElt(node) || !node.data || !node.data.parsoid ) {
return node.getAttribute( name );
}
var curVal = node.getAttribute(name),
dp = node.data.parsoid;
-
- // If tplAttrs is truish, check if this attribute was
- // template-generated. Return that value if set.
- if ( tplAttrs ) {
- var type = node.getAttribute('typeof'),
- about = node.getAttribute('about') || '',
- tplAttrState = tplAttrs[about];
- if (type &&
/(?:^|\s)mw:ExpandedAttrs\/[^\s]+/.test(type) &&
- tplAttrState &&
- tplAttrState.vs[name] )
- {
- return {
- value: tplAttrState.vs[name],
- modified: false,
- fromsrc: true
- };
- }
- }
// Not the case, continue regular round-trip information.
if ( dp.a === undefined ) {
diff --git a/js/lib/mediawiki.WikitextSerializer.js
b/js/lib/mediawiki.WikitextSerializer.js
index 68adca6..ec9e035 100644
--- a/js/lib/mediawiki.WikitextSerializer.js
+++ b/js/lib/mediawiki.WikitextSerializer.js
@@ -399,10 +399,6 @@
* Stack of wikitext escaping handlers -- these handlers are responsible
* for smart escaping when the surrounding wikitext context is known.
*
- * tplAttrs
- * Tag attributes that came from templates in source wikitext -- these
- * are collected upfront from the DOM from mw-marked nodes.
- *
* currLine
* This object is used by the wikitext escaping algorithm -- represents
* a "single line" of output wikitext as represented by a block node in
@@ -424,7 +420,6 @@
inIndentPre: false,
inPHPBlock: false,
wteHandlerStack: [],
- tplAttrs: {},
// XXX: replace with output buffering per line
currLine: {
text: '',
@@ -757,10 +752,7 @@
return value;
};
-// Temporarily, keep this working with old-style meta tags
-// so we dont have to purge the cache. But, on cache purge,
-// we can ditch oldStyleTplAttrs and all support for it.
-WSP.serializedAttrVal = function(node, name, oldStyleTplAttrs) {
+WSP.serializedAttrVal = function(node, name) {
DU.getDataParsoid( node );
if ( !DU.isElt(node) || !node.data || !node.data.parsoid ) {
return node.getAttribute( name );
@@ -774,7 +766,7 @@
fromsrc: true
};
} else {
- return DU.getAttributeShadowInfo(node, name, oldStyleTplAttrs);
+ return DU.getAttributeShadowInfo(node, name);
}
};
@@ -1263,8 +1255,7 @@
// Helper function for getting RT data from the tokens
var getLinkRoundTripData = function( env, node, state ) {
- var tplAttrs = state.tplAttrs,
- dp = node.data.parsoid;
+ var dp = node.data.parsoid;
var rtData = {
type: null,
target: null, // filled in below
@@ -1288,7 +1279,7 @@
rtData.href = href.replace( /^(\.\.?\/)+/, '' );
// Now get the target from rt data
- rtData.target = state.serializer.serializedAttrVal(node, 'href',
tplAttrs);
+ rtData.target = state.serializer.serializedAttrVal(node, 'href', {});
// Check if the link content has been modified
// FIXME: This will only work with selser of course. Hard to test
without
@@ -1890,7 +1881,7 @@
// we need to fully shadow the sort key.
//if ( ! target.modified ) {
// The target and source key was not
modified
- var sortKeySrc =
this.serializedAttrVal(node, 'mw:sortKey', state.tplAttrs);
+ var sortKeySrc =
this.serializedAttrVal(node, 'mw:sortKey', {});
if ( sortKeySrc.value !== null ) {
linkData.contentNode =
undefined;
linkData.content.string =
sortKeySrc.value;
@@ -2761,7 +2752,7 @@
if (out === 'categorydefaultsort') {
if (node.data.parsoid.src) {
// Use content so that
VE modifications are preserved
- var contentInfo =
state.serializer.serializedAttrVal(node, "content", state.tplAttrs);
+ var contentInfo =
state.serializer.serializedAttrVal(node, "content", {});
out =
node.data.parsoid.src.replace(/^([^:]+:)(.*)$/, "$1" + contentInfo.value +
"}}");
} else {
console.warn('defaultsort is missing source. Rendering as DEFAULTSORT
magicword');
@@ -3077,22 +3068,8 @@
return (/(?:^|\s)mw:ExpandedAttrs\/[^\s]+/).test(tokType);
}
- var tplAttrState = { kvs: {}, ks: {}, vs: {} },
- tokType = token.getAttribute("typeof"),
+ var tokType = token.getAttribute("typeof"),
attribs = token.attribs;
-
- // Check if this token has attributes that have been
- // expanded from templates or extensions
- if (hasExpandedAttrs(tokType)) {
- tplAttrState = state.tplAttrs[token.getAttribute("about")];
- if (!tplAttrState) {
- console.error("ERROR: Missing info about tpl-affected
attribute");
- console.error("-> about: " +
JSON.stringify(token.getAttribute("about")));
- console.error("-> token: " + JSON.stringify(token));
- // Reset to default so we dont crash
- tplAttrState = { kvs: {}, ks: {}, vs: {} };
- }
- }
var out = [],
// Strip Parsoid generated values
@@ -3135,47 +3112,32 @@
}
if (k.length > 0) {
- tplKV = tplAttrState.kvs[k];
- if (tplKV) {
- out.push(tplKV);
+ vInfo = token.getAttributeShadowInfo(k);
+ v = vInfo.value;
+
+ // Deal with k/v's that were template-generated
+ k = this.getAttributeKey(node, k);
+
+ // Pass in kv.k, not k since k can potentially
+ // be original wikitext source for 'k' rather than
+ // the string value of the key.
+ v = this.getAttributeValue(node, kv.k, v);
+
+ // Remove encapsulation from protected attributes
+ // in pegTokenizer.pegjs.txt:generic_newline_attribute
+ k = k.replace( /^data-x-/i, '' );
+
+ if (v.length > 0) {
+ if (!vInfo.fromsrc) {
+ // Escape HTML entities
+ v = Util.escapeEntities(v);
+ }
+ out.push(k + '=' + '"' + v.replace( /"/g,
'"' ) + '"');
+ } else if (k.match(/[{<]/)) {
+ // Templated, <*include*>, or <ext-tag>
generated
+ out.push(k);
} else {
- tplK = tplAttrState.ks[k];
- tplV = tplAttrState.vs[k];
- vInfo = token.getAttributeShadowInfo(k);
- v = vInfo.value;
-
- // Deal with k/v's that were template-generated
- if (tplK) {
- k = tplK;
- } else {
- k = this.getAttributeKey(node, k);
- }
-
- if (tplV) {
- v = tplV;
- } else {
- // Pass in kv.k, not k since k can
potentially
- // be original wikitext source for 'k'
rather than
- // the string value of the key.
- v = this.getAttributeValue(node, kv.k,
v);
- }
-
- // Remove encapsulation from protected
attributes
- // in
pegTokenizer.pegjs.txt:generic_newline_attribute
- k = k.replace( /^data-x-/i, '' );
-
- if (v.length > 0) {
- if (!vInfo.fromsrc) {
- // Escape HTML entities
- v = Util.escapeEntities(v);
- }
- out.push(k + '=' + '"' + v.replace(
/"/g, '"' ) + '"');
- } else if (k.match(/[{<]/)) {
- // Templated, <*include*>, or <ext-tag>
generated
- out.push(k);
- } else {
- out.push(k + '=""');
- }
+ out.push(k + '=""');
}
} else if ( kv.v.length ) {
// not very likely..
@@ -3198,21 +3160,8 @@
k = aKeys[i];
// Attrib not present -- sanitized away!
if (!Util.lookupKV(attribs, k)) {
- // Deal with k/v's that were template-generated
- // and then sanitized away!
- tplK = tplAttrState.ks[k];
- if (tplK) {
- k = tplK;
- }
-
v = dataAttribs.sa[k];
if (v) {
- tplV = tplAttrState.vs[k];
-
- if (tplV){
- v = tplV;
- }
-
out.push(k + '=' + '"' + v.replace(
/"/g, '"' ) + '"');
} else {
// at least preserve the key
@@ -3713,54 +3662,6 @@
}
};
-
-/**
- * Update state with the set of templated attributes.
- */
-WSP.extractTemplatedAttributes = function(node, state) {
- if (node.nodeName.toLowerCase() === "meta") {
- var prop = node.getAttribute("property");
- if (prop && prop.match(/mw:objectAttr/)) {
- var templateId = node.getAttribute("about") || '';
- var src = this._getDOMRTInfo(node).src;
- if (!state.tplAttrs[templateId]) {
- state.tplAttrs[templateId] = { kvs: {}, ks: {},
vs: {} };
- }
-
- // prop is one of:
- // "mw:ObjectAttr#foo" -- "foo=blah" came from a
template
- // "mw:objectAttrKey#foo" -- "foo" came from a template
- // "mw:objectAttrVal#foo -- "blah" (foo's value) came
from a template
- var pieces = prop.split("#");
- var attr = pieces[1];
-
- if (pieces[0] === "mw:objectAttr") {
- state.tplAttrs[templateId].kvs[attr] = src;
- } else if (pieces[0] === "mw:objectAttrKey") {
- state.tplAttrs[templateId].ks[attr] = src;
- } else {
- state.tplAttrs[templateId].vs[attr] = src;
- }
-
- // Remove it from the DOM
- //node.parentNode.removeChild(node);
- }
- } else {
- var child = node.firstChild;
- var next, prev, childIsPre;
-
- while (child) {
- // Get the next sibling first thing because we may
delete this child
- next = child.nextSibling; prev = child.previousSibling;
- childIsPre = DU.hasNodeName(child, "pre");
-
- // Descend and recurse
- this.extractTemplatedAttributes(child, state);
-
- child = next;
- }
- }
-};
/**
* Helper for updateSeparatorConstraints
@@ -4479,9 +4380,6 @@
// Normalize the DOM (coalesces adjacent text body)
// FIXME: Disabled as this strips empty comments (<!---->).
//body.normalize();
-
- // collect tpl attr tags
- this.extractTemplatedAttributes(body, state);
// Minimize I/B tags
minimizeWTQuoteTags(body);
diff --git a/js/lib/mediawiki.parser.defines.js
b/js/lib/mediawiki.parser.defines.js
index 3bbaa9a..2acd385 100644
--- a/js/lib/mediawiki.parser.defines.js
+++ b/js/lib/mediawiki.parser.defines.js
@@ -144,33 +144,14 @@
* context to be set to a token.
*
* @param {string} name
- * @param {Array} tplAttrs The list of expanded attributes.
* @returns {Object} Information about the shadow info attached to this
attribute.
* @returns {Mixed} return.value
* @returns {boolean} return.modified Whether the attribute was changed
between parsing and now.
* @returns {boolean} return.fromsrc Whether we needed to get the
source of the attribute to round-trip it.
*/
- getAttributeShadowInfo: function ( name, tplAttrs ) {
+ getAttributeShadowInfo: function ( name ) {
var Util = require('./mediawiki.Util.js').Util; // (circular
dep)
var curVal = Util.lookup( this.attribs, name );
-
- // If tplAttrs is truish, check if this attribute was
- // template-generated. Return that value if set.
- if ( tplAttrs ) {
- var type = Util.lookup(this.attribs, 'typeof'),
- about = Util.lookup(this.attribs, 'about'),
- tplAttrState = tplAttrs[about];
- if (/(?:^|\s)mw:ExpandedAttrs\/[^\s]+/.test(type) &&
- tplAttrState &&
- tplAttrState.vs[name] )
- {
- return {
- value: tplAttrState.vs[name],
- modified: false,
- fromsrc: true
- };
- }
- }
// Not the case, continue regular round-trip information.
if ( this.dataAttribs.a === undefined ) {
--
To view, visit https://gerrit.wikimedia.org/r/99735
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4e0dbcce2064857dd96de8d90bf90beea817e25f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits