From f6d65e533c62f6deb21342d4901ece24497b433e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 4 Jun 2015 07:31:04 +0200 Subject: Update to MediaWiki 1.25.1 --- includes/parser/CoreParserFunctions.php | 92 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 48 deletions(-) (limited to 'includes/parser/CoreParserFunctions.php') diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index eacbecd4..830a68fc 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -36,7 +36,7 @@ class CoreParserFunctions { # Syntax for arguments (see Parser::setFunctionHook): # "name for lookup in localized magic words array", # function callback, - # optional SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}} + # optional Parser::SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}} # instead of {{#int:...}}) $noHashFunctions = array( 'ns', 'nse', 'urlencode', 'lcfirst', 'ucfirst', 'lc', 'uc', @@ -44,7 +44,7 @@ class CoreParserFunctions { 'canonicalurle', 'formatnum', 'grammar', 'gender', 'plural', 'numberofpages', 'numberofusers', 'numberofactiveusers', 'numberofarticles', 'numberoffiles', 'numberofadmins', - 'numberingroup', 'numberofedits', 'numberofviews', 'language', + 'numberingroup', 'numberofedits', 'language', 'padleft', 'padright', 'anchorencode', 'defaultsort', 'filepath', 'pagesincategory', 'pagesize', 'protectionlevel', 'namespacee', 'namespacenumber', 'talkspace', 'talkspacee', @@ -57,24 +57,24 @@ class CoreParserFunctions { 'revisiontimestamp', 'revisionuser', 'cascadingsources', ); foreach ( $noHashFunctions as $func ) { - $parser->setFunctionHook( $func, array( __CLASS__, $func ), SFH_NO_HASH ); + $parser->setFunctionHook( $func, array( __CLASS__, $func ), Parser::SFH_NO_HASH ); } - $parser->setFunctionHook( 'namespace', array( __CLASS__, 'mwnamespace' ), SFH_NO_HASH ); - $parser->setFunctionHook( 'int', array( __CLASS__, 'intFunction' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'namespace', array( __CLASS__, 'mwnamespace' ), Parser::SFH_NO_HASH ); + $parser->setFunctionHook( 'int', array( __CLASS__, 'intFunction' ), Parser::SFH_NO_HASH ); $parser->setFunctionHook( 'special', array( __CLASS__, 'special' ) ); $parser->setFunctionHook( 'speciale', array( __CLASS__, 'speciale' ) ); - $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS ); + $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), Parser::SFH_OBJECT_ARGS ); $parser->setFunctionHook( 'formatdate', array( __CLASS__, 'formatDate' ) ); if ( $wgAllowDisplayTitle ) { - $parser->setFunctionHook( 'displaytitle', array( __CLASS__, 'displaytitle' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'displaytitle', array( __CLASS__, 'displaytitle' ), Parser::SFH_NO_HASH ); } if ( $wgAllowSlowParserFunctions ) { $parser->setFunctionHook( 'pagesinnamespace', array( __CLASS__, 'pagesinnamespace' ), - SFH_NO_HASH + Parser::SFH_NO_HASH ); } } @@ -111,7 +111,7 @@ class CoreParserFunctions { $pref = $parser->getOptions()->getDateFormat(); - // Specify a different default date format other than the the normal default + // Specify a different default date format other than the normal default // if the user has 'default' for their setting if ( $pref == 'default' && $defaultPref ) { $pref = $defaultPref; @@ -309,15 +309,12 @@ class CoreParserFunctions { * @return string */ public static function gender( $parser, $username ) { - wfProfileIn( __METHOD__ ); $forms = array_slice( func_get_args(), 2 ); // Some shortcuts to avoid loading user data unnecessarily if ( count( $forms ) === 0 ) { - wfProfileOut( __METHOD__ ); return ''; } elseif ( count( $forms ) === 1 ) { - wfProfileOut( __METHOD__ ); return $forms[0]; } @@ -341,7 +338,6 @@ class CoreParserFunctions { $gender = GenderCache::singleton()->getGenderOf( $parser->getOptions()->getUser(), __METHOD__ ); } $ret = $parser->getFunctionLang()->gender( $gender, $forms ); - wfProfileOut( __METHOD__ ); return $ret; } @@ -379,8 +375,7 @@ class CoreParserFunctions { $text = $parser->doQuotes( $text ); // remove stripped text (e.g. the UNIQ-QINU stuff) that was generated by tag extensions/whatever - $text = preg_replace( '/' . preg_quote( $parser->uniqPrefix(), '/' ) . '.*?' - . preg_quote( Parser::MARKER_SUFFIX, '/' ) . '/', '', $text ); + $text = $parser->killMarkers( $text ); // list of disallowed tags for DISPLAYTITLE // these will be escaped even though they are allowed in normal wiki text @@ -489,10 +484,6 @@ class CoreParserFunctions { public static function numberofedits( $parser, $raw = null ) { return self::formatRaw( SiteStats::edits(), $raw ); } - public static function numberofviews( $parser, $raw = null ) { - global $wgDisableCounters; - return !$wgDisableCounters ? self::formatRaw( SiteStats::views(), $raw ) : ''; - } public static function pagesinnamespace( $parser, $namespace = 0, $raw = null ) { return self::formatRaw( SiteStats::pagesInNs( intval( $namespace ) ), $raw ); } @@ -902,9 +893,17 @@ class CoreParserFunctions { } } - // Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}} - // or {{filepath|300|nowiki}} or {{filepath|300px}}, {{filepath|200x300px}}, - // {{filepath|nowiki|200x300px}}, {{filepath|200x300px|nowiki}}. + /** + * Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}} + * or {{filepath|300|nowiki}} or {{filepath|300px}}, {{filepath|200x300px}}, + * {{filepath|nowiki|200x300px}}, {{filepath|200x300px|nowiki}}. + * + * @param Parser $parser + * @param string $name + * @param string $argA + * @param string $argB + * @return array|string + */ public static function filepath( $parser, $name = '', $argA = '', $argB = '' ) { $file = wfFindFile( $name ); @@ -943,7 +942,7 @@ class CoreParserFunctions { * Parser function to extension tag adaptor * @param Parser $parser * @param PPFrame $frame - * @param array $args + * @param PPNode[] $args * @return string */ public static function tagObj( $parser, $frame, $args ) { @@ -958,13 +957,6 @@ class CoreParserFunctions { $inner = null; } - $stripList = $parser->getStripList(); - if ( !in_array( $tagName, $stripList ) ) { - return '' . - wfMessage( 'unknown_extension_tag', $tagName )->inContentLanguage()->text() . - ''; - } - $attributes = array(); foreach ( $args as $arg ) { $bits = $arg->splitArg(); @@ -978,6 +970,19 @@ class CoreParserFunctions { } } + $stripList = $parser->getStripList(); + if ( !in_array( $tagName, $stripList ) ) { + // we can't handle this tag (at least not now), so just re-emit it as an ordinary tag + $attrText = ''; + foreach ( $attributes as $name => $value ) { + $attrText .= ' ' . htmlspecialchars( $name ) . '="' . htmlspecialchars( $value ) . '"'; + } + if ( $inner === null ) { + return "<$tagName$attrText/>"; + } + return "<$tagName$attrText>$inner"; + } + $params = array( 'name' => $tagName, 'inner' => $inner, @@ -1000,11 +1005,6 @@ class CoreParserFunctions { * @since 1.23 */ private static function getCachedRevisionObject( $parser, $title = null ) { - static $cache = null; - if ( $cache == null ) { - $cache = new MapCacheLRU( 50 ); - } - if ( is_null( $title ) ) { return null; } @@ -1024,22 +1024,18 @@ class CoreParserFunctions { // Normalize name for cache $page = $title->getPrefixedDBkey(); - if ( $cache->has( $page ) ) { // cache contains null values - return $cache->get( $page ); + if ( !( $parser->currentRevisionCache && $parser->currentRevisionCache->has( $page ) ) + && !$parser->incrementExpensiveFunctionCount() ) { + return null; } - if ( $parser->incrementExpensiveFunctionCount() ) { - $rev = Revision::newFromTitle( $title, false, Revision::READ_NORMAL ); - $pageID = $rev ? $rev->getPage() : 0; - $revID = $rev ? $rev->getId() : 0; - $cache->set( $page, $rev ); // maybe null + $rev = $parser->fetchCurrentRevisionOfTitle( $title ); + $pageID = $rev ? $rev->getPage() : 0; + $revID = $rev ? $rev->getId() : 0; - // Register dependency in templatelinks - $parser->getOutput()->addTemplate( $title, $pageID, $revID ); + // Register dependency in templatelinks + $parser->getOutput()->addTemplate( $title, $pageID, $revID ); - return $rev; - } - $cache->set( $page, null ); - return null; + return $rev; } /** -- cgit v1.2.2