jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/357961 )

Change subject: Version 0.5.0 -- extension registration support and more
......................................................................


Version 0.5.0 -- extension registration support and more

* Moved PHP code into a new, separate class & file
* Added extension.json for extension registration support
* Added version number to extension credits
* Removed old PHP i18n file

MediaWiki 1.25 or newer is now required

Change-Id: Ied8476ee5e0143d78f291d986c7e79abe3c3b1ce
---
A OpenGraphMeta.class.php
D OpenGraphMeta.i18n.php
M OpenGraphMeta.php
A extension.json
4 files changed, 156 insertions(+), 134 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/OpenGraphMeta.class.php b/OpenGraphMeta.class.php
new file mode 100644
index 0000000..c0efcc8
--- /dev/null
+++ b/OpenGraphMeta.class.php
@@ -0,0 +1,111 @@
+<?php
+/**
+ * OpenGraphMeta
+ *
+ * @file
+ * @ingroup Extensions
+ * @author Daniel Friesen (http://danf.ca/mw/)
+ * @license https://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
+ * @link https://www.mediawiki.org/wiki/Extension:OpenGraphMeta Documentation
+ */
+
+class OpenGraphMeta {
+
+       /**
+        * @param Parser $parser
+        * @return bool
+        */
+       public static function onParserFirstCallInit( Parser $parser ) {
+               $parser->setFunctionHook( 'setmainimage', array( __CLASS__, 
'setMainImagePF' ) );
+               return true;
+       }
+
+       /**
+        * @param Parser $parser
+        * @param string $mainImage
+        * @return string
+        */
+       public static function setMainImagePF( Parser $parser, $mainImage ) {
+               $parserOutput = $parser->getOutput();
+               $setMainImage = $parserOutput->getExtensionData( 'setmainimage' 
);
+               if ( $setMainImage !== null ) {
+                       return $mainImage;
+               }
+
+               $file = Title::newFromText( $mainImage, NS_FILE );
+               $parserOutput->setExtensionData( 'setmainimage', 
$file->getDBkey() );
+
+               return $mainImage;
+       }
+
+       public static function onOutputPageParserOutput( OutputPage &$out, 
ParserOutput $parserOutput ) {
+               global $wgLogo, $wgSitename, $wgXhtmlNamespaces, 
$egFacebookAppId, $egFacebookAdmins;
+
+               $setMainImage = $parserOutput->getExtensionData( 'setmainimage' 
);
+               if ( $setMainImage !== null ) {
+                       $mainImage = wfFindFile( Title::newFromDBkey( 
$setMainImage ) );
+               } else {
+                       $mainImage = false;
+               }
+
+               $wgXhtmlNamespaces['og'] = 
'http://opengraphprotocol.org/schema/';
+               $title = $out->getTitle();
+               $isMainpage = $title->isMainPage();
+
+               $meta = array();
+
+               if ( $isMainpage ) {
+                       $meta['og:type'] = 'website';
+                       $meta['og:title'] = $wgSitename;
+               } else {
+                       $meta['og:type'] = 'article';
+                       $meta['og:site_name'] = $wgSitename;
+                       // Try to chose the most appropriate title for showing 
in news feeds.
+                       if (
+                               ( defined( 'NS_BLOG_ARTICLE' ) && 
$title->getNamespace() == NS_BLOG_ARTICLE ) ||
+                               ( defined( 'NS_BLOG_ARTICLE_TALK' ) && 
$title->getNamespace() == NS_BLOG_ARTICLE_TALK )
+                       ) {
+                               $meta['og:title'] = $title->getSubpageText();
+                       } else {
+                               $meta['og:title'] = $title->getText();
+                       }
+               }
+
+               if ( ( $mainImage !== false ) ) {
+                       if ( is_object( $mainImage ) ) {
+                               $meta['og:image'] = wfExpandUrl( 
$mainImage->createThumb( 100 * 3, 100 ) );
+                       } else {
+                               // In some edge-cases we won't have defined an 
object but rather a full URL.
+                               $meta['og:image'] = $mainImage;
+                       }
+               } elseif ( $isMainpage ) {
+                       $meta['og:image'] = wfExpandUrl( $wgLogo );
+               }
+               $description = $parserOutput->getProperty( 'description' );
+               if ( $description !== false ) { // set by Description2 
extension, install it if you want proper og:description support
+                       $meta['og:description'] = $description;
+               }
+               $meta['og:url'] = $title->getFullURL();
+               if ( $egFacebookAppId ) {
+                       $meta['fb:app_id'] = $egFacebookAppId;
+               }
+               if ( $egFacebookAdmins ) {
+                       $meta['fb:admins'] = $egFacebookAdmins;
+               }
+
+               foreach( $meta as $property => $value ) {
+                       if ( $value ) {
+                               $out->addHeadItem(
+                                       "meta:property:$property",
+                                       '       ' . Html::element( 'meta', 
array(
+                                               'property' => $property,
+                                               'content' => $value
+                                       ) ) . "\n"
+                               );
+                       }
+               }
+
+               return true;
+       }
+
+}
diff --git a/OpenGraphMeta.i18n.php b/OpenGraphMeta.i18n.php
deleted file mode 100644
index a65cdcf..0000000
--- a/OpenGraphMeta.i18n.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * This is a backwards-compatibility shim, generated by:
- * 
https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php
- *
- * Beginning with MediaWiki 1.23, translation strings are stored in json files,
- * and the EXTENSION.i18n.php file only exists to provide compatibility with
- * older releases of MediaWiki. For more information about this migration, see:
- * https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format
- *
- * This shim maintains compatibility back to MediaWiki 1.17.
- */
-$messages = array();
-if ( !function_exists( 'wfJsonI18nShim6192261aa89efbe1' ) ) {
-       function wfJsonI18nShim6192261aa89efbe1( $cache, $code, &$cachedData ) {
-               $codeSequence = array_merge( array( $code ), 
$cachedData['fallbackSequence'] );
-               foreach ( $codeSequence as $csCode ) {
-                       $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json";
-                       if ( is_readable( $fileName ) ) {
-                               $data = FormatJson::decode( file_get_contents( 
$fileName ), true );
-                               foreach ( array_keys( $data ) as $key ) {
-                                       if ( $key === '' || $key[0] === '@' ) {
-                                               unset( $data[$key] );
-                                       }
-                               }
-                               $cachedData['messages'] = array_merge( $data, 
$cachedData['messages'] );
-                       }
-
-                       $cachedData['deps'][] = new FileDependency( $fileName );
-               }
-               return true;
-       }
-
-       $GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 
'wfJsonI18nShim6192261aa89efbe1';
-}
diff --git a/OpenGraphMeta.php b/OpenGraphMeta.php
index 93c25f9..0b62735 100644
--- a/OpenGraphMeta.php
+++ b/OpenGraphMeta.php
@@ -9,102 +9,16 @@
  * @link https://www.mediawiki.org/wiki/Extension:OpenGraphMeta Documentation
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki 
package and cannot be run standalone." );
-
-$wgExtensionCredits['parserhook'][] = array(
-       'path' => __FILE__,
-       'name' => "OpenGraphMeta",
-       'author' => "[http://danf.ca/mw/ Daniel Friesen]",
-       'descriptionmsg' => 'opengraphmeta-desc',
-       'url' => 'https://www.mediawiki.org/wiki/Extension:OpenGraphMeta',
-       'license-name' => 'GPL-2.0+',
-);
-
-$dir = dirname( __FILE__ );
-$wgExtensionMessagesFiles['OpenGraphMetaMagic'] = $dir . 
'/OpenGraphMeta.magic.php';
-$wgMessagesDirs['OpenGraphMeta'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['OpenGraphMeta'] = $dir . '/OpenGraphMeta.i18n.php';
-
-$wgHooks['ParserFirstCallInit'][] = 'efOpenGraphMetaParserInit';
-function efOpenGraphMetaParserInit( $parser ) {
-       $parser->setFunctionHook( 'setmainimage', 'efSetMainImagePF' );
-       return true;
-}
-
-function efSetMainImagePF( $parser, $mainimage ) {
-       $parserOutput = $parser->getOutput();
-       if ( isset($parserOutput->eHasMainImageAlready) && 
$parserOutput->eHasMainImageAlready )
-               return $mainimage;
-       $file = Title::newFromText( $mainimage, NS_FILE );
-       $parserOutput->addOutputHook( 'setmainimage', array( 'dbkey' => 
$file->getDBkey() ) );
-       $parserOutput->eHasMainImageAlready = true;
-
-       return $mainimage;
-}
-
-$wgParserOutputHooks['setmainimage'] = 'efSetMainImagePH';
-function efSetMainImagePH( $out, $parserOutput, $data ) {
-       $out->mMainImage = wfFindFile( Title::newFromDBkey($data['dbkey'], 
NS_FILE) );
-}
-
-$wgHooks['BeforePageDisplay'][] = 'efOpenGraphMetaPageHook';
-function efOpenGraphMetaPageHook( &$out, &$sk ) {
-       global $wgLogo, $wgSitename, $wgXhtmlNamespaces, $egFacebookAppId, 
$egFacebookAdmins;
-       $wgXhtmlNamespaces["og"] = "http://opengraphprotocol.org/schema/";;
-       $title = $out->getTitle();
-       $isMainpage = $title->isMainPage();
-
-       $meta = array();
-
-       if ( $isMainpage ) {
-               $meta["og:type"] = "website";
-               $meta["og:title"] = $wgSitename;
-       } else {
-               $meta["og:type"] = "article";
-               $meta["og:site_name"] = $wgSitename;
-               // Try to chose the most appropriate title for showing in news 
feeds.
-               if ( ( defined('NS_BLOG_ARTICLE') && $title->getNamespace() == 
NS_BLOG_ARTICLE ) ||
-                       ( defined('NS_BLOG_ARTICLE_TALK') && 
$title->getNamespace() == NS_BLOG_ARTICLE_TALK ) ){
-                       $meta["og:title"] = $title->getSubpageText();
-               } else {
-                       $meta["og:title"] = $title->getText();
-               }
-       }
-
-       if ( isset( $out->mMainImage ) && ( $out->mMainImage !== false ) ) {
-               if( is_object( $out->mMainImage ) ){
-                       $meta["og:image"] = 
wfExpandUrl($out->mMainImage->createThumb(100*3, 100));
-               } else {
-                       // In some edge-cases we won't have defined an object 
but rather a full URL.
-                       $meta["og:image"] = $out->mMainImage;
-               }
-       } elseif ( $isMainpage ) {
-               $meta["og:image"] = wfExpandUrl($wgLogo);
-       }
-       if ( isset($out->mDescription) ) { // set by Description2 extension, 
install it if you want proper og:description support
-               $meta["og:description"] = $out->mDescription;
-       }
-       $meta["og:url"] = $title->getFullURL();
-       if ( $egFacebookAppId ) {
-               $meta["fb:app_id"] = $egFacebookAppId;
-       }
-       if ( $egFacebookAdmins ) {
-               $meta["fb:admins"] = $egFacebookAdmins;
-       }
-
-       foreach( $meta as $property => $value ) {
-               if ( $value ) {
-                       if ( isset( OutputPage::$metaAttrPrefixes ) && isset( 
OutputPage::$metaAttrPrefixes['property'] ) ) {
-                               $out->addMeta( "property:$property", $value );
-                       } else {
-                               $out->addHeadItem("meta:property:$property", "  
".Html::element( 'meta', array( 'property' => $property, 'content' => $value ) 
)."\n");
-                       }
-               }
-       }
-
-       return true;
-}
-
-$egFacebookAppId = null;
-$egFacebookAdmins = null;
-
+if ( function_exists( 'wfLoadExtension' ) ) {
+       wfLoadExtension( 'OpenGraphMeta' );
+       // Keep i18n globals so mergeMessageFileList.php doesn't break
+       $wgMessagesDirs['OpenGraphMeta'] = __DIR__ . '/i18n';
+       wfWarn(
+               'Deprecated PHP entry point used for OpenGraphMeta extension. ' 
.
+               'Please use wfLoadExtension instead, ' .
+               'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
+       );
+       return;
+} else {
+       die( 'This version of the OpenGraphMeta extension requires MediaWiki 
1.25+' );
+}
\ No newline at end of file
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..f92adcc
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,32 @@
+{
+       "name": "OpenGraphMeta",
+       "version": "0.5.0",
+       "author": [
+               "[http://danf.ca/mw/ Daniel Friesen]"
+       ],
+       "url": "https://www.mediawiki.org/wiki/Extension:OpenGraphMeta";,
+       "descriptionmsg": "opengraphmeta-desc",
+       "license-name": "GPL-2.0+",
+       "type": "parserhook",
+       "config": {
+               "_prefix": "eg",
+               "FacebookAppId": null,
+               "FacebookAdmins": null
+       },
+       "AutoloadClasses": {
+               "OpenGraphMeta": "OpenGraphMeta.class.php"
+       },
+       "ExtensionMessagesFiles": {
+               "OpenGraphMetaMagic": "OpenGraphMeta.magic.php"
+       },
+       "MessagesDirs": {
+               "OpenGraphMeta": [
+                       "i18n"
+               ]
+       },
+       "Hooks": {
+               "OutputPageParserOutput": 
"OpenGraphMeta::onOutputPageParserOutput",
+               "ParserFirstCallInit": "OpenGraphMeta::onParserFirstCallInit"
+       },
+       "manifest_version": 1
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/357961
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ied8476ee5e0143d78f291d986c7e79abe3c3b1ce
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/OpenGraphMeta
Gerrit-Branch: master
Gerrit-Owner: Jack Phoenix <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to