// require_once('Tokenizer.php');
-if( $GLOBALS['wgUseWikiHiero'] ){
- require_once('extensions/wikihiero/wikihiero.php');
-}
-if( $GLOBALS['wgUseTimeline'] ){
- require_once('extensions/timeline/Timeline.php');
-}
-
# PHP Parser
#
# Processes wiki markup
# prefix for escaping, used in two functions at least
define( "UNIQ_PREFIX", "NaodW29");
+/* private */ $wgParserHooks = array();
+
class Parser
{
# Cleared with clearState():
# counting the sections in the wikisource
function strip( $text, &$state, $stripcomments = false )
{
+ global $wgParserHooks;
+
$render = ($this->mOutputType == OT_HTML);
$nowiki_content = array();
- $hiero_content = array();
- $timeline_content = array();
$math_content = array();
$pre_content = array();
$comment_content = array();
-
+ $ext_content = array();
+
# Replace any instances of the placeholders
$uniq_prefix = UNIQ_PREFIX;
#$text = str_replace( $uniq_prefix, wfHtmlEscapeFirst( $uniq_prefix ), $text );
+
+ # nowiki
$text = Parser::extractTags('nowiki', $text, $nowiki_content, $uniq_prefix);
foreach( $nowiki_content as $marker => $content ){
if( $render ){
}
}
- $text = Parser::extractTags('hiero', $text, $hiero_content, $uniq_prefix);
- foreach( $hiero_content as $marker => $content ){
- if( $render && $GLOBALS['wgUseWikiHiero']){
- $hiero_content[$marker] = WikiHiero( $content, WH_MODE_HTML);
- } else {
- $hiero_content[$marker] = "<hiero>$content</hiero>";
- }
- }
-
- $text = Parser::extractTags('timeline', $text, $timeline_content, $uniq_prefix);
- foreach( $timeline_content as $marker => $content ){
- if( $render && $GLOBALS['wgUseTimeline']){
- $timeline_content[$marker] = renderTimeline( $content );
- } else {
- $timeline_content[$marker] = "<timeline>$content</timeline>";
- }
- }
-
+ # math
$text = Parser::extractTags('math', $text, $math_content, $uniq_prefix);
foreach( $math_content as $marker => $content ){
if( $render ) {
}
}
+ # pre
$text = Parser::extractTags('pre', $text, $pre_content, $uniq_prefix);
foreach( $pre_content as $marker => $content ){
if( $render ){
$pre_content[$marker] = "<pre>$content</pre>";
}
}
+
+ # Comments
if($stripcomments) {
$text = Parser::extractTags(STRIP_COMMENTS, $text, $comment_content, $uniq_prefix);
foreach( $comment_content as $marker => $content ){
}
}
+ # Extensions
+ foreach ( $wgParserHooks as $tag => $callback ) {
+ $ext_contents[$tag] = array();
+ $text = Parser::extractTags( $tag, $text, $ext_content[$tag], $uniq_prefix );
+ foreach( $ext_content[$tag] as $marker => $content ) {
+ if ( $render ) {
+ $ext_content[$tag][$marker] = $callback( $content );
+ } else {
+ $ext_content[$tag][$marker] = "<$tag>$content</$tag>";
+ }
+ }
+ }
+
# Merge state with the pre-existing state, if there is one
if ( $state ) {
$state['nowiki'] = $state['nowiki'] + $nowiki_content;
- $state['hiero'] = $state['hiero'] + $hiero_content;
- $state['timeline'] = $state['timeline'] + $timeline_content;
$state['math'] = $state['math'] + $math_content;
$state['pre'] = $state['pre'] + $pre_content;
$state['comment'] = $state['comment'] + $comment_content;
+
+ foreach( $ext_content as $tag => $array ) {
+ if ( array_key_exists( $tag, $state ) ) {
+ $state[$tag] = $state[$tag] + $array;
+ }
+ }
} else {
$state = array(
'nowiki' => $nowiki_content,
- 'hiero' => $hiero_content,
- 'timeline' => $timeline_content,
'math' => $math_content,
'pre' => $pre_content,
- 'comment' => $comment_content
- );
+ 'comment' => $comment_content,
+ ) + $ext_content;
}
return $text;
}
if ( !$state ) {
$state = array(
'nowiki' => array(),
- 'hiero' => array(),
'math' => array(),
'pre' => array()
);
$res = wfQuery ( $sql, DB_READ ) ;
while ( $x = wfFetchObject ( $res ) )
{
- $t = $wgLang->getNsText ( $x->cur_namespace ) ;
+ $t = $ns = $wgLang->getNsText ( $x->cur_namespace ) ;
if ( $t != '' ) $t .= ':' ;
$t .= $x->cur_title ;
if ( $x->cur_namespace == $cns ) {
- array_push ( $children, $sk->makeKnownLink ( $t, str_replace( '_',' ',$x->cur_title) ) ) ; # Subcategory
- array_push ( $children_start_char, $wgLang->firstChar( $x->cur_title ) ) ;
+ $ctitle = str_replace( '_',' ',$x->cur_title );
+ array_push ( $children, $sk->makeKnownLink ( $t, $ctitle ) ) ; # Subcategory
+
+ // If there's a link from Category:A to Category:B, the sortkey of the resulting
+ // entry in the categorylinks table is Category:A, not A, which it SHOULD be.
+ // Workaround: If sortkey == "Category:".$title, than use $title for sorting,
+ // else use sortkey...
+ if ( ($ns.":".$ctitle) == $x->cl_sortkey ) {
+ array_push ( $children_start_char, $wgLang->firstChar( $x->cur_title ) );
+ } else {
+ array_push ( $children_start_char, $wgLang->firstChar( $x->cl_sortkey ) ) ;
+ }
} else {
array_push ( $articles , $sk->makeLink ( $t ) ) ; # Page in this category
array_push ( $articles_start_char, $wgLang->firstChar( $x->cl_sortkey ) ) ;
# Showing subcategories
$r .= '<h2>' . wfMsg( 'subcategories' ) . "</h2>\n"
. wfMsg( 'subcategorycount', count( $children ) );
- if ( count ( $children ) > 20) {
+ if ( count ( $children ) > 6 ) {
// divide list into three equal chunks
$chunk = (int) (count ( $children ) / 3);
$executing = false;
return $text;
}
+
+ # Create an HTML-style tag, e.g. <yourtag>special text</yourtag>
+ # Callback will be called with the text within
+ # Transform and return the text within
+ /* static */ function setHook( $tag, $callback ) {
+ global $wgParserHooks;
+ $oldVal = @$wgParserHooks[$tag];
+ $wgParserHooks[$tag] = $callback;
+ return $oldVal;
+ }
}
class ParserOutput