Last modified: 2014-10-28 06:57:24 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T59964, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 57964 - Importing an invalid gettext file causes "Fatal exception of type MWException"
Importing an invalid gettext file causes "Fatal exception of type MWException"
Status: NEW
Product: MediaWiki extensions
Classification: Unclassified
Translate (Other open bugs)
unspecified
All All
: Low minor (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-12-04 07:55 UTC by Tilman Bayer
Modified: 2014-10-28 06:57 UTC (History)
10 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Removed else throw MWexception line -111 (18.32 KB, text/plain)
2014-10-09 14:58 UTC, ntekriwal
Details

Description Tilman Bayer 2013-12-04 07:55:20 UTC
Steps to reproduce:

* Create a .po file that solely consist of the text "test"

* Upload this file at https://meta.wikimedia.org/wiki/Special:ImportTranslations

This results in an internal error page: "Fatal exception of type MWException"


Instead, the user should receive a proper error message, if possible with more detail about the invalid parts. The corresponding internal error on testwiki at least tells the user that file lacks a valid header:


* Upload the file at https://test.wikipedia.org/wiki/Special:ImportTranslations 

This results in the following error message:


Internal error - Test {{SITENAME}}
[609c3d98] /wiki/Special:ImportTranslations Exception from line 107 of /usr/local/apache/common-local/php-1.23wmf5/extensions/Translate/ffs/GettextFFS.php: Gettext file header was not found:

test
Backtrace:
#0 /usr/local/apache/common-local/php-1.23wmf5/extensions/Translate/ffs/GettextFFS.php(67): GettextFFS::parseGettextData(string, boolean, StringMatcher, string)
#1 /usr/local/apache/common-local/php-1.23wmf5/extensions/Translate/ffs/GettextFFS.php(47): GettextFFS->parseGettext(string)
#2 /usr/local/apache/common-local/php-1.23wmf5/extensions/Translate/specials/SpecialImportTranslations.php(196): GettextFFS->readFromVariable(string)
#3 /usr/local/apache/common-local/php-1.23wmf5/extensions/Translate/specials/SpecialImportTranslations.php(70): SpecialImportTranslations->parseFile(string)
#4 /usr/local/apache/common-local/php-1.23wmf5/includes/SpecialPage.php(670): SpecialImportTranslations->execute(NULL)
#5 /usr/local/apache/common-local/php-1.23wmf5/includes/SpecialPageFactory.php(488): SpecialPage->run(NULL)
#6 /usr/local/apache/common-local/php-1.23wmf5/includes/Wiki.php(298): SpecialPageFactory::executePath(Title, RequestContext)
#7 /usr/local/apache/common-local/php-1.23wmf5/includes/Wiki.php(596): MediaWiki->performRequest()
#8 /usr/local/apache/common-local/php-1.23wmf5/includes/Wiki.php(460): MediaWiki->main()
#9 /usr/local/apache/common-local/php-1.23wmf5/index.php(49): MediaWiki->run()
#10 /usr/local/apache/common-local/w/index.php(3): require(string)
#11 {main}
Comment 1 ntekriwal 2014-10-09 14:58:07 UTC
Created attachment 16734 [details]
Removed else throw MWexception line -111

The fatal exception is being thrown because in /Translate/ffs/GettextFFS.php its defined 
if ( $match !== null ) {
			$headerBlock = self::formatForWiki( $match, 'trim' );
			$headers = self::parseHeaderTags( $headerBlock );

			// Check for pot-mode by checking if the header is fuzzy
			$flags = self::parseFlags( $headerSection );
			if ( in_array( 'fuzzy', $flags, true ) ) {
				$potmode = true;
			}
		} else {
			throw new MWException( "Gettext file header was not found:\n\n$data" );
		}

This overwrites the checkError call in SpecialImportTransaltions.php 


protected function checkError( $msg ) {
		// Give grep a chance to find the usages:
		// translate-import-err-dl-failed, translate-import-err-ul-failed,
		// translate-import-err-invalid-title, translate-import-err-no-such-file,
		// translate-import-err-stale-group, translate-import-err-no-headers,
		// translate-import-err-warnings
		if ( $msg[0] !== 'ok' ) {
			$errorWrap = "<div class='error'>\n$1\n</div>";
         
			$msg[0] = 'translate-import-err-' . $msg[0];

			$this->getOutput()->wrapWikiMsg( $errorWrap, $msg );
			$this->outputForm();

			return true;
		}

		return false;
	}


Remove the else statement in
 public static function parseGettextData( $data, $useCtxtAsKey, $mangler, $keyAlgorithm )
 GettextFFS.php  

I have attached the correct file.
Comment 2 Nemo 2014-10-09 15:11:19 UTC
(In reply to ntekriwal from comment #1)
> I have attached the correct file.

Thank you! Can you submit the patch in gerrit next time? See instructions at https://www.mediawiki.org/wiki/Git/Tutorial or do it via web with the https://www.mediawiki.org/wiki/Gerrit_patch_uploader

With your patch, did you verify that the output is a "translate-import-err-no-headers" error? Removing the exception is an improvement only if we actually give useful information to the user as requested in comment 0. :)
Comment 3 ntekriwal 2014-10-10 05:33:19 UTC
Yes I verified $msg[0] gets "no headers"
And the error shown is : 
"File is not a well formed Gettext file in Translate extension format: Unable to determine message group and language from file headers."
Comment 4 Andre Klapper 2014-10-10 16:08:08 UTC
So we need a patch in Gerrit, to review it there. Would you be interested in trying that? :)
Comment 5 Gerrit Notification Bot 2014-10-11 12:53:39 UTC
Change 166187 had a related patch set uploaded by Brainzest:
Fix for bug 57964

https://gerrit.wikimedia.org/r/166187
Comment 6 Gerrit Notification Bot 2014-10-13 10:28:11 UTC
Change 166187 abandoned by Brainzest:
Fix for bug 57964

https://gerrit.wikimedia.org/r/166187
Comment 7 Gerrit Notification Bot 2014-10-13 10:39:06 UTC
Change 166391 had a related patch set uploaded by Brainzest:
Fix for bug 57964

https://gerrit.wikimedia.org/r/166391
Comment 8 Gerrit Notification Bot 2014-10-27 23:31:46 UTC
Change 166391 abandoned by Siebrand:
Fix for bug 57964

Reason:
I'm abandoning this. This should be mitigated in the caller.

https://gerrit.wikimedia.org/r/166391

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links