r111438 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111437‎ | r111438 | r111439 >
Date:01:02, 14 February 2012
Author:dantman
Status:deferred (Comments)
Tags:
Comment:
Update the extension so that on the mainpage it outputs the sitename in og:title and omits the og:site_name.
Modified paths:
  • /trunk/extensions/OpenGraphMeta/OpenGraphMeta.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenGraphMeta/OpenGraphMeta.php
@@ -63,23 +63,27 @@
6464 global $wgLogo, $wgSitename, $wgXhtmlNamespaces, $egFacebookAppId, $egFacebookAdmins;
6565 $wgXhtmlNamespaces["og"] = "http://opengraphprotocol.org/schema/";
6666 $title = $out->getTitle();
67 - $isMainpage = $title->equals(Title::newMainPage());
 67+ $isMainpage = $title->isMainPage();
6868
6969 $meta = array();
7070
71 - $meta["og:type"] = $isMainpage ? "website" : "article";
72 - $meta["og:site_name"] = $wgSitename;
73 -
74 - // Try to chose the most appropriate title for showing in news feeds.
75 - if ((defined('NS_BLOG_ARTICLE') && $title->getNamespace() == NS_BLOG_ARTICLE) ||
76 - (defined('NS_BLOG_ARTICLE_TALK') && $title->getNamespace() == NS_BLOG_ARTICLE_TALK)){
77 - $meta["og:title"] = $title->getSubpageText();
 71+ if ( $isMainpage ) {
 72+ $meta["og:type"] = "website";
 73+ $meta["og:title"] = $wgSitename;
7874 } else {
79 - $meta["og:title"] = $title->getText();
 75+ $meta["og:type"] = "article";
 76+ $meta["og:site_name"] = $wgSitename;
 77+ // Try to chose the most appropriate title for showing in news feeds.
 78+ if ( ( defined('NS_BLOG_ARTICLE') && $title->getNamespace() == NS_BLOG_ARTICLE ) ||
 79+ ( defined('NS_BLOG_ARTICLE_TALK') && $title->getNamespace() == NS_BLOG_ARTICLE_TALK ) ){
 80+ $meta["og:title"] = $title->getSubpageText();
 81+ } else {
 82+ $meta["og:title"] = $title->getText();
 83+ }
8084 }
8185
82 - if ( isset($out->mMainImage) && ($out->mMainImage !== false) ) {
83 - if( is_object($out->mMainImage) ){
 86+ if ( isset( $out->mMainImage ) && ( $out->mMainImage !== false ) ) {
 87+ if( is_object( $out->mMainImage ) ){
8488 $meta["og:image"] = wfExpandUrl($out->mMainImage->createThumb(100*3, 100));
8589 } else {
8690 // In some edge-cases we won't have defined an object but rather a full URL.

Comments

#Comment by MZMcBride (talk | contribs)   01:04, 14 February 2012

Did you consider using MediaWiki:Pagetitle-view-mainpage for this? I would've thought it would be the obvious candidate.

#Comment by Dantman (talk | contribs)   02:08, 14 February 2012

I dunno. Those pagetitles are geared towards the unstructured <title> element and can have some pretty lengthy junk shoved into them.

Status & tagging log