* performs brace substitution on MediaWiki messages
*
* Globals used:
- * objects: $wgLang
+ * objects: $wgLang, $wgContLang
*
* NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
*
$this->replaceLinkHolders( $text );
- # the position of the convert() call should not be changed. it
- # assumes that the links are all replaces and the only thing left
+ # the position of the parserConvert() call should not be changed. it
+ # assumes that the links are all replaced and the only thing left
# is the <nowiki> mark.
- $text = $wgContLang->convert($text);
- $this->mOutput->setTitleText($wgContLang->getParsedTitle());
+ # Side-effects: this calls $this->mOutput->setTitleText()
+ $text = $wgContLang->parserConvert( $text, $this );
$text = $this->unstripNoWiki( $text, $this->mStripState );
return dechex(mt_rand(0, 0x7fffffff)) . dechex(mt_rand(0, 0x7fffffff));
}
+ function &getTitle() { return $this->mTitle; }
+ function getOptions() { return $this->mOptions; }
+
/**
* Replaces all occurrences of <$tag>content</$tag> in the text
* with a random marker and returns the new text. the output parameter
$state['nowiki'] = $state['nowiki'] + $nowiki_content;
$state['math'] = $state['math'] + $math_content;
$state['pre'] = $state['pre'] + $pre_content;
- $state['comment'] = $state['comment'] + $comment_content;
$state['gallery'] = $state['gallery'] + $gallery_content;
+ $state['comment'] = $state['comment'] + $comment_content;
foreach( $ext_content as $tag => $array ) {
if ( array_key_exists( $tag, $state ) ) {
'nowiki' => $nowiki_content,
'math' => $math_content,
'pre' => $pre_content,
- 'comment' => $comment_content,
'gallery' => $gallery_content,
+ 'comment' => $comment_content,
) + $ext_content;
}
return $text;
$pipes = array();
$process = proc_open("$wgTidyBin -config $wgTidyConf $wgTidyOpts$opts", $descriptorspec, $pipes);
if (is_resource($process)) {
+ // Theoretically, this style of communication could cause a deadlock
+ // here. If the stdout buffer fills up, then writes to stdin could
+ // block. This doesn't appear to happen with tidy, because tidy only
+ // writes to stdout after it's finished reading from stdin. Search
+ // for tidyParseStdin and tidySaveStdout in console/tidy.c
fwrite($pipes[0], $text);
fclose($pipes[0]);
while (!feof($pipes[1])) {
$ltd = array () ; # Was it TD or TH?
$tr = array () ; # Is currently a tr tag open?
$ltr = array () ; # tr attributes
+ $has_opened_tr = array(); # Did this table open a <tr> element?
$indent_level = 0; # indent level of the table
foreach ( $t AS $k => $x )
{
array_push ( $ltd , '' ) ;
array_push ( $tr , false ) ;
array_push ( $ltr , '' ) ;
+ array_push ( $has_opened_tr, false );
}
else if ( count ( $td ) == 0 ) { } # Don't do any of the following
else if ( '|}' == substr ( $x , 0 , 2 ) ) {
$z = "</table>" . substr ( $x , 2);
$l = array_pop ( $ltd ) ;
+ if ( !array_pop ( $has_opened_tr ) ) $z = "<tr><td></td></tr>" . $z ;
if ( array_pop ( $tr ) ) $z = '</tr>' . $z ;
if ( array_pop ( $td ) ) $z = '</'.$l.'>' . $z ;
array_pop ( $ltr ) ;
while ( $x != '' && substr ( $x , 0 , 1 ) == '-' ) $x = substr ( $x , 1 ) ;
$z = '' ;
$l = array_pop ( $ltd ) ;
+ array_pop ( $has_opened_tr );
+ array_push ( $has_opened_tr , true ) ;
if ( array_pop ( $tr ) ) $z = '</tr>' . $z ;
if ( array_pop ( $td ) ) $z = '</'.$l.'>' . $z ;
array_pop ( $ltr ) ;
if ( !array_pop ( $tr ) ) $z = '<tr'.$tra.">\n" ;
array_push ( $tr , true ) ;
array_push ( $ltr , '' ) ;
+ array_pop ( $has_opened_tr );
+ array_push ( $has_opened_tr , true ) ;
}
$l = array_pop ( $ltd ) ;
# Closing open td, tr && table
while ( count ( $td ) > 0 )
{
+ $l = array_pop ( $ltd ) ;
if ( array_pop ( $td ) ) $t[] = '</td>' ;
if ( array_pop ( $tr ) ) $t[] = '</tr>' ;
+ if ( !array_pop ( $has_opened_tr ) ) $t[] = "<tr><td></td></tr>" ;
$t[] = '</table>' ;
}
* @access private
*/
function internalParse( $text ) {
- global $wgContLang;
$args = array();
$isMain = true;
$fname = 'Parser::internalParse';
/**
* Replace unusual URL escape codes with their equivalent characters
- * @param string
+ * @param string
* @return string
* @static
*/
function replaceUnusualEscapes( $url ) {
- return preg_replace_callback( '/%[0-9A-Fa-f]{2}/',
+ return preg_replace_callback( '/%[0-9A-Fa-f]{2}/',
array( 'Parser', 'replaceUnusualEscapesCallback' ), $url );
}
return $this->mTitle->getPrefixedText();
case MAG_FULLPAGENAMEE:
return $this->mTitle->getPrefixedURL();
+ case MAG_SUBPAGENAME:
+ return $this->mTitle->getSubpageText();
case MAG_REVISIONID:
return $this->mRevisionId;
case MAG_NAMESPACE:
$fname = 'Parser::braceSubstitution';
wfProfileIn( $fname );
- # Flags
+ # Flags
$found = false; # $text has been filled
$nowiki = false; # wiki markup in $text should be escaped
$noparse = false; # Unsafe HTML tags should not be stripped, etc.
}
/**
- * Fetch the unparsed text of a template and register a reference to it.
+ * Fetch the unparsed text of a template and register a reference to it.
*/
function fetchTemplate( $title ) {
$text = false;
# strip out HTML
$canonized_headline = preg_replace( '/<.*?' . '>/','',$canonized_headline );
$tocline = trim( $canonized_headline );
+ # Save headline for section edit hint before it's escaped
+ $headline_hint = trim( $canonized_headline );
$canonized_headline = Sanitizer::escapeId( $tocline );
$refers[$headlineCount] = $canonized_headline;
if( $istemplate )
$head[$headlineCount] .= $sk->editSectionLinkForOther($templatetitle, $templatesection);
else
- $head[$headlineCount] .= $sk->editSectionLink($this->mTitle, $sectionCount+1);
+ $head[$headlineCount] .= $sk->editSectionLink($this->mTitle, $sectionCount+1, $headline_hint);
}
# give headline the correct <h#> tag
# Signatures
$sigText = $this->getUserSig( $user );
- $text = strtr( $text, array(
+ $text = strtr( $text, array(
'~~~~~' => $d,
'~~~~' => "$sigText $d",
'~~~' => $sigText
* @access private
*/
function getUserSig( &$user ) {
- global $wgContLang;
-
$username = $user->getName();
$nickname = $user->getOption( 'nickname' );
$nickname = $nickname === '' ? $username : $nickname;
/**
* 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
+ * The callback should have the following form:
+ * function myParserHook( $text, $params, &$parser ) { ... }
+ *
+ * Transform and return $text. Use $parser for any required context, e.g. use
+ * $parser->getTitle() and $parser->getOptions() not $wgTitle or $wgOut->mParserOptions
*
* @access public
*
* @return string
*/
function replaceLinkHoldersText( $text ) {
- global $wgUser;
- global $wgOutputReplace;
-
$fname = 'Parser::replaceLinkHoldersText';
wfProfileIn( $fname );
* Parse image options text and use it to make an image
*/
function makeImage( &$nt, $options ) {
- global $wgContLang, $wgUseImageResize, $wgUser;
+ global $wgUseImageResize;
$align = '';
$this->mOutput->mCacheTime = -1;
}
- /**#@+
+ /**#@+
* Callback from the Sanitizer for expanding items found in HTML attribute
* values, so they can be safely tested and escaped.
* @param string $text
/** Get user options */
function initialiseFromUser( &$userInput ) {
- global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages,
- $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion;
+ global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
+ global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion;
$fname = 'ParserOptions::initialiseFromUser';
wfProfileIn( $fname );
if ( !$userInput ) {