From: Dan F. <dfr...@cs...> - 2004-07-15 21:22:22
|
Dan Frankowski wrote: > Anyway, while I was looking at it, I got very confused about how it's > displayed, and that's because if you save version N of InterWikiMap, > it displays version N-1. This is a bug, no? I have caching NONE, and > furthermore I instrumented WikiDB_Page::save() to print "wikitext" > (the actual text of the page) and "type" (the > PageType_InterWikiMap-interpreted version, which turns out to be N-1). > I include it below my sig, and you can see that the wikitext doesn't > match the type. > > Note: I'm running phpwiki 1.3.9+ with a 'SQL' backend on Linux with > Apache. > > ** Question: Should I be filing these as bugs @ SourceForge, or is it > sufficient to email phpwiki-talk? > > I am currently trying to figure out where the interpretation happens. > For some reason, I find InlineParser, BlockParser, etc. incredibly > time consuming to figure out. > > Dan I attach a patch that fixes this bug. The basic idea is to pass the pagetext itself for getting the map while rendering, instead of having it go to the database (which has not yet been updated). If no pagetext is passed, it falls back to the DB page. PageType.php has the only substantial changes. The other files just change the call not to pass the request object. I changed function PageType_interwikimap($request = false) to function PageType_interwikimap($pagetext = false) since the request object wasn't being used (or was being pulled up through "global $request;" instead) and I needed the $pagetext parameter. Please advise on what to do with the patch. Dan Files affected: lib/CachedMarkup.php lib/InlineParser.php lib/PageType.php lib/stdlib.php lib/plugin/ExternalSearch.php ========================== diff -b -u -r1.4 CachedMarkup.php --- lib/CachedMarkup.php 16 Jun 2004 19:26:06 -0000 1.4 +++ lib/CachedMarkup.php 15 Jul 2004 18:57:51 -0000 @@ -412,7 +412,7 @@ function expand($basepage, &$markup) { //include_once('lib/interwiki.php'); - $intermap = PageType_interwikimap::GetMap($GLOBALS['request']); + $intermap = PageType_interwikimap::GetMap(); $label = isset($this->_label) ? $this->_label : false; return $intermap->link($this->_link, $label); } ========================== diff -b -u -r1.5 InlineParser.php --- lib/InlineParser.php 3 Jun 2004 18:23:48 -0000 1.5 +++ lib/InlineParser.php 15 Jul 2004 18:58:17 -0000 @@ -286,7 +286,7 @@ global $request, $AllowedProtocols, $InlineImages; //include_once("lib/interwiki.php"); - $intermap = PageType_interwikimap::GetMap($request); + $intermap = PageType_interwikimap::GetMap(); // $bracketlink will start and end with brackets; in between will // be either a page name, a URL or both separated by a pipe. @@ -423,13 +423,13 @@ { function getMatchRegexp () { global $request; - $map = PageType_interwikimap::GetMap($request); + $map = PageType_interwikimap::GetMap(); return "(?<! [[:alnum:]])" . $map->getRegexp(). ": \S+ (?<![ ,.?;! \] \) \" \' ])"; } function markup ($match) { global $request; - $map = PageType_interwikimap::GetMap($request); + $map = PageType_interwikimap::GetMap(); return new Cached_InterwikiLink(UnWikiEscape($match)); } } ========================== diff -b -u -r1.2 PageType.php --- lib/PageType.php 7 Jul 2004 19:07:20 -0000 1.2 +++ lib/PageType.php 15 Jul 2004 19:09:28 -0000 @@ -128,10 +128,21 @@ class PageType_interwikimap extends PageType { - function PageType_interwikimap() { + function PageType_interwikimap($pagetext = false) { global $request; $dbi = $request->getDbh(); - $intermap = $this->_getMapFromWikiPage($dbi->getPage(_("InterWikiMap"))); + + if (!$pagetext) { + $page = $dbi->getPage(_("InterWikiMap")); + if ($page->get('locked')) { + $current = $page->getCurrentRevision(); + $pagetext = $current->getPackedContent(); + } + else { + trigger_error(_("WARNING: InterWikiMap page is unlocked, so not using those links.")); + } + } + $intermap = $this->_getMapFromWikiPageText($pagetext); if (!$intermap && defined('INTERWIKI_MAP_FILE')) $intermap = $this->_getMapFromFile(INTERWIKI_MAP_FILE); @@ -139,13 +150,8 @@ $this->_regexp = $this->_getRegexp(); } - function GetMap ($request = false) { - if (empty($this->_map)) { - $map = new PageType_interwikimap(); - return $map; - } else { - return $this; - } + function GetMap ($pagetext = false) { + return new PageType_interwikimap($pagetext); } function getRegexp() { @@ -153,7 +159,6 @@ } function link ($link, $linktext = false) { - list ($moniker, $page) = split (":", $link, 2); if (!isset($this->_map[$moniker])) { @@ -201,14 +206,9 @@ return $map; } - function _getMapFromWikiPage ($page) { - if (! $page->get('locked')) - return false; - - $current = $page->getCurrentRevision(); - + function _getMapFromWikiPageText ($pagetext) { if (preg_match('|^<verbatim>\n(.*)^</verbatim>|ms', - $current->getPackedContent(), $m)) { + $pagetext, $m)) { return $m[1]; } return false; @@ -287,7 +287,7 @@ function format($text) { return HTML::div(array('class' => 'wikitext'), $this->_transform($this->_getHeader($text)), - $this->_formatMap(), + $this->_formatMap($text), $this->_transform($this->_getFooter($text))); } @@ -299,13 +299,13 @@ return preg_replace('@.*?(</verbatim>|\Z)@s', '', $text, 1); } - function _getMap() { - $map = PageType_interwikimap::getMap(); + function _getMap($pagetext) { + $map = PageType_interwikimap::getMap($pagetext); return $map->_map; } - function _formatMap() { - $map = $this->_getMap(); + function _formatMap($pagetext) { + $map = $this->_getMap($pagetext); if (!$map) return HTML::p("<No map found>"); // Shouldn't happen. diff -b -u -r1.1.1.2 stdlib.php --- lib/stdlib.php 14 Apr 2004 21:22:35 -0000 1.1.1.2 +++ lib/stdlib.php 15 Jul 2004 18:58:48 -0000 @@ -559,7 +559,7 @@ // change ! escapes to ~'s. global $AllowedProtocols, $WikiNameRegexp, $request; //include_once('lib/interwiki.php'); - $map = PageType_interwikimap::GetMap($request); + $map = PageType_interwikimap::GetMap(); $bang_esc[] = "(?:$AllowedProtocols):[^\s<>\[\]\"'()]*[^\s<>\[\]\"'(),.?]"; $bang_esc[] = $map->getRegexp() . ":[^\\s.,;?()]+"; // FIXME: is this really needed? $bang_esc[] = $WikiNameRegexp; @@ -1375,6 +1375,26 @@ } return $a; } ========================== diff -b -u -r1.1.1.2 ExternalSearch.php --- lib/plugin/ExternalSearch.php 14 Apr 2004 21:22:39 -0000 1.1.1.2 +++ lib/plugin/ExternalSearch.php 15 Jul 2004 18:59:07 -0000 @@ -42,7 +42,7 @@ } function _getInterWikiUrl(&$request) { - $intermap = PageType_interwikimap::GetMap($request); + $intermap = PageType_interwikimap::GetMap(); $map = $intermap->_map; if (in_array($this->_url, array_keys($map))) { |