SuchetaG has submitted this change and it was merged.
Change subject: Handle null message content gracefully
......................................................................
Handle null message content gracefully
This skips messages for which we fail to load any content.
This avoids null messages showing up in Special:TranslationStash.
Change-Id: I019e6635726f06f6c1bf1de1ccaf977b587ce44e
---
M messagegroups/SandboxMessageGroup.php
1 file changed, 34 insertions(+), 5 deletions(-)
Approvals:
SuchetaG: Looks good to me, approved
Amire80: Looks good to me, but someone else must approve
diff --git a/messagegroups/SandboxMessageGroup.php
b/messagegroups/SandboxMessageGroup.php
index d54c573..02f1ffc 100644
--- a/messagegroups/SandboxMessageGroup.php
+++ b/messagegroups/SandboxMessageGroup.php
@@ -101,15 +101,26 @@
$handle = new MessageHandle( $title );
if ( MessageGroups::isTranslatableMessage( $handle ) ) {
- $count++;
+ // Modified by reference
$translation = $this->getMessageContent(
$handle );
+ if ( $translation === null ) {
+ // Something is not in sync or badly
broken. Handle gracefully.
+ unset( $list[$index] );
+ wfWarn( "No message definition for
$index while preparing the sandbox" );
+
+ continue;
+ }
} else {
// This might include messages that the user
has already translated
// or messages given in
$wgTranslateSandboxSuggestions or just dated
// message index.
unset( $list[$index] );
- wfWarn( "Unsuitable or unknown message $index
while preparing sanbox" );
+ wfWarn( "Unsuitable or unknown message $index
while preparing sandbox" );
+
+ continue;
}
+
+ $count++;
// Always show 20 messages (or less in rare cases)
if ( $count === 20 ) {
@@ -133,10 +144,28 @@
public function getMessageContent( MessageHandle $handle ) {
$groupId = MessageIndex::getPrimaryGroupId( $handle );
$group = MessageGroups::getGroup( $groupId );
- if ( $group ) {
- return $group->getMessage( $handle->getKey(),
$group->getSourceLanguage() );
+ $key = $handle->getKey();
+
+ $source = $group->getMessage( $key, $group->getSourceLanguage()
);
+ if ( $source !== null ) {
+ return $source;
}
- throw new MWException( 'Could not find group for ' .
$handle->getKey() );
+ // Try harder
+ $keys = array();
+ if ( method_exists( $group, 'getKeys' ) ) {
+ $keys = $group->getKeys();
+ } else {
+ $keys = array_keys( $group->getDefinitions() );
+ }
+ // Try to find the original key with correct case
+ foreach ( $keys as $realkey ) {
+ if ( $key === strtolower( $realkey ) ) {
+ $key = $realkey;
+ break;
+ }
+ }
+
+ return $group->getMessage( $key, $group->getSourceLanguage() );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/89632
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I019e6635726f06f6c1bf1de1ccaf977b587ce44e
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: SuchetaG <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits