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 |
1 | 39 | + native |