X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=blobdiff_plain;f=includes%2FOutputPage.php;h=eee879ce6666ad67ce247f197f939d1e6f6764bb;hb=3a2853e218acb586a00f2e59638de4176aee287f;hp=76bfaa26f9f366e4a6046f9776723002c9589e28;hpb=69ae945e8d39972a07bea89ddb64bc0189b43ac2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 76bfaa26f9..eee879ce66 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -21,6 +21,7 @@ */ use MediaWiki\Logger\LoggerFactory; +use MediaWiki\MediaWikiServices; use MediaWiki\Session\SessionManager; use WrappedString\WrappedString; use WrappedString\WrappedStringList; @@ -107,7 +108,10 @@ class OutputPage extends ContextSource { protected $mCategoryLinks = []; /** @var array */ - protected $mCategories = []; + protected $mCategories = [ + 'hidden' => [], + 'normal' => [], + ]; /** @var array */ protected $mIndicators = []; @@ -295,9 +299,6 @@ class OutputPage extends ContextSource { */ private $copyrightUrl; - /** @var array Profiling data */ - private $limitReportData = []; - /** * Constructor for OutputPage. This should not be called directly. * Instead a new RequestContext should be created and it will implicitly create @@ -1010,8 +1011,9 @@ class OutputPage extends ContextSource { if ( $title->isRedirect() ) { $query['redirect'] = 'no'; } + $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); return wfMessage( 'backlinksubtitle' ) - ->rawParams( Linker::link( $title, null, [], $query ) ); + ->rawParams( $linkRenderer->makeLink( $title, null, [], $query ) ); } /** @@ -1252,31 +1254,7 @@ class OutputPage extends ContextSource { return; } - # Add the links to a LinkBatch - $arr = [ NS_CATEGORY => $categories ]; - $lb = new LinkBatch; - $lb->setArray( $arr ); - - # Fetch existence plus the hiddencat property - $dbr = wfGetDB( DB_REPLICA ); - $fields = array_merge( - LinkCache::getSelectFields(), - [ 'page_namespace', 'page_title', 'pp_value' ] - ); - - $res = $dbr->select( [ 'page', 'page_props' ], - $fields, - $lb->constructSet( 'page', $dbr ), - __METHOD__, - [], - [ 'page_props' => [ 'LEFT JOIN', [ - 'pp_propname' => 'hiddencat', - 'pp_page = page_id' - ] ] ] - ); - - # Add the results to the link cache - $lb->addResultToCache( LinkCache::singleton(), $res ); + $res = $this->addCategoryLinksToLBAndGetResult( $categories ); # Set all the values to 'normal'. $categories = array_fill_keys( array_keys( $categories ), 'normal' ); @@ -1293,6 +1271,7 @@ class OutputPage extends ContextSource { 'OutputPageMakeCategoryLinks', [ &$this, $categories, &$this->mCategoryLinks ] ) ) { + $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); foreach ( $categories as $category => $type ) { // array keys will cast numeric category names to ints, so cast back to string $category = (string)$category; @@ -1306,12 +1285,46 @@ class OutputPage extends ContextSource { continue; } $text = $wgContLang->convertHtml( $title->getText() ); - $this->mCategories[] = $title->getText(); - $this->mCategoryLinks[$type][] = Linker::link( $title, $text ); + $this->mCategories[$type][] = $title->getText(); + $this->mCategoryLinks[$type][] = $linkRenderer->makeLink( $title, new HtmlArmor( $text ) ); } } } + /** + * @param array $categories + * @return bool|ResultWrapper + */ + protected function addCategoryLinksToLBAndGetResult( array $categories ) { + # Add the links to a LinkBatch + $arr = [ NS_CATEGORY => $categories ]; + $lb = new LinkBatch; + $lb->setArray( $arr ); + + # Fetch existence plus the hiddencat property + $dbr = wfGetDB( DB_REPLICA ); + $fields = array_merge( + LinkCache::getSelectFields(), + [ 'page_namespace', 'page_title', 'pp_value' ] + ); + + $res = $dbr->select( [ 'page', 'page_props' ], + $fields, + $lb->constructSet( 'page', $dbr ), + __METHOD__, + [], + [ 'page_props' => [ 'LEFT JOIN', [ + 'pp_propname' => 'hiddencat', + 'pp_page = page_id' + ] ] ] + ); + + # Add the results to the link cache + $lb->addResultToCache( LinkCache::singleton(), $res ); + + return $res; + } + /** * Reset the category links (but not the category list) and add $categories * @@ -1335,12 +1348,26 @@ class OutputPage extends ContextSource { } /** - * Get the list of category names this page belongs to + * Get the list of category names this page belongs to. * + * @param string $type The type of categories which should be returned. Possible values: + * * all: all categories of all types + * * hidden: only the hidden categories + * * normal: all categories, except hidden categories * @return array Array of strings */ - public function getCategories() { - return $this->mCategories; + public function getCategories( $type = 'all' ) { + if ( $type === 'all' ) { + $allCategories = []; + foreach ( $this->mCategories as $categories ) { + $allCategories = array_merge( $allCategories, $categories ); + } + return $allCategories; + } + if ( !isset( $this->mCategories[$type] ) ) { + throw new InvalidArgumentException( 'Invalid category type given: ' . $type ); + } + return $this->mCategories[$type]; } /** @@ -1775,16 +1802,11 @@ class OutputPage extends ContextSource { } } - // Enable OOUI if requested via ParserOutput + // enable OOUI if requested via ParserOutput if ( $parserOutput->getEnableOOUI() ) { $this->enableOOUI(); } - // Include profiling data - if ( !$this->limitReportData ) { - $this->setLimitReportData( $parserOutput->getLimitReportData() ); - } - // Link flags are ignored for now, but may in the future be // used to mark individual language links. $linkFlags = []; @@ -2281,7 +2303,7 @@ class OutputPage extends ContextSource { $response->header( "Content-Type: text/html; charset=utf-8" ); if ( $config->get( 'DebugRedirects' ) ) { $url = htmlspecialchars( $redirect ); - print "\n\nRedirect\n\n\n"; + print "\n\n\nRedirect\n\n\n"; print "

Location: $url

\n"; print "\n\n"; } else { @@ -2634,8 +2656,10 @@ class OutputPage extends ContextSource { * @param array $options Options array to pass to Linker */ public function addReturnTo( $title, array $query = [], $text = null, $options = [] ) { + $linkRenderer = MediaWikiServices::getInstance() + ->getLinkRendererFactory()->createFromLegacyOptions( $options ); $link = $this->msg( 'returnto' )->rawParams( - Linker::link( $title, $text, [], $query, $options ) )->escaped(); + $linkRenderer->makeLink( $title, $text, [], $query ) )->escaped(); $this->addHTML( "

{$link}

\n" ); } @@ -2716,7 +2740,6 @@ class OutputPage extends ContextSource { 'site.styles', 'noscript', 'user.styles', - 'user.cssprefs', ] ); $this->getSkin()->setupSkinUserCss( $this ); @@ -2829,6 +2852,14 @@ class OutputPage extends ContextSource { $bodyClasses[] = $userdir; $bodyClasses[] = "sitedir-$sitedir"; + $underline = $this->getUser()->getOption( 'underline' ); + if ( $underline < 2 ) { + // The following classes can be used here: + // * mw-underline-always + // * mw-underline-never + $bodyClasses[] = 'mw-underline-' . ( $underline ? 'always' : 'never' ); + } + if ( $this->getLanguage()->capitalizeAllNouns() ) { # A class is probably not the best way to do this . . . $bodyClasses[] = 'capitalize-all-nouns'; @@ -2966,15 +2997,6 @@ class OutputPage extends ContextSource { } } - if ( $this->limitReportData ) { - $chunks[] = ResourceLoader::makeInlineScript( - ResourceLoader::makeConfigSetScript( - [ 'wgPageParseReport' => $this->limitReportData ], - true - ) - ); - } - return self::combineWrappedStrings( $chunks ); } @@ -3876,12 +3898,4 @@ class OutputPage extends ContextSource { 'mediawiki.widgets.styles', ] ); } - - /** - * @param array $data Data from ParserOutput::getLimitReportData() - * @since 1.28 - */ - public function setLimitReportData( array $data ) { - $this->limitReportData = $data; - } }