From: jenkins-bot Date: Wed, 29 Aug 2018 16:25:22 +0000 (+0000) Subject: Merge "Apply content wrapping in ParserOutput::getText()" X-Git-Tag: 1.34.0-rc.0~4261 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/supprimer.php?a=commitdiff_plain;h=ba6c8274856d34f9e524ce66e707f19555c31f1f;hp=-c;p=lhc%2Fweb%2Fwiklou.git Merge "Apply content wrapping in ParserOutput::getText()" --- ba6c8274856d34f9e524ce66e707f19555c31f1f diff --combined includes/parser/Parser.php index 78265e830d,47f81e612a..c1f86b63bd --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@@ -517,7 -517,7 +517,7 @@@ class Parser # with CSS (T37247) $class = $this->mOptions->getWrapOutputClass(); if ( $class !== false && !$this->mOptions->getInterfaceMessage() ) { - $text = Html::rawElement( 'div', [ 'class' => $class ], $text ); + $this->mOutput->addWrapperDivClass( $class ); } $this->mOutput->setText( $text ); @@@ -3783,68 -3783,57 +3783,68 @@@ * Transclude an interwiki link. * * @param Title $title - * @param string $action + * @param string $action Usually one of (raw, render) * * @return string */ public function interwikiTransclude( $title, $action ) { - global $wgEnableScaryTranscluding; + global $wgEnableScaryTranscluding, $wgTranscludeCacheExpiry; if ( !$wgEnableScaryTranscluding ) { return wfMessage( 'scarytranscludedisabled' )->inContentLanguage()->text(); } $url = $title->getFullURL( [ 'action' => $action ] ); - - if ( strlen( $url ) > 255 ) { + if ( strlen( $url ) > 1024 ) { return wfMessage( 'scarytranscludetoolong' )->inContentLanguage()->text(); } - return $this->fetchScaryTemplateMaybeFromCache( $url ); - } - /** - * @param string $url - * @return mixed|string - */ - public function fetchScaryTemplateMaybeFromCache( $url ) { - global $wgTranscludeCacheExpiry; - $dbr = wfGetDB( DB_REPLICA ); - $tsCond = $dbr->timestamp( time() - $wgTranscludeCacheExpiry ); - $obj = $dbr->selectRow( 'transcache', [ 'tc_time', 'tc_contents' ], - [ 'tc_url' => $url, "tc_time >= " . $dbr->addQuotes( $tsCond ) ] ); - if ( $obj ) { - return $obj->tc_contents; - } - - $req = MWHttpRequest::factory( $url, [], __METHOD__ ); - $status = $req->execute(); // Status object - if ( $status->isOK() ) { - $text = $req->getContent(); - } elseif ( $req->getStatus() != 200 ) { + $wikiId = $title->getTransWikiID(); // remote wiki ID or false + + $fname = __METHOD__; + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); + + $data = $cache->getWithSetCallback( + $cache->makeGlobalKey( + 'interwiki-transclude', + ( $wikiId !== false ) ? $wikiId : 'external', + sha1( $url ) + ), + $wgTranscludeCacheExpiry, + function ( $oldValue, &$ttl ) use ( $url, $fname, $cache ) { + $req = MWHttpRequest::factory( $url, [], $fname ); + + $status = $req->execute(); // Status object + if ( !$status->isOK() ) { + $ttl = $cache::TTL_UNCACHEABLE; + } elseif ( $req->getResponseHeader( 'X-Database-Lagged' ) !== null ) { + $ttl = min( $cache::TTL_LAGGED, $ttl ); + } + + return [ + 'text' => $status->isOK() ? $req->getContent() : null, + 'code' => $req->getStatus() + ]; + }, + [ + 'checkKeys' => ( $wikiId !== false ) + ? [ $cache->makeGlobalKey( 'interwiki-page', $wikiId, $title->getDBkey() ) ] + : [], + 'pcGroup' => 'interwiki-transclude:5', + 'pcTTL' => $cache::TTL_PROC_LONG + ] + ); + + if ( is_string( $data['text'] ) ) { + $text = $data['text']; + } elseif ( $data['code'] != 200 ) { // Though we failed to fetch the content, this status is useless. - return wfMessage( 'scarytranscludefailed-httpstatus' ) - ->params( $url, $req->getStatus() /* HTTP status */ )->inContentLanguage()->text(); + $text = wfMessage( 'scarytranscludefailed-httpstatus' ) + ->params( $url, $data['code'] )->inContentLanguage()->text(); } else { - return wfMessage( 'scarytranscludefailed', $url )->inContentLanguage()->text(); + $text = wfMessage( 'scarytranscludefailed', $url )->inContentLanguage()->text(); } - $dbw = wfGetDB( DB_MASTER ); - $dbw->replace( 'transcache', [ 'tc_url' ], [ - 'tc_url' => $url, - 'tc_time' => $dbw->timestamp( time() ), - 'tc_contents' => $text - ] ); return $text; }