debug mode: wfMsg, wfMsgNoTrans, wfMsgForContent, wfMsgForContentNoTrans,
wfMsgReal, wfMsgGetKey, wfMsgHtml, wfMsgWikiHtml, wfMsgExt, wfEmptyMsg. Use
the Message class, or the global method wfMessage.
+* Added $wgEnableCanonicalServerLink, off by default. If enabled, a
+ <link rel=canonical> tag is added to every page indicating the correct server
+ to use.
* Debug message emitted by wfDebugLog() will now be prefixed with the group
name when its logged to the default log file. That is the case whenever the
group has no key in wgDebugLogGroups, that will help triage the default log.
}
// Add a <link rel="canonical"> tag
- $outputPage->addLink( array( 'rel' => 'canonical',
- 'href' => $this->getTitle()->getLocalURL() )
- );
+ $outputPage->setCanonicalUrl( $this->getTitle()->getLocalURL() );
// Tell the output object that the user arrived at this article through a redirect
$outputPage->setRedirectedFrom( $this->mRedirectedFrom );
/** Whether to enable language variant conversion for links. */
$wgDisableTitleConversion = false;
-/** Whether to enable cononical language links in meta data. */
+/** Whether to enable canonical language links in meta data. */
$wgCanonicalLanguageLinks = true;
/** Default variant code, if false, the default will be the language code */
*/
$wgShowRollbackEditCount = 10;
+/**
+ * Output a <link rel="canonical"> tag on every page indicating the canonical
+ * server which should be used, i.e. $wgServer or $wgCanonicalServer. Since
+ * detection of the current server is unreliable, the link is sent
+ * unconditionally.
+ */
+$wgEnableCanonicalServerLink = false;
+
/** @} */ # End of output format settings }
/*************************************************************************//**
/* Add canonical to head if there is no local page for this shared file */
if( $descUrl && $this->mPage->getID() == 0 ) {
- $out->addLink( array( 'rel' => 'canonical', 'href' => $descUrl ) );
+ $out->setCanonicalUrl( $descUrl );
}
$wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
var $mKeywords = array();
var $mLinktags = array();
+ var $mCanonicalUrl = false;
/// Additional stylesheets. Looks like this is for extensions. Might be replaced by resource loader.
var $mExtStyles = array();
}
/**
- * Add a new \<link\> tag to the page header
+ * Add a new \<link\> tag to the page header.
+ *
+ * Note: use setCanonicalUrl() for rel=canonical.
*
* @param $linkarr Array: associative array of attributes.
*/
$this->addLink( $linkarr );
}
+ /**
+ * Set the URL to be used for the <link rel=canonical>. This should be used
+ * in preference to addLink(), to avoid duplicate link tags.
+ */
+ function setCanonicalUrl( $url ) {
+ $this->mCanonicalUrl = $url;
+ }
+
/**
* Get the value of the "rel" attribute for metadata links
*
$tags = array();
+ $canonicalUrl = $this->mCanonicalUrl;
+
if ( $addContentType ) {
if ( $wgHtml5 ) {
# More succinct than <meta http-equiv=Content-Type>, has the
);
}
} else {
- $tags['canonical'] = Html::element( 'link', array(
- 'rel' => 'canonical',
- 'href' => $this->getTitle()->getCanonicalUrl()
- ) );
+ $canonicalUrl = $this->getTitle()->getLocalURL();
}
}
}
}
}
}
+
+ # Canonical URL
+ global $wgEnableCanonicalServerLink;
+ if ( $wgEnableCanonicalServerLink ) {
+ if ( $canonicalUrl !== false ) {
+ $canonicalUrl = wfExpandUrl( $canonicalUrl, PROTO_CANONICAL );
+ } else {
+ $reqUrl = $this->getRequest()->getRequestURL();
+ $canonicalUrl = wfExpandUrl( $reqUrl, PROTO_CANONICAL );
+ }
+ }
+ if ( $canonicalUrl !== false ) {
+ $tags[] = Html::element( 'link', array(
+ 'rel' => 'canonical',
+ 'href' => $canonicalUrl
+ ) );
+ }
+
return $tags;
}