-
Notifications
You must be signed in to change notification settings - Fork 3
Better template parsing (previously: _Cleanup removes submission templates) #196
Comments
It's due to a messed up submission template:
Notice how |
OK, I think we should rework that again and store all stuff in an array obeject so [ts]= 2013... |
Maybe just write a basic template parsing engine, tbh. |
Wrote a little function: function afcHelper_parseTemplate(wikicode,returntitle) {
var contents = $.trim(wikicode).replace(/(^\{\{|\}\}$)/g,'');
var pieces = contents.split('|');
var title = pieces.shift();
var params = {};
var increm = 1;
$.each(pieces, function(index,piece) {
if (piece.indexOf('=') != -1) {
var varparts = piece.split(/=/);
var key = varparts.shift();
var val = varparts.join('=');
params[key] = val;
} else {
params[increm.toString()] = piece;
increm++;
}
});
if (returntitle)
return [title,params];
else
return params;
} Demo:
Supports both positional and named parameters in the template (additionally, |
How about that "crazy" but valid stuff?
|
This is what I was talking about as far as complexity goes. it's not easy. |
yeah, I meant more that this isn't that untypical. but, I don't understand: isn't
simply including the whole template as it is? That would mean it would work... (did you tested the code anywhere? XD) |
No, the problem isn't in THAT code but rather in whatever code we use to find the templates initially: In this example:
The regex would match
and then stop. We'd need to use some sort of method for keeping track of the number of "{"s and "}"s we encounter, then break them apart, etc., etc.... |
BTW, downgraded this from "critical" -- it was a malformed template. |
i have a idea and a workaround. I will come online later |
@theopolisme: how about using a function similar to the bottom of https://en.wikipedia.org/wiki/User:Ohconfucius/test/formatgeneral.js/core.js so we can replace | and {{}} within a parameter first and the revert them back after being in the array. ^^ |
Uh...no...you still don't understand. Just tell me how to parse the templates out of the following page:
Now do you understand why your method wouldn't work? |
Stayed up way too late (around 3 am now...and I have to be up at 7 :/ ) working on a template parsing engine that i'm calling Here's a demo string of what it can handle right now:
TODO list for self
Getting excited. |
https://github.com/theopolisme/jsmwparser Just run parser.js in your console to see the results for several testcases, and feel free to paste in your own. Try to make it break! (and then i'll try to fix it ;) ) |
will do next week. this weekend is busy |
Why are we still using implicit parameters in the first place. They are fairly unstable and a pain to deal with. I can get the templates updated as needed to make all of the variable explicit (yes, we would still need backwards compatibility for a while to handle existing pages). It's as simple as replacing |
@Technical-13 the implicit parameters are easily parsed in jsmwparser...no need to make it more complicated :/ https://github.com/theopolisme/jsmwparser/blob/master/parser.js#L90-L111 |
Problem is it doesn't catch malformed template usage like |
https://en.wikipedia.org/w/index.php?title=Wikipedia_talk%3AArticles_for_creation%2FReabrook_Valley&diff=cur&oldid=prev
dunno what happened here. Will have to check. (develop script used)
The text was updated successfully, but these errors were encountered: