User:Lord Farin/Long-Term Projects/Extension

= Motivation =

On this page I will describe the ideas I have pertaining an extension of PW which will allow for more consistent style, easier transclusions and general ease of use. To this end, I seek to develop (together with Joe) a set of custom tags, maybe namespaces and templates to accommodate for this.

Of course, for this project to be viable, documentation needs to be extensive, and Help:Editing will need serious expansion/adaptation.

Feel free to comment and/or contribute ideas/prototypes.

= Progress/Overview of Ideas =

Rigour in Page Style
In order to achieve maximal consistency, it will be a good idea to add tags like:

Maybe more can be thought of. These will go with possible HTML attributes (and default values, of course); for example:

title="Section Title" foldable="folded/unfolded/false" headerlevel="2/3/4..." sectionname="For transclusion reference; eg. 'proof1'"

Furthermore, ideally users could set preferences (like 'by default, expand all folded sections').

This basically comes down to a DOM structure.

Approach Overview
The general idea is as follows:


 * A template   producing standard transclusion bracketed by:
 * A tag   which 'flips a switch' in the processing of the tags presented in the page rigour section above.
 * This switch then ensures that the header levels are changed as desired.

Detailed Discussion and Updates
My currently most viable idea to achieve rigour in transclusions is the introduction of the tag or parser function Title of page whose section must be transcluded

It will be endowed with further attributes as deemed necessary/possible.

I strive for the possibility to adjust the heading level of all stuff inside the transcluded tag automatically, avoiding the struggle now often encountered.

A snippet of PHP that increments all headers in the input string $subject by the positive integer $increment: function fnPWadjustHeadings($subject, $increment){ //Some input checking might be necessary, I skip it for now

if($increment <= 0){ return $subject; }

$eq = ""; $i = 0; while($i < $increment){ $eq .= "="; $i++; }

$result = preg_replace('#={2,}#', '$1'.$eq, $subject);

return $result; }

Unfortunately, parser functions do not naturally support named parameters. However, it is possible to work around this, as I have found out. Compare the   function; fortunately, after the first parameter (the page name), only named parameters will be necessary. This means I can build a lot of the code on the implementation of that function.

It appears that parser functions really should be time-invariant constructs, according to MediaWiki documentation (in particular, the paragraph directly after the numbered list at the top of the page). However, I will exploit the 'usually' as a justification to go off the standard path.

The attack plan has changed a little; I will now simply use the template  with appropriate options, and restricted editing. This will subsequently add some XML tags around the transcluded parts. A custom hook will then be invoked to process the page, removing the tags and applying the desired operations to what is inside them.

]*?)>(?P ((?!(<transclude| )).)*?) #s'; //Find the proto-transcluded sections at deepest level and store them in $matches preg_match_all($reg, $text, $matches, PREG_SET_ORDER); //As long as results are found, we need to process $text further to process possible nesting while($matches.length){ foreach($matches as $section){ //Process the HTML attributes given with the tag $attributes = array; $args = explode($section['args'], " "); foreach($args as $arg){ if($arg == "") continue; //Put the $arg into processable form $attribute = explode($arg, "="); $value = strtolower(trim($attribute[1])); $option = trim($attribute[0], " \"\'\t\n\r\0\x0B");				switch($option){					//TODO: process the tags which are allowed to occur				}			}			//TODO: process the subject according to the given attributes			$section['subject']		}		fnPWparseTransclusion($parser, $text);	}	return true; } ?>

For now, I will spend some time verifying that this regexp string actually catches what I want (all  section  at deepest level (no occurrence of this thing in 'section')). The new regexp seems to achieve exactly this.

I have started writing more of the main body class, and it is almost ready for functional implementation. The attributes I want to implement at the moment are: section='sectionname' header_increase='1/2/3...'

To prevent issues with the parsing of the page rigour tags as to whether they are transcluded or not, their processing will have to be delayed to a later point of the page parsing process. Then, it is required to use the command  $parser->recursiveTagParse  to process them. This is a bit of a workaround but it will ensure that the desired functionality can be implemented.

The whole process of parsing the 'transclusion' tags can be done by adding the tag as a tag extension, probably using some sort of flag to indicate processing stage. --Lord_Farin 17:42, 5 March 2012 (EST)