Skip to content

Commit

Permalink
Special:Browse recognize inclusion mode (#2150)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Jan 8, 2017
1 parent 7d5536e commit 7f05215
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 44 deletions.
8 changes: 4 additions & 4 deletions src/MediaWiki/Api/BrowseBySubject.php
Expand Up @@ -5,7 +5,7 @@
use ApiBase;
use SMW\ApplicationFactory;
use SMW\DIWikiPage;
use SMW\MediaWiki\Specials\Browse\HtmlContentBuilder;
use SMW\MediaWiki\Specials\Browse\HtmlContentsBuilder;

/**
* Browse a subject api module
Expand Down Expand Up @@ -54,14 +54,14 @@ protected function getHtmlFormat( $params ) {
$params['subobject']
);

$htmlContentBuilder = new HtmlContentBuilder(
$HtmlContentsBuilder = new HtmlContentsBuilder(
ApplicationFactory::getInstance()->getStore(),
$subject
);

$htmlContentBuilder->setOptionsFromJsonFormat( $params['options'] );
$HtmlContentsBuilder->setOptionsFromJsonFormat( $params['options'] );

return $htmlContentBuilder->getHtml();
return $HtmlContentsBuilder->getHtml();
}

protected function getRawFormat( $params ) {
Expand Down
Expand Up @@ -21,7 +21,7 @@
* @author Denny Vrandecic
* @author mwjames
*/
class HtmlContentBuilder {
class HtmlContentsBuilder {

/**
* @var Store
Expand Down Expand Up @@ -172,7 +172,7 @@ public function getEmptyHtml() {
$html .= $this->displayData( $semanticData, $leftside, true );
$html .= $this->displayBottom( false );

if ( $this->getOption( 'printable' ) !== 'yes' ) {
if ( $this->getOption( 'printable' ) !== 'yes' && !$this->getOption( 'including' ) ) {
$html .= $this->queryForm( $this->articletext );
}

Expand Down Expand Up @@ -227,7 +227,7 @@ private function doGenerateHtml() {
\Hooks::run( 'SMW::Browse::AfterDataLookupComplete', array( $this->store, $semanticData, &$html, &$this->extraModules ) );
}

if ( $this->getOption( 'printable' ) !== 'yes' ) {
if ( $this->getOption( 'printable' ) !== 'yes' && !$this->getOption( 'including' ) ) {
$html .= $this->queryForm( $this->articletext );
}

Expand Down
63 changes: 38 additions & 25 deletions src/MediaWiki/Specials/SpecialBrowse.php
Expand Up @@ -8,7 +8,7 @@
use SMW\Localizer;
use SMW\SemanticData;
use SMW\UrlEncoder;
use SMW\MediaWiki\Specials\Browse\HtmlContentBuilder;
use SMW\MediaWiki\Specials\Browse\HtmlContentsBuilder;
use SMW\Message;
use SpecialPage;
use Html;
Expand Down Expand Up @@ -99,8 +99,8 @@ public function execute( $query ) {

private function getHtml( $webRequest, $isEmptyRequest ) {

if ( $isEmptyRequest ) {
return HtmlContentBuilder::getPageSearchQuickForm();
if ( $isEmptyRequest && !$this->including() ) {
return HtmlContentsBuilder::getPageSearchQuickForm();
}

if ( !$this->subjectDV->isValid() ) {
Expand All @@ -117,21 +117,29 @@ private function getHtml( $webRequest, $isEmptyRequest ) {
Message::get( array( 'smw-browse-invalid-subject', $error ), Message::ESCAPED )
);

return $html . HtmlContentBuilder::getPageSearchQuickForm();
if ( !$this->including() ) {
$html . HtmlContentsBuilder::getPageSearchQuickForm();
}

return $html;
}

$htmlContentBuilder = $this->newHtmlContentBuilder( $webRequest );
$HtmlContentsBuilder = $this->newHtmlContentsBuilder(
$webRequest,
$this->applicationFactory->getSettings()
);

if ( $webRequest->getVal( 'output' ) === 'legacy' || !$htmlContentBuilder->getOption( 'byApi' ) ) {
return $htmlContentBuilder->getHtml();
if ( $webRequest->getVal( 'output' ) === 'legacy' || !$HtmlContentsBuilder->getOption( 'byApi' ) ) {
return $HtmlContentsBuilder->getHtml();
}

$options = array(
'dir' => $htmlContentBuilder->getOption( 'dir' ),
'offset' => $htmlContentBuilder->getOption( 'offset' ),
'printable' => $htmlContentBuilder->getOption( 'printable' ),
'showInverse' => $htmlContentBuilder->getOption( 'showInverse' ),
'showAll' => $htmlContentBuilder->getOption( 'showAll' )
'dir' => $HtmlContentsBuilder->getOption( 'dir' ),
'offset' => $HtmlContentsBuilder->getOption( 'offset' ),
'printable' => $HtmlContentsBuilder->getOption( 'printable' ),
'showInverse' => $HtmlContentsBuilder->getOption( 'showInverse' ),
'showAll' => $HtmlContentsBuilder->getOption( 'showAll' ),
'including' => $HtmlContentsBuilder->getOption( 'including' )
);

// Ajax/API is doing the data fetch
Expand Down Expand Up @@ -168,51 +176,56 @@ private function getHtml( $webRequest, $isEmptyRequest ) {
array(
'class' => 'smw-overlay-spinner large inline'
)
) . $htmlContentBuilder->getEmptyHtml()
) . $HtmlContentsBuilder->getEmptyHtml()
)
);

return $html;
}

private function newHtmlContentBuilder( $webRequest ) {
private function newHtmlContentsBuilder( $webRequest, $settings ) {

$htmlContentBuilder = new HtmlContentBuilder(
$HtmlContentsBuilder = new HtmlContentsBuilder(
$this->applicationFactory->getStore(),
$this->subjectDV->getDataItem()
);

$htmlContentBuilder->setOption(
$HtmlContentsBuilder->setOption(
'dir',
$webRequest->getVal( 'dir' )
);

$htmlContentBuilder->setOption(
$HtmlContentsBuilder->setOption(
'printable',
$webRequest->getVal( 'printable' )
);

$htmlContentBuilder->setOption(
$HtmlContentsBuilder->setOption(
'offset',
$webRequest->getVal( 'offset' )
);

$htmlContentBuilder->setOption(
$HtmlContentsBuilder->setOption(
'including',
$this->including()
);

$HtmlContentsBuilder->setOption(
'showInverse',
$this->applicationFactory->getSettings()->get( 'smwgBrowseShowInverse' )
$settings->get( 'smwgBrowseShowInverse' )
);

$htmlContentBuilder->setOption(
$HtmlContentsBuilder->setOption(
'showAll',
$this->applicationFactory->getSettings()->get( 'smwgBrowseShowAll' )
$settings->get( 'smwgBrowseShowAll' )
);

$htmlContentBuilder->setOption(
$HtmlContentsBuilder->setOption(
'byApi',
$this->applicationFactory->getSettings()->get( 'smwgBrowseByApi' )
$settings->get( 'smwgBrowseByApi' )
);

return $htmlContentBuilder;
return $HtmlContentsBuilder;
}

private function addExternalHelpLinks() {
Expand Down
Expand Up @@ -2,21 +2,21 @@

namespace SMW\Tests\MediaWiki\Specials\Browse;

use SMW\MediaWiki\Specials\Browse\HtmlContentBuilder;
use SMW\MediaWiki\Specials\Browse\HtmlContentsBuilder;
use SMW\Tests\TestEnvironment;
use SMW\DIWikiPage;
use SMW\SemanticData;

/**
* @covers \SMW\MediaWiki\Specials\Browse\HtmlContentBuilder
* @covers \SMW\MediaWiki\Specials\Browse\HtmlContentsBuilder
* @group semantic-mediawiki
*
* @license GNU GPL v2+
* @since 2.5
*
* @author mwjames
*/
class HtmlContentBuilderTest extends \PHPUnit_Framework_TestCase {
class HtmlContentsBuilderTest extends \PHPUnit_Framework_TestCase {

private $testEnvironment;
private $store;
Expand All @@ -40,20 +40,20 @@ protected function tearDown() {

public function testCanConstruct() {

$instance = new HtmlContentBuilder(
$instance = new HtmlContentsBuilder(
$this->store,
DIWikiPage::newFromText( 'Foo' )
);

$this->assertInstanceOf(
HtmlContentBuilder::class,
HtmlContentsBuilder::class,
$instance
);
}

public function testGetEmptyHtml() {

$instance = new HtmlContentBuilder(
$instance = new HtmlContentsBuilder(
$this->store,
DIWikiPage::newFromText( 'Foo' )
);
Expand All @@ -68,7 +68,7 @@ public function testGetPageSearchQuickForm() {

$this->assertInternalType(
'string',
HtmlContentBuilder::getPageSearchQuickForm()
HtmlContentsBuilder::getPageSearchQuickForm()
);
}

Expand All @@ -80,7 +80,7 @@ public function testGetHtml() {
->method( 'getSemanticData' )
->will( $this->returnValue( new SemanticData( $subject ) ) );

$instance = new HtmlContentBuilder(
$instance = new HtmlContentsBuilder(
$this->store,
$subject
);
Expand All @@ -103,7 +103,7 @@ public function testGetHtmlWithOptions() {
->method( 'getInProperties' )
->will( $this->returnValue( array() ) );

$instance = new HtmlContentBuilder(
$instance = new HtmlContentsBuilder(
$this->store,
$subject
);
Expand All @@ -130,7 +130,7 @@ public function testOptions() {

$subject = DIWikiPage::newFromText( 'Foo' );

$instance = new HtmlContentBuilder(
$instance = new HtmlContentsBuilder(
$this->store,
$subject
);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/Unit/MediaWiki/Specials/SpecialBrowseTest.php
Expand Up @@ -80,7 +80,7 @@ public function queryParameterProvider() {
'Foo/Bar',
array(
'data-subject="Foo/Bar#0#"',
'data-options="{"dir":null,"offset":null,"printable":null,"showInverse":false,"showAll":true}"'
'data-options="{"dir":null,"offset":null,"printable":null,"showInverse":false,"showAll":true,"including":null}"'
)
);

Expand All @@ -89,7 +89,7 @@ public function queryParameterProvider() {
':Main-20Page-23_QUERY140d50d705e9566904fc4a877c755964',
array(
'data-subject="Main_Page#0##_QUERY140d50d705e9566904fc4a877c755964"',
'data-options="{"dir":null,"offset":null,"printable":null,"showInverse":false,"showAll":true}"'
'data-options="{"dir":null,"offset":null,"printable":null,"showInverse":false,"showAll":true,"including":null}"'
)
);

Expand Down

0 comments on commit 7f05215

Please sign in to comment.