var $mScriptLoaderClassList = array();
// the most recent id of any script that is grouped in the script request
- var $mLatestScriptRevID = 0;
+ var $mLatestScriptRevID = 0;
var $mScripts = '', $mLinkColours, $mPageLinkTitle = '', $mHeadItems = array();
var $mTemplateIds = array();
array_push( $this->mKeywords, $text );
}
}
- function addScript( $script ) { $this->mScripts .= "\t\t" . $script . "\n"; }
+ function addScript( $script ) {
+ $this->mScripts .= "\t\t" . $script . "\n";
+ }
- function addExtensionStyle( $url ) {
- $linkarr = array( 'rel' => 'stylesheet', 'href' => $url, 'type' => 'text/css' );
- array_push( $this->mExtStyles, $linkarr );
+ /**
+ * Register and add a stylesheet from an extension directory.
+ * @param $url String path to sheet. Provide either a full url (beginning
+ * with 'http', etc) or a relative path from the document root
+ * (beginning with '/'). Otherwise it behaves identically to
+ * addStyle() and draws from the /skins folder.
+ */
+ public function addExtensionStyle( $url ) {
+ array_push( $this->mExtStyles, $url );
}
/**
* @param string $file filename in skins/common or complete on-server path (/foo/bar.js)
*/
function addScriptFile( $file ) {
- global $wgStylePath, $wgStyleVersion, $wgJsMimeType, $wgScript, $wgUser;
+ global $wgStylePath, $wgScript, $wgUser;
global $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $wgEnableScriptLoader, $wgScriptPath;
if( substr( $file, 0, 1 ) == '/' ) {
if( $wgEnableScriptLoader ){
if( strpos( $path, $wgScript ) !== false ){
$reqPath = str_replace( $wgScript . '?', '', $path );
- $reqArgs = split( '&', $reqPath );
+ $reqArgs = explode( '&', $reqPath );
$reqSet = array();
foreach( $reqArgs as $arg ){
- list( $key, $var ) = split( '=', $arg );
+ list( $key, $var ) = explode( '=', $arg );
$reqSet[$key] = $var;
}
// add the title revision to the key
$t = Title::newFromText( $reqSet['title'] );
// if there is no title (don't worry we just use the $wgStyleVersion var (which should be updated on relevant commits)
- if( $t->exists() ){
+ if( $t && $t->exists() ){
if( $t->getLatestRevID() > $this->mLatestScriptRevID )
$this->mLatestScriptRevID = $t->getLatestRevID();
}
}
// if the script loader did not find a way to add the script than add using addScript
- $this->addScript(
- Xml::element( 'script',
- array(
- 'type' => $wgJsMimeType,
- 'src' => "$path?" . $this->getURIDparam(),
- ),
- '', false
- )
- );
+ $this->addScript( Html::linkedScript( wfAppendQuery( $path, $this->getURIDparam() ) ) );
}
/**
* different page load types (edit, upload, view, etc)
*/
function addCoreScripts2Top(){
- global $wgEnableScriptLoader, $wgStyleVersion, $wgJSAutoloadLocalClasses, $wgJsMimeType, $wgScriptPath, $wgEnableJS2system;
+ global $wgEnableScriptLoader, $wgJSAutoloadLocalClasses, $wgScriptPath, $wgEnableJS2system;
//@@todo we should deprecate wikibits in favor of mv_embed and native jQuery functions
if( $wgEnableJS2system ){
$so = '';
foreach( $core_classes as $s ){
if( isset( $wgJSAutoloadLocalClasses[$s] ) ){
- $so.= Xml::element( 'script', array(
- 'type' => $wgJsMimeType,
- 'src' => "{$wgScriptPath}/{$wgJSAutoloadLocalClasses[$s]}?" . $this->getURIDparam()
- ),
- '', false
- );
+ $so .= Html::linkedScript( "{$wgScriptPath}/{$wgJSAutoloadLocalClasses[$s]}?" . $this->getURIDparam() );
}
}
$this->mScripts = $so . $this->mScripts;
* @return Boolean: false if class wasn't found, true on success
*/
function addScriptClass( $js_class ){
- global $wgJSAutoloadClasses, $wgJSAutoloadLocalClasses, $wgJsMimeType,
+ global $wgDebugJavaScript, $wgJSAutoloadLocalClasses, $wgJSAutoloadClasses,
$wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath;
if( isset( $wgJSAutoloadClasses[$js_class] ) || isset( $wgJSAutoloadLocalClasses[$js_class] ) ){
} else {
// do a normal load of without the script-loader:
$path = $wgScriptPath . '/';
- $path.= isset( $wgJSAutoloadClasses[$js_class] ) ? $wgJSAutoloadClasses[$js_class]:
- $wgJSAutoloadLocalClasses[$js_class];
- $this->addScript(
- Xml::element( 'script',
- array(
- 'type' => $wgJsMimeType,
- 'src' => "$path?$wgStyleVersion",
- ),
- '', false
- )
- );
+ if( isset( $wgJSAutoloadClasses[$js_class] ) ){
+ $path.= $wgJSAutoloadClasses[$js_class];
+ }else if( isset( $wgJSAutoloadLocalClasses[$js_class] ) ){
+ $path.= $wgJSAutoloadLocalClasses[$js_class];
+ }
+ $urlAppend = ( $wgDebugJavaScript ) ? time() : $wgStyleVersion;
+ $this->addScript( Html::linkedScript( "$path?$urlAppend" ) );
}
return true;
}
* @param $forcClassAry Boolean: false by default
*/
function getScriptLoaderJs( $forceClassAry = false ){
- global $wgScriptPath, $wgJsMimeType, $wgStyleVersion, $wgRequest, $wgDebugJavaScript;
+ global $wgRequest, $wgDebugJavaScript;
if( !$forceClassAry ){
$class_list = implode( ',', $this->mScriptLoaderClassList );
//generate the unique request param (combine with the most recent revision id of any wiki page with the $wgStyleVersion var)
-
- return Xml::element( 'script',
- array(
- 'type' => $wgJsMimeType,
- 'src' => "$wgScriptPath/mwScriptLoader.php?class={$class_list}{$debug_param}&".$this->getURIDparam(),
- ),
- '', false
- );
+ return Html::linkedScript( wfScript( 'mwScriptLoader' ) . "?class={$class_list}{$debug_param}&" . $this->getURIDparam() );
}
function getURIDparam(){
* @param string $script JavaScript text, no <script> tags
*/
function addInlineScript( $script ) {
- global $wgJsMimeType;
- $this->mScripts .= "\t\t<script type=\"$wgJsMimeType\">/*<![CDATA[*/\n\t\t$script\n\t\t/*]]>*/</script>\n";
+ $this->mScripts .= "\t\t" . Html::inlineScript( "\n\t\t$script\n\t\t" ) . "\n";
}
function getScript() {
$this->setIndexPolicy( $parserOutput->getIndexPolicy() );
}
- $this->addKeywords( $parserOutput );
$this->mParseWarnings = $parserOutput->getWarnings();
if ( $parserOutput->getCacheTime() == -1 ) {
$this->enableClientCache( false );
}
public function sendCacheControl() {
- global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest;
+ global $wgUseSquid, $wgUseESI, $wgUseETag, $wgSquidMaxage, $wgRequest, $wgUseXVO;
$response = $wgRequest->response();
if ($wgUseETag && $this->mETag)
# maintain different caches for logged-in users and non-logged in ones
$response->header( 'Vary: Accept-Encoding, Cookie' );
- # Add an X-Vary-Options header for Squid with Wikimedia patches
- $response->header( $this->getXVO() );
+ if ( $wgUseXVO ) {
+ # Add an X-Vary-Options header for Squid with Wikimedia patches
+ $response->header( $this->getXVO() );
+ }
if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache ) {
if( $wgUseSquid && session_id() == '' &&
public function output() {
global $wgUser, $wgOutputEncoding, $wgRequest;
global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
- global $wgJsMimeType, $wgUseAjax, $wgAjaxWatch;
+ global $wgUseAjax, $wgAjaxWatch;
global $wgEnableMWSuggest, $wgUniversalEditButton;
global $wgArticle;
* @param Title $title Title to link
* @param string $query Query string
*/
- public function addReturnTo( $title, $query ) {
+ public function addReturnTo( $title, $query = array() ) {
global $wgUser;
$this->addLink( array( 'rel' => 'next', 'href' => $title->getFullUrl() ) );
$link = wfMsgHtml( 'returnto', $wgUser->getSkin()->link(
if ( $returnto == null ) {
$returnto = $wgRequest->getText( 'returnto' );
}
-
+
if ( $returntoquery == null ) {
$returntoquery = $wgRequest->getText( 'returntoquery' );
}
$this->addReturnTo( $titleObj, $returntoquery );
}
- /**
- * This function takes the title (first item of mGoodLinks), categories,
- * existing and broken links for the page
- * and uses the first 10 of them for META keywords
- *
- * @param ParserOutput &$parserOutput
- */
- private function addKeywords( &$parserOutput ) {
- global $wgContLang;
- // Get an array of keywords if there are more than one
- // variant of the site language
- $text = $wgContLang->autoConvertToAllVariants( $this->getTitle()->getPrefixedText());
- // array_values: We needn't to merge variant's code name
- // into $this->mKeywords;
- // array_unique: We should insert a keyword just for once
- if( is_array( $text ))
- $text = array_unique( array_values( $text ));
- $this->addKeyword( $text );
- $count = 1;
- $links2d =& $parserOutput->getLinks();
- if ( !is_array( $links2d ) ) {
- return;
- }
- foreach ( $links2d as $dbkeys ) {
- foreach( $dbkeys as $dbkey => $unused ) {
- $dbkey = $wgContLang->autoConvertToAllVariants( $dbkey );
- if( is_array( $dbkey ))
- $dbkey = array_unique( array_values( $dbkey ));
- $this->addKeyword( $dbkey );
- if ( ++$count > 10 ) {
- break 2;
- }
- }
- }
- }
-
/**
* @return string The doctype, opening <html>, and head element.
*/
$ret .= "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
}
- if ( $wgHtml5 ) {
- $ret .= "<!doctype html>\n";
- } else {
- $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
- }
-
if ( '' == $this->getHTMLTitle() ) {
$this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
}
$dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
- $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
- foreach($wgXhtmlNamespaces as $tag => $ns) {
- $ret .= "xmlns:{$tag}=\"{$ns}\" ";
+
+ if ( $wgHtml5 ) {
+ $ret .= "<!doctype html>\n";
+ $ret .= "<html lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
+ } else {
+ $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
+ $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
+ foreach($wgXhtmlNamespaces as $tag => $ns) {
+ $ret .= "xmlns:{$tag}=\"{$ns}\" ";
+ }
+ $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
}
- $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
+
$ret .= "<head>\n\t<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n\t";
$ret .= implode( "\n", array(
$this->getHeadLinks(),
$this->getHeadItems(),
));
if( $sk->usercss ){
- $ret .= "<style type='text/css'>{$sk->usercss}</style>";
+ $ret .= Html::inlineStyle( $sk->usercss );
}
if( $wgEnableScriptLoader )
*/
public function addStyle( $style, $media='', $condition='', $dir='' ) {
$options = array();
+ // In Opera, fullscreen mode is treated as projection mode, and it causes
+ // styles set for screen to not be loaded - thus breaking the page - so
+ // we can just append projection to the media attribute when it's screen
+ // so the browser is happy and - with no side-effects on other browsers.
+ // Also - even though we expect the media type to be lowercase, but here
+ // we force it to lowercase to be safe.
+ if ( strtolower( $media ) == 'screen' )
+ $media .= ',projection';
if( $media )
$options['media'] = $media;
if( $condition )
* @param $style_css Mixed: inline CSS
*/
public function addInlineStyle( $style_css ){
- $this->mScripts .= "<style type=\"text/css\">$style_css</style>";
+ $this->mScripts .= Html::inlineStyle( $style_css );
}
/**
return '';
}
} else {
- $media = '';
+ $media = null;
}
if( substr( $style, 0, 1 ) == '/' ||
$url = $wgStylePath . '/' . $style . '?' . $wgStyleVersion;
}
- $attribs = array(
- 'rel' => 'stylesheet',
- 'href' => $url,
- 'type' => 'text/css' );
- if( $media ) {
- $attribs['media'] = $media;
- }
-
- $link = Xml::element( 'link', $attribs );
+ $link = Html::linkedStyle( $url, $media );
if( isset( $options['condition'] ) ) {
$condition = htmlspecialchars( $options['condition'] );