Last modified: 2011-03-13 18:04:30 UTC
The CanonicalHref extension http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/CanonicalHref/CanonicalHref.php does not work with the 1.16svn skins. Attached is a patch that makes it work on my system. Changed the hook and used wgOut->addLink instead of $template->set('headlinks', $template->data['headlinks'] . "\n" . $link . "\n"); Not sure if this is the correct way, but seems to be more compatible than adding \n$link\n to the end of a template section.
Created attachment 6679 [details] diff file for with fixes
rel="canonical" links are produced by MediaWiki 1.16; this extension is obsolete.
I am running rev 57770 from svn, and without this extension I see no rel="canonical" in the outputted source. does it need to be enabled somehow ?
Trust me it's there. :) Article::showRedirectedFromHeader() includes: // Add a <link rel="canonical"> tag $wgOut->addLink( array( 'rel' => 'canonical', 'href' => $this->mTitle->getLocalURL() ) ); Possibilities: 1) you're not looking at a redirected page (if it doesn't say "Redirected from XYZ" in the subtitle space, it's not a redirect view) 2) you're running a release branch that's not 1.16 (revision number that you svn up'd to doesn't tell you what branch your own) 3) you have an extension that overrides ArticleViewRedirect hook and replaces the behavior.
Reopening as enhancement -- apparently reporter wants things other than just redirects labeled, such as views with extra URL parameters that don't affect the display significantly. Apparently at least some subset of these cases is covered by the extension that isn't covered in core; where useful this should be integrated.
the "such as views with extra URL parameters that don't affect the display significantly" is the most important thing to me. this is where I believe not having a canonical url is most damaging when it comes to search rank. I rather have a few places where perhaps it says the canonical url is Foo when infact its the Foo "history" (so they get marked as the same page for hits etc), rather than 18,000 pages all with 5 entry points with no canonical url hint at all. Adding a selective case like this is beyond my knowledge of mediawiki, so I shall continue using the extension + patch.
Note that action=history gives completely different content from a page view; it would be absolutely wrong to emit a rel=canonical link pointing to the article, and we would definitely not do that. (Nor would that be something I'd worry about from an SEO perspective -- who on earth is going to link to article history pages all the time?) It might make sense for an action=history&offset=200908124455 link to point to action=history... but both of them will be marked as not indexable anyway, so there's no point. The cases where we'd realistically want a rel=canonical for things that aren't redirects are probably going to be things like permalinks or links with ?curid from RC patrol etc.
(In reply to comment #7) > who on earth is going to link to article > history pages all the time?) > Something like a source link? This article is copied from <a href="http://link/to/page">some wiki</a>. See its <a href="http://link/to/page?action=history">history</a> for a list of authors.
Whether or not my patch is the right way to do it, or whether the extension is considered obsolete, I rather like it, and since the extension doesn't work at all without my patch, it surely isn't a problem to commit it? those who dont want to use its "broken functionality" can just not use it?
Applied in r60870. Thanks.
I've completely deleted the extension in r60913, because it was broken and very likely useless. If you have any specific cases where you think rel="canonical" should actually be output, per its definition and intended use, please open new bugs requesting that this be added to core (feel free to assign to me).