$data = array () ;
$id = $this->mTitle->getArticleID() ;
- # For existing categories
- if( $id ) {
- $sql = "SELECT DISTINCT cur_title,cur_namespace FROM cur,links WHERE l_to={$id} AND l_from=cur_id";
- $res = wfQuery ( $sql, DB_READ ) ;
- while ( $x = wfFetchObject ( $res ) ) $data[] = $x ;
- } else {
- # For non-existing categories
- $t = wfStrencode( $this->mTitle->getPrefixedDBKey() );
- $sql = "SELECT DISTINCT cur_title,cur_namespace FROM cur,brokenlinks WHERE bl_to='$t' AND bl_from=cur_id" ;
- $res = wfQuery ( $sql, DB_READ ) ;
- while ( $x = wfFetchObject ( $res ) ) $data[] = $x ;
- }
+ # FIXME: add limits
+ $t = wfStrencode( $this->mTitle->getDBKey() );
+ $sql = "SELECT DISTINCT cur_title,cur_namespace FROM cur,categorylinks WHERE cl_to='$t' AND cl_from=cur_id ORDER BY cl_sortkey" ;
+ $res = wfQuery ( $sql, DB_READ ) ;
+ while ( $x = wfFetchObject ( $res ) ) $data[] = $x ;
# For all pages that link to this category
foreach ( $data AS $x )
wfFreeResult ( $res ) ;
# Showing subcategories
- if ( count ( $children ) > 0 )
- {
- asort ( $children ) ;
+ if ( count ( $children ) > 0 ) {
$r .= "<h2>".wfMsg("subcategories")."</h2>\n" ;
$r .= implode ( ", " , $children ) ;
}
# Showing pages in this category
- if ( count ( $articles ) > 0 )
- {
+ if ( count ( $articles ) > 0 ) {
$ti = $this->mTitle->getText() ;
- asort ( $articles ) ;
$h = wfMsg( "category_header", $ti );
$r .= "<h2>{$h}</h2>\n" ;
$r .= implode ( ", " , $articles ) ;
return $t ;
}
+ # Parses the text and adds the result to the strip state
+ # Returns the strip tag
+ function stripParse( $text, $linestart, $args )
+ {
+ $text = $this->strip( $text, $this->mStripState );
+ $text = $this->internalParse( $text, $linestart, $args, false );
+ if( $linestart ) {
+ $text = "\n" . $text;
+ }
+ return $this->insertStripItem( $text, $this->mStripState );
+ }
+
function internalParse( $text, $linestart, $args = array(), $isMain=true )
{
$fname = "Parser::internalParse";
$text = $sk->transformContent( $text );
if ( !isset ( $this->categoryMagicDone ) ) {
- $text .= $this->categoryMagic () ;
- $this->categoryMagicDone = true ;
- }
+ $text .= $this->categoryMagic () ;
+ $this->categoryMagicDone = true ;
+ }
wfProfileOut( $fname );
return $text;
} else {
$noslash=substr($m[1],1);
}
- if($wgNamespacesWithSubpages[$this->mTitle->getNamespace()]) { # subpages allowed here
+ if(!empty($wgNamespacesWithSubpages[$this->mTitle->getNamespace()])) { # subpages allowed here
$link = $this->mTitle->getPrefixedText(). "/" . trim($noslash);
if( "" == $text ) {
$text= $m[1];
} else {
$link = substr( $m[1], 1 );
}
- if( "" == $text )
+ $wasblank = ( "" == $text );
+ if( $wasblank )
$text = $link;
$nt = Title::newFromText( $link );
if ( $ns == $category ) {
$t = $nt->getText() ;
$nnt = Title::newFromText ( Namespace::getCanonicalName($category).":".$t ) ;
+
+ $wgLinkCache->suspend(); # Don't save in links/brokenlinks
$t = $sk->makeLinkObj( $nnt, $t, "", "" , $prefix );
+ $wgLinkCache->resume();
+
+ $sortkey = $wasblank ? $this->mTitle->getPrefixedText() : $text;
+ $wgLinkCache->addCategoryLinkObj( $nt, $sortkey );
$this->mOutput->mCategoryLinks[] = $t ;
$s .= $prefix . $trail ;
return $s ;
# No prefix (not in list)--go to paragraph mode
$uniq_prefix = UNIQ_PREFIX;
// XXX: use a stack for nestable elements like span, table and div
- $openmatch = preg_match("/(<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<div|<pre|<tr|<td|<p|<ul|<li)/i", $t );
+ $openmatch = preg_match("/(<table|<blockquote|<h1|<h2|<h3|<h4|<h5|<h6|<pre|<tr|<td|<p|<ul|<li)/i", $t );
$closematch = preg_match(
"/(<\\/table|<\\/blockquote|<\\/h1|<\\/h2|<\\/h3|<\\/h4|<\\/h5|<\\/h6|".
- "<\\/div|<hr|<\\/td|<\\/pre|<\\/p|".$uniq_prefix."-pre|<\\/li|<\\/ul)/i", $t );
+ "<div|<\\/div|<hr|<\\/td|<\\/pre|<\\/p|".$uniq_prefix."-pre|<\\/li|<\\/ul)/i", $t );
if ( $openmatch or $closematch ) {
$paragraphStack = false;
$output .= $this->closeParagraph();
$this->initialiseVariables();
}
$titleChars = Title::legalChars();
- $regex = "/(\\n?){{([$titleChars]*?)(\\|.*?|)}}/s";
# This function is called recursively. To keep track of arguments we need a stack:
array_push( $this->mArgStack, $args );
# PHP global rebinding syntax is a bit weird, need to use the GLOBALS array
$GLOBALS['wgCurParser'] =& $this;
+
+ # Argument substitution
+ if ( $this->mOutputType == OT_HTML ) {
+ $text = preg_replace_callback( "/(\\n?){{{([$titleChars]*?)}}}/", "wfArgSubstitution", $text );
+ }
+
+ # Double brace substitution
+ $regex = "/(\\n?){{([$titleChars]*?)(\\|.*?|)}}/s";
$text = preg_replace_callback( $regex, "wfBraceSubstitution", $text );
array_pop( $this->mArgStack );
$fname = "Parser::braceSubstitution";
$found = false;
$nowiki = false;
+ $noparse = false;
+
$title = NULL;
# $newline is an optional newline character before the braces
$args = array();
}
$argc = count( $args );
+
+ # {{{}}}
+ if ( strpos( $matches[0], "{{{" ) !== false ) {
+ $text = $matches[0];
+ $found = true;
+ $noparse = true;
+ }
# SUBST
- $mwSubst =& MagicWord::get( MAG_SUBST );
- if ( $mwSubst->matchStartAndRemove( $part1 ) ) {
- if ( $this->mOutputType != OT_WIKI ) {
- # Invalid SUBST not replaced at PST time
- # Return without further processing
+ if ( !$found ) {
+ $mwSubst =& MagicWord::get( MAG_SUBST );
+ if ( $mwSubst->matchStartAndRemove( $part1 ) ) {
+ if ( $this->mOutputType != OT_WIKI ) {
+ # Invalid SUBST not replaced at PST time
+ # Return without further processing
+ $text = $matches[0];
+ $found = true;
+ $noparse= true;
+ }
+ } elseif ( $this->mOutputType == OT_WIKI ) {
+ # SUBST not found in PST pass, do nothing
$text = $matches[0];
$found = true;
}
- } elseif ( $this->mOutputType == OT_WIKI ) {
- # SUBST not found in PST pass, do nothing
- $text = $matches[0];
- $found = true;
}
# MSG, MSGNW and INT
$found = true;
$this->mOutput->mContainsOldMagic = true;
}
-
+/*
# Arguments input from the caller
$inputArgs = end( $this->mArgStack );
if ( !$found && array_key_exists( $part1, $inputArgs ) ) {
$text = $inputArgs[$part1];
$found = true;
}
-
+*/
# Load from database
if ( !$found ) {
$title = Title::newFromText( $part1, NS_TEMPLATE );
# Only for HTML output
if ( $nowiki && $found && $this->mOutputType == OT_HTML ) {
$text = wfEscapeWikiText( $text );
- } elseif ( $this->mOutputType == OT_HTML && $found ) {
+ } elseif ( $this->mOutputType == OT_HTML && $found && !$noparse) {
# Clean up argument array
$assocArgs = array();
$index = 1;
}
# Run full parser on the included text
- $text = $this->strip( $text, $this->mStripState );
- $text = $this->internalParse( $text, (bool)$newline, $assocArgs, false );
- if(!empty($newline)) $text = "\n".$text;
-
- # Add the result to the strip state for re-inclusion after
- # the rest of the processing
- $text = $this->insertStripItem( $text, $this->mStripState );
+ $text = $this->stripParse( $text, (bool)$newline, $assocArgs );
# Resume the link cache and register the inclusion as a link
if ( !is_null( $title ) ) {
}
}
+ # Triple brace replacement -- used for template arguments
+ function argSubstitution( $matches )
+ {
+ $newline = $matches[1];
+ $arg = trim( $matches[2] );
+ $text = $matches[0];
+ $inputArgs = end( $this->mArgStack );
+
+ if ( array_key_exists( $arg, $inputArgs ) ) {
+ $text = $this->stripParse( $inputArgs[$arg], (bool)$newline, array() );
+ }
+
+ return $text;
+ }
+
# Returns true if the function is allowed to include this entity
function incrementIncludeCount( $dbk )
{
return $wgCurParser->braceSubstitution( $matches );
}
+function wfArgSubstitution( $matches )
+{
+ global $wgCurParser;
+ return $wgCurParser->argSubstitution( $matches );
+}
+
?>