$output = MathRenderer::renderMath( $content );
break;
case 'gallery':
- $output = $this->renderImageGallery( $content );
+ $output = $this->renderImageGallery( $content, $params );
break;
default:
if( isset( $this->mTagHooks[$tagName] ) ) {
# Normalize any HTML entities in input. They will be
# re-escaped by makeExternalLink().
$url = Sanitizer::decodeCharReferences( $url );
+
+ # Escape any control characters introduced by the above step
+ $url = preg_replace( '/[\][<>"\\x00-\\x20\\x7F]/e', "urlencode('\\0')", $url );
# Process the trail (i.e. everything after this link up until start of the next link),
# replacing any non-bracketed links
# Normalize any HTML entities in input. They will be
# re-escaped by makeExternalLink() or maybeMakeExternalImage()
$url = Sanitizer::decodeCharReferences( $url );
+
+ # Escape any control characters introduced by the above step
+ $url = preg_replace( '/[\][<>"\\x00-\\x20\\x7F]/e', "urlencode('\\0')", $url );
# Is this an external image?
$text = $this->maybeMakeExternalImage( $url );
$sortkey = $text;
}
$sortkey = Sanitizer::decodeCharReferences( $sortkey );
+ $sortkey = str_replace( "\n", '', $sortkey );
$sortkey = $wgContLang->convertCategoryKey( $sortkey );
$this->mOutput->addCategory( $nt->getDBkey(), $sortkey );
$ts = time();
wfRunHooks( 'ParserGetVariableValueTs', array( &$this, &$ts ) );
- # Use the time zone
- global $wgLocaltimezone;
- if ( isset( $wgLocaltimezone ) ) {
- $oldtz = getenv( 'TZ' );
- putenv( 'TZ='.$wgLocaltimezone );
- }
- $timestamp = date( 'YmdHis', $ts );
- $month = date( 'm', $ts );
- $monthname = date( 'n', $ts );
- $day = date( 'j', $ts );
- $day2 = date( 'd', $ts );
- $dayofweek = date( 'w', $ts );
- $week = date( 'W', $ts );
- $year = date( 'Y', $ts );
- if ( isset( $wgLocaltimezone ) ) {
- putenv( 'TZ='.$oldtz );
- }
-
switch ( $index ) {
case MAG_CURRENTMONTH:
- return $varCache[$index] = $wgContLang->formatNum( $month );
+ return $varCache[$index] = $wgContLang->formatNum( date( 'm', $ts ) );
case MAG_CURRENTMONTHNAME:
- return $varCache[$index] = $wgContLang->getMonthName( $monthname );
+ return $varCache[$index] = $wgContLang->getMonthName( date( 'n', $ts ) );
case MAG_CURRENTMONTHNAMEGEN:
- return $varCache[$index] = $wgContLang->getMonthNameGen( $monthname );
+ return $varCache[$index] = $wgContLang->getMonthNameGen( date( 'n', $ts ) );
case MAG_CURRENTMONTHABBREV:
- return $varCache[$index] = $wgContLang->getMonthAbbreviation( $monthname );
+ return $varCache[$index] = $wgContLang->getMonthAbbreviation( date( 'n', $ts ) );
case MAG_CURRENTDAY:
- return $varCache[$index] = $wgContLang->formatNum( $day );
+ return $varCache[$index] = $wgContLang->formatNum( date( 'j', $ts ) );
case MAG_CURRENTDAY2:
- return $varCache[$index] = $wgContLang->formatNum( $day2 );
+ return $varCache[$index] = $wgContLang->formatNum( date( 'd', $ts ) );
case MAG_PAGENAME:
return $this->mTitle->getText();
case MAG_PAGENAMEE:
case MAG_SUBJECTSPACEE:
return( wfUrlencode( $this->mTitle->getSubjectNsText() ) );
case MAG_CURRENTDAYNAME:
- return $varCache[$index] = $wgContLang->getWeekdayName( $dayofweek + 1 );
+ return $varCache[$index] = $wgContLang->getWeekdayName( date( 'w', $ts ) + 1 );
case MAG_CURRENTYEAR:
- return $varCache[$index] = $wgContLang->formatNum( $year, true );
+ return $varCache[$index] = $wgContLang->formatNum( date( 'Y', $ts ), true );
case MAG_CURRENTTIME:
- return $varCache[$index] = $wgContLang->time( $timestamp, false, false );
+ return $varCache[$index] = $wgContLang->time( wfTimestamp( TS_MW, $ts ), false, false );
case MAG_CURRENTWEEK:
// @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
// int to remove the padding
- return $varCache[$index] = $wgContLang->formatNum( (int)$week );
+ return $varCache[$index] = $wgContLang->formatNum( (int)date( 'W', $ts ) );
case MAG_CURRENTDOW:
- return $varCache[$index] = $wgContLang->formatNum( $dayofweek );
+ return $varCache[$index] = $wgContLang->formatNum( date( 'w', $ts ) );
case MAG_NUMBEROFARTICLES:
return $varCache[$index] = $wgContLang->formatNum( wfNumberOfArticles() );
case MAG_NUMBEROFFILES:
case MAG_NUMBEROFADMINS:
return $varCache[$index] = $wgContLang->formatNum( wfNumberOfAdmins() );
case MAG_CURRENTTIMESTAMP:
- return $varCache[$index] = $timestamp;
+ return $varCache[$index] = wfTimestampNow();
case MAG_CURRENTVERSION:
global $wgVersion;
return $wgVersion;
'text' => substr($text, $pieceStart, $pieceEnd - $pieceStart),
'title' => trim($openingBraceStack[$lastOpeningBrace]['title']),
'parts' => $openingBraceStack[$lastOpeningBrace]['parts'],
- 'lineStart' => (($pieceStart > 0) && ($text[$pieceStart-1] == '\n')),
+ 'lineStart' => (($pieceStart > 0) && ($text[$pieceStart-1] == "\n")),
);
# finally we can call a user callback and replace piece of text
$replaceWith = call_user_func( $matchingCallback, $cbArgs );
$text = $linestart . $wgContLang->getNsText( intval( $part1 ) );
$found = true;
} else {
- $index = Namespace::getCanonicalIndex( strtolower( $part1 ) );
+ $param = str_replace( ' ', '_', strtolower( $part1 ) );
+ $index = Namespace::getCanonicalIndex( strtolower( $param ) );
if ( !is_null( $index ) ) {
$text = $linestart . $wgContLang->getNsText( $index );
$found = true;
$colonPos = strpos( $part1, ':' );
if ( $colonPos !== false ) {
$function = strtolower( substr( $part1, 1, $colonPos - 1 ) );
+ if ( !isset( $this->mFunctionHooks[$function] ) ) {
+ foreach ($this->mFunctionHooks as $key => $value) {
+ if( is_int( $key ) ) {
+ $mwExtension =& MagicWord::get( $key );
+ if( $mwExtension->matchVariableStartToEnd( $function ) ) {
+ $function = $key;
+ break;
+ }
+ }
+ }
+ }
if ( isset( $this->mFunctionHooks[$function] ) ) {
$funcArgs = array_map( 'trim', $args );
$funcArgs = array_merge( array( &$this, trim( substr( $part1, $colonPos + 1 ) ) ), $funcArgs );
}
}
+ // Make sure nickname doesnt get a sig in a sig
+ $nickname = $this->cleanSigInSig( $nickname );
+
# If we're still here, make it a link to the user page
$userpage = $user->getUserPage();
return( '[[' . $userpage->getPrefixedText() . '|' . wfEscapeWikiText( $nickname ) . ']]' );
/**
* Clean up signature text
*
- * 1) Strip ~~~, ~~~~ and ~~~~~ out of signatures
+ * 1) Strip ~~~, ~~~~ and ~~~~~ out of signatures @see cleanSigInSig
* 2) Substitute all transclusions
*
* @param string $text
$substText = '{{' . $substWord->getSynonym( 0 );
$text = preg_replace( $substRegex, $substText, $text );
- $text = preg_replace( '/~{3,5}/', '', $text );
+ $text = $this->cleanSigInSig( $text );
$text = $this->replaceVariables( $text );
$this->clearState();
return $text;
}
+
+ /**
+ * Strip ~~~, ~~~~ and ~~~~~ out of signatures
+ * @param string $text
+ * @return string Signature text with /~{3,5}/ removed
+ */
+ function cleanSigInSig( $text ) {
+ $text = preg_replace( '/~{3,5}/', '', $text );
+ return $text;
+ }
/**
* Set up some variables which are usually set up in parse()
*
* @public
*
- * @param string $name The function name. Function names are case-insensitive.
+ * @param mixed $id The magic word ID, or (deprecated) the function name. Function names are case-insensitive.
* @param mixed $callback The callback function (and object) to use
*
* @return The old callback function for this name, if any
*/
- function setFunctionHook( $name, $callback ) {
- $name = strtolower( $name );
- $oldVal = @$this->mFunctionHooks[$name];
- $this->mFunctionHooks[$name] = $callback;
+ function setFunctionHook( $id, $callback ) {
+ if( is_string( $id ) ) {
+ $id = strtolower( $id );
+ }
+ $oldVal = @$this->mFunctionHooks[$id];
+ $this->mFunctionHooks[$id] = $callback;
return $oldVal;
}
* labeled 'The number "1"' and
* 'A tree'.
*/
- function renderImageGallery( $text ) {
+ function renderImageGallery( $text, $params ) {
$ig = new ImageGallery();
$ig->setShowBytes( false );
$ig->setShowFilename( false );
$ig->setParsing();
- $lines = explode( "\n", $text );
+ $ig->useSkin( $this->mOptions->getSkin() );
+ if( isset( $params['caption'] ) )
+ $ig->setCaption( $params['caption'] );
+
+ $lines = explode( "\n", $text );
foreach ( $lines as $line ) {
# match lines like these:
# Image:someimage.jpg|This is some image
(=+) # Should this be limited to 6?
.+? # Section title...
\\2 # Ending = count must match start
- (?:$comment|<\/?noinclude>|\s+)* # Trailing whitespace ok
+ (?:$comment|<\/?noinclude>|[ \\t]+)* # Trailing whitespace ok
$
|
<h([1-6])\b.*?>