Converted TextExtracts to new extension registration system

Moved most of TextExtracts.php to the new extension.json
and added method for backward compatable implementation
of the extension if still called though the php file. Moved
unit test hook to Hooks.php and deleted old il8n.php.

Bug: T87979
Change-Id: I3d26bd931ad2941268b94474f3e6327282da24ec
This commit is contained in:
mhutti1 2015-12-10 00:33:24 +01:00
parent 13d6592978
commit 80703452ed
5 changed files with 83 additions and 102 deletions

View file

@ -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( 'wfJsonI18nShim46d28b26aa21add6' ) ) {
function wfJsonI18nShim46d28b26aa21add6( $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'][] = 'wfJsonI18nShim46d28b26aa21add6';
}

View file

@ -18,71 +18,16 @@
* @file
*/
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'TextExtracts',
'author' => array( 'Max Semenik' ),
'descriptionmsg' => 'textextracts-desc',
'url' => 'https://www.mediawiki.org/wiki/Extension:TextExtracts',
);
define( 'TEXT_EXTRACTS_INSTALLED', true );
$dir = __DIR__;
if ( function_exists( 'wfLoadExtension' ) ) {
wfLoadExtension( 'TextExtracts' );
// Keep i18n globals so mergeMessageFileList.php doesn't break
$wgMessagesDirs['TextExtracts'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['TextExtracts'] = "$dir/TextExtracts.i18n.php";
$wgConfigRegistry['textextracts'] = 'GlobalVarConfig::newInstance';
$wgAutoloadClasses['TextExtracts\ApiQueryExtracts'] = "$dir/includes/ApiQueryExtracts.php";
$wgAutoloadClasses['TextExtracts\ExtractFormatter'] = "$dir/includes/ExtractFormatter.php";
$wgAutoloadClasses['TextExtracts\Hooks'] = "$dir/includes/Hooks.php";
$wgAPIPropModules['extracts'] = array(
'class' => 'TextExtracts\ApiQueryExtracts',
'factory' => 'wfNewApiQueryExtracts'
);
/**
* @param ApiQuery $query
* @param string $action
* @return TextExtracts\ApiQueryExtracts
*/
function wfNewApiQueryExtracts( $query, $action ) {
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'textextracts' );
return new TextExtracts\ApiQueryExtracts( $query, $action, $config );
/*wfWarn(
'Deprecated PHP entry point used for TextExtracts extension. ' .
'Please use wfLoadExtension instead, ' .
'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
);*/
return;
} else {
die( 'This version of the TextExtracts extension requires MediaWiki 1.25+' );
}
$wgHooks['OpenSearchXml'][] = 'TextExtracts\Hooks::onApiOpenSearchSuggest';
$wgHooks['ApiOpenSearchSuggest'][] = 'TextExtracts\Hooks::onApiOpenSearchSuggest';
$wgHooks['UnitTestsList'][] = function( &$files ) {
$files[] = __DIR__ . '/tests/ExtractFormatterTest.php';
return true;
};
// Configuration variables
/**
* Selectors of content to be removed from HTML
*/
$wgExtractsRemoveClasses = array(
// These usually represent content that is not part of usual text flow
'table', 'div', 'ul.gallery',
// Section edit links
'.mw-editsection',
// Extension:Cite references
'sup.reference',
// Used by parser for various wikitext errors, no point having them in extracts
'.error',
// Ignored in MobileFrontend. @todo: decide if it's really needed
'.nomobile',
// Elements marked not to show up in the print version
'.noprint',
// Class specifically for this extension
'.noexcerpt',
);
/**
* Whether this extension should provide its extracts for OpenSearch
*/
$wgExtractsExtendOpenSearchXml = false;

54
extension.json Normal file
View file

@ -0,0 +1,54 @@
{
"name": "TextExtracts",
"author": [
"Max Semenik"
],
"url": "https://www.mediawiki.org/wiki/Extension:TextExtracts",
"descriptionmsg": "textextracts-desc",
"type": "other",
"ConfigRegistry": {
"textextracts": "GlobalVarConfig::newInstance"
},
"APIPropModules": {
"extracts": {
"class": "TextExtracts\\ApiQueryExtracts",
"factory": "TextExtracts\\ApiQueryExtracts::factory"
}
},
"MessagesDirs": {
"TextExtracts": [
"i18n"
]
},
"AutoloadClasses": {
"TextExtracts\\ApiQueryExtracts": "includes/ApiQueryExtracts.php",
"TextExtracts\\ExtractFormatter": "includes/ExtractFormatter.php",
"TextExtracts\\Hooks": "includes/Hooks.php"
},
"Hooks": {
"OpenSearchXml": [
"TextExtracts\\Hooks::onApiOpenSearchSuggest"
],
"ApiOpenSearchSuggest": [
"TextExtracts\\Hooks::onApiOpenSearchSuggest"
],
"UnitTestsList": [
"TextExtracts\\Hooks::onUnitTestsList"
]
},
"config": {
"ExtractsRemoveClasses": [
"table",
"div",
"ul.gallery",
".mw-editsection",
"sup.reference",
".error",
".nomobile",
".noprint",
".noexcerpt"
],
"ExtractsExtendOpenSearchXml": false
},
"manifest_version": 1
}

View file

@ -240,6 +240,16 @@ class ApiQueryExtracts extends ApiQueryBase {
return $data['parse']['text']['*'];
}
/**
* @param ApiQuery $query
* @param string $action
* @return TextExtracts\ApiQueryExtracts
*/
public static function factory( $query, $action ) {
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'textextracts' );
return new TextExtracts\ApiQueryExtracts( $query, $action, $config );
}
/**
* Converts page HTML into an extract
* @param string $text

View file

@ -9,6 +9,13 @@ use ConfigFactory;
use FauxRequest;
class Hooks {
// Unit test hook
public static function onUnitTestsList( &$files ) {
$files = array_merge( $files, glob( __DIR__ . '/tests/ExtractFormatterTest.php' ) );
return true;
}
/**
* ApiOpenSearchSuggest hook handler
* @param array $results