Page MenuHomePhabricator

Syntax highlighting - translate and tvar tags
Closed, ResolvedPublic5 Story Points

Description

A request from Karen on wmfall:

Don't suppose you can find a way to have the highlighter handle <translate> and <tvar> tags on Meta as well? It would make readability of translated pages' wikitext (and finding where I borked translation markup) MUCH easier

As usual, as soon as I hit sent I realized I hadn't been clear: the new highlighter doesn't exactly NOT handle translate tags and tvars, but it looks like it's inconsistent, at least on the complex page I'm testing viewing it on (see attached screenshots), and it would be awesome if those could be made really visually distinct in some way (it would make it WAY easier to find unmatched tags, etc).

Also, from IKhitron: "We already talked about nesting problem, in files, and here is another one. Open the last Tech News issue and see the <tvar> tags."

Event Timeline

DannyH created this task.Aug 3 2017, 10:36 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptAug 3 2017, 10:36 PM
DannyH updated the task description. (Show Details)Aug 3 2017, 10:41 PM
Kbrown added a subscriber: Kbrown.Aug 3 2017, 10:42 PM
DannyH updated the task description. (Show Details)Aug 3 2017, 10:49 PM
Quiddity updated the task description. (Show Details)Aug 3 2017, 10:53 PM
kaldari triaged this task as Normal priority.Aug 22 2017, 11:22 PM
kaldari set the point value for this task to 5.
TBolliger moved this task from Estimated to Archive on the Community-Tech board.Feb 14 2018, 12:58 AM
MusikAnimal edited projects, added Community-Tech-Sprint; removed Community-Tech.
MusikAnimal moved this task from Ready to In Development on the Community-Tech-Sprint board.

Change 416501 had a related patch set uploaded (by MusikAnimal; owner: MusikAnimal):
[mediawiki/extensions/CodeMirror@master] Add <translate> as a permitted tag

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

MusikAnimal added a comment.EditedMar 5 2018, 8:06 PM

The above adds <translate> as a valid tag. We can definitely make it have a unique colour, but I'll need help deciding what colour that should be :)

<tvar> is tricky because the closing tag strangely is </>. I think making this work is probably a 5 or 8-pointer by itself, and can be saved for a different patch. Hopefully adding support for <translate> is a good enough start.

The other thing to note is <translate> is not part of MediaWiki core. CodeMirror will treat this tag as valid even for wikis without the Translate extension, but I think that's okay...?

The above adds <translate> as a valid tag. We can definitely make it have a unique colour, but I'll need help deciding what colour that should be :)
<tvar> is tricky because the closing tag strangely is </>. I think making this work is probably a 5 or 8-pointer by itself, and can be saved for a different patch. Hopefully adding support for <translate> is a good enough start.
The other thing to note is <translate> is not part of MediaWiki core. CodeMirror will treat this tag as valid even for wikis without the Translate extension, but I think that's okay...?

So the correct way to do this would be as described in T163238: Integration of CodeMirror with other tag extensions. There is an example here - https://gerrit.wikimedia.org/r/#/c/348673/
But if that's too hard, I don't really mind rolling with this.

Interestingly the Translate extension does not have an extension.json file. I'm not sure where the configuration should go. Any ideas? Maybe @Nikerabbit ? (in short, we need to do this for the Translate extension: https://gerrit.wikimedia.org/r/#/c/348673/5/extension.json)

Reedy added a subscriber: Reedy.Mar 7 2018, 5:49 PM

Add it to Translate.php

Thanks! I tried $wgCodeMirrorTagModes['translate'] = 'text/mediawiki'; in Translate.php which I think is the way to do it... but no dice :/

There may be an issue with my local setup. Translate is definitely installed because I can browse to Special:Translate, but for instance Cite apparently is not. That supposedly is now bundled in with MediaWiki, and I'm using the latest version. <ref> does not get highlighted, nor do references work at all. Any ideas on that front? I'd like to see <ref> get highlighted before I conclude I'm configuring <translate> incorrectly.

Reedy added a comment.Mar 7 2018, 6:58 PM

Does var_dump( $wgCodeMirrorTagModes, $wgCodeMirrorTagModes['translate'] ); in eval.php on your wiki to what you expect?

Just because it's bundled, doesn't mean it's enabled... Special:Version?

This is quickly turning into a rabbit hole. It seems the Translate extension doesn't queue itself in ExtensionRegistry, which is what CodeMirror pulls from. I can't find a way to hack in tag specifications using global variables, unless we update CodeMirror to look for them.

I'm more inclined to introduce <translate> as if it were a core tag, with 416501. This won't hurt wikis using CodeMirror that don't have Translate, it just may be misleading, is all? I'd be surprised if anyone complained.

Again adding support for <tvar> is especially challenging because the closing tag is </>. I'd prefer to side step that, for now.

Reedy added a comment.Mar 7 2018, 8:06 PM

This is quickly turning into a rabbit hole. It seems the Translate extension doesn't queue itself in ExtensionRegistry, which is what CodeMirror pulls from. I can't find a way to hack in tag specifications using global variables, unless we update CodeMirror to look for them.

It wouldn't, MW does that

function wfLoadExtension( $ext, $path = null ) {
	if ( !$path ) {
		global $wgExtensionDirectory;
		$path = "$wgExtensionDirectory/$ext/extension.json";
	}
	ExtensionRegistry::getInstance()->queue( $path );
}
MusikAnimal added a comment.EditedMar 7 2018, 8:12 PM

Right, but Translate does not have an extension.json? So it seems it is never queued, or at least that's how I'm reading it.

extension.json is coming, but I could use some help: https://gerrit.wikimedia.org/r/c/391645/

I think most blockers are resolved now, except I still have no idea how to update https://www.mediawiki.org/wiki/Help:Extension:Translate/Configuration after the migration.

Reedy added a comment.Mar 8 2018, 5:40 PM

extension.json is coming, but I could use some help: https://gerrit.wikimedia.org/r/c/391645/
I think most blockers are resolved now, except I still have no idea how to update https://www.mediawiki.org/wiki/Help:Extension:Translate/Configuration after the migration.

I don't think you need to make many changes to that page...

I'm more inclined to introduce <translate> as if it were a core tag, with 416501. This won't hurt wikis using CodeMirror that don't have Translate, it just may be misleading, is all? I'd be surprised if anyone complained.

I am inclined to agree but we can wait a few days to see if 391645 gets merged in the meantime.

Change 416501 merged by jenkins-bot:
[mediawiki/extensions/CodeMirror@master] Add <translate> as a permitted tag

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

Niharika closed this task as Resolved.Mar 13 2018, 8:25 PM
Niharika moved this task from Needs Review/Feedback to Q1 2018-19 on the Community-Tech-Sprint board.

Change 416501 merged by jenkins-bot:
[mediawiki/extensions/CodeMirror@master] Add <translate> as a permitted tag
https://gerrit.wikimedia.org/r/416501

Or we could roll with that. :)
I'll create another ticket to deal with tvar tags in future,