Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions src/EntryPoints/NetworkFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
use MediaWiki\Extension\Network\NetworkFunction\NetworkPresenter;
use MediaWiki\Extension\Network\NetworkFunction\NetworkUseCase;
use MediaWiki\Extension\Network\NetworkFunction\RequestModel;
use MediaWiki\Parser\Parser;
use MediaWiki\Title\Title;
use Parser;

class NetworkFunction {

/**
* @var NetworkConfig
*/
private $config;

public function __construct( NetworkConfig $config ) {
$this->config = $config;
public function __construct(
private readonly NetworkConfig $config
) {
}

public static function onParserFirstCallInit( Parser $parser ): void {
Expand All @@ -32,12 +28,7 @@ static function () {
);
}

/**
* @param Parser $parser
* @param string ...$arguments
* @return array|string
*/
public function handleParserFunctionCall( Parser $parser, string ...$arguments ) {
public function handleParserFunctionCall( Parser $parser, string ...$arguments ): array|string {
$parser->getOutput()->addModules( [ 'ext.network' ] );
$parser->getOutput()->setJsConfigVar( 'networkExcludeTalkPages', $this->config->getExcludeTalkPages() );

Expand Down
10 changes: 6 additions & 4 deletions src/EntryPoints/SpecialNetwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace MediaWiki\Extension\Network\EntryPoints;

use IncludableSpecialPage;
use MediaWiki\Extension\Network\Extension;
use MediaWiki\Extension\Network\NetworkFunction\NetworkConfig;
use MediaWiki\Extension\Network\NetworkFunction\NetworkPresenter;
use MediaWiki\Extension\Network\NetworkFunction\NetworkUseCase;
use MediaWiki\Extension\Network\NetworkFunction\RequestModel;
use MediaWiki\Html\Html;
use MediaWiki\MediaWikiServices;
use MediaWiki\Message\Message;
use MediaWiki\Request\WebRequest;
use MediaWiki\SpecialPage\IncludableSpecialPage;
use MediaWiki\Title\Title;
use Message;
use WebRequest;

/**
* @psalm-suppress PropertyNotSetInConstructor
Expand All @@ -25,7 +25,9 @@ public function __construct() {
parent::__construct( 'Network' );
}

// phpcs:ignore MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic
/**
* @inheritDoc
*/
public function execute( $subPage ): void {
$this->setHeaders();

Expand Down
31 changes: 7 additions & 24 deletions src/NetworkFunction/NetworkConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,13 @@
use MediaWiki\MediaWikiServices;

class NetworkConfig {
/**
* @var array
*/
private $options;

/**
* @var bool
*/
private $excludeTalkPages;

/**
* @var string[]
*/
private $excludedNamespaces;

/**
* @var bool
*/
private $enableDisplayTitle;

/**
* @var int
*/
private $labelMaxLength;

private readonly array $options;
private readonly bool $excludeTalkPages;
/** @var string[] */
private readonly array $excludedNamespaces;
private readonly bool $enableDisplayTitle;
private readonly int $labelMaxLength;

public function __construct() {
$config = MediaWikiServices::getInstance()->getMainConfig();
Expand Down
9 changes: 2 additions & 7 deletions src/NetworkFunction/NetworkUseCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@

class NetworkUseCase {

private NetworkPresenter $presenter;
private array $visJsOptions;

public function __construct(
NetworkPresenter $presenter,
array $visJsOptions
private readonly NetworkPresenter $presenter,
private readonly array $visJsOptions
) {
$this->presenter = $presenter;
$this->visJsOptions = $visJsOptions;
}

public function run( RequestModel $request ): void {
Expand Down
5 changes: 1 addition & 4 deletions src/NetworkFunction/ParserFunctionNetworkPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

class ParserFunctionNetworkPresenter extends AbstractNetworkPresenter {

/**
* @var array
*/
private $parserFunctionReturnValue = [];
private array $parserFunctionReturnValue = [];

public function buildGraph( ResponseModel $viewModel ): void {
$this->setHtml( $viewModel );
Expand Down
5 changes: 1 addition & 4 deletions src/NetworkFunction/SpecialNetworkPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ public function buildGraph( ResponseModel $viewModel ): void {
$this->setHtml( $viewModel );
}

/**
* @return string
*/
public function getReturnValue() {
public function getReturnValue(): string {
return $this->html;
}

Expand Down
34 changes: 17 additions & 17 deletions tests/php/NetworkFunction/NetworkUseCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NetworkUseCaseTest extends TestCase {

private const RENDERING_PAGE_NAME = 'MyPage';

public function testDefaultPageName() {
public function testDefaultPageName(): void {
$this->assertSame(
[ self::RENDERING_PAGE_NAME ],
$this->runAndReturnPresenter( $this->newBasicRequestModel() )->getResponseModel()->pageNames
Expand Down Expand Up @@ -53,7 +53,7 @@ private function newBasicRequestModel(): RequestModel {
return $request;
}

public function testSpecifiedPageName() {
public function testSpecifiedPageName(): void {
$request = $this->newBasicRequestModel();
$request->functionArguments = [ 'page = Kittens' ];

Expand All @@ -63,7 +63,7 @@ public function testSpecifiedPageName() {
);
}

public function testDefaultCssClass() {
public function testDefaultCssClass(): void {
$request = $this->newBasicRequestModel();

$this->assertSame(
Expand All @@ -72,7 +72,7 @@ public function testDefaultCssClass() {
);
}

public function testSpecifiedCssClass() {
public function testSpecifiedCssClass(): void {
$request = $this->newBasicRequestModel();
$request->functionArguments = [ 'class = col-lg-3 mt-2 ' ];

Expand All @@ -82,7 +82,7 @@ public function testSpecifiedCssClass() {
);
}

public function testMultiplePageNames() {
public function testMultiplePageNames(): void {
$request = $this->newBasicRequestModel();
$request->functionArguments = [ 'Kittens', 'Cats', 'page = Tigers', 'page=Bobcats ' ];

Expand All @@ -92,7 +92,7 @@ public function testMultiplePageNames() {
);
}

public function testPageParametersWithPipe() {
public function testPageParametersWithPipe(): void {
$request = $this->newBasicRequestModel();
$request->functionArguments = [ 'Kittens|Cats', 'pages = Tigers|Bobcats' ];

Expand All @@ -102,14 +102,14 @@ public function testPageParametersWithPipe() {
);
}

public function testNothingExcludedByDefault() {
public function testNothingExcludedByDefault(): void {
$this->assertSame(
[],
$this->runAndReturnPresenter( $this->newBasicRequestModel() )->getResponseModel()->excludedPages
);
}

public function testExclude() {
public function testExclude(): void {
$request = $this->newBasicRequestModel();
$request->functionArguments = [ 'Kittens', 'exclude = Foo ; Bar ; Baz:bah' ];

Expand All @@ -119,7 +119,7 @@ public function testExclude() {
);
}

public function testCanUseMaxPages() {
public function testCanUseMaxPages(): void {
$request = $this->newBasicRequestModel();
$request->functionArguments = $this->getPageNames( 100 );

Expand All @@ -139,7 +139,7 @@ private function getPageNames( int $count ): array {
return $pageNames;
}

public function testMoreThanMaxPagesResultsInError() {
public function testMoreThanMaxPagesResultsInError(): void {
$request = $this->newBasicRequestModel();
$request->functionArguments = $this->getPageNames( 101 );

Expand All @@ -149,15 +149,15 @@ public function testMoreThanMaxPagesResultsInError() {
);
}

public function testDefaultEnableDisplayTitle() {
public function testDefaultEnableDisplayTitle(): void {
$request = $this->newBasicRequestModel();

$this->assertTrue(
$this->runAndReturnPresenter( $request )->getResponseModel()->enableDisplayTitle
);
}

public function testOverrideEnableDisplayTitleTrue() {
public function testOverrideEnableDisplayTitleTrue(): void {
$request = $this->newBasicRequestModel();
$request->functionArguments = [ 'enableDisplayTitle = true' ];

Expand All @@ -166,7 +166,7 @@ public function testOverrideEnableDisplayTitleTrue() {
);
}

public function testOverrideEnableDisplayTitleFalse() {
public function testOverrideEnableDisplayTitleFalse(): void {
$request = $this->newBasicRequestModel();
$request->functionArguments = [ 'enableDisplayTitle = false' ];

Expand All @@ -175,7 +175,7 @@ public function testOverrideEnableDisplayTitleFalse() {
);
}

public function testNoOptionsInLocalSettingsAndNoOptionsParameter() {
public function testNoOptionsInLocalSettingsAndNoOptionsParameter(): void {
$presenter = new SpyNetworkPresenter();
( new NetworkUseCase( $presenter, [] ) )->run( $this->newBasicRequestModel() );

Expand All @@ -185,7 +185,7 @@ public function testNoOptionsInLocalSettingsAndNoOptionsParameter() {
);
}

public function testOptionsInLocalSettings() {
public function testOptionsInLocalSettings(): void {
$setting = [
'height' => '42%',
'layout' => [
Expand All @@ -202,7 +202,7 @@ public function testOptionsInLocalSettings() {
);
}

public function testOptionsParameter() {
public function testOptionsParameter(): void {
$request = $this->newBasicRequestModel();
$request->functionArguments = [ 'options={"nodes": {"shape": "box"}}' ];

Expand All @@ -219,7 +219,7 @@ public function testOptionsParameter() {
);
}

public function testOptionsParameterWithLocalSettingsConfig() {
public function testOptionsParameterWithLocalSettingsConfig(): void {
$setting = [
'height' => '42%',
'nodes' => [
Expand Down
2 changes: 1 addition & 1 deletion tests/php/NetworkFunction/SpyNetworkPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class SpyNetworkPresenter implements NetworkPresenter {

private ResponseModel $viewModel;
private ?ResponseModel $viewModel = null;
private array $errors = [];

public function buildGraph( ResponseModel $viewModel ): void {
Expand Down
4 changes: 2 additions & 2 deletions tests/php/NetworkFunctionIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ private function parse( string $textToParse ): string {
->getContentHolderText();
}

public function testWhenThereAreNoParameters_contextPageIsUsed() {
public function testWhenThereAreNoParameters_contextPageIsUsed(): void {
$this->assertStringContainsString(
'data-pages="["ContextPageTitle"]"',
$this->parse( '{{#network:}}' )
);
}

public function testOptionsParameters() {
public function testOptionsParameters(): void {
$this->assertStringContainsString(
'"shape":"tomato"',
$this->parse( '{{#network:options={"nodes": {"shape": "tomato"} } }}' )
Expand Down
Loading