summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
52017fa)
Right now, getInlineHeadScripts(), buildCssLinks() and getExternalHeadScripts()
all return WrappedString::join(). But because they don't know about each other
and because they need to return strings (not arrays), headElement() has no way
of merging them.
WrappedStringList allows this array to be kept, whilst still being backward-compatible
with code that calls these methods and assumig a string (since it will lazy-join
the array if the object is treated like a string).
To be used by I8b6c6a10d965e7396. Output is not changed in this commit.
Merely refactoring.
Change-Id: Iae08345473bd93cc0948d51b62c48aeb1ea460a3
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\Session\SessionManager;
use WrappedString\WrappedString;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\Session\SessionManager;
use WrappedString\WrappedString;
+use WrappedString\WrappedStringList;
/**
* This class should be covered by a general architecture document which does
/**
* This class should be covered by a general architecture document which does
$userdir = $this->getLanguage()->getDir();
$sitedir = $wgContLang->getDir();
$userdir = $this->getLanguage()->getDir();
$sitedir = $wgContLang->getDir();
- $ret = Html::htmlHeader( $sk->getHtmlElementAttributes() );
+ $pieces = [];
+ $pieces[] = Html::htmlHeader( $sk->getHtmlElementAttributes() );
if ( $this->getHTMLTitle() == '' ) {
$this->setHTMLTitle( $this->msg( 'pagetitle', $this->getPageTitle() )->inContentLanguage() );
if ( $this->getHTMLTitle() == '' ) {
$this->setHTMLTitle( $this->msg( 'pagetitle', $this->getPageTitle() )->inContentLanguage() );
$openHead = Html::openElement( 'head' );
if ( $openHead ) {
$openHead = Html::openElement( 'head' );
if ( $openHead ) {
- # Don't bother with the newline if $head == ''
- $ret .= "$openHead\n";
}
if ( !Html::isXmlMimeType( $this->getConfig()->get( 'MimeType' ) ) ) {
}
if ( !Html::isXmlMimeType( $this->getConfig()->get( 'MimeType' ) ) ) {
// 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
// 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
- $ret .= Html::element( 'meta', [ 'charset' => 'UTF-8' ] ) . "\n";
+ $pieces[] = Html::element( 'meta', [ 'charset' => 'UTF-8' ] );
- $ret .= Html::element( 'title', null, $this->getHTMLTitle() ) . "\n";
- $ret .= $this->getInlineHeadScripts() . "\n";
- $ret .= $this->buildCssLinks() . "\n";
- $ret .= $this->getExternalHeadScripts() . "\n";
+ $pieces[] = Html::element( 'title', null, $this->getHTMLTitle() );
+ $pieces[] = $this->getInlineHeadScripts();
+ $pieces[] = $this->buildCssLinks();
+ $pieces[] = $this->getExternalHeadScripts();
foreach ( $this->getHeadLinksArray() as $item ) {
foreach ( $this->getHeadLinksArray() as $item ) {
}
foreach ( $this->mHeadItems as $item ) {
}
foreach ( $this->mHeadItems as $item ) {
}
$closeHead = Html::closeElement( 'head' );
if ( $closeHead ) {
}
$closeHead = Html::closeElement( 'head' );
if ( $closeHead ) {
- $ret .= "$closeHead\n";
+ $pieces[] = $closeHead;
$sk->addToBodyAttributes( $this, $bodyAttrs );
Hooks::run( 'OutputPageBodyAttributes', [ $this, $sk, &$bodyAttrs ] );
$sk->addToBodyAttributes( $this, $bodyAttrs );
Hooks::run( 'OutputPageBodyAttributes', [ $this, $sk, &$bodyAttrs ] );
- $ret .= Html::openElement( 'body', $bodyAttrs ) . "\n";
+ $pieces[] = Html::openElement( 'body', $bodyAttrs );
+ return WrappedStringList::join( "\n", $pieces );
/**
* Build html output from an array of links from makeResourceLoaderLink.
* @param array $links
/**
* Build html output from an array of links from makeResourceLoaderLink.
* @param array $links
+ * @return string|WrappedStringList HTML
*/
protected static function getHtmlFromLoaderLinks( array $links ) {
$html = [];
*/
protected static function getHtmlFromLoaderLinks( array $links ) {
$html = [];
// Filter out empty values
$html = array_filter( $html, 'strlen' );
// Filter out empty values
$html = array_filter( $html, 'strlen' );
- if ( count( $states ) ) {
array_unshift( $html, ResourceLoader::makeInlineScript(
ResourceLoader::makeLoaderStateScript( $states )
) );
array_unshift( $html, ResourceLoader::makeInlineScript(
ResourceLoader::makeLoaderStateScript( $states )
) );
- * <script src="..."> tags for "<head>". This is the startup module
+ * <script src="..."> tags for "<head>".This is the startup module
* and other modules marked with position 'top'.
*
* and other modules marked with position 'top'.
*
- * @return string HTML fragment
+ * @return string|WrappedStringList HTML
*/
function getExternalHeadScripts() {
*/
function getExternalHeadScripts() {
// Startup - this provides the client with the module
// manifest and loads jquery and mediawiki base modules
// Startup - this provides the client with the module
// manifest and loads jquery and mediawiki base modules
$links[] = $this->makeResourceLoaderLink( 'startup', ResourceLoaderModule::TYPE_SCRIPTS );
$links[] = $this->makeResourceLoaderLink( 'startup', ResourceLoaderModule::TYPE_SCRIPTS );
return self::getHtmlFromLoaderLinks( $links );
}
/**
return self::getHtmlFromLoaderLinks( $links );
}
/**
- * <script>...</script> tags to put in "<head>".
+ * Inline "<script>" tags to put in "<head>".
- * @return string HTML fragment
+ * @return string|WrappedStringList HTML
*/
function getInlineHeadScripts() {
$links = [];
*/
function getInlineHeadScripts() {
$links = [];
*
* @param bool $unused Previously used to let this method change its output based
* on whether it was called by getExternalHeadScripts() or getBottomScripts().
*
* @param bool $unused Previously used to let this method change its output based
* on whether it was called by getExternalHeadScripts() or getBottomScripts().
+ * @return string|WrappedStringList HTML
*/
function getScriptsForBottomQueue( $unused = null ) {
// Scripts "only" requests marked for bottom inclusion
*/
function getScriptsForBottomQueue( $unused = null ) {
// Scripts "only" requests marked for bottom inclusion
- * Build a set of "<link>" elements for the stylesheets specified in the $this->styles array.
- * These will be applied to various media & IE conditionals.
+ * Build a set of "<link>" elements for stylesheets specified in the $this->styles array.
+ * @return string|WrappedStringList HTML
*/
public function buildCssLinks() {
global $wgContLang;
*/
public function buildCssLinks() {
global $wgContLang;
}
// Add stuff in $otherTags (previewed user CSS if applicable)
}
// Add stuff in $otherTags (previewed user CSS if applicable)
- return self::getHtmlFromLoaderLinks( $links ) . implode( '', $otherTags );
+ $links[] = implode( '', $otherTags );
+
+ return self::getHtmlFromLoaderLinks( $links );