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

Change subject: Version 0.4.0 -- cleanup, extension registration support, etc.
......................................................................


Version 0.4.0 -- cleanup, extension registration support, etc.

* Old i18n shim removed
* extension.json added
* PHP code moved into the new Description2 class
* Old PHP entry point still exists for b/c with older installations, but MW 
1.25 or newer is now required

Change-Id: I0670c203b62dcf500ded1b82957e473edf864fb1
---
A Description2.class.php
D Description2.i18n.php
M Description2.php
A extension.json
4 files changed, 150 insertions(+), 127 deletions(-)

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



diff --git a/Description2.class.php b/Description2.class.php
new file mode 100644
index 0000000..c3a6683
--- /dev/null
+++ b/Description2.class.php
@@ -0,0 +1,105 @@
+<?php
+/**
+ * Description2 – Adds meaningful description <meta> tag to MW pages and into 
the parser output
+ *
+ * @file
+ * @ingroup Extensions
+ * @author Daniel Friesen (http://danf.ca/mw/)
+ * @copyright Copyright 2010 – Daniel Friesen
+ * @license https://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
+ * @link https://www.mediawiki.org/wiki/Extension:Description2 Documentation
+ */
+
+class Description2 {
+
+       /**
+        * @param Parser $parser
+        * @param string $desc
+        */
+       public static function setDescription( Parser $parser, $desc ) {
+               $parserOutput = $parser->getOutput();
+               if ( $parserOutput->getProperty( 'description' ) !== false ) {
+                       return;
+               }
+               $parserOutput->setProperty( 'description', $desc );
+       }
+
+       /**
+        * @param Parser $parser
+        * @param string $text
+        * @return bool
+        */
+       public static function onParserAfterTidy( Parser &$parser, &$text ) {
+               $desc = '';
+
+               $myText = preg_replace( 
'%<table\b[^>]*+>(?:(?R)|[^<]*+(?:(?!</?table\b)<[^<]*+)*+)*+</table>%i', '', 
$text );
+
+               $paragraphs = array();
+               if ( preg_match_all( '#<p>.*?</p>#is', $myText, $paragraphs ) ) 
{
+                       foreach ( $paragraphs[0] as $paragraph ) {
+                               $paragraph = trim( strip_tags( $paragraph ) );
+                               if ( !$paragraph ) {
+                                       continue;
+                               }
+                               $desc = $paragraph;
+                               break;
+                       }
+               }
+
+               if ( $desc ) {
+                       self::setDescription( $parser, $desc );
+               }
+
+               return true;
+       }
+
+       /**
+        * @param Parser $parser
+        * @return bool
+        */
+       public static function onParserFirstCallInit( Parser &$parser ) {
+               global $wgEnableMetaDescriptionFunctions;
+               if ( !$wgEnableMetaDescriptionFunctions ) {
+                       // Functions and tags are disabled
+                       return true;
+               }
+               $parser->setFunctionHook( 'description2', array( 
'Description2', 'parserFunctionCallback' ), Parser::SFH_OBJECT_ARGS );
+               $parser->setFunctionTagHook( 'metadesc', array( 'Description2', 
'tagCallback' ), Parser::SFH_OBJECT_ARGS );
+               return true;
+       }
+
+       /**
+        * @param Parser $parser
+        * @param $frame
+        * @param $args
+        * @return string
+        */
+       public static function parserFunctionCallback( Parser $parser, $frame, 
$args ) {
+               $desc = isset( $args[0] ) ? $frame->expand( $args[0] ) : '';
+               self::setDescription( $parser, $desc );
+               return '';
+       }
+
+       /**
+        * @param Parser $parser
+        * @param $frame
+        * @param $content
+        * @param $attributes
+        * @return string
+        */
+       public static function tagCallback( Parser $parser, $frame, $content, 
$attributes ) {
+               $desc = ( isset( $content ) ? $content : ( isset( 
$attributes['content'] ) ? $attributes['content'] : null ) );
+               if ( isset( $desc ) ) {
+                       self::setDescription( $parser, $desc );
+               }
+               return '';
+       }
+
+       public static function onOutputPageParserOutput( OutputPage &$out, 
ParserOutput $parserOutput ) {
+               // Export the description from the main parser output into the 
OutputPage
+               $description = $parserOutput->getProperty( 'description' );
+               if ( $description !== false ) {
+                       $out->addMeta( 'description', $description );
+               }
+       }
+}
diff --git a/Description2.i18n.php b/Description2.i18n.php
deleted file mode 100644
index f635e78..0000000
--- a/Description2.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( 'wfJsonI18nShimc2f50022c755bbdf' ) ) {
-       function wfJsonI18nShimc2f50022c755bbdf( $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'][] = 
'wfJsonI18nShimc2f50022c755bbdf';
-}
diff --git a/Description2.php b/Description2.php
index 68d9b4b..35fb4d4 100644
--- a/Description2.php
+++ b/Description2.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * Description2.php – Adds meaningful description <meta> tag to MW pages and 
into the parser output
+ * Description2 – Adds meaningful description <meta> tag to MW pages and into 
the parser output
  *
  * @file
  * @ingroup Extensions
@@ -10,94 +10,16 @@
  * @link https://www.mediawiki.org/wiki/Extension:Description2 Documentation
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki 
package and cannot be run standalone." );
-
-$wgExtensionCredits['other'][] = array(
-       'path' => __FILE__,
-       'name' => 'Description2',
-       'version' => '0.3.0',
-       'author' => "[http://danf.ca/mw/ Daniel Friesen]",
-       'url' => 'https://www.mediawiki.org/wiki/Extension:Description2',
-       'descriptionmsg' => 'description2-desc',
-);
-
-$dir = dirname( __FILE__ );
-$wgMessagesDirs['Description2'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['Description2'] = $dir . '/Description2.i18n.php';
-$wgExtensionMessagesFiles['Description2Magic'] = $dir . 
'/Description2.i18n.magic.php';
-
-function efDescription2SetDescription( $parser, $desc ) {
-       $pOut = $parser->getOutput();
-       if ( $pOut->getProperty("description") !== false ) {
-               return;
-       }
-       $pOut->setProperty("description", $desc);
-       $pOut->addOutputHook("setdescription");
-}
-
-$wgHooks['ParserAfterTidy'][] = 'egDescription2ParserAfterTidy';
-function egDescription2ParserAfterTidy( &$parser, &$text ) {
-       $desc = '';
-
-       $myText = 
preg_replace('%<table\b[^>]*+>(?:(?R)|[^<]*+(?:(?!</?table\b)<[^<]*+)*+)*+</table>%i',
 '', $text);
-
-       $paragraphs = array();
-       if ( preg_match_all('#<p>.*?</p>#is', $myText, $paragraphs) ) {
-               foreach ( $paragraphs[0] as $paragraph ) {
-                       $paragraph = trim(strip_tags($paragraph));
-                       if ( !$paragraph )
-                               continue;
-                       $desc = $paragraph;
-                       break;
-               }
-       }
-
-       if ( $desc ) {
-               efDescription2SetDescription( $parser, $desc );
-       }
-
-       return true;
-}
-
-$wgHooks['ParserFirstCallInit'][] = array( 'efDescription2RegisterParser' );
-function efDescription2RegisterParser( &$parser ) {
-       global $wgEnableMetaDescriptionFunctions;
-       if ( !$wgEnableMetaDescriptionFunctions ) {
-               // Functions and tags are disabled
-               return true;
-       }
-       $parser->setFunctionHook( 'description2', 'efDescription2Function', 
Parser::SFH_OBJECT_ARGS );
-       $parser->setFunctionTagHook( 'metadesc', 'efDescription2Tag', 
Parser::SFH_OBJECT_ARGS );
-       return true;
-}
-
-function efDescription2Function( $parser, $frame, $args ) {
-       $desc = isset( $args[0] ) ? $frame->expand( $args[0] ) : '';
-       efDescription2SetDescription( $parser, $desc );
-       return '';
-}
-function efDescription2Tag( $parser, $frame, $content, $attributes ) {
-       $desc = (isset( $content ) ? $content : (isset($attributes["content"]) 
? $attributes["content"] : null));
-       if ( isset($desc) ) {
-               efDescription2SetDescription( $parser, $desc );
-       }
-       return '';
-}
-
-$wgParserOutputHooks['setdescription'] = 
'egDescription2ParserOutputSetDescription';
-function egDescription2ParserOutputSetDescription( $out, $parserOutput, $data 
) {
-       // Export the description from the main parser output into the 
OutputPage
-       $out->mDescription = $parserOutput->getProperty("description");
-}
-
-$wgHooks['BeforePageDisplay'][] = 'egDescription2PageHook';
-function egDescription2PageHook( &$out, &$sk ) {
-       if ( isset($out->mDescription) && $out->mDescription )
-               $out->addMeta("description", $out->mDescription);
-       return true;
-}
-
-
-## Configuration
-$wgEnableMetaDescriptionFunctions = false;
-
+if ( function_exists( 'wfLoadExtension' ) ) {
+       wfLoadExtension( 'Description2' );
+       // Keep i18n globals so mergeMessageFileList.php doesn't break
+       $wgMessagesDirs['Description2'] = __DIR__ . '/i18n';
+       wfWarn(
+               'Deprecated PHP entry point used for Description2 extension. ' .
+               'Please use wfLoadExtension instead, ' .
+               'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
+       );
+       return;
+} else {
+       die( 'This version of the Description2 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..1cd1ba5
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,31 @@
+{
+       "name": "Description2",
+       "version": "0.4.0",
+       "author": [
+               "[http://danf.ca/mw/ Daniel Friesen]"
+       ],
+       "url": "https://www.mediawiki.org/wiki/Extension:Description2";,
+       "descriptionmsg": "description2-desc",
+       "license-name": "GPL-2.0+",
+       "type": "other",
+       "config": {
+               "EnableMetaDescriptionFunctions": false
+       },
+       "AutoloadClasses": {
+               "Description2": "Description2.class.php"
+       },
+       "ExtensionMessagesFiles": {
+               "Description2Magic": "Description2.i18n.magic.php"
+       },
+       "MessagesDirs": {
+               "Description2": [
+                       "i18n"
+               ]
+       },
+       "Hooks": {
+               "OutputPageParserOutput": 
"Description2::onOutputPageParserOutput",
+               "ParserAfterTidy": "Description2::onParserAfterTidy",
+               "ParserFirstCallInit": "Description2::onParserFirstCallInit"
+       },
+       "manifest_version": 1
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0670c203b62dcf500ded1b82957e473edf864fb1
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Description2
Gerrit-Branch: master
Gerrit-Owner: Jack Phoenix <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to