Page MenuHomePhabricator

{{ns:##}} makes php to print notices if namespace doesn't exists
Closed, ResolvedPublic

Description

The code replacing {{ns:##}} with namespace names doesn't check if the namespace
exists but directly accesses the array, which of course makes php to produces
notices about undefined index.


Version: 1.5.x
Severity: trivial

Details

Reference
bz2287

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 8:33 PM
bzimport set Reference to bz2287.
bzimport added a subscriber: Unknown Object (MLST).

Created attachment 584
Proposed patch

Attached:

  • Bug 2321 has been marked as a duplicate of this bug. ***

gangleri wrote:

This relates also to configurations where only one namespace is defined, where
primary or talk namespace is missing. Eighter the tags "primary" or "talk" can
generate the php error.

Regards Reinhardt

Astronouth7303 wrote:

(In reply to comment #3)

This relates also to configurations where only one namespace is defined, where
primary or talk namespace is missing. Eighter the tags "primary" or "talk" can
generate the php error.

Not necessarily. In my case, it was generated by namespaces -3, 16, 17, 102, and
103, which are in article/talk pairs (except -3, which is a non-existant
psuedo-namespace).

This error is generated whenever Language::getNsText() is called. For example,
the PHP code
$badtitle = Title::makeName(42, 'foo_bar');
Will generate the error.

Nothing is wrong with the parser, just a simple check in Language::getNsText()
is needed (Language.php, line 1725-1728 in 1.4.4). I believe array_key_exists()
would be the function.

(In reply to comment #4)

Nothing is wrong with the parser, just a simple check in Language::getNsText()
is needed (Language.php, line 1725-1728 in 1.4.4). I believe array_key_exists()
would be the function.

That function is overwritten in other language files. In my opinion it's easier
to fix it once in Parser than in every existing and new language file.

Astronouth7303 wrote:

(In reply to comment #5)

That function is overwritten in other language files. In my opinion it's easier
to fix it once in Parser than in every existing and new language file.

If something goes wrong with an extension, or the DB is modified, or some other
internal error, it still will come up.

Fix the bug at the source, don't hack around it. (And yes, I know how many
language files there are.)

Astronouth7303 wrote:

(My apologies for a harsh reply in #6)

Try something like this:
function getNsText( $index ) {

		$NamespaceNames = $this->getNamespaces();
		if (!isset($NamespaceNames[$index])) return '';
		return $NamespaceNames[$index];

}

Then you just have to remove the function in the other files. (Assuming nothing
funny is going on.) A similar thing should probably be done for
Language::getNsIndex() as well.

(In reply to comment #7)
Indeed that seems to be the best solution.

avarab wrote:

I modified the code suggested by Jamie and applied it to HEAD, marking it as FIXED.

avarab wrote:

*** Bug 2140 has been marked as a duplicate of this bug. ***