https://bugzilla.wikimedia.org/show_bug.cgi?id=26092

--- Comment #9 from Happy-melon <happy-me...@live.com> 2010-12-29 00:49:38 UTC 
---
(In reply to comment #7)
> I am going to regret asking this, but *exactly* which features do you want 
> this
> to have?

As enwiki has demonstrated admirably with [[Category:String manipulation
templates]], the only fundamental requirement is a truncate function: one that
returns the first n characters of a string.  This is [[Template:Str left]], and
the part of the hierarchy which uses the {{padleft:}} hack.  From that enwiki
has built {{str index}} to return the n'th character of a string, by iterating
through a (limited) character set and checking whether 
   {{str left|<string>|n-1}} . X == {{str left|<string>|n}}

>From that enwiki has built {{str sub}}, exactly analogous to PHP's substr(), by
selecting the individual characters with {{str index}} and concatenating them
together at the end; and {{str len}} to get the length of a string by checking
for 

    {{str left|<string>|n}} == {{str left|<string>|n+1}}

>From there, {{str right}}, analogous to substr(<string>|<n>).  From there,
{{str find}}, a crude pattern match, and from there {{str sub}}, an even cruder
replace-in-string function.

All of these higher functions are built on enormous pyramids of lower functions
and come at substantial performance penalties.  But there is very clearly a use
for them, and their utilisation is only currently constrained by that poor
performance, and specifically that people are afraid of incurring the
sysadmins' wrath by overusing them.  People know that it is literally a
one-line code change (r46628) to bring the whole house of cards tumbling down. 
But fighting against that is very clearly a demand to use these features.

So the order of precedence is as follows:

1) an implementation of PHP's substr(<string>|0|<n>) is what is currently
provided by the {{padleft:|<n>|<string>}} hack.

2) a full implementation of string slicing is the next level which avoids an
obvious wikitext hack; in PHP this would be the full
substr(<string>|<start>|<length>); IIRC in python it would be
string[<start>:<length>].  

3) an implementation of PHP's strpos().

4) an implementation of PHP's str_replace().

All of these levels, as enwiki has demonstrated, can be built out of only the
levels below.

The real question is, given str_replace() as a baseline rather than {{str
left}}, what can you build?  :D

-- 
Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
You are on the CC list for the bug.

_______________________________________________
Wikibugs-l mailing list
Wikibugs-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to