Wikia code/includes/OutputPage.php
Appearance
< Wikia code | includes
This page is obsolete. It is being retained for archival purposes. It may document extensions or features that are obsolete and/or no longer supported. Do not rely on the information here being up-to-date. The information shown below refers to the now unmaintained 1.16 MediaWiki release. The current stable release number is 1.42.3. |
--- D:\Programming\SVN\mediawiki\branches\REL1_16\phase3\includes\OutputPage.php 2011-07-18 22:31:28.136718800 +0100
+++ D:\Programming\SVN\wikia\trunk\includes\OutputPage.php 2011-08-17 15:28:46.499023400 +0100
@@ -34,6 +34,7 @@
var $mNewSectionLink = false;
var $mHideNewSectionLink = false;
var $mNoGallery = false;
+ var $mRedirectsEnabled = true;
var $mPageTitleActionText = '';
var $mParseWarnings = array();
var $mSquidMaxage = 0;
@@ -50,8 +51,10 @@
/**
* Whether to load jQuery core.
+ *
+ * Wikia change: jQuery is a part of StaticChute
*/
- protected $mJQueryDone = false;
+ protected $mJQueryDone = true;
private $mIndexPolicy = 'index';
private $mFollowPolicy = 'follow';
@@ -68,6 +71,12 @@
$this->mAllowUserJs = $wgAllowUserJs;
}
+ public function enableRedirects($state = true) {
+ $returnval = $this->mRedirectsEnabled;
+ $this->mRedirectsEnabled = $state;
+ return $returnval;
+ }
+
/**
* Redirect to $url rather than displaying the normal page
*
@@ -75,9 +84,18 @@
* @param $responsecode String: HTTP status code
*/
public function redirect( $url, $responsecode = '302' ) {
+ if( !$this->mRedirectsEnabled ) {
+ return false;
+ }
+
# Strip newlines as a paranoia check for header injection in PHP<5.1.2
$this->mRedirect = str_replace( "\n", '', $url );
$this->mRedirectCode = $responsecode;
+
+ # Cache permanent redirects for 20 minutes, see rt#18297
+ if( $responsecode == '301' ) {
+ $this->setSquidMaxage( 1200 );
+ }
}
/**
@@ -102,7 +120,8 @@
/**
* Add a new <meta> tag
- * To add an http-equiv meta tag, precede the name with "http:"
+ * To add an http-equiv meta tag, precede the name with "http:".
+ * To add an Open Graph meta tag, precede the name with "property:".
*
* @param $name tag name
* @param $val tag value
@@ -413,6 +432,19 @@
}
}
+ public function getWikiaPageTitle( $name ) {
+ $msgPagetitle = wfMsg( 'pagetitle', $name );
+ if( $msgPagetitle == '#wikiapagetitle#' ) {
+ global $wgSitename;
+ if( $name == wfMsgForContent( 'mainpage' ) ) {
+ return $wgSitename;
+ } else {
+ return "$name - $wgSitename";
+ }
+ } else {
+ return $msgPagetitle;
+ }
+ }
/**
* Set the new value of the "action text", this will be added to the
@@ -442,13 +474,10 @@
* but if it is not from page title, it can override all other names.
*/
public function setHTMLTitle( $name, $frompagetitle = false ) {
- if ( $frompagetitle && $this->mHTMLtitleFromPagetitle ) {
- $this->mHTMLtitle = $name;
- }
- elseif ( $this->mHTMLtitleFromPagetitle ) {
+ /* Wikia change start */
+ //Fix FB#1672, change extracted from http://www.mediawiki.org/wiki/Special:Code/MediaWiki/64876
$this->mHTMLtitle = $name;
- $this->mHTMLtitleFromPagetitle = false;
- }
+ /* Wikia change end */
}
/**
@@ -1081,6 +1110,12 @@
$this->mNewSectionLink = $parserOutput->getNewSection();
$this->mHideNewSectionLink = $parserOutput->getHideNewSection();
+ /* Wikia change start
+ * @author tor
+ * re-added default keywords
+ */
+ $this->addKeywords( $parserOutput );
+ /* Wikia change end */
$this->mParseWarnings = $parserOutput->getWarnings();
if ( $parserOutput->getCacheTime() == -1 ) {
$this->enableClientCache( false );
@@ -1096,10 +1131,15 @@
}
}
// Page title
+ /* Wikia change start */
+ //Commented out, Fix FB#1672, change extracted from http://www.mediawiki.org/wiki/Special:Code/MediaWiki/64876
+ /*
$title = $parserOutput->getTitleText();
if ( $title != '' ) {
$this->setPageTitle( $title );
}
+ */
+ /* Wikia change end */
// Hooks registered in the object
global $wgParserOutputHooks;
@@ -1442,9 +1482,14 @@
# In general, the absence of a last modified header should be enough to prevent
# the client from using its cache. We send a few other things just to make sure.
- $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
- $response->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
- $response->header( 'Pragma: no-cache' );
+ if(session_id() == '') {
+ if($this->mLastModified) $wgRequest->response()->header( "Last-modified: {$this->mLastModified}" );
+ $wgRequest->response()->header( 'Cache-Control: s-maxage=30, must-revalidate, max-age=0' );
+ } else {
+ $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
+ $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
+ $wgRequest->response()->header( 'Pragma: no-cache' );
+ }
}
}
@@ -1554,18 +1599,28 @@
$sk = $wgUser->getSkin();
if ( $wgUseAjax ) {
+ // macbre: following files are part of merged JS for following skins - don't load them from here
+ $skinName = get_class($sk);
+ $skipWikiaSkins = array('SkinMonoBook', 'SkinUncyclopedia', 'SkinMonaco', 'SkinAnswers', 'SkinCorporate', 'SkinCorporateHome', 'SkinCorporateHubs', 'SkinLyricsMinimal', 'SkinOasis');
+
+ if (!in_array($skinName, $skipWikiaSkins)) {
$this->addScriptFile( 'ajax.js' );
+ }
wfRunHooks( 'AjaxAddScript', array( &$this ) );
+ if (!in_array($skinName, $skipWikiaSkins)) {
if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
$this->addScriptFile( 'ajaxwatch.js' );
}
+ }
+ if (!in_array($skinName, $skipWikiaSkins)) {
if ( $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
$this->addScriptFile( 'mwsuggest.js' );
}
}
+ }
if( $wgUser->getBoolOption( 'editsectiononrightclick' ) ) {
$this->addScriptFile( 'rightclickedit.js' );
@@ -1617,6 +1672,7 @@
}
$this->sendCacheControl();
+ wfSendTimerHeader(); // Wikia change -- emit X-Timer: header
ob_end_flush();
wfProfileOut( __METHOD__ );
}
@@ -1847,12 +1903,19 @@
$this->setRobotPolicy( 'noindex,nofollow' );
$this->setArticleFlag( false );
+ $returnToQueryValues = $_GET;
+ if(isset($returnToQueryValues['title'])){
+ unset($returnToQueryValues['title']);
+ }
$loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
$loginLink = $skin->link(
$loginTitle,
wfMsgHtml( 'loginreqlink' ),
- array(),
- array( 'returnto' => $this->getTitle()->getPrefixedText() ),
+ array( 'rel' => 'nofollow' ),
+ array(
+ 'returnto' => $this->getTitle()->getPrefixedText(),
+ 'returntoquery' => wfArrayToCGI( $returnToQueryValues )
+ ),
array( 'known', 'noclasses' )
);
$this->addHTML( wfMsgWikiHtml( 'loginreqpagetext', $loginLink ) );
@@ -2069,6 +2132,7 @@
*
* @param $title Title to link
* @param $query String: query string
+ * @param string $query Query string
*/
public function addReturnTo( $title, $query = array() ) {
global $wgUser;
@@ -2103,6 +2167,10 @@
if ( is_object( $returnto ) ) {
$titleObj = $returnto;
+ } else if ( $returnto == '/forum' ) {
+ // macbre: fix to enable redirect back to forum after log in (requested by JohnQ)
+ $this->redirect( '/forum' );
+ $this->output();
} else {
$titleObj = Title::newFromText( $returnto );
}
@@ -2113,6 +2181,26 @@
$this->addReturnTo( $titleObj, $returntoquery );
}
+ private function addKeywords( &$parserOutput ) {
+ global $wgTitle, $wgSitename, $wgDBname;
+ $this->addKeyword( $wgSitename );
+ $this->addKeyword( $wgDBname );
+ $this->addKeyword( $wgTitle->getPrefixedText() );
+ $count = 1;
+ $links2d =& $parserOutput->getLinks();
+ if ( !is_array( $links2d ) ) {
+ return;
+ }
+ foreach ( $links2d as $dbkeys ) {
+ foreach( $dbkeys as $dbkey => $unused ) {
+ $this->addKeyword( $dbkey );
+ if ( ++$count > 10 ) {
+ break 2;
+ }
+ }
+ }
+ }
+
/**
* @param $sk Skin The given Skin
* @param $includeStyle Unused (?)
@@ -2122,9 +2210,11 @@
global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
global $wgContLang, $wgUseTrackbacks, $wgStyleVersion, $wgHtml5, $wgWellFormedXml;
- global $wgUser, $wgRequest, $wgLang;
+ global $wgUser, $wgRequest, $wgLang, $wgDevelEnvironment;
$this->addMeta( "http:Content-Type", "$wgMimeType; charset={$wgOutputEncoding}" );
+ if( $wgDevelEnvironment ) $this->addMeta( 'robots', 'noindex, nofollow' );
+
if ( $sk->commonPrintStylesheet() ) {
$this->addStyle( 'common/wikiprintable.css', 'print' );
}
@@ -2137,7 +2227,9 @@
}
if ( $this->getHTMLTitle() == '' ) {
- $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
+ wfProfileIn( "parsePageTitle" );
+ $this->setHTMLTitle( $this->getWikiaPageTitle( $this->getPageTitle() ) );
+ wfProfileOut( "parsePageTitle" );
}
$dir = $wgContLang->getDir();
@@ -2214,6 +2306,11 @@
$bodyAttrs['class'] .= ' ' . Sanitizer::escapeClass( 'page-' . $this->getTitle()->getPrefixedText() );
$bodyAttrs['class'] .= ' skin-' . Sanitizer::escapeClass( $wgUser->getSkin()->getSkinName() );
+ /* Wikia change begin - @author: Macbre */
+ /* allow extensions to change body tag attribute (RT #14017) */
+ wfRunHooks( 'SkinGetPageClasses', array( &$bodyAttrs['class'] ) );
+ /* Wikia change end */
+
$ret .= Html::openElement( 'body', $bodyAttrs ) . "\n";
return $ret;
@@ -2231,7 +2328,19 @@
global $wgStylePath, $wgStyleVersion;
$scripts = Skin::makeGlobalVariablesScript( $sk->getSkinName() );
+
+ /* Wikia change begin - @author: Macbre */
+ /* allow old skins to inject JS code before files from MW core (BugId:960) */
+ wfRunHooks('SkinGetHeadScripts', array(&$scripts));
+
+ // wikibits is a part of StaticChute package for monobook - don't load it twice
+ $skinName = get_class($sk);
+ $skipWikiaSkins = array('SkinMonoBook', 'SkinUncyclopedia');
+
+ if (!in_array($skinName, $skipWikiaSkins)) {
$scripts .= Html::linkedScript( "{$wgStylePath}/common/wikibits.js?$wgStyleVersion" );
+ }
+ /* Wikia change end */
//add site JS if enabled:
if( $wgUseSiteJs ) {
@@ -2315,6 +2424,9 @@
if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
$a = 'http-equiv';
$tag[0] = substr( $tag[0], 5 );
+ } else if ( 0 == strcasecmp( 'property:', substr( $tag[0], 0, 9 ) ) ) {
+ $a = 'property';
+ $tag[0] = substr( $tag[0], 9 );
} else {
$a = 'name';
}