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 raised the priority of this task from to Needs Triage.
Fomafix updated the task description. (Show Details)
Fomafix added a project: TextExtracts.
Fomafix added a subscriber: Fomafix.
Fomafix triaged this task as Medium priority.Nov 2 2015, 8:44 AM
Fomafix updated the task description. (Show Details)
Fomafix set Security to None.

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.

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.

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

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