X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=43d71abca07d0e532c99eeffdc03493204004562;hb=9964ca1a390c446397dcd466916ffed356cdc3c9;hp=bf59c9a5d205f60576bf00f12261ac535c5267e6;hpb=719fcde25741c858fa05039bb21ad4ee163153d1;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputPage.php b/includes/OutputPage.php index bf59c9a5d2..43d71abca0 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -107,7 +107,10 @@ class OutputPage extends ContextSource { protected $mCategoryLinks = []; /** @var array */ - protected $mCategories = []; + protected $mCategories = [ + 'hidden' => [], + 'normal' => [], + ]; /** @var array */ protected $mIndicators = []; @@ -295,9 +298,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 @@ -1214,8 +1214,8 @@ class OutputPage extends ContextSource { /** * Add new language links * - * @param array $newLinkArray Associative array mapping language code to the page - * name + * @param string[] $newLinkArray Array of interwiki-prefixed (non DB key) titles + * (e.g. 'fr:Test page') */ public function addLanguageLinks( array $newLinkArray ) { $this->mLanguageLinks += $newLinkArray; @@ -1224,8 +1224,8 @@ class OutputPage extends ContextSource { /** * Reset the language links and add new language links * - * @param array $newLinkArray Associative array mapping language code to the page - * name + * @param string[] $newLinkArray Array of interwiki-prefixed (non DB key) titles + * (e.g. 'fr:Test page') */ public function setLanguageLinks( array $newLinkArray ) { $this->mLanguageLinks = $newLinkArray; @@ -1234,7 +1234,7 @@ class OutputPage extends ContextSource { /** * Get the list of language links * - * @return array Array of Interwiki Prefixed (non DB key) Titles (e.g. 'fr:Test page') + * @return string[] Array of interwiki-prefixed (non DB key) titles (e.g. 'fr:Test page') */ public function getLanguageLinks() { return $this->mLanguageLinks; @@ -1252,31 +1252,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' ); @@ -1306,12 +1282,46 @@ class OutputPage extends ContextSource { continue; } $text = $wgContLang->convertHtml( $title->getText() ); - $this->mCategories[] = $title->getText(); + $this->mCategories[$type][] = $title->getText(); $this->mCategoryLinks[$type][] = Linker::link( $title, $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 +1345,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]; } /** @@ -1713,7 +1737,6 @@ class OutputPage extends ContextSource { $popts->setTidy( $oldTidy ); $this->addParserOutput( $parserOutput ); - } /** @@ -1776,16 +1799,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 = []; @@ -2811,8 +2829,8 @@ class OutputPage extends ContextSource { // The spec recommends defining XHTML5's charset using the XML declaration // instead of meta. // Our XML declaration is output by Html::htmlHeader. - // http://www.whatwg.org/html/semantics.html#attr-meta-http-equiv-content-type - // http://www.whatwg.org/html/semantics.html#charset + // https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-content-type + // https://html.spec.whatwg.org/multipage/semantics.html#charset $pieces[] = Html::element( 'meta', [ 'charset' => 'UTF-8' ] ); } @@ -2967,15 +2985,6 @@ class OutputPage extends ContextSource { } } - if ( $this->limitReportData ) { - $chunks[] = ResourceLoader::makeInlineScript( - ResourceLoader::makeConfigSetScript( - [ 'wgPageParseReport' => $this->limitReportData ], - true - ) - ); - } - return self::combineWrappedStrings( $chunks ); } @@ -3696,7 +3705,7 @@ class OutputPage extends ContextSource { public static function transformCssMedia( $media ) { global $wgRequest; - // http://www.w3.org/TR/css3-mediaqueries/#syntax + // https://www.w3.org/TR/css3-mediaqueries/#syntax $screenMediaQueryRegex = '/^(?:only\s+)?screen\b/i'; // Switch in on-screen display for media testing @@ -3877,12 +3886,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; - } }