Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special:Browse use structured array instead of hash #4452

Merged
merged 1 commit into from Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 4 additions & 15 deletions res/smw/special/ext.smw.special.browse.js
Expand Up @@ -49,25 +49,14 @@
var self = this,
subject = self.context.data( 'subject' );

// Expect a serialization format (see DIWikiPage::getHash)
if ( subject.indexOf( "#" ) == -1 ) {
return this.context.find( '.smwb-status' )
.append(
mw.msg( 'smw-browse-api-subject-serialization-invalid' )
)
.addClass( 'smw-callout smw-callout-error' );
}

subject = subject.split( "#" );

self.api.post( {
action: "smwbrowse",
browse: "subject",
params: JSON.stringify( {
subject: subject[0],
ns: subject[1],
iw: subject[2],
subobject: subject[3],
subject: subject.dbkey,
ns: subject.ns,
iw: subject.iw,
subobject: subject.subobject,
options: self.options,
type: 'html'
} )
Expand Down
20 changes: 18 additions & 2 deletions src/MediaWiki/Specials/Browse/HtmlBuilder.php
Expand Up @@ -140,10 +140,18 @@ public function getOption( $key, $default = null ) {
* @return string
*/
public function legacy() {

$subject = [
'dbkey' => $this->subject->getDBKey(),
'ns' => $this->subject->getNamespace(),
'iw' => $this->subject->getInterwiki(),
'subobject' => $this->subject->getSubobjectName(),
];

return Html::rawElement(
'div',
[
'data-subject' => $this->subject->getHash(),
'data-subject' => json_encode( $subject, JSON_UNESCAPED_UNICODE ),
'data-options' => json_encode( $this->options )
],
$this->buildHTML()
Expand All @@ -156,11 +164,19 @@ public function legacy() {
* @return string
*/
public function placeholder() {

$subject = [
'dbkey' => $this->subject->getDBKey(),
'ns' => $this->subject->getNamespace(),
'iw' => $this->subject->getInterwiki(),
'subobject' => $this->subject->getSubobjectName(),
];

return Html::rawElement(
'div',
[
'class' => 'smwb-container',
'data-subject' => $this->subject->getHash(),
'data-subject' => json_encode( $subject, JSON_UNESCAPED_UNICODE ),
'data-options' => json_encode( $this->options )
],
Html::rawElement(
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/Unit/MediaWiki/Specials/SpecialBrowseTest.php
Expand Up @@ -81,7 +81,7 @@ public function queryParameterProvider() {
$provider[] = [
'Foo/Bar',
[
'data-subject="Foo/Bar#0##"',
'data-subject="{"dbkey":"Foo\/Bar","ns":0,"iw":"","subobject":""}"',
'data-options="{"dir":null,"group":null,"printable":null,"offset":null,"including":null,"showInverse":false,"showAll":true,"showGroup":false,"showSort":false,"api":true,"valuelistlimit.out":"30","valuelistlimit.in":"20"}"'
]
];
Expand All @@ -90,7 +90,7 @@ public function queryParameterProvider() {
$provider[] = [
':Main-20Page-23_QUERY140d50d705e9566904fc4a877c755964',
[
'data-subject="Main_Page#0##_QUERY140d50d705e9566904fc4a877c755964"',
'data-subject="{"dbkey":"Main_Page","ns":0,"iw":"","subobject":"_QUERY140d50d705e9566904fc4a877c755964"}"',
'data-options="{"dir":null,"group":null,"printable":null,"offset":null,"including":null,"showInverse":false,"showAll":true,"showGroup":false,"showSort":false,"api":true,"valuelistlimit.out":"30","valuelistlimit.in":"20"}"'
]
];
Expand Down