[pmwiki-users] SectionEdit (:include:) bug

Hans design5 at softflow.co.uk
Sun Mar 30 10:12:00 CDT 2008


There are some bugs in sectionedit.php which show when including pages with the (:include :) markup, and when using arguments inside the include which use quotation marks.

Here is an example to show both problems, and suggestions how to solve it: 
PageB is included in PageA:

Test.PageA content:
-----------------------------------------------------------------
!!!First Header Testpage
text first

include markup code:\\
[@(:include Test.PageB editlink="{[foxedit abc 'edit abc']}":)@]

(:include Test.PageB editlink="{[foxedit abc 'edit abc']}":)

!!!Second Header Testpage
text second

abc: 12345
-------------------------------------------------------------------


Test.PageB content:
-------------------------------------------------------------------
!!!!Included page first header
text

{$$editlink}

!!!!Included page second header
text
-------------------------------------------------------------------


With sectionedit.php installed PageA looks like:
---------------------------------------------------------------------
                                                      (EditSection ↓)
First Header Testpage

text first

include markup code:
(:include Test.PageB editlink="{[foxedit abc 'edit abc']}":)

(:sectionedit Test.PageB Test.TestA:)
                                                      (EditSection ↓)
Included page first header

text

\"{[foxedit
                                                      (Edit Section ↓)
Included page second header

text incl
                                                      (Edit Section ↓)
Second Header Testpage

text second

abc: 12345
----------------------------------------------------------------------

It shows the EditSection links in the right places, but only the first and last are functioning okay. The second opens the included PageB  with an empty edit textarea. The third opens PageB's first section, but it should open the second section for editing.

The markup (:sectionedit Test.PageB Test.TestA:) appears as text and is not rendered.

The other problem you see in the rendering of the FoxEdit link as text
\"{[foxedit

SectionEdit ignores the quote marks for arguments in the include markup, so the foxedit link markup cannot be rendered, because it is truncated.

I played around with sectionedit.php and found the following will mend these problems:

First use PSS() in sectionedit's own (:include:) markup definition:

Markup('include', '>if',
  '/\\(:include\\s+(\\S.*?):\\)/ei',
  "PRR(SectionEditIncludeText(\$pagename, '$1'))");

should be changed to

Markup('include', '>if',
  '/\\(:include\\s+(\\S.*?):\\)/ei',
  "PRR(SectionEditIncludeText(\$pagename, PSS('$1')))");

Without the PSS all quote marks are passed on and escaped. 
The default PmWiki (:include:) definition uses PSS as well.

Then in function SectionEditIncludeText change 

	foreach($args as $k => $v) #{ 
		$argsparam .= ($k != '#' && !is_array($v) ) ?
			 " ".$k."=".$v : ""; #}

to this:
	foreach($args as $k => $v) #{ 
		$argsparam .= ($k != '#' && !is_array($v) ) ? 
			" ".$k."=\"".$v."\"" : ""; #}

This will enclose all argument values in double quotes and make sure arguments are passed on intact.

Last to get rid of the not-rendered markup 
	(:sectionedit Test.PageB Test.TestA:)
and get the included section edit links working right,
I changed in function SectionEditCreateLink at the end

	$SectionEditSectionCounter[$pagename]++;
	return $out;
to
	if ($SectionEditSectionCounter[$pagename] == 0) $out = '';
	$SectionEditSectionCounter[$pagename]++;
	return $out;

The added code line will prevent showing of a link for section 0.

(:sectionedit Test.PageB Test.TestA:) was the markup for section 0 of the included page, with  a missing second argument, and therefor not rendered as link. It seems to me that edit section 0 does not need a link.

If I do not suppress a section 0 link by not making the change above, but instead make sure that SectionEditCreateLink has a $type parameter even if none is given (by declaring the function like
function SectionEditCreateLink($pagename, $type='', $from='') {... )
then I get an edit link, but it opens an empty edit textarea.
So I thought it is better to suppress section 0 links.

So with the changes made SectionEdit worked fine with include markup and quoted arguments in the include markup.

It worked fine with the FoxForum which has pages full of such markup.  
But if anyone wants FoxForum and SectionEdit with the existing version of SectionEdit, either do not load sectionedit.php for any Forum group, or set $SectionEditInIncludes to false for the Forum groups, which will tell SectionEdit not to bother about sections in included pages (and so avoid all the problems with SectionEdit's (:include:) markup).

So either of the conditions below should work.

$group = PageVar($pagename, '$Group');
if ($group=='Forum') $SectionEditInIncludes = 0;

if ($group!='Forum') include_once('cookbook/sectionedit.php');



  ~Hans   




More information about the pmwiki-users mailing list