Commit graph

58 commits

Author SHA1 Message Date
Subramanya Sastry 23359fb60b Minor tweak to data-mw output for <ref name='foo' /> tags
* Serializer was complaining about missing source for these tags.
  Tweaked code to serialize these back to self-closed tag form.

* Tested with which rts this with the regular serializer in edit mode.
echo "one <ref name='foo'>bar</ref> two<ref name='foo' />\n<references/>" | node parse --extensions ref,references --wt2wt

Change-Id: Iaac63b26660d8b03af937d00d04540c3b8c0c86c
2013-06-01 17:05:59 -05:00
jenkins-bot 1a606ef147 Merge "(Bug 48941) Normalize whitespace in ext-tag attribute values." 2013-06-01 13:39:04 +00:00
Gabriel Wicke 1299a00587 Add capability for DOM-based template expansion, and use DOM fragments for extensions
This patch adds the capability to expand individual transclusions all the way
to DOM, which enforces properly nested templates. This is also needed for
DOM-based template re-expansion, which the VE folks would like to use for
template editing.

In normal parsing, DOM-based expansion is currently disabled by default for
transclusions, and enabled by default for extensions. The decision whether to
balance a particular transclusion can be based on a statistics-based
classification of templates into balanced and unbalanced ones. The advantage
of this approach is consistency in behavior for old revisions. Another
alternative is to wrap unbalanced transclusions into <domparse> tags which
disable DOM-based parsing for all transclusions in its content. This has the
advantage that all special cases can be handled after tag insertion, and that
balancing could also be enforced in the PHP parser using an extension.

Other major changes:
* Renamed transclusion content typeof from mw:Object/Template to
  mw:Transclusion
* Renamed extension typeof from mw:Object/Extensions/foo to mw:Extension/foo
  and switched Cite to use lower-case ref/references too

Other minor changes:
* Only apply template encapsulation algorithm on DOM to mw:Transclusion and
  mw:Param objects, and no longer to all mw:Object/* elements. We should
  probably switch to a more explicit encapsulation type instead. Maybe
  something like mw:EncapStart/Transclusion and mw:EncapEnd/Transclusion
  instead of the current mw:Transclusion and mw:Transclusion/End, so that
  stripping those metas out selectively is easy?
* Changed the DOMTraverser logic to let handlers explicitly return the next
  element to handle. Useful when several siblings are handled, as is the case
  for the fragment unwrapper for example, and avoids some cases where deleted
  nodes were still being processed.
* Changed Cite to use mw:Extension/Ref{,erences} as all other extensions.
* Make sure we round-trip gallery when the PHP preprocessor is not used

Five parsoid-specific wt2html tests are failing due to the typeof change.
They will be fine once those tests are adjusted.  For now, adding them
to parser tests blacklist.

TODO:
* Switch the Cite extension to the generic DOMFragment mechanism instead of
  marker tokens.

Change-Id: I64b560a12695256915d2196d0646347381400e80
2013-05-31 14:35:05 -05:00
Subramanya Sastry ffd41827f4 (Bug 48941) Normalize whitespace in ext-tag attribute values.
* PHP parser normalizes whitespace in attribute values of all
  extension tags.  This patch mimics that behavior.

* Removed special case whitespace stripping for references.group
  attribute since that is now handled by the general case.

* As a result, <ref name='foo' /> and <ref name=' foo  ' /> are
  and treated as being identical.

Change-Id: I34009ab6662d05453fe46379c58d6e989f296958
2013-05-30 15:11:57 -05:00
Subramanya Sastry 63f307ee27 (Bug 48808) Serialize edited extension content
* Extensions were being serialized back to original wikitext src.
* This patch now uses data-mw content to serialize to extension
  wikitext.
* Fixed Cite to add attributes for ref to data-mw so that attributes
  roundtrip back (WS and quotes are normalized).
* TODO:
  1. add data-mw for <references> in Cite.js
  2. add data-mw for all other extensions in the extension handler

Change-Id: If3c35398a409f4775204407b3dcf2442ec2fb4e5
2013-05-26 12:17:38 +02:00
Subramanya Sastry bd31e371d2 Updates to cite to reflect spec for references and ref
* Updated references output DOM to match spec better.
* Also refactored some repetitive DOM code into helper functions.
* Turned on tpl encapsulation inside extensions.
* Verified output on the example in the spec and the example in
  commit 3c88b310.

Change-Id: I1b894759d2cd89b6453156e6b0246f6cc8f0d60b
2013-05-10 22:36:52 +05:30
Subramanya Sastry 6b7425b5f7 Set end-tsr on references section to enable accurate DSR on it
* Fixes rt error of <references/> section on ko:담티역

Change-Id: I8eb1c82e5ff7ba021b2d347a76102d68486cdaf3
2013-04-26 09:20:26 +05:30
C. Scott Ananian c97d363f6a Remove unused variables.
'jshint --show-non-errors' shows unused variables.  Some of these are unused
function arguments, which are rarely bugs.  But try to fix the ones which
are forgotten/dead code and unnecessary require()s.

Change-Id: I685ccd8e388fd3acf75053a07e2f729398fa2855
2013-04-25 15:33:09 -04:00
Subramanya Sastry e3d8c0c4e6 Cleanup: Fixed some comments, formatting, removed dead code
* No change in functionality or parser test results.

Change-Id: I66a7b1f2a1618d0809d6783156fcc6bc89b44885
2013-04-25 16:10:33 +05:30
Subramanya Sastry 3c88b3109b Moved ref-index generation to DOM post-pass
* When I last fixed Cite in commit 0164b846, I didn't take it
  all the way through. I was assigning ref indexes in the
  async pipeline which is incorrect since ref-tokens and
  references-tokens should be processed in the same order
  as they show up in the input.

* I now moved ref-index assignment to the DOM post processor
  phase where they always belonged.

* Fixed references and cite reset functions to only reset a
  specific group, if necessary.

* Pipelines processing template transclusions should propagate
  the extension tag if the transclusion showed up in the context of
  extension source so that any extension-specific constraints are
  respected. (Ex: ref-tags in reference-extension context are handled
  differently -- and this should continue to be true even when the
  tags show up via transcluded content)

* These fixes were tested on the following snippet from 0164b846.
  Where this snippet was generating buggy output earlier, it is now
  being handled correctly.

---------------------------
X1<ref name="x" /> X2<ref name="x" />
<references>
<ref name="x">x</ref>
</references>

Y<ref name="y">{{echo|y}}</ref>
Z<ref name="z" />
<references>
{{echo|<ref name="z">z</ref>}}
</references>

A<ref name="a">a</ref>
B<ref name="b" />
<references>
{{echo|<ref name="b">b</ref>}}
</references>

C<ref name="c">c</ref>
D<ref name="d" />
<references>
<ref name="d">{{echo|d}}</ref>
</references>
---------------------------
X1<ref name="x" /> X2<ref name="x" />

Change-Id: I838d188c90b526878a72e4baf1e54cac644aadfc
2013-04-25 01:09:55 +05:30
C. Scott Ananian 80c29be19f Fix crasher on 🇫🇷126e_méridien_ouest
This code is being run on:
  <meta property="mw:PageProp/categorydefaultsort" content="0 126">
which doesn't have a 'typeof' attribute, and so the match is crashing
with a null pointer dereference.

Turn the expression around. RegExp.test is more efficient, and it handles
a null argument with no problems.  Add start/end anchors to the regexp
while we're at it.

Change-Id: I11bc9fdc902a21ce0bc1c05f08d3b615d5483e2e
2013-04-24 10:50:11 -04:00
C. Scott Ananian dca9f9d8c3 Fix a bunch of jshint warnings.
Most of these warnings are globals defined in mediawiki.parser.defines.js,
which we turn into proper local variables.  But there are a grab page of
other use-before-def, missing semicolon, bad line break, and other minor
warnings.

No tricky stuff attempted in this patch, this should be safe obvious
fixes only... although there is a nasty circular dependency between
Util and parser.defines which had to be broken.

Change-Id: I8810da3a5ec287d7ae9078463ba01472a87a492e
2013-04-22 19:45:05 -04:00
Subramanya Sastry 0164b84689 Updated native <ref> and <references> tag implementations.
* Updated native implementations of the <ref> and <references>
  tag implementations of the cite extension.

* <references> tag was not being processed properly by Parsoid.
  This led to lost references on the BO page.  This patch fixes
  it which fills out references and more closely matches output
  en:WP.

* Extracted extension content processing code into a helper and
  reused it for both <ref> and <references> handler.
  - Leading ws-only lines are unconditionally stripped. Is this
    accurate or is this extension-specific?  Given that this code
    is right now tied to <ref> and <references> tag, this is not
    yet a problem, but if made more generic, this issue has to
    be addressed.

* PreHandler should not run when processing the refs-tag. Right
  now, this is a hard check in the pre-handler.  Probably worth
  making this more generic by letting every stage in the pipeline
  get a chance at turning themselves on/off based on the extension
  being processed by the pipeline (can use the _applyToStage fn.
  on ParserPipeline). TO BE DONE.

* <ref> extension needs to be reset after each <references> tag
  is processed to duplicate behavior of existing cite extension.
  TO BE DONE.

* Updated refs group index to start at 1.

* No change in parser tests. References section output on the
  en:Barack Obama page now more closely matches the refs output
  on enwp.

* In addition to the en:BO page, the following wikitext was used to
  fix bugs and test the implementation.
  CMD: "node parse --extensions ref,references < /tmp/test"
----------------------------------------------
X1<ref name="x" /> X2<ref name="x" />
<references>
<ref name="x">x</ref>
</references>

Y<ref name="y">{{echo|y}}</ref>
Z<ref name="z" />
<references>
{{echo|<ref name="z">z</ref>}}
</references>

A<ref name="a">a</ref>
B<ref name="b" />
<references>
{{echo|<ref name="b">b</ref>}}
</references>

C<ref name="c">c</ref>
D<ref name="d" />
<references>
<ref name="d">{{echo|d}}</ref>
</references>
----------------------------------------------

Change-Id: I2d243656e9e903d8dadb55ee7c0630824c65cc01
2013-03-28 13:09:10 -05:00
Subramanya Sastry b059502b3e Extension handling rewrite + cite extension refactoring.
Tokenization
------------
* Fixed tokenizer to correctly parse extension tags in different
  contexts: with start and end tags, in self-closing tag mode,
  and to correctly handle scenarios when the exension end-tag is
  followed by a '#' (the special char used to skip over extension
  content).

* Removed the distinction in the tokenizer between installed
  extensions and natively supported extension tags (<ref> and
  <references> for ex.).  They all tokenize and get processed
  identically and get handled by different paths in the extension
  handler.

* Template and TemplateArg tokens now carry tpl. transclusion
  source alongwith them since tsr information will not be
  accurate when they show up in extension contexts that in turn
  showed up in template context that were expanded by the php
  preprocessor.

  Ex: {{echo|<ref>{{echo|foo}}</ref>}}

  The tsr for the ref-tag will correspond to the
  template-source of the echo-template, NOT the original top-level
  page. So, env.page.src.substring(..) will return incorrect
  source for the innermost {{echo|foo}}. This fix of carrying
  along tpl transclusion source in the token itself eliminates
  this problem.

Knowledge of native extensions
------------------------------
* Natively implemented extension tags (<ref> and <references>)
  are hardcoded in env.conf.parsoid.  At some point, it would
  be good to have a registration mechanism for parsoid-native
  extensions.

Extension handling
------------------
* Extracted extension handling out of the template handler into
  its own handler class. Right now, this class inherits from the
  template handler in order to be able to reuse a lot of the
  expansion and encapsulation functionality currently in the
  Template Handler.

* This handler now handles extensions that are:
  (a) natively implemented and registered with Parsoid.
  (b) implemented as a PHP extension and expanded by relying on
      the PHP preprocessor.

  For (a), it uses information from env.conf.parsoid to find
  ext-handlers for natively implemented ext-tags.  However, this
  can be cleaned up at some point by making available a registration
  mechanism.

Cite/Ref/References
-------------------
* Reworked the cite handler to split up ref-token processing
  and references token processing.
  * The handler now processes ref-tokens, parses content all
    the way to html output and encapsulates the html in an
    attribute of a meta-token that serves as a placeholder for
    where the ref-token occured.
  * References are handled as a DOM post-pass where these meta
    placeholder tokens are collected, content extracted from
    the attribute and spit out at the site of a references tag.
    The DOM walking is in DOMPostProcessor.js, but the actual
    processing is part of the Cite.js to keep all cite extension
    handling code in one place.

Parser pipeline
---------------
* Restructured parser pipeline recipes based on changes to Cite,
  TemplateHandler, and ExtensionHandler.

* Added a couple functions to the parser pipeline:
  1. resetState to reset state before starting a new top-level parse
     when pipelines are reused across top-level parses (ex: parser
     tests)
  2. setSourceOffsets to set start/end offsets of the source being
     handled by the pipeline.  This is required to correctly set tsr
     values when extension content (which is a substring of original
     top-level text) is parsed in its own pipeline.

Other fixes
-----------
* Removed env parameter from the Params object since it was not
  being used and seemed like unnecessary state propagation.
* Removed a FIXME in DOMUtils.buildTokensFromDOM by reusing code
  in the tokenizer that converts "\n" in text to NlTks.
* Cleanup of Util.shiftTokenTSR.
* ext.util.TokenCollection is now no longer used by anything.
  Added a FIXME and left around in case we are able to improve
  tokenizing and handling of *include* tags that can eliminate the
  need for the messy TokenAndAttrCollector.

Test results
------------
* No change in parser tests results.

* Tested with a few different files.
  - en:BO page seems to be parsed about 10% faster than before
    (needs verification).
  - Referencs on the en:BO page seem to be more accurate than
    before.

Change-Id: I8a095fa9fa976c7b3a2a4bd968dc9db4270b105f
2013-03-14 15:25:45 -05:00
Subramanya Sastry a2e817311d Clear refs for a group after references are emitted for the group.
* A references tag for a group can appear multiple times on a page.
  Ex: en:List_of_number-one_albums_from_the_1960s_%28UK%29 uses
  {{Reflist|group=lower-alpha}} more than once, and each reflist
  tag emits references accumulated since the previous references
  output.  This requires clearing the refs for the group after it
  is emitted.

* Parsoid wasn't clearing the group's refs.  This resulted in
  duplicate ref output which in turn crashed template encapsulation
  code that relies on template ids being unique.

* This patch fixes it which fixes the crasher on
  en:List_of_number-one_albums_from_the_1960s_%28UK%29

* No change in parser test results.

Change-Id: I48ba9c3fe2249c6ef1c1bf068c22c7985fa16e8f
2013-02-28 17:07:03 -06:00
Subramanya Sastry fb27cd0b4a Handle multiply-referenced ref-tags without duplicate ref-content.
* When named-ref-tags are used multiple times in a document, the
  Cite.onReferences function was outputting the ref-content once
  for each use in the references section. While this is "harmless"
  for regular ref-content, when the ref-content has templates
  (ex: {[cite .. }}), that template content is duplicated several
  times -- this also means that template expansions seen in the
  output no longer has unique ids. Occasionally, this trips up
  DOM passes (template encapsulation) which make the reasonable
  assumption that template ids are unique. It introduced an
  infinite loop in the code that detects template range nestings
  and overlaps. This is not triggered always, but only in certain
  scenarios. en:Euphoria (Enrique Iglesias album) was a page that
  sent the parser into an infinite loop.

* Now fixed by outputting ref-content once.

* In addition, added an error-check in the DOM post-pass that might
  get stuck in an infinite loop to output an error message.

* No change in parser test results.

* en:Euphoria (Enrique Iglesias album) now parses and rts without
  getting stuck in an infinite loop.  Possibly other pages as well.

Change-Id: I81a055999eefe3ca36dfb8a9cda3fee538ae6c65
2013-02-20 17:50:52 -06:00
C. Scott Ananian cade728dcb Replace jquery dependency with a minimal 'fakejquery'.
The 'fakejquery' module just defines the bits we use: $.each, $.map,
$.extend, $.isArray, $.isEmptyObject (and the internal functions required
to implement those).

Change-Id: I626b2f3a3d3a8d395d0c9679e01d3399403636dd
2013-02-15 17:54:43 -05:00
Gabriel Wicke 2013cd72ea Eradicate env.text, only use env.page.src from now on.
Change-Id: Id87390a5d0e46f6bc1b713b04335cad43bc66baa
2013-01-09 18:07:21 -08:00
Subramanya Sastry 1de2752f0d Added a new parsing pipeline for processing ref tokens.
* Added a tokens/x-mediawiki/post-expansion sub-pipeline that
  is used to process ref-content.  This same pipeline type
  could also be used to post-process tokenized content from
  other extensions.
* Cleaned up transform handler ranks a bit.
* Fixed paragraph-handler to accept initial state and also
  fixed it to do a complete reset on encountering EOFTk.
  Cite ref-content handling uses the sub-pipeline while
  passing the inBlockToken flag to prevent top-level p-wrapping
  of ref-content.
* Fixes references output on en:Barack Obama and introduces
  lists in individual ref items.
* No change in parser tests -- how do we add tests for testing
  extensions like cite/ref?

Change-Id: I928a3a0f5f989ec28bbe73383794fe6f32599fd1
2012-11-29 15:58:15 -06:00
Subramanya Sastry d257cee069 Fixed #tag parser function.
* Updated #tag parser function code to set tag attributes.
  This lets {{Reflist|group=n}} to pass the group=n attribute
  to the <references> tag.  In turn, this fixes incorrect
  reference listing in the above template call.  This then
  fixes crashers in en:Prophet Muhammed, en:The PS3 and such
  pages.

  - TODO: parser output for Prophet Muhammed is still broken
  where content from body ends up in a table that has
  display:none css set.

* Minor code cleanup in AttributeTransformManager.process
  and added comment about lazy processing.

Change-Id: If528a3a5c6e22d3ff691dfc6b5b2f00201a26384
2012-11-29 11:24:24 -06:00
Gabriel Wicke fdde795b0f Trivial: Remove dead variable
And a commit so I can restart the test run with the native template expansion
enabled.

Change-Id: Ie3f44ac6f681257dc690ab230a880601b9799ade
2012-11-28 00:56:45 -08:00
Gabriel Wicke bad9921a2d Make Cite <references> group attribute handling more robust
The PHP preprocessor returns a references tag with an empty group attribute,
which we did not map to the null reference group. This caused the references
listing to vanish when using the PHP preprocessor.

This patch makes sure the attribute is converted to a string, stripped of
leading/trailing whitespace and finally set to null if no string remains.

No changes in parser tests, since Cite is in a separate extension.

Change-Id: Ib3de375225947a78c362370be8d78504fa24def2
2012-11-27 15:18:42 -08:00
Subramanya Sastry 3eff5dfc13 Unrelated fixes/cleanup addressing recent git-review comments.
* Replaced empty (mw:Placeholder) span tags with meta-tag.
* Minor code refactoring in DSR computation.
* Removed hardcoding of "mwt" prefix for object ids.
* Added rt-info for html tags that are not lower-case in the
  source wikitext.
  - Additional 2 wt2wt tests green.

Change-Id: I9bb6a075bc60b6d78186d23000128eef6a04c787
2012-11-20 19:42:30 -06:00
Subramanya Sastry 7069ef41c4 RT <references> as well as </references> tag.
* Fixes RT diff in en:Standing Sushi Bar.

Change-Id: Ia05f9d01503e3003260a10663d1dd845a261beab
2012-11-16 17:36:07 -06:00
Gabriel Wicke f4841b86ab Reset the Cite extension state with the end token
This should hopefully fix some spurious semantic diffs that are purely based
on ref numbering, which changes if the references are not reset.

Change-Id: I37b1f4cfe69538e1c5ccc81fdad3084c01151700
2012-11-16 10:04:35 -08:00
Subramanya Sastry 3144feec25 JSHint fixes only.
Change-Id: I1a4df6765a9606cb7d1f47c2e5b473b5524b64a7
2012-11-06 17:09:44 -06:00
Subramanya Sastry 5578953555 Run cite handler first thing in phase 3.
* Run cite handler first thing in phase 3 so that ref-content
  is pulled out of the main token stream.  This effectively
  prevents unclosed/unbalanced tags within ref-tags from
  affecting the main stream.

* No change in parser tests.

* Fixes rt diffs on the following pages:
  1. en:Bandaid surgeries (zero rt diffs)
  2. en:Gondi bank (zero rt diffs)
  3. en:Ashland, oh (1 syntactic diff)
  The reverted commit (78989e8) had fixed rt-diffs in 1. above,
  hadn't changed diffs in 2. and introduced regressions in 3.

Change-Id: I6ad498d9d3711b71e7f427eea214acd10da8647b
2012-11-06 12:47:42 -06:00
Subramanya Sastry 6dcfba79fa Dont set TSR on ref-end-meta-tags if incoming TSR is missing.
* Setting tsr to (endTsr || [null, text.length]) was causing
  serious duplication of rt-src on the following page:
    en:Almirante Latorre-class battleship
  This is the case for ref-tokens that come from templates
  which have their TSR stripped.  So, we shouldn't attempt
  to set it to [null, text.length] again.
* No change in parserTests.
* No change in errors for en:L'Opéra national de Paris.

Change-Id: If6a79638c349c9a3fab42094aad51e2e476f9632
2012-11-01 13:25:08 -05:00
Gabriel Wicke 2a774f0720 Set proper TSR on cite expansion output end meta
Also remove the src, as we re-set it based on DSR anyway.

No change in parserTests, but three less diffs in L'Opéra national de Paris.

Change-Id: Ia6784efe7d76c41f24a183465393bda78641a8eb
2012-10-31 16:43:28 -07:00
Gabriel Wicke a884a28b09 Deep-freeze cache returns and enable strict mode
This exposed a few bugs (primarily missing var declarations), which are fixed.
It would for example have caught the shallow clone bug we just fixed, and
should catch similar bugs early in the future.

TODO / issues this exposed:
Avoid attempted tsr modification in ext.core.TemplateHandler.js:306:29. This
is fixed for now by cloning the tokens, but should really be avoided by
stripping the tsr before caching the tokens (anything in phase 1 will work for
example).

Change-Id: I6a1a07de7ac333f31da9cf0ae9ed20e5507bacba
2012-10-30 12:53:27 -07:00
Subramanya Sastry 7aad9fc1b7 Enable RT-ing of references tag if page has no refs/citations.
* There was a fixme for this in ext.Cite.js which was triggering
  an error in the serializer and introducing rt-diffs.
* No change in parser tests.
* Eliminates semantic error in en:Birkenhauer Island and other
  pages.

Change-Id: I9fe6ea26fdf1859d751b02a288393af610be5474
2012-10-29 12:10:40 -05:00
Mark Holmquist d39d4fa9e8 Modularizing the roundtrip-testing code
In response to comments on change I55c31a83, I've made things a bit
more modular.

Change-Id: I462dca175f26bc22e18a357831167358c63eefe0
2012-10-12 21:28:03 +00:00
Siebrand Mazeland 10650dd977 More updates suggested by JSHint/JSLint.
Also removed some superfluous newlines.

Change-Id: I4014888383d6500fa14030e37b4aba17d2082cf2
2012-09-25 16:35:56 -07:00
Subramanya Sastry 760d63d033 Improved template roundtripping based on WT ranges on DOM nodes.
- Fixed several bugs in the DSR computation.
- Deleted comment tokens from template output.
- Eliminated TSR info from template output.
- Rearranged order of DOM post passes.
- Updated template encapsulation to use DSR values.
- There are still a few missing pieces and scenarios that are
  not handled properly.

Change-Id: I644914902ec1d27418138b107abe765f81178398
2012-09-17 21:08:35 -05:00
Subramanya Sastry 0520effd3d JSHint fixes only.
Change-Id: I8ad4e283685ab460802e69e21504ddc241985f80
2012-09-12 12:06:48 -05:00
Subramanya Sastry dbd628fd87 Added getWTSource convenience method to tokens.
Change-Id: I8c99fcd4ccefbae62a1639e5738fe2d4c88f122a
2012-09-06 09:29:38 -07:00
Subramanya Sastry 67326f063a Check if tsr is present in references tokens before generating src rt-info.
* Only one instance of Cite handler is created and it deals with the
  final expanded token stream.  So, effectively there is no information
  about whether we are processing in a top-level or nested template
  context.  So, we instead use tsr.

Change-Id: I002f421fc78576e869cc8fbcdc386ef0abb09ca9
2012-09-05 19:48:08 -05:00
Subramanya Sastry d3f0007f1b Updates to the references tag rt-ing to get rid of FIXMEs.
Change-Id: I8b832925ad476fb8043f9beb1e39e6efb27ea336
2012-09-04 20:53:33 -05:00
Subramanya Sastry 23f3e0f1aa RT references extension tag.
Change-Id: Ibd1be584e17814a84154549b7bc353465734b847
2012-09-04 20:07:26 -05:00
Subramanya Sastry ca04fdc293 Experimental ref-tag support (for demoing purposes).
* Added template-wrapping information in cite-expansion with
  Object/Ext/Cite RDFa type.
* Added 'ref' tag to whitelisted tags (temporary workaround to
  let <ref name='blah' /> to RT correctly till we handle this
  properly).
* Added support for self-closing, but non-void tags.
* Deleted Object/Template/Content type attribute since it was
  not used.
* Renamed Object/Template/Attributes to ExpandedAttrs/Template
  to distinguish template attribute code paths from content
  code paths -- could possibly be renamed to something more
  suitable later on.

Results:
- With this experimental support, RT diffs on the en:Barack_Obama
  page are vastly reduced.

Change-Id: I018f03df102764d3e39442ae359b751056a38c2f
2012-09-04 18:51:29 -05:00
Subramanya Sastry f733af93c4 Code cleanup.
* Moved tokensToString and KVtoHash from parser.environment
  to Util -- got rid of excessive warnings from tokensToString.
* Replaced used of Util.lookupKV(blah).v with Util.lookup(blah)

Change-Id: Ic48d5d0c79045b9789dc61a2b14df3fc2acf7aa5
2012-08-24 15:29:53 -05:00
Subramanya Sastry 2d15258803 Fixed template meta-wrapping to handle nesting and attributes.
* Nested parser functions are no longer meta-wrapped similar to
  nested templates.
* HTML attributes which derive all or part of their key/value
  from a template are not template-wrapped, but are marked to
  be tracked via different rdfa meta attributes.  The actual
  tracking and addition of new meta attrs. is yet to be
  implemented.
* Parser pipeline construction updated to use an options object
  rather than individual option args -- used to support the two
  features above.
* With this fix, we can now distinguish between the following
  scenarios:

  Templates:
  - {{echo|[[Foo|bar]]}} -- regular wrapping of the entire link
  - [[{{echo|Foo}}|bar]] -- no wrapping, but href marked for tracking
  - [[Foo|{{echo|bar}}]] -- link text is wrapped.

  Parser functions:
  - {{uc:foo}} -- regular wrapping.
  - {{uc:{{lc:{{uc:foo}}}}}} -- only the top-level parser function
    is wrapped, the nested lc and uc parser functions are not.

Change-Id: I512b8de9838ad42d9255ebcd73074b3898294cd8
2012-08-19 15:21:36 -05:00
Gabriel Wicke 4900d85606 Reorganize Parsoid repo after split from VisualEditor
* /js/ for JavaScript / nodjs implementation
* /js/lib for js modules
* /js/tests for js test runners and unit tests

Change-Id: I7da1ea2a62b9312be0f1b492447340427f6a14fb
2012-07-30 13:10:22 -07:00
Subramanya Sastry 4ae497db1e Renamed ext.Util.js to mediawiki.Util.js
Change-Id: I909847686c8239a0b00cbaa9a0b1583826ee1487
2012-07-24 13:07:53 -05:00
Subramanya Sastry 194c7afb34 Added utility methods to ext.Util.js
* Copied over utility methods from mediawiki.parser.environment.js
  to ext.Util.js.
* Moved over utility method from mediawiki.parser.defines.js to
  ext.Util.js.
* Converted Util to be a singleton object rather than an allocatable
  class.  There is no reason to allocate a new utility class everywhere
  since this utility object has no useful state.
* Fixed up use of utility methods to use Util rather than env.

Change-Id: Ib81f96b894f6528f2ccbe36e1fd4c3d50cd1f6b7
2012-07-20 18:12:37 -05:00
Subramanya Sastry c0ab29779c In trace mode, wrap transform to output trace info
- Added extra debug_name parameter to addTransform which is
  used in addTransform to output useful trace info.

Change-Id: I160ba0c45f681149375e32ab19f97baa439b09a8
2012-07-20 18:12:37 -05:00
Gabriel Wicke 0a4f1d435b Very basic interwiki support
Pages titles with a wikipedia interwiki prefix now load the page from
corresponding Wikipedia. Links in a page then stay within the given language.

Note that Parsoid currently makes no effort to recognize localized namespaces,
so it won't render media files, categories etc correctly.

Change-Id: I7bc4102e81a402772ea23231170734d580ea15b9
2012-06-05 11:19:58 +02:00
Gabriel Wicke 89c5f4aae4 Forward-port Cite extension
* Adapted Cite extension to use current interfaces and token formats
* Improved TokenCollector

Change-Id: I20419b19edd9bbad2c2abf17a2ff1411b99c0c04
2012-05-03 13:22:01 +02:00
Gabriel Wicke 42af5277ab Token representation clean-up. Now all tokens are differentiated using
constructors instead of type attributes.
2012-03-07 20:06:54 +00:00
Gabriel Wicke 06b257089b Replace console.log with console.warn in all debug statements 2012-02-14 20:56:14 +00:00