From bd30ccd795b0e4329bf64c7fc306cf6f97e284ec Mon Sep 17 00:00:00 2001 From: "Amir E. Aharoni" Date: Sat, 26 Sep 2015 20:17:49 +0300 Subject: [PATCH] Make lines shorter to pass phpcs in some files under includes/parser This doesn't fix all the files under includes/parser - some of them deserve their own patches. Bug: T102614 Change-Id: I2fcbc19ee337e1b7db4635b5e5f324c651b4d144 --- includes/parser/CacheTime.php | 15 ++++++++--- includes/parser/CoreParserFunctions.php | 16 ++++++++--- includes/parser/Parser.php | 13 ++++++--- includes/parser/ParserCache.php | 17 +++++++++--- includes/parser/ParserOptions.php | 35 ++++++++++++++----------- 5 files changed, 67 insertions(+), 29 deletions(-) diff --git a/includes/parser/CacheTime.php b/includes/parser/CacheTime.php index c450689708..7acfe38cfc 100644 --- a/includes/parser/CacheTime.php +++ b/includes/parser/CacheTime.php @@ -32,10 +32,17 @@ class CacheTime { */ public $mUsedOptions; - public $mVersion = Parser::VERSION, # Compatibility check - $mCacheTime = '', # Time when this object was generated, or -1 for uncacheable. Used in ParserCache. - $mCacheExpiry = null, # Seconds after which the object should expire, use 0 for uncacheable. Used in ParserCache. - $mCacheRevisionId = null; # Revision ID that was parsed + # Compatibility check + public $mVersion = Parser::VERSION; + + # Time when this object was generated, or -1 for uncacheable. Used in ParserCache. + public $mCacheTime = ''; + + # Seconds after which the object should expire, use 0 for uncacheable. Used in ParserCache. + public $mCacheExpiry = null; + + # Revision ID that was parsed + public $mCacheRevisionId = null; /** * @return string TS_MW timestamp diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 7639e2f837..b0737f60d4 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -60,7 +60,11 @@ class CoreParserFunctions { $parser->setFunctionHook( $func, array( __CLASS__, $func ), Parser::SFH_NO_HASH ); } - $parser->setFunctionHook( 'namespace', array( __CLASS__, 'mwnamespace' ), Parser::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' ) ); @@ -68,7 +72,11 @@ class CoreParserFunctions { $parser->setFunctionHook( 'formatdate', array( __CLASS__, 'formatDate' ) ); if ( $wgAllowDisplayTitle ) { - $parser->setFunctionHook( 'displaytitle', array( __CLASS__, 'displaytitle' ), Parser::SFH_NO_HASH ); + $parser->setFunctionHook( + 'displaytitle', + array( __CLASS__, 'displaytitle' ), + Parser::SFH_NO_HASH + ); } if ( $wgAllowSlowParserFunctions ) { $parser->setFunctionHook( @@ -810,7 +818,9 @@ class CoreParserFunctions { * @param int $direction * @return string */ - public static function pad( $parser, $string, $length, $padding = '0', $direction = STR_PAD_RIGHT ) { + public static function pad( + $parser, $string, $length, $padding = '0', $direction = STR_PAD_RIGHT + ) { $padding = $parser->killMarkers( $padding ); $lengthOfPadding = mb_strlen( $padding ); if ( $lengthOfPadding == 0 ) { diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 3e5e8a1e9c..3b49ccf538 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -511,7 +511,10 @@ class Parser { } $limitReport .= 'Cached time: ' . $this->mOutput->getCacheTime() . "\n"; $limitReport .= 'Cache expiry: ' . $this->mOutput->getCacheExpiry() . "\n"; - $limitReport .= 'Dynamic content: ' . ( $this->mOutput->hasDynamicContent() ? 'true' : 'false' ) . "\n"; + $limitReport .= 'Dynamic content: ' . + ( $this->mOutput->hasDynamicContent() ? 'true' : 'false' ) . + "\n"; + foreach ( $this->mOutput->getLimitReportData() as $key => $value ) { if ( Hooks::run( 'ParserLimitReportFormat', array( $key, &$value, &$limitReport, false, false ) @@ -1468,7 +1471,6 @@ class Parser { * @private */ public function makeFreeExternalLink( $url, $numPostProto ) { - $trail = ''; # The characters '<' and '>' (which were escaped by @@ -1476,7 +1478,12 @@ class Parser { # URLs, per RFC 2396. # Make   terminate a URL as well (bug T84937) $m2 = array(); - if ( preg_match( '/&(lt|gt|nbsp|#x0*(3[CcEe]|[Aa]0)|#0*(60|62|160));/', $url, $m2, PREG_OFFSET_CAPTURE ) ) { + if ( preg_match( + '/&(lt|gt|nbsp|#x0*(3[CcEe]|[Aa]0)|#0*(60|62|160));/', + $url, + $m2, + PREG_OFFSET_CAPTURE + ) ) { $trail = substr( $url, $m2[0][1] ) . $trail; $url = substr( $url, 0, $m2[0][1] ); } diff --git a/includes/parser/ParserCache.php b/includes/parser/ParserCache.php index abff543510..c03b5c2112 100644 --- a/includes/parser/ParserCache.php +++ b/includes/parser/ParserCache.php @@ -226,11 +226,17 @@ class ParserCache { wfIncrStats( "pcache.miss.revid" ); $revId = $article->getLatest(); $cachedRevId = $value->getCacheRevisionId(); - wfDebug( "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n" ); + wfDebug( + "ParserOutput key is for an old revision, latest $revId, cached $cachedRevId\n" + ); $value = false; - } elseif ( Hooks::run( 'RejectParserCacheValue', array( $value, $wikiPage, $popts ) ) === false ) { + } elseif ( + Hooks::run( 'RejectParserCacheValue', array( $value, $wikiPage, $popts ) ) === false + ) { wfIncrStats( 'pcache.miss.rejected' ); - wfDebug( "ParserOutput key valid, but rejected by RejectParserCacheValue hook handler.\n" ); + wfDebug( + "ParserOutput key valid, but rejected by RejectParserCacheValue hook handler.\n" + ); $value = false; } else { wfIncrStats( "pcache.hit" ); @@ -284,7 +290,10 @@ class ParserCache { // ...and its pointer $this->mMemc->set( $this->getOptionsKey( $page ), $optionsKey, $expire ); - Hooks::run( 'ParserCacheSaveComplete', array( $this, $parserOutput, $page->getTitle(), $popts, $revId ) ); + Hooks::run( + 'ParserCacheSaveComplete', + array( $this, $parserOutput, $page->getTitle(), $popts, $revId ) + ); } else { wfDebug( "Parser output was marked as uncacheable and has not been saved.\n" ); } diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index 1073aed817..e6d5274726 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -831,8 +831,8 @@ class ParserOptions { } /** - * Sets a hook to force that a page exists, and sets a current revision callback to return a - * revision with custom content when the current revision of the page is requested. + * Sets a hook to force that a page exists, and sets a current revision callback to return + * a revision with custom content when the current revision of the page is requested. * * @since 1.25 * @param Title $title @@ -841,20 +841,25 @@ class ParserOptions { * @return ScopedCallback to unset the hook */ public function setupFakeRevision( $title, $content, $user ) { - $oldCallback = $this->setCurrentRevisionCallback( function ( $titleToCheck, $parser = false ) use ( $title, $content, $user, &$oldCallback ) { - if ( $titleToCheck->equals( $title ) ) { - return new Revision( array( - 'page' => $title->getArticleID(), - 'user_text' => $user->getName(), - 'user' => $user->getId(), - 'parent_id' => $title->getLatestRevId(), - 'title' => $title, - 'content' => $content - ) ); - } else { - return call_user_func( $oldCallback, $titleToCheck, $parser ); + $oldCallback = $this->setCurrentRevisionCallback( + function ( + $titleToCheck, $parser = false ) use ( $title, $content, $user, &$oldCallback + ) { + if ( $titleToCheck->equals( $title ) ) { + return new Revision( array( + 'page' => $title->getArticleID(), + 'user_text' => $user->getName(), + 'user' => $user->getId(), + 'parent_id' => $title->getLatestRevId(), + 'title' => $title, + 'content' => $content + ) ); + } else { + return call_user_func( $oldCallback, $titleToCheck, $parser ); + } } - } ); + ); + global $wgHooks; $wgHooks['TitleExists'][] = function ( $titleToCheck, &$exists ) use ( $title ) { -- 2.20.1