r47223 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47222‎ | r47223 | r47224 >
Date:18:45, 13 February 2009
Author:nick
Status:deferred (Comments)
Tags:
Comment:
This extension prints out a link tag with a canonical url to the article,
which handles Mediawiki's "soft" redirects much more elegantly.

This tag is supported by Google, Yahoo!, and MSN. It's been in production at Wikia, wanted to
share with all.

http://www.techyouruniverse.com/wikia/google-canonical-href-with-mediawiki
http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html
http://ysearchblog.com/2009/02/12/fighting-duplication-adding-more-arrows-to-your-quiver/
http://blogs.msdn.com/webmaster/archive/2009/02/12/partnering-to-help-solve-duplicate-content-issues.aspx

-Nick
Modified paths:
  • /trunk/extensions/CanonicalHref (added) (history)
  • /trunk/extensions/CanonicalHref/CanonicalHref.php (added) (history)

Diff [purge]

Index: trunk/extensions/CanonicalHref/CanonicalHref.php
@@ -0,0 +1,37 @@
 2+<?php
 3+/* This extension prints out a link tag with a canonical url to the article,
 4+ * which handles Mediawiki's "soft" redirects much more elegantly.
 5+ *
 6+ * http://www.techyouruniverse.com/wikia/google-canonical-href-with-mediawiki
 7+ * http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html
 8+ * http://ysearchblog.com/2009/02/12/fighting-duplication-adding-more-arrows-to-your-quiver/
 9+ * http://blogs.msdn.com/webmaster/archive/2009/02/12/partnering-to-help-solve-duplicate-content-issues.aspx
 10+ *
 11+ * Note this extension should be mutually exclusive with extensions that do "Hard" redirects,
 12+ * https://wikia-code.com/wikia/trunk/extensions/wikia/HardRedirectsWithJSText/
 13+ */
 14+
 15+$wgHooks['SkinTemplateOutputPageBeforeExec'][] = "canonicalHref";
 16+
 17+$wgExtensionCredits['specialpage'][] = array(
 18+ 'name' => 'Canonical Href',
 19+ 'author' => 'Nick Sullivan nick at wikia-inc.com',
 20+ 'description' => 'This extension prints a link type="canonical" tag with a canonical representation of the url, which is used by Google, MSN, and Yahoo! to funnel PageRank'
 21+);
 22+
 23+
 24+function canonicalHref(&$skin, &$template){
 25+ global $wgTitle;
 26+ if (!is_object($wgTitle) || !method_exists($wgTitle, "getFullURL")){
 27+ // Avoid a fatal error if for any reason $wgTitle isn't an object
 28+ return true;
 29+ }
 30+ $link = Xml::element("link", array(
 31+ 'rel' => 'canonical',
 32+ 'href' => $wgTitle->getFullURL()
 33+ )
 34+ );
 35+ $template->set('headlinks', $template->data['headlinks'] . "\n" . $link . "\n");
 36+ return true;
 37+}
 38+
Property changes on: trunk/extensions/CanonicalHref/CanonicalHref.php
___________________________________________________________________
Added: svn:eol-style
139 + native

Comments

#Comment by Simetrical (talk | contribs)   18:53, 13 February 2009

This was already added to core a couple of hours ago in r47217. Comparing the implementations, I think the one in core is preferable. It works for all skins, not just SkinTemplate-based; it's shorter; the functionality should be in core, not in an extension; and it doesn't have that odd $wgTitle stuff (it uses Article::$mTitle, which I'm fairly sure will always work). So I'd be inclined to say that this extension isn't necessary.

#Comment by Catrope (talk | contribs)   20:20, 13 February 2009

I think the best option would be to deprecate or remove this extension and to backport r47217 (which adds only 3 lines of code) to the 1.14 branch so it'll be available soon. If we don't backport, keeping this extension around until we release a version with this feature would be a good idea.

Status & tagging log