Page MenuHomePhabricator

weird code for onlyinclude
Closed, DeclinedPublic

Description

Author: giecrilj

Description:
This is not a bug report but rather a code review remark. Preprocessor_Hash::preprocessToObj says:

00075 if ( strpos( $text, '<onlyinclude>' ) !== false && strpos( $text, '</onlyinclude>' ) !== false ) {
00076 $enableOnlyinclude = true;
00077 }

that means "</onlyinclude><onlyinclude>" is covered by the case.
Whas that intended?
I suppose it was not
and this is only some heuristic
to detect "<onlyinclude>…</onlyinclude>";
however, an obvious improvement seems to exist.

I would rather say this

if(
($oip = strpos($text, '<onlyinclude>')) !== false &&
strpos($text, '</onlyinclude>', $oip + strlen('<onlyinclude>'))
!= false)


Version: unspecified
Severity: trivial
URL: http://svn.wikimedia.org/doc/

Details

Reference
bz15566

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 21 2014, 10:18 PM
bzimport set Reference to bz15566.
bzimport added a subscriber: Unknown Object (MLST).

Regexes are needlessly slow, you just need to compare those two strpos'es.

This isn't really worth adding code complexity and overhead for this case.