Search code examples
phpdokuwiki

Peculiar Search Error in DokuWiki


Cross-posting this from the DokuWiki forums:

So, I was making some modifications in order to allow for three things: Capitalization in page names, natural case sorting in the sidebar ToC, and case insensitive search.

Bear with me, because I know this looks like a file permissions error. I do not believe it is.

Upon searching for "nul" and any variation of that(nUl, Nul, nuL, etc), I receive the following error message:

Warning: Cannot unset offset in a non-array variable in C:\Websites\dokuwiki\inc\parserutils.php on line 365

Warning: Cannot unset offset in a non-array variable in C:\Websites\dokuwiki\inc\parserutils.php on line 366

Warning: Cannot unset offset in a non-array variable in C:\Websites\dokuwiki\inc\parserutils.php on line 367

Warning: Cannot unset offset in a non-array variable in C:\Websites\dokuwiki\inc\parserutils.php on line 368

Warning: Cannot unset offset in a non-array variable in C:\Websites\dokuwiki\inc\parserutils.php on line 369

Warning: filesize() [function.filesize]: stat failed for C:/Websites/dokuwiki/data/meta/nul.changes in C:\Websites\dokuwiki\inc\changelog.php on line 305

There is not and never has been a page named "nul." Once the search has completed, it adds a new line to \dokuwiki\data\index\page.idx with the same content as what I searched for(nul, NuL, nUl, etc, etc). Once that line has been added to page.idx, any search for the letters "n" "u" or "l" will also result in an error:

Warning: Cannot unset offset in a non-array variable in C:\Websites\dokuwiki\inc\parserutils.php on line 365

Warning: Cannot unset offset in a non-array variable in C:\Websites\dokuwiki\inc\parserutils.php on line 366

Warning: Cannot unset offset in a non-array variable in C:\Websites\dokuwiki\inc\parserutils.php on line 367

Warning: Cannot unset offset in a non-array variable in C:\Websites\dokuwiki\inc\parserutils.php on line 368

Warning: Cannot unset offset in a non-array variable in C:\Websites\dokuwiki\inc\parserutils.php on line 369

Warning: filectime() [function.filectime]: stat failed for C:/Websites/dokuwiki/data/pages/nul.txt in C:\Websites\dokuwiki\inc\parser\metadata.php on line 46

Warning: filemtime() [function.filemtime]: stat failed for C:/Websites/dokuwiki/data/pages/nul.txt in C:\Websites\dokuwiki\inc\parser\metadata.php on line 72

Once again, the page "nul" has not ever existed on the wiki and is being written to page.idx upon searching.

Here are the modifications I made to achieve the three things I noted in the beginning of my post:

/inc/fulltext.php, lines 255 and 263: I replaced "strpos" with "stripos."

if ($id !== '' && $cleaned !== '') {
        foreach ($pages as $p_id => $p_title) {
            if ((stripos($in_ns ? $p_id : noNSorNS($p_id), $cleaned) === false) &&
                (!$in_title || (stripos($p_title, $id) === false)) ) {
                unset($pages[$p_id]);
            }
        }
    }
    if (isset($ns)) {
        foreach (array_keys($pages) as $p_id) {
            if (stripos($p_id, $ns) !== 0) {
                unset($pages[$p_id]);
            }
        }
    }

/inc/pageutils.php, line 114 removed:

//$id = utf8_strtolower($id);

/inc/search.php, lines 40 and 41: I replaced "sort" with "natcasesort"

natcasesort($files);
natcasesort($dirs);

These are all minor changes as far as I can tell, and I don't see anything immediately apparent that would be causing this issue.

Any ideas?

Update -

I reverted all my changes and the error persists.

I then installed a fresh DokuWiki(Release 2010-11-07a "Anteater") in a completely separate directory, the error persists.

I then installed the nightly snapshot from splitbrain.org, and the error persists.

Anyone have any ideas?


Solution

  • It turns out that this is a Windows specific error due to "NUL" being reserved. Per Charles suggestion, I will post the answer here as well as in the forum post linked in my original comment. I feel like it's a kludgey fix, but I needed to get it working. I'm just rewriting the word "nul" into its ASCII characters and then translating it back for display on the page and in the title:

    \inc\pageutils.php, line 137(ish):

    if(strtolower($id) == 'nul') {
        for($i=0;$i != strlen($id);$i++) {
            $stupidWindowsFix .= "&#".ord($id[$i]).";";
        }
        $id = $stupidWindowsFix;
    }
    

    \inc\template.php, line 876:

    $name = html_entity_decode($id);