Page MenuHomePhabricator

config/index.php generates bad LocalSettings.php if uses CR/LF EOL.
Closed, ResolvedPublic

Description

Author: zigger

Description:
If the MediaWiki distribution is unpacked with WinZip with the option "TAR file
smart CR/LF conversion" turned on (under Options|Configuration|Miscellaneous),
config/index.php is created with CR/LF EOLs. Once configured, the created
LocalSettings.php has CR/CR/LF EOLs, which get further corrupted with subsequent
edits by Notepad or Wordpad.

One solution is to distribute the GZ file without the intermediary TAR file.

Another solution is to pre-process the LocalSettings.php text before writing it
to disk.


Version: 1.3.x
Severity: normal
Platform: PC
URL: http://meta.wikimedia.org/wiki/Wiki_on_a_stick#Install_the_wiki

Details

Reference
bz750

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 7:02 PM
bzimport set Reference to bz750.
bzimport added a subscriber: Unknown Object (MLST).

rowan.collins wrote:

(In reply to comment #0)

One solution is to distribute the GZ file without the intermediary TAR file.

A gzip (.gz) file is a compressed copy of exactly one file; there's no way of
gzipping multiple files to one target without first combining them into an
archive format, such as tar.

zigger wrote:

Thanks Rowan. So how about compressing the distribution with something that
supports multiple files, & in config/index.php add $local = strtr($local,
"\r\n", "\n") or similar before writing LocalSettings.php ?

zigger wrote:

HEAD patch for config/index.php

Attached:

zigger wrote:

REL1_4 patch for config/index.php

Attached:

What exactly is the source of this problem? Where do the extra characters come from? It presumably ought to
work correctly if the files are CR/LF to begin with; where does it go wrong?

zigger wrote:

(In reply to comment #5)

What exactly is the source of this problem? Where do the extra characters come

from? It presumably ought to

work correctly if the files are CR/LF to begin with; where does it go wrong?

This is what I think happens:

config/index.php has CR/LF EOLs (thanks to a WinZip default for example).
So writeLocalSettings() returns $local with CR/LF EOLs.
$localsettings then adds lines at the start and end using $endl,
which is also based on the config/index.php EOLs.
The output file is fopen()'ed with a "t" mode, causing EOL translation
from LF to CR/LF, so CR/LF becomes CR/CR/LF.
Saving the LocalSettings.php from various editors then does more horrible EOL

stuff.

Using a mode of "b" would prevent the EOL translation, so LocalSettings.php
would get the same EOLs as config/index.php. As administrators are likely to
edit LocalSettings.php, it seems like a good idea that this file has a native
EOL style instead of whatever default style the unpacking software happened to
use. So the attached patches force LF-style EOLs after the output of
writeLocalSettings, allowing the "t" mode to do its thing.

I applied a slightly modified patch; moved the two str_replaces into a single one in
writeLocalSettings itself.

Applied on REL1_4 and HEAD.