Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/201342
Change subject: registration: Make it easier for other code to get extension
metadata
......................................................................
registration: Make it easier for other code to get extension metadata
Right now if other code wanted to access extension metadata from
extension.json, it would have to either re-implement parts of
loadFromQueue() or make assumptions about the processor and schema being
used.
Lets split that code out in to a public readFromQueue() function that
returns all extracted data from the processors.
Change-Id: I314d73341d3faaa47e01f722123c20fd8f61da8a
---
M includes/registration/ExtensionRegistry.php
1 file changed, 41 insertions(+), 27 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/42/201342/1
diff --git a/includes/registration/ExtensionRegistry.php
b/includes/registration/ExtensionRegistry.php
index c06f7e3..5ef3853 100644
--- a/includes/registration/ExtensionRegistry.php
+++ b/includes/registration/ExtensionRegistry.php
@@ -91,41 +91,55 @@
if ( $data ) {
$this->exportExtractedData( $data );
} else {
- $data = array( 'globals' => array( 'wgAutoloadClasses'
=> array() ) );
- $autoloadClasses = array();
- foreach ( $this->queued as $path => $mtime ) {
- $json = file_get_contents( $path );
- $info = json_decode( $json, /* $assoc = */ true
);
- if ( !is_array( $info ) ) {
- throw new Exception( "$path is not a
valid JSON file." );
- }
- $autoload = $this->processAutoLoader( dirname(
$path ), $info );
- // Set up the autoloader now so custom
processors will work
- $GLOBALS['wgAutoloadClasses'] += $autoload;
- $autoloadClasses += $autoload;
- if ( isset( $info['processor'] ) ) {
- $processor = $this->getProcessor(
$info['processor'] );
- } else {
- $processor = $this->getProcessor(
'default' );
- }
- $processor->extractInfo( $path, $info );
- }
- foreach ( $this->processors as $processor ) {
- $data = array_merge_recursive( $data,
$processor->getExtractedInfo() );
- }
- foreach ( $data['credits'] as $credit ) {
-
$data['globals']['wgExtensionCredits'][$credit['type']][] = $credit;
- }
- $this->processors = array(); // Reset
+ $data = $this->readFromQueue( $this->queued );
$this->exportExtractedData( $data );
// Do this late since we don't want to extract it since
we already
// did that, but it should be cached
- $data['globals']['wgAutoloadClasses'] +=
$autoloadClasses;
+ $data['globals']['wgAutoloadClasses'] +=
$data['autoload'];
+ unset( $data['autoload'] );
$this->cache->set( $key, $data );
}
$this->queued = array();
}
+ /**
+ * Process a queue of extensions and return their extracted data
+ *
+ * @param array $queue keys are filenames, values are ignored
+ * @return array extracted info
+ * @throws Exception
+ */
+ public function readFromQueue( array $queue ) {
+ $data = array( 'globals' => array( 'wgAutoloadClasses' =>
array() ) );
+ $autoloadClasses = array();
+ foreach ( $queue as $path => $mtime ) {
+ $json = file_get_contents( $path );
+ $info = json_decode( $json, /* $assoc = */ true );
+ if ( !is_array( $info ) ) {
+ throw new Exception( "$path is not a valid JSON
file." );
+ }
+ $autoload = $this->processAutoLoader( dirname( $path ),
$info );
+ // Set up the autoloader now so custom processors will
work
+ $GLOBALS['wgAutoloadClasses'] += $autoload;
+ $autoloadClasses += $autoload;
+ if ( isset( $info['processor'] ) ) {
+ $processor = $this->getProcessor(
$info['processor'] );
+ } else {
+ $processor = $this->getProcessor( 'default' );
+ }
+ $processor->extractInfo( $path, $info );
+ }
+ foreach ( $this->processors as $processor ) {
+ $data = array_merge_recursive( $data,
$processor->getExtractedInfo() );
+ }
+ foreach ( $data['credits'] as $credit ) {
+
$data['globals']['wgExtensionCredits'][$credit['type']][] = $credit;
+ }
+ $this->processors = array(); // Reset
+ $data['autoload'] = $autoloadClasses;
+ return $data;
+ }
+
protected function getProcessor( $type ) {
if ( !isset( $this->processors[$type] ) ) {
$processor = $type === 'default' ? new
ExtensionProcessor() : new $type();
--
To view, visit https://gerrit.wikimedia.org/r/201342
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I314d73341d3faaa47e01f722123c20fd8f61da8a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits