From 8f9e12de0ea6e92f662e5f2d4583ae51a0d10914 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Mon, 24 May 2010 16:35:23 +0000 Subject: [PATCH] bug 18608 done in a fashion much closer to how I should've done it originally. Latching onto bug 22061 output Following up r62195 and r61125 --- includes/OutputPage.php | 9 ++++++--- includes/api/ApiParse.php | 32 +++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 9f4d61e8e3..f8acd0b1aa 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2415,15 +2415,18 @@ class OutputPage { * These will be applied to various media & IE conditionals. */ public function buildCssLinks() { + return implode( "\n", $this->buildCssLinksArray() ); + } + + public function buildCssLinksArray() { $links = array(); foreach( $this->styles as $file => $options ) { $link = $this->styleLink( $file, $options ); if( $link ) { - $links[] = $link; + $links[$file] = $link; } } - - return implode( "\n", $links ); + return $links; } /** diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 1c22ceda85..86cadc19f3 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -217,15 +217,26 @@ class ApiParse extends ApiBase { $titleObj->getPrefixedText(); } + if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) { + $out = new OutputPage; + $out->addParserOutputNoText( $p_result ); + $userSkin = $wgUser->getSkin(); + } + if ( isset( $prop['headitems'] ) ) { - $result_array['headitems'] = $this->formatHeadItems( $p_result->getHeadItems() ); + $headItems = $this->formatHeadItems( $p_result->getHeadItems() ); + + $userSkin->setupUserCss( $out ); + $css = $this->formatCss( $out->buildCssLinksArray() ); + + $scripts = array( $out->getHeadScripts( $userSkin ) ); + + $result_array['headitems'] = array_merge( $headItems , $css, $scripts ); } if ( isset( $prop['headhtml'] ) ) { - $out = new OutputPage; - $out->addParserOutputNoText( $p_result ); $result_array['headhtml'] = array(); - $result->setContent( $result_array['headhtml'], $out->headElement( $wgUser->getSkin() ) ); + $result->setContent( $result_array['headhtml'], $out->headElement( $userSkin ) ); } if ( !is_null( $oldid ) ) { @@ -241,7 +252,7 @@ class ApiParse extends ApiBase { 'images' => 'img', 'externallinks' => 'el', 'sections' => 's', - 'headitems' => 'hi' + 'headitems' => 'hi', ); $this->setIndexedTagNames( $result_array, $result_mapping ); $result->addValue( null, $this->getModuleName(), $result_array ); @@ -310,6 +321,17 @@ class ApiParse extends ApiBase { return $result; } + private function formatCss( $css ) { + $result = array(); + foreach ( $css as $file => $link ) { + $entry = array(); + $entry['file'] = $file; + $this->getResult()->setContent( $entry, $link ); + $result[] = $entry; + } + return $result; + } + private function setIndexedTagNames( &$array, $mapping ) { foreach ( $mapping as $key => $name ) { if ( isset( $array[$key] ) ) { -- 2.20.1