Skip to content

Commit

Permalink
Special:Browse use stuctured array instead of hash (#4452)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Jan 25, 2020
1 parent abe1789 commit 51a804c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
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

0 comments on commit 51a804c

Please sign in to comment.