Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Wikitech

On templates and programming languages

 

 

First page Previous page 1 2 3 4 5 Next page Last page  View All Wikipedia wikitech RSS feed   Index | Next | Previous | View Threaded


brion at wikimedia

Jun 30, 2009, 9:16 AM

Post #1 of 116 (1582 views)
Permalink
On templates and programming languages

As many folks have noted, our current templating system works ok for
simple things, but doesn't scale well -- even moderately complex
conditionals or text-munging will quickly turn your template source into
what appears to be line noise.

And we all thought Perl was bad! ;)

There's been talk of Lua as an embedded templating language for a while,
and there's even an extension implementation.

One advantage of Lua over other languages is that its implementation is
optimized for use as an embedded language, and it looks kind of pretty.

An _inherent_ disadvantage is that it's a fairly rarely-used language,
so still requires special learning on potential template programmers' part.

An _implementation_ disadvantage is that it currently is dependent on an
external Lua binary installation -- something that probably won't be
present on third-party installs, meaning Lua templates couldn't be
easily copied to non-Wikimedia wikis.


There are perhaps three primary alternative contenders that don't
involve making up our own scripting language (something I'd dearly like
to avoid):

* PHP

Advantage: Lots of webbish people have some experience with PHP or can
easily find references.

Advantage: we're pretty much guaranteed to have a PHP interpreter
available. :)

Disadvantage: PHP is difficult to lock down for secure execution.


* JavaScript

Advantage: Even more folks have been exposed to JavaScript programming,
including Wikipedia power-users.

Disadvantage: Server-side interpreter not guaranteed to be present. Like
Lua, would either restrict our portability or would require an
interpreter reimplementation. :P


* Python

Advantage: A Python interpreter will be present on most web servers,
though not necessarily all. (Windows-based servers especially.)

Wash: Python is probably better known than Lua, but not as well as PHP
or JS.

Disadvantage: Like PHP, Python is difficult to lock down securely.


Any thoughts? Does anybody happen to have a PHP implementation of a Lua
or JavaScript interpreter? ;)

-- brion

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


innocentkiller at gmail

Jun 30, 2009, 9:27 AM

Post #2 of 116 (1542 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 12:16 PM, Brion Vibber<brion [at] wikimedia> wrote:
> As many folks have noted, our current templating system works ok for
> simple things, but doesn't scale well -- even moderately complex
> conditionals or text-munging will quickly turn your template source into
> what appears to be line noise.
>
> And we all thought Perl was bad! ;)
>
> There's been talk of Lua as an embedded templating language for a while,
> and there's even an extension implementation.
>
> One advantage of Lua over other languages is that its implementation is
> optimized for use as an embedded language, and it looks kind of pretty.
>
> An _inherent_ disadvantage is that it's a fairly rarely-used language,
> so still requires special learning on potential template programmers' part.
>
> An _implementation_ disadvantage is that it currently is dependent on an
> external Lua binary installation -- something that probably won't be
> present on third-party installs, meaning Lua templates couldn't be
> easily copied to non-Wikimedia wikis.
>
>
> There are perhaps three primary alternative contenders that don't
> involve making up our own scripting language (something I'd dearly like
> to avoid):
>
> * PHP
>
> Advantage: Lots of webbish people have some experience with PHP or can
> easily find references.
>
> Advantage: we're pretty much guaranteed to have a PHP interpreter
> available. :)
>
> Disadvantage: PHP is difficult to lock down for secure execution.
>
>
> * JavaScript
>
> Advantage: Even more folks have been exposed to JavaScript programming,
> including Wikipedia power-users.
>
> Disadvantage: Server-side interpreter not guaranteed to be present. Like
> Lua, would either restrict our portability or would require an
> interpreter reimplementation. :P
>
>
> * Python
>
> Advantage: A Python interpreter will be present on most web servers,
> though not necessarily all. (Windows-based servers especially.)
>
> Wash: Python is probably better known than Lua, but not as well as PHP
> or JS.
>
> Disadvantage: Like PHP, Python is difficult to lock down securely.
>
>
> Any thoughts? Does anybody happen to have a PHP implementation of a Lua
> or JavaScript interpreter? ;)
>
> -- brion
>
> _______________________________________________
> Wikitech-l mailing list
> Wikitech-l [at] lists
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>

I haven't tried it, but there seems to be a Lua Pecl extension.

-Chad

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


amir.aharoni at gmail

Jun 30, 2009, 9:34 AM

Post #3 of 116 (1546 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 19:16, Brion Vibber<brion [at] wikimedia> wrote:
> As many folks have noted, our current templating system works ok for
> simple things, but doesn't scale well -- even moderately complex
> conditionals or text-munging will quickly turn your template source into
> what appears to be line noise.
>
> And we all thought Perl was bad! ;)

I never thought that Perl is bad. There are some irresponsible Perl
programmers, just as there are some irresponsible PHP and Python
programmers.

You could try add Perl into your questionnaire.

Advantage: At least as portable as Python. Someone who can have PHP,
can have Perl, too.

Advantage: Anyone who knows PHP, knows Perl almost completely.

Not sure whether it's an advantage: Perl has some built-in security
features (taint), but i'm not really a security expert.

--
Amir Elisha Aharoni

http://aharoni.wordpress.com

"We're living in pieces,
I want to live in peace." - T. Moore

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


rarohde at gmail

Jun 30, 2009, 9:40 AM

Post #4 of 116 (1551 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 9:27 AM, Chad<innocentkiller [at] gmail> wrote:
> I haven't tried it, but there seems to be a Lua Pecl extension.

The Lua Pecl says:

"We should emphasize that is still under development and is completely
experimental."

That was nearly two years ago and there doesn't appear to have been
any real work on it since. Someone would probably need to look at it
carefully to make sure it is adequately functional before considering
that path.

-Robert Rohde

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


vasilvv at gmail

Jun 30, 2009, 9:47 AM

Post #5 of 116 (1541 views)
Permalink
Re: On templates and programming languages [In reply to]

Brion Vibber wrote:
> As many folks have noted, our current templating system works ok for
> simple things, but doesn't scale well -- even moderately complex
> conditionals or text-munging will quickly turn your template source into
> what appears to be line noise.
>
> And we all thought Perl was bad! ;)
>
> There's been talk of Lua as an embedded templating language for a while,
> and there's even an extension implementation.
>
> One advantage of Lua over other languages is that its implementation is
> optimized for use as an embedded language, and it looks kind of pretty.
>
> An _inherent_ disadvantage is that it's a fairly rarely-used language,
> so still requires special learning on potential template programmers' part.
>
> An _implementation_ disadvantage is that it currently is dependent on an
> external Lua binary installation -- something that probably won't be
> present on third-party installs, meaning Lua templates couldn't be
> easily copied to non-Wikimedia wikis.
>
>
> There are perhaps three primary alternative contenders that don't
> involve making up our own scripting language (something I'd dearly like
> to avoid):
>
> * PHP
>
> Advantage: Lots of webbish people have some experience with PHP or can
> easily find references.
>
> Advantage: we're pretty much guaranteed to have a PHP interpreter
> available. :)
>
> Disadvantage: PHP is difficult to lock down for secure execution.
>
>
> * JavaScript
>
> Advantage: Even more folks have been exposed to JavaScript programming,
> including Wikipedia power-users.
>
> Disadvantage: Server-side interpreter not guaranteed to be present. Like
> Lua, would either restrict our portability or would require an
> interpreter reimplementation. :P
>
>
> * Python
>
> Advantage: A Python interpreter will be present on most web servers,
> though not necessarily all. (Windows-based servers especially.)
>
> Wash: Python is probably better known than Lua, but not as well as PHP
> or JS.
>
> Disadvantage: Like PHP, Python is difficult to lock down securely.
>
>
> Any thoughts? Does anybody happen to have a PHP implementation of a Lua
> or JavaScript interpreter? ;)
>
> -- brion
>
> _______________________________________________
> Wikitech-l mailing list
> Wikitech-l [at] lists
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>
>
I'm working on rewriting abuse filter parser so it's suitable for
embedding in wikitext. It's half-done and will be ready soon.
--vvvv

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


rarohde at gmail

Jun 30, 2009, 9:50 AM

Post #6 of 116 (1542 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 9:16 AM, Brion Vibber<brion [at] wikimedia> wrote:
<snip>

> There are perhaps three primary alternative contenders that don't
> involve making up our own scripting language (something I'd dearly like
> to avoid):

<snip>

In the Lua Bugzilla thread (#19298), there was some extended
discussion about using the AbuseFilter parser as the basis for a
Mediawiki scripting language. From your comment should I assume we
are taking that option off the table?

There are advantages to that approach in terms of integration and
flexibility, though rolling our own scripting language would obviously
be a quite complex (and probably long-term) undertaking.

-Robert Rohde

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


brion at wikimedia

Jun 30, 2009, 9:50 AM

Post #7 of 116 (1544 views)
Permalink
Re: On templates and programming languages [In reply to]

Victor Vasiliev wrote:
> I'm working on rewriting abuse filter parser so it's suitable for
> embedding in wikitext. It's half-done and will be ready soon.

Eh, I'd rather replace the AbuseFilter scripting with
JS/Lua/Python/whatever too. :)

-- brion

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


brion at wikimedia

Jun 30, 2009, 9:51 AM

Post #8 of 116 (1543 views)
Permalink
Re: On templates and programming languages [In reply to]

Robert Rohde wrote:
> On Tue, Jun 30, 2009 at 9:27 AM, Chad<innocentkiller [at] gmail> wrote:
>> I haven't tried it, but there seems to be a Lua Pecl extension.
>
> The Lua Pecl says:
>
> "We should emphasize that is still under development and is completely
> experimental."
>
> That was nearly two years ago and there doesn't appear to have been
> any real work on it since. Someone would probably need to look at it
> carefully to make sure it is adequately functional before considering
> that path.

A PECL extension wouldn't be a compatibility improvement over shelling
out to a Lua binary; it still requires compilation and installation on
the server. (Though it could be a performance win by having the Lua
interpreter available in-process.)

-- brion

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


brion at wikimedia

Jun 30, 2009, 9:53 AM

Post #9 of 116 (1543 views)
Permalink
Re: On templates and programming languages [In reply to]

Robert Rohde wrote:
> In the Lua Bugzilla thread (#19298), there was some extended
> discussion about using the AbuseFilter parser as the basis for a
> Mediawiki scripting language. From your comment should I assume we
> are taking that option off the table?
>
> There are advantages to that approach in terms of integration and
> flexibility, though rolling our own scripting language would obviously
> be a quite complex (and probably long-term) undertaking.

Right, that's exactly what I don't want to have to do.

I'd honestly rather implement a JS interpreter in PHP than create and
maintain our own programming language, if it came to that. :)

-- brion

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


tparscal at wikimedia

Jun 30, 2009, 10:03 AM

Post #10 of 116 (1542 views)
Permalink
Re: On templates and programming languages [In reply to]

On 6/30/09 9:16 AM, Brion Vibber wrote:
> Any thoughts? Does anybody happen to have a PHP implementation of a Lua
> or JavaScript interpreter? ;)
>
> -- brion
>
>
GPL, Alpha software, seems to be abandoned in 2005
http://j4p5.sourceforge.net/

Perhaps this could be tested, considered, brought back to life, etc?

- Trevor

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


rarohde at gmail

Jun 30, 2009, 10:09 AM

Post #11 of 116 (1545 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 10:03 AM, Trevor Parscal<tparscal [at] wikimedia> wrote:
> On 6/30/09 9:16 AM, Brion Vibber wrote:
>> Any thoughts? Does anybody happen to have a PHP implementation of a Lua
>> or JavaScript interpreter? ;)
>>
>> -- brion
>>
>>
> GPL, Alpha software, seems to be abandoned in 2005
> http://j4p5.sourceforge.net/
>
> Perhaps this could be tested, considered, brought back to life, etc?

Google also turns up
http://phpjs.berlios.de/

Like J4P5 it also seems to be an abandoned alpha.

For a stand-alone JavaScript interpreters there are some
well-supported projects, like Jaxer:
http://www.aptana.com/jaxer

However, this again gets back to separately compiled code, and would
not easily be able to interact with PHP.

-Robert Rohde

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


vasilvv at gmail

Jun 30, 2009, 10:13 AM

Post #12 of 116 (1543 views)
Permalink
Re: On templates and programming languages [In reply to]

Brion Vibber wrote:
> Victor Vasiliev wrote:
>
>> I'm working on rewriting abuse filter parser so it's suitable for
>> embedding in wikitext. It's half-done and will be ready soon.
>>
>
> Eh, I'd rather replace the AbuseFilter scripting with
> JS/Lua/Python/whatever too. :)
>
> -- brion
>
> _______________________________________________
> Wikitech-l mailing list
> Wikitech-l [at] lists
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>
We'll anyway have to remove for() and while() from it and restrict it in
other ways.
--vvv

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


removed at example

Jun 30, 2009, 10:15 AM

Post #13 of 116 (1550 views)
Permalink
Re: On templates and programming languages [In reply to]

So far my favorite idea is to use a restricted subset of PHP.

I would like to broach an important topic however: How can we convert all of
the existing ParserFunctions and difficult-to-read template code to this new
language automatically? Are we really talking about the dream of getting rid
of templates entirely? The end of {{||||||}} ?

How difficult would it be to modify the parser to spit out some of its data
structures in the new language as opposed to HTML etc.. ?

This seems to be the more difficult part of the project.

There is a more practical/pragmatic approach which is to deprecate the
current syntax similar to the way languages sometimes deprecate language
features. I fear that the conversion is a superhuman task, however.

On Tue, Jun 30, 2009 at 10:16 AM, Brion Vibber <brion [at] wikimedia> wrote:

> As many folks have noted, our current templating system works ok for
> simple things, but doesn't scale well -- even moderately complex
> conditionals or text-munging will quickly turn your template source into
> what appears to be line noise.
>
> And we all thought Perl was bad! ;)
>
> There's been talk of Lua as an embedded templating language for a while,
> and there's even an extension implementation.
>
> One advantage of Lua over other languages is that its implementation is
> optimized for use as an embedded language, and it looks kind of pretty.
>
> An _inherent_ disadvantage is that it's a fairly rarely-used language,
> so still requires special learning on potential template programmers' part.
>
> An _implementation_ disadvantage is that it currently is dependent on an
> external Lua binary installation -- something that probably won't be
> present on third-party installs, meaning Lua templates couldn't be
> easily copied to non-Wikimedia wikis.
>
>
> There are perhaps three primary alternative contenders that don't
> involve making up our own scripting language (something I'd dearly like
> to avoid):
>
> * PHP
>
> Advantage: Lots of webbish people have some experience with PHP or can
> easily find references.
>
> Advantage: we're pretty much guaranteed to have a PHP interpreter
> available. :)
>
> Disadvantage: PHP is difficult to lock down for secure execution.
>
>
> * JavaScript
>
> Advantage: Even more folks have been exposed to JavaScript programming,
> including Wikipedia power-users.
>
> Disadvantage: Server-side interpreter not guaranteed to be present. Like
> Lua, would either restrict our portability or would require an
> interpreter reimplementation. :P
>
>
> * Python
>
> Advantage: A Python interpreter will be present on most web servers,
> though not necessarily all. (Windows-based servers especially.)
>
> Wash: Python is probably better known than Lua, but not as well as PHP
> or JS.
>
> Disadvantage: Like PHP, Python is difficult to lock down securely.
>
>
> Any thoughts? Does anybody happen to have a PHP implementation of a Lua
> or JavaScript interpreter? ;)
>
> -- brion
>
> _______________________________________________
> Wikitech-l mailing list
> Wikitech-l [at] lists
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
>
_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


rarohde at gmail

Jun 30, 2009, 10:20 AM

Post #14 of 116 (1546 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 10:15 AM, Brian<Brian.Mingus [at] colorado> wrote:
> So far my favorite idea is to use a restricted subset of PHP.
>
> I would like to broach an important topic however: How can we convert all of
> the existing ParserFunctions and difficult-to-read template code to this new
> language automatically? Are we really talking about the dream of getting rid
> of templates entirely? The end of {{||||||}} ?
>
> How difficult would it be to modify the parser to spit out some of its data
> structures in the new language as opposed to HTML etc.. ?
>
> This seems to be the more difficult part of the project.
>
> There is a more practical/pragmatic approach which is to deprecate the
> current syntax similar to the way languages sometimes deprecate language
> features. I fear that the conversion is a superhuman task, however.

You couldn't ever turn template syntax off without making old
revisions unrenderable. The best one could likely do is encourage
people to upgrade and provide tools to make that easier. However,
given the nastiness of template syntax, I would expect no end of wiki
authors willing to help convert the commonly used stuff.

-Robert Rohde

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


bryan.tongminh at gmail

Jun 30, 2009, 10:22 AM

Post #15 of 116 (1542 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 6:16 PM, Brion Vibber<brion [at] wikimedia> wrote:

> * Python
>
> Advantage: A Python interpreter will be present on most web servers,
> though not necessarily all. (Windows-based servers especially.)
>
> Wash: Python is probably better known than Lua, but not as well as PHP
> or JS.
>
> Disadvantage: Like PHP, Python is difficult to lock down securely.
>
Also for Python you really will want an editor that supports
indenting. Web browsers are not suitable for programming Python.


Bryan

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


removed at example

Jun 30, 2009, 10:24 AM

Post #16 of 116 (1540 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 11:20 AM, Robert Rohde <rarohde [at] gmail> wrote:

> You couldn't ever turn template syntax off without making old
> revisions unrenderable. The best one could likely do is encourage
> people to upgrade and provide tools to make that easier. However,
> given the nastiness of template syntax, I would expect no end of wiki
> authors willing to help convert the commonly used stuff.
>
> -Robert Rohde
>

The solution (no doubt first developed on this list many years ago) is to
have mark revisions that still trigger the template/parser functions parser
as using that syntax, and to mark revisions that have moved on as using the
new language.

Moreover, old revisions already are unrenderable. They may look like they
render correctly but in fact they don't. This is because mediawiki has no
notion of the fact that a particular revision of an article also uses
particular revisions of templates etc...

At any rate, I don't see how this nitpick is a difficult problem
technically.
_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


rarohde at gmail

Jun 30, 2009, 10:42 AM

Post #17 of 116 (1544 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 10:22 AM, Bryan Tong
Minh<bryan.tongminh [at] gmail> wrote:
> On Tue, Jun 30, 2009 at 6:16 PM, Brion Vibber<brion [at] wikimedia> wrote:
>
>> * Python
>>
>> Advantage: A Python interpreter will be present on most web servers,
>> though not necessarily all. (Windows-based servers especially.)
>>
>> Wash: Python is probably better known than Lua, but not as well as PHP
>> or JS.
>>
>> Disadvantage: Like PHP, Python is difficult to lock down securely.
>>
> Also for Python you really will want an editor that supports
> indenting. Web browsers are not suitable for programming Python.

Though indenting is mandatory for Python, the use or reasonable
indenting is pretty much necessary to produce readable code in any
language.

That said, I don't see any reason we couldn't use two or three
consecutive spaces to indicate indentations.

-Robert Rohde

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


amir.aharoni at gmail

Jun 30, 2009, 10:45 AM

Post #18 of 116 (1552 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 20:42, Robert Rohde<rarohde [at] gmail> wrote:
> On Tue, Jun 30, 2009 at 10:22 AM, Bryan Tong
>> Also for Python you really will want an editor that supports
>> indenting. Web browsers are not suitable for programming Python.
>
> Though indenting is mandatory for Python, the use or reasonable
> indenting is pretty much necessary to produce readable code in any
> language.
>
> That said, I don't see any reason we couldn't use two or three
> consecutive spaces to indicate indentations.

Four!

--
Amir Elisha Aharoni

http://aharoni.wordpress.com

"We're living in pieces,
I want to live in peace." - T. Moore

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


rarohde at gmail

Jun 30, 2009, 10:57 AM

Post #19 of 116 (1541 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 10:45 AM, Amir E. Aharoni<amir.aharoni [at] gmail> wrote:
> On Tue, Jun 30, 2009 at 20:42, Robert Rohde<rarohde [at] gmail> wrote:
>> On Tue, Jun 30, 2009 at 10:22 AM, Bryan Tong
>>> Also for Python you really will want an editor that supports
>>> indenting. Web browsers are not suitable for programming Python.
>>
>> Though indenting is mandatory for Python, the use or reasonable
>> indenting is pretty much necessary to produce readable code in any
>> language.
>>
>> That said, I don't see any reason we couldn't use two or three
>> consecutive spaces to indicate indentations.
>
> Four!

Four is the default size of a tab in Python, but indents aren't
actually required to be that size. If we are required to type
consecutive spaces to format code, I'd actually prefer a smaller
default size.

-Robert Rohde

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


ssanbeg at ask

Jun 30, 2009, 11:00 AM

Post #20 of 116 (1550 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, 30 Jun 2009 09:16:41 -0700, Brion Vibber wrote:

> As many folks have noted, our current templating system works ok for
> simple things, but doesn't scale well -- even moderately complex
> conditionals or text-munging will quickly turn your template source into
> what appears to be line noise.
>
> And we all thought Perl was bad! ;)
>
> There's been talk of Lua as an embedded templating language for a while,
> and there's even an extension implementation.
>
> One advantage of Lua over other languages is that its implementation is
> optimized for use as an embedded language, and it looks kind of pretty.
>
> An _inherent_ disadvantage is that it's a fairly rarely-used language,
> so still requires special learning on potential template programmers' part.
>
> An _implementation_ disadvantage is that it currently is dependent on an
> external Lua binary installation -- something that probably won't be
> present on third-party installs, meaning Lua templates couldn't be
> easily copied to non-Wikimedia wikis.
>
>
> There are perhaps three primary alternative contenders that don't
> involve making up our own scripting language (something I'd dearly like
> to avoid):
>

I was thinking about something similar this weekend, although I'd thought
about different languages:

1 - XSLT

Since the syntax is XML (like the extensions tags) and XPath (vaguely
similar to template syntax, although it's XML that calls XPath, the
opposite of what we have) It would be reasonably consistent with current
syntax. It also should also already be fairly well locked down, and the
interface seems fairly clear - present template parameters as stylesheet
parameters, and other magic words as an input document. We may just need
a few simplifications to make it easier to use.

2- lisp/scheme

Should be easy to write a parser for if needed, since the grammer is so simple,
and it should be relatively simple to lock down or extend as needed.

Of course, those are both a bit more esoteric than your recommendations.
Perl is nice for getting useful results from short code, if we're not
bothered by one parser with no grammer specification calling another one. Tcl may
be a reasonable compromise; a less esoteric, imperative language which is often
used as an extension language.







_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


Simetrical+wikilist at gmail

Jun 30, 2009, 12:56 PM

Post #21 of 116 (1526 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 12:16 PM, Brion Vibber<brion [at] wikimedia> wrote:
> * PHP
>
> Advantage: Lots of webbish people have some experience with PHP or can
> easily find references.
>
> Advantage: we're pretty much guaranteed to have a PHP interpreter
> available. :)
>
> Disadvantage: PHP is difficult to lock down for secure execution.

I think it would be easy to provide a very simple locked-down version,
with most of the features gone. You could, for instance, only permit
variable assignment, use of built-in operators, a small whitelist of
functions, and conditionals. You could omit loops, function
definitions, and abusable functions like str_repeat() (let alone
exec(), eval(), etc.) from a first pass. This would still be vastly
more powerful, more readable, and faster than ParserFunctions.

Hopefully, we could make this secure enough for your average
shared-host website to run it by default with no special measures
taken and without much risk. Installations with more access and
higher security requirements, like Wikimedia, could shell out to a
process that's sandboxed on the OS level to be on the safe side. I'd
like to hear what Tim thinks about the possibility of securing PHP
like this.

Of course, PHP is evil, and supporting it sucks. :( But if we
*really* *really* need to support users who can't shell out to other
programs, I think it's the only real language that's a feasible
solution.


I'd encourage you to consider requiring exec() support for full use of
Wikipedia templates, though. Many really big shared hosts allow it,
like 1and1.com. Anyone big enough to include much Wikipedia content
will likely be on at least a VPS anyway. And if your host doesn't
support exec(), then at *worst* you can still get the articles in a
totally usable form -- just run Special:ExpandTemplates on all the
article's templates. You can then transclude those on a per-article
basis; we could update Special:Export to make this easier. The only
problem in this case would be that you can't easily change the
formatting of all the templates at once -- but such a small site would
likely have few enough articles to do it by hand, if they even want
to.

I think saying that users without exec() support get to use Wikipedia
content in a somewhat less usable form would be just fine, and it
would *really* open up our options. We could support basically any
programming language in that case.

> * Python
>
> Advantage: A Python interpreter will be present on most web servers,
> though not necessarily all. (Windows-based servers especially.)
>
> Wash: Python is probably better known than Lua, but not as well as PHP
> or JS.
>
> Disadvantage: Like PHP, Python is difficult to lock down securely.

It doesn't matter whether it's present, does it? If the user has
exec() support, they could download a binary interpreter for *any*
language to their webspace and run it from there regardless of whether
the language is supported on the host. So Python is on exactly the
same level as Lua here.

Much though I love Python, Lua looks like the better option. First of
all, it's *very* small. sudo apt-get install lua50 on my machine uses
up only 180 KB of disk space, and the package is 30 KB gzipped. Our
current tarballs are 10 MB; we could easily just chuck in Lua binaries
for Linux x86-32 and Windows without even noticing the size increase,
and allow users to enable it with one line in LocalSettings.php. By
contrast, python2.6 is around 10 MB uncompressed, 2.5 MB compressed.
Perl is twice that size. Windows users, or users with exec() allowed
but open_basedir preventing access to /usr/bin, would have to obtain
Python/Perl/etc. themselves.

It looks to me like Lua would be a lot easier to sandbox. It seems
pretty simple to deny all I/O within the language itself, so you'd
(hopefully) just need memory and CPU limits. Both of those could be
implemented on Linux with hard setrlimit() values plus nice. Similar
things exist on Windows, hopefully accessible by command line somehow.
If we're shipping binaries with MediaWiki, we could even hack the
code if necessary, to use whatever sandboxing mechanisms the OS makes
available, although hopefully that would be unneeded.

I don't think we should fixate too much on how many people know the
language. It's not hard to pick up a new language if you already know
one, and Lua has the reputation of being simple (although I haven't
tried to learn it). I think Lua is the best option here.

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


michael.daly at kayakwiki

Jun 30, 2009, 1:04 PM

Post #22 of 116 (1534 views)
Permalink
Re: On templates and programming languages [In reply to]

Brion Vibber wrote:
> Any thoughts? Does anybody happen to have a PHP implementation of a
> Lua or JavaScript interpreter?

Rather than reinventing the wheel, why not look at fixing the existing
template syntax?

The biggest problem that I see is the excessive dependence on the
parentheses { and }. In a moderately complex template, you've got a mix
of double {{...}} and triple {{{...}}} brackets, occasionally nested,
that result in an unreadable mess.

If {{{xxx}}} was replaced with a local-variable-like syntax, say $xxx
(where xxx is whatever name you wish, $1, $2... for unnamed), then the
mess is reduced from something like:

{{blah|{{{xxx}}}|{{{yyy}}}}}{{#if: {{{ggg}}}|{{{h}}}|{{{4}}}}}{{{5}}}

becomes:

{{blah|$xxx|$yyy}}{{#if: $ggg|$h|$4}}$5

which is somewhat more tolerable. (whether or not the above makes real
sense is not my objective - I'm just trying to show how removing the
blizzard of {{{}}} reduces visual clutter).

Since $ doesn't have a close, that makes things like {{{xxx|default
value}}} slightly problematic, since "$xxx|$default_value" is slightly
more awkward to parse. But that only shows how templates are also
overly reliant on the pipe (|) symbol - as anyone who has tried to use
tables in templates has discovered.

If parsing templates allows the semi-restricted use of a couple of
symbols (unlike parsing other pages - I know... don't go there), then
both {{{}}} and | could be replaced with $ and
I-don't-care-what-make-a-choice. Then templates become a tad more
readable and we get rid of kludges like {{!}} and other clutter or
confusion in tables, parser functions, etc.

As an aside - obliging template writers to declare variables used in the
template, say, as a definition of the input format at the top of the
template definition, would make parsing the variables out later a tad
easier. If it's declared, it's a variable; if not, it's not a variable
and is treated as plain text. Thus the first line of a template would
be the example of its use:

Template:foobar
----------------------------------------------------------------------
{{Foobar|$var1|$var2|$andAnotherVar}}
...(implementation)...
----------------------------------------------------------------------

But what do I know, I've only implemented one OO language compiler in my
life and that was 20 years ago.

Mike


_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


brion at wikimedia

Jun 30, 2009, 1:25 PM

Post #23 of 116 (1528 views)
Permalink
Re: On templates and programming languages [In reply to]

Aryeh Gregor wrote:
> On Tue, Jun 30, 2009 at 12:16 PM, Brion Vibber<brion [at] wikimedia> wrote:
>> * PHP
>>
>> Advantage: Lots of webbish people have some experience with PHP or can
>> easily find references.
>>
>> Advantage: we're pretty much guaranteed to have a PHP interpreter
>> available. :)
>>
>> Disadvantage: PHP is difficult to lock down for secure execution.
>
> I think it would be easy to provide a very simple locked-down version,
> with most of the features gone. You could, for instance, only permit
> variable assignment, use of built-in operators, a small whitelist of
> functions, and conditionals. You could omit loops, function
> definitions, and abusable functions like str_repeat() (let alone
> exec(), eval(), etc.) from a first pass. This would still be vastly
> more powerful, more readable, and faster than ParserFunctions.

IMO by the time you've implemented your whitelisting parser you might as
well just interpret it rather than eval()ing. (And of course, eval()
might be disabled on the server. :)

Looping constructs are also extremely valuable -- at a minimum in a
foreach() kind of way.

> I'd encourage you to consider requiring exec() support for full use of
> Wikipedia templates, though. Many really big shared hosts allow it,
> like 1and1.com. Anyone big enough to include much Wikipedia content
> will likely be on at least a VPS anyway.

It's not about "Wikipedia content", but about being able to grab things
you see on another wiki and use or adapt them to your own needs. We get
lots of questions from people trying to grab some particular template
off Wikipedia to use on their own site for their own needs.

>> * Python
>>
>> Advantage: A Python interpreter will be present on most web servers,
>> though not necessarily all. (Windows-based servers especially.)
>>
>> Wash: Python is probably better known than Lua, but not as well as PHP
>> or JS.
>>
>> Disadvantage: Like PHP, Python is difficult to lock down securely.
>
> It doesn't matter whether it's present, does it? If the user has
> exec() support, they could download a binary interpreter for *any*
> language to their webspace and run it from there regardless of whether
> the language is supported on the host.

Considering the amount of trouble people have getting texvc working, I
wouldn't want to force that on people just to use templates.

> Much though I love Python, Lua looks like the better option. First of
> all, it's *very* small. sudo apt-get install lua50 on my machine uses
> up only 180 KB of disk space, and the package is 30 KB gzipped.

Python "comes with batteries included", which is to say it's got a huge
standard library (most of which of course wouldn't be available in a
restricted environment). Lua's bare interpreter of course wins in an
embedded-shipping contest. :D

> Our
> current tarballs are 10 MB; we could easily just chuck in Lua binaries
> for Linux x86-32 and Windows without even noticing the size increase,
> and allow users to enable it with one line in LocalSettings.php.

Hmm... it might be interesting to experiment with something like this,
if it can _really_ be compiled standalone. (Linux binary distribution is
a hellhole of incompatible linked library versions!)

> It looks to me like Lua would be a lot easier to sandbox. It seems
> pretty simple to deny all I/O within the language itself, so you'd
> (hopefully) just need memory and CPU limits.

*nod* being designed as an embedded language is a win. :D

-- brion

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


marco at harddisk

Jun 30, 2009, 1:33 PM

Post #24 of 116 (1524 views)
Permalink
Re: On templates and programming languages [In reply to]

On Tue, Jun 30, 2009 at 10:25 PM, Brion Vibber <brion [at] wikimedia> wrote:

> Aryeh Gregor wrote:
> > Our
> > current tarballs are 10 MB; we could easily just chuck in Lua binaries
> > for Linux x86-32 and Windows without even noticing the size increase,
> > and allow users to enable it with one line in LocalSettings.php.
>
> Hmm... it might be interesting to experiment with something like this,
> if it can _really_ be compiled standalone. (Linux binary distribution is
> a hellhole of incompatible linked library versions!)
>
Static compiling the stuff? How would this affect the binary size? (And: is
static linking working across different libc versions?)

BTW, what about Mac OS / FreeBSD hosts?

Marco

--
VMSoft GbR
Nabburger Str. 15
81737 München
Geschäftsführer: Marco Schuster, Volker Hemmert
http://vmsoft-gbr.de
_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l


thomas.dalton at gmail

Jun 30, 2009, 1:38 PM

Post #25 of 116 (1526 views)
Permalink
Re: On templates and programming languages [In reply to]

2009/6/30 Michael Daly <michael.daly [at] kayakwiki>:
> Brion Vibber wrote:
>  > Any thoughts? Does anybody happen to have a PHP implementation of a
>  > Lua or JavaScript interpreter?
>
> Rather than reinventing the wheel, why not look at fixing the existing
> template syntax?

I would support that. We really don't need a Turing-complete template system.

> As an aside - obliging template writers to declare variables used in the
> template, say, as a definition of the input format at the top of the
> template definition, would make parsing the variables out later a tad
> easier.  If it's declared, it's a variable; if not, it's not a variable
> and is treated as plain text.  Thus the first line of a template would
> be the example of its use:
>
> Template:foobar
> ----------------------------------------------------------------------
> {{Foobar|$var1|$var2|$andAnotherVar}}
> ...(implementation)...
> ----------------------------------------------------------------------

How does that work with anonymous variables? Are all $[NUMBER] style
names count as auto-declared?

_______________________________________________
Wikitech-l mailing list
Wikitech-l [at] lists
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

First page Previous page 1 2 3 4 5 Next page Last page  View All Wikipedia wikitech RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.