Smuggli has submitted this change and it was merged.
Change subject: Translators are read in on request
......................................................................
Translators are read in on request
- Removed maintenance script to generate JSON translatorsfile
- Translators are cached for one day
- Removed key when list was created
Change-Id: Ibb69083152e6297e7d0936f182ce837fb93c029d
---
M i18n/credits/en.json
M includes/specials/SpecialCredits.class.php
D maintenance/generateTranslators.php
3 files changed, 54 insertions(+), 83 deletions(-)
Approvals:
Smuggli: Verified; Looks good to me, approved
Swidmann: Checked; Looks good to me, but someone else must approve
Raimond Spekking: Looks good to me, but someone else must approve
diff --git a/i18n/credits/en.json b/i18n/credits/en.json
index 3c6e342..439c3c6 100644
--- a/i18n/credits/en.json
+++ b/i18n/credits/en.json
@@ -10,6 +10,5 @@
"bs-credits-contributors": "Contributors",
"bs-credits-translators": "Translators",
"bs-credits-translation": "Translation",
- "bs-credits-th": "Thanks to all translators from $1.",
- "bs-credits-createdon": "List created on: $1."
+ "bs-credits-th": "Thanks to all translators from $1."
}
diff --git a/includes/specials/SpecialCredits.class.php
b/includes/specials/SpecialCredits.class.php
index 2a100f5..d3c66a9 100644
--- a/includes/specials/SpecialCredits.class.php
+++ b/includes/specials/SpecialCredits.class.php
@@ -14,6 +14,8 @@
class SpecialCredits extends BsSpecialPage {
+ private $aTranslators = array();
+
public function __construct() {
parent::__construct( 'SpecialCredits' );
}
@@ -64,7 +66,23 @@
$sOlContributors = '<ul>' . $sLiContributors . '</ul>';
$sOlTl = '<ul>' . $sLiTranslation . '</ul>';
- $aTranslators = $this->generateTranslatorsList();
+ $sKey = BsCacheHelper::getCacheKey( 'BlueSpice', 'Credits',
'Translators' );
+ $aData = BsCacheHelper::get( $sKey );
+
+ if ( $aData !== false ) {
+ wfDebugLog( 'BsMemcached', __CLASS__ . ': Fetching
translators from cache' );
+ $this->aTranslators = $aData;
+ } else {
+ wfDebugLog( 'BsMemcached', __CLASS__ . ': Fetching
translators from DB' );
+ $this->generateTranslatorsList();
+ // Keep list for one day
+ BsCacheHelper::set( $sKey, $this->aTranslators, 86400 );
+ }
+
+ $sLiTranslators = '';
+ foreach ( $this->aTranslators as $sTranslator ) {
+ $sLiTranslators .= Html::element( 'li', array(),
$sTranslator );
+ }
$sLink = '<a
href="https://translatewiki.net">translatewiki.net</a>';
$aOut = array();
@@ -89,8 +107,7 @@
$aOut[] = '<tr>';
$aOut[] = '<td style="vertical-align: top;">';
$aOut[] = '<i><h6>' . wfMessage( 'bs-credits-th', $sLink
)->text() . '</h6></i>';
- $aOut[] = '<ul><li>'. implode( '</li><li>',
$aTranslators['translators'] ) .'</li></ul>';
- $aOut[] = '<br />'. wfMessage( 'bs-credits-createdon',
$aTranslators['ts'] )->plain();
+ $aOut[] = '<ul>'. $sLiTranslators .'</ul>';
$aOut[] = '</td>';
$aOut[] = '<td style="vertical-align: top;">'. $sOlTl .'</td>';
$aOut[] = '</tr>';
@@ -99,23 +116,43 @@
$this->getOutput()->addHtml(implode( "\n", $aOut ) );
}
- public function generateTranslatorsList() {
- $vTranslators = file_get_contents( BSROOTDIR .
'/includes/specials/translators.json' );
- $vTranslators = FormatJson::decode( $vTranslators );
- $aTranslators = array();
- $vTs = 0;
+ private function generateTranslatorsList() {
+ global $IP;
+ $aPaths = array(
+ $IP . '/extensions/BlueSpiceExtensions/',
+ $IP . '/extensions/BlueSpiceFoundation/',
+ $IP . '/skins/BlueSpiceSkin/'
+ );
- foreach ( $vTranslators as $aData ) {
- if ( $aData instanceof StdClass ) {
- foreach ( $aData as $key => $sTranslator ) {
- $aTranslators['translators'][] =
$sTranslator;
+ foreach ( $aPaths as $sPath ) {
+ $this->readInTranslators( $sPath );
+ }
+
+ $this->aTranslators = array_map( 'trim', $this->aTranslators );
+ $this->aTranslators = array_unique( $this->aTranslators );
+ asort( $this->aTranslators );
+ }
+
+ private function readInTranslators( $sDir ) {
+ $oCurrentDirectory = new DirectoryIterator( $sDir );
+ foreach ( $oCurrentDirectory as $oFileinfo ) {
+ if ( $oFileinfo->isFile() && strpos(
$oFileinfo->getFilename(), '.json' ) !== false ) {
+ $sContent = json_decode(
+ file_get_contents(
$oFileinfo->getPath() .DS. $oFileinfo->getFilename() )
+ );
+ foreach ( $sContent as $aData ) {
+ if ( $aData instanceof StdClass &&
isset( $aData->authors ) ) {
+ foreach ( $aData->authors as
$Author ) {
+ $Author = preg_replace(
'#\<([0-9a-zA-Z]+)@(\w+)\.(\w+)\>#', '', $Author );
+ $this->aTranslators[] =
$Author;
+ }
+ }
}
+ continue;
}
- if ( is_numeric( $aData ) ) {
- $vTs =
RequestContext::getMain()->getLanguage()->date( $aData );
- $aTranslators['ts'] = $vTs;
+ if ( $oFileinfo->isDir() && !$oFileinfo->isDot() &&
$oFileinfo->getFilename() != $sDir ) {
+ $this->readInTranslators( $oFileinfo->getPath()
.DS. $oFileinfo->getFilename() );
}
}
- return $aTranslators;
}
}
\ No newline at end of file
diff --git a/maintenance/generateTranslators.php
b/maintenance/generateTranslators.php
deleted file mode 100644
index 24fa5aa..0000000
--- a/maintenance/generateTranslators.php
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-
-/**
- * @author Stephan Muggli
- */
-
-//We are on
<mediawiki>/extensions/BlueSpiceExtensions/ExtendedSearch/maintenance
-$IP = realpath( dirname( dirname( dirname( __DIR__ ) ) ) );
-
-require_once(
$IP.'/extensions/BlueSpiceFoundation/maintenance/BSMaintenance.php' );
-
-class generateTranslators extends BSMaintenance {
-
- private $aTranslators = array();
-
- public function execute() {
- global $IP;
- $aPaths = array(
- $IP . '/extensions/BlueSpiceExtensions/',
- $IP . '/extensions/BlueSpiceFoundation/',
- $IP . '/skins/BlueSpiceSkin/'
- );
-
- foreach( $aPaths as $sPath ) {
- $this->readInFiles( $sPath );
- }
- $this->aTranslators['translators'] = array_map( 'trim',
$this->aTranslators['translators'] );
- $this->aTranslators['translators'] = array_unique(
$this->aTranslators['translators'] );
- asort( $this->aTranslators['translators'] );
- $this->aTranslators['ts'] = wfTimestampNow();
-
- touch( $IP .
'/extensions/BlueSpiceFoundation/includes/specials/translators.json' );
- $vData = json_encode( $this->aTranslators );
- file_put_contents( $IP .
'/extensions/BlueSpiceFoundation/includes/specials/translators.json', $vData );
- }
-
- public function readInFiles( $sDir ) {
- $oCurrentDirectory = new DirectoryIterator( $sDir );
- foreach ( $oCurrentDirectory as $oFileinfo ) {
- if ( $oFileinfo->isFile() && strpos(
$oFileinfo->getFilename(), '.json' ) !== false ) {
- $sContent = json_decode(
- file_get_contents(
$oFileinfo->getPath() .DS. $oFileinfo->getFilename() )
- );
- foreach ( $sContent as $aData ) {
- if ( $aData instanceof StdClass &&
isset( $aData->authors ) ) {
- foreach ( $aData->authors as
$Author ) {
-
$this->aTranslators['translators'][] = $Author;
- }
- }
- }
- continue;
- }
- if ( $oFileinfo->isDir() && !$oFileinfo->isDot() &&
$oFileinfo->getFilename() != $sDir ) {
- $this->readInFiles( $oFileinfo->getPath() .DS.
$oFileinfo->getFilename() );
- }
- }
- }
-}
-
-$maintClass = 'generateTranslators';
-if (defined('RUN_MAINTENANCE_IF_MAIN')) {
- require_once( RUN_MAINTENANCE_IF_MAIN );
-} else {
- require_once( DO_MAINTENANCE ); # Make this work on versions before 1.17
-}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/157809
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibb69083152e6297e7d0936f182ce837fb93c029d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceFoundation
Gerrit-Branch: master
Gerrit-Owner: Smuggli <[email protected]>
Gerrit-Reviewer: Mglaser <[email protected]>
Gerrit-Reviewer: Pigpen <[email protected]>
Gerrit-Reviewer: Raimond Spekking <[email protected]>
Gerrit-Reviewer: Robert Vogel <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Smuggli <[email protected]>
Gerrit-Reviewer: Swidmann <[email protected]>
Gerrit-Reviewer: Tweichart <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits