Page MenuHomePhabricator

Deliver page content language together with the extract
Closed, ResolvedPublic

Description

The language code of the page content language and the direction of the language is needed to generate the HTML attributes lang and dir. The lang must be BCP 47 conform. The mapping from the internal language code to the BCP 47 conform language code and the mapping from the language code to the direction of the language exists only in PHP, so they have to delivered with the response.

I see two possibilities:

"extract": "<p>Eine <b>Strasse</b> (von lat. [via] <i>strata</i> «gepflasterter Weg») ist ein …</p>",
"lang": "de-CH",
"dir": "ltr",

or

"extract": "<div class=\"mw-content-ltr\" dir=\"ltr\" lang=\"de-CH\"><p>Eine <b>Strasse</b> (von lat. [via] <i>strata</i> «gepflasterter Weg») ist ein …</p></div>",

I prefer the second option but this is an incompatible change.

Event Timeline

Fomafix created this task.Nov 2 2015, 8:37 AM
Fomafix updated the task description. (Show Details)
Fomafix raised the priority of this task from to Needs Triage.
Fomafix added a project: TextExtracts.
Fomafix added a subscriber: Fomafix.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptNov 2 2015, 8:37 AM
Fomafix updated the task description. (Show Details)Nov 2 2015, 8:44 AM
Fomafix triaged this task as Normal priority.
Fomafix set Security to None.
Fomafix updated the task description. (Show Details)Nov 2 2015, 9:03 AM
Fomafix updated the task description. (Show Details)Nov 2 2015, 10:19 AM
Fomafix updated the task description. (Show Details)Nov 2 2015, 1:49 PM
Fomafix claimed this task.Nov 2 2015, 5:13 PM

Change 250456 had a related patch set uploaded (by Gerrit Patch Uploader):
API: Enclose extract in an element with page content language attributes

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

Adding prop=info already delivers

"pagelanguage": "de-ch"

But this language code has to wfBCP47()fied and the mapping to the direction of the language is missing in JavaScript.

TheDJ added a subscriber: TheDJ.Nov 2 2015, 9:20 PM

actually lang->getHtmlCode() is already BCP47'ified:

public function getHtmlCode() {
                if ( is_null( $this->mHtmlCode ) ) {
                        $this->mHtmlCode = wfBCP47( $this->getCode() );
}

I think the first solution you propose is actually a better one - the caller should take care of the rendering/wrapping.

TheDJ added a comment.Nov 3 2015, 9:53 AM

I agree with jon that it the first solution is better. It matches what we do in other areas of the api.

Change 250760 had a related patch set uploaded (by Gerrit Patch Uploader):
ApiQueryInfo.php: Add code and direction of the page content language

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

Change 250760 merged by jenkins-bot:
ApiQueryInfo.php: Add code and direction of the page content language

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

Jdlrobson closed this task as Resolved.Nov 6 2015, 7:27 PM

pagelanguagehtmlcode and pagelanguagedir are now available! yay!

Change 250456 abandoned by Fomafix:
API: Add the code and the direction of the page content language

Reason:
Superseded by https://gerrit.wikimedia.org/r/250760

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