-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid loading extensions when building localization cache (#412)
* Avoid loading extensions when building localization cache * Refactor into a separate class * Simplify by using ExtensionProcessor --------- Co-authored-by: Thomas Arrow <tarrow@users.noreply.github.com>
- Loading branch information
1 parent
99b1625
commit ded9dcd
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
class Localization { | ||
private $extensionMessagesFiles; | ||
private $messagesDirs; | ||
private $baseDirectory; | ||
private $isLocalisationRebuild; | ||
|
||
public function __construct( | ||
&$extensionMessagesFiles, | ||
&$messagesDirs, | ||
$baseDirectory, | ||
$isLocalisationRebuild | ||
) { | ||
$this->extensionMessagesFiles = &$extensionMessagesFiles; | ||
$this->messagesDirs = &$messagesDirs; | ||
$this->baseDirectory = $baseDirectory; | ||
$this->isLocalisationRebuild = $isLocalisationRebuild; | ||
} | ||
|
||
private function addLocalization( $path ) { | ||
$processor = new ExtensionProcessor(); | ||
$processor->extractInfoFromFile( $path ); | ||
$info = $processor->getExtractedInfo(); | ||
|
||
if ( isset( $info[ 'globals' ][ 'wgExtensionMessagesFiles' ] ) ) { | ||
$this->extensionMessagesFiles = array_merge( | ||
$this->extensionMessagesFiles, $info[ 'globals' ][ 'wgExtensionMessagesFiles' ] | ||
); | ||
} | ||
if ( isset( $info[ 'globals' ][ 'wgMessagesDirs' ] ) ) { | ||
$this->messagesDirs = array_merge( | ||
$this->messagesDirs, $info[ 'globals' ][ 'wgMessagesDirs' ] | ||
); | ||
} | ||
} | ||
|
||
public function loadExtension( $name ) { | ||
if ( $this->isLocalisationRebuild ) { | ||
self::addLocalization( "$this->baseDirectory/extensions/" . $name . "/extension.json" ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
class Localization { | ||
private $extensionMessagesFiles; | ||
private $messagesDirs; | ||
private $baseDirectory; | ||
private $isLocalisationRebuild; | ||
|
||
public function __construct( | ||
&$extensionMessagesFiles, | ||
&$messagesDirs, | ||
$baseDirectory, | ||
$isLocalisationRebuild | ||
) { | ||
$this->extensionMessagesFiles = &$extensionMessagesFiles; | ||
$this->messagesDirs = &$messagesDirs; | ||
$this->baseDirectory = $baseDirectory; | ||
$this->isLocalisationRebuild = $isLocalisationRebuild; | ||
} | ||
|
||
private function addLocalization( $path ) { | ||
$processor = new ExtensionProcessor(); | ||
$processor->extractInfoFromFile( $path ); | ||
$info = $processor->getExtractedInfo(); | ||
|
||
if ( isset( $info[ 'globals' ][ 'wgExtensionMessagesFiles' ] ) ) { | ||
$this->extensionMessagesFiles = array_merge( | ||
$this->extensionMessagesFiles, $info[ 'globals' ][ 'wgExtensionMessagesFiles' ] | ||
); | ||
} | ||
if ( isset( $info[ 'globals' ][ 'wgMessagesDirs' ] ) ) { | ||
$this->messagesDirs = array_merge( | ||
$this->messagesDirs, $info[ 'globals' ][ 'wgMessagesDirs' ] | ||
); | ||
} | ||
} | ||
|
||
public function loadExtension( $name ) { | ||
if ( $this->isLocalisationRebuild ) { | ||
self::addLocalization( "$this->baseDirectory/extensions/" . $name . "/extension.json" ); | ||
} | ||
} | ||
} |