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

Adding new parameters: AllowOnlyLinksToPages and AllowLinkExpansion #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ Example with parameters
Overrides the value of the <code>$wgPageNetworkLabelMaxLength</code> configuration variable.
</td>
</tr>
<tr>
<th>AllowOnlyLinksToPages</th>
<td>true</td>
<td>false</td>
<td>
When set to true, during initialization nodes have only links drawn between the listed pages (from page or pages parameter).
</td>
</tr>
<tr>
<th>AllowLinkExpansion</th>
<td>true</td>
<td>false</td>
<td>
When set to true, when holding the left mouse button over graph node the links from node will be drawn.
Otherwise (when set to false) this behaviour is supressed.
</td>
</tr>
</table>

There is also an includable special page, Special:Network, that can be used to construct graphs interactively. The
Expand Down Expand Up @@ -315,6 +332,32 @@ Wrong: `"font.color": "red"`, right: `"font": { "color": "red" }`, also right: `

Where `NetworkPages` contains `Page1 | Page2 | Page3` and `NetworkOptions` contains `{ "nodes": { "shape": "box" } } `

#### Using with Semantic Mediawiki inline queries

```
{{#network:
{{#ask: [[NextPage::+]]
| format=list
| headers=show
| link=none
| order=ascending
| merge=true
|limit=50
|searchlabel=|
|sep={{!}}
|template=ReturnTemplatesFirstArgument
|outro={{!}}
|intro={{!}}
}}
| class = col-lg-3 mt-0
|AllowOnlyLinksToPages = true
|AllowLinkExpansion = false
|enableDisplayTitle = true
}}
```

where "ReturnTemplatesFirstArgument" contains only "{{{1}}}". Resulting graph will show only pages with NextPage property and how they are interlinked.

## Performance / caching

This extension bypasses the MediaWiki page cache. This means that your network graphs will always be up to date,
Expand Down
12 changes: 11 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
},
"PageNetworkLabelMaxLength": {
"value": 20
},
"PageNetworkAllowOnlyLinksToPages": {
"value": false
},
"PageNetworkAllowLinkExpansion": {
"value": true
}
},

Expand Down Expand Up @@ -174,7 +180,11 @@
"pagenetwork-labelMaxLength-field-label",
"pagenetwork-labelMaxLength-field-help",
"pagenetwork-basic-tab-label",
"pagenetwork-advanced-tab-label"
"pagenetwork-advanced-tab-label",
"pagenetwork-AllowOnlyLinksToPages-field-label",
"pagenetwork-AllowOnlyLinksToPages-field-help",
"pagenetwork-AllowLinkExpansion-field-label",
"pagenetwork-AllowLinkExpansion-field-help"
],
"targets": [ "desktop", "mobile" ]
}
Expand Down
8 changes: 6 additions & 2 deletions i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
"network-aria": "Die Netzwerkvisualisierung zeigt eingehende und ausgehende Links der {{PLURAL:$1|Seite|Seiten}} $2",
"pagenetwork-pages-field-label": "Seiten",
"pagenetwork-class-field-label": "CSS-Klassen",
"pagenetwork-basic-tab-label": "Basisoptionen"
}
"pagenetwork-basic-tab-label": "Basisoptionen",
"pagenetwork-AllowOnlyLinksToPages-field-label": "Nur Links zu Seiten zulassen",
"pagenetwork-AllowOnlyLinksToPages-field-help": "Wenn wahr, werden nur die angegebenen Seiten als Knoten angezeigt",
"pagenetwork-AllowLinkExpansion-field-label": "Linkerweiterung zulassen",
"pagenetwork-AllowLinkExpansion-field-help": "Wenn wahr, ist eine Linkerweiterung beim Halten des Knotens möglich"
}
6 changes: 5 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@
"pagenetwork-labelMaxLength-field-label": "Maximum Label Length",
"pagenetwork-labelMaxLength-field-help": "The maximum text length of a node's label or 0 if unlimited. If the node label must be truncated, an ellipsis (…) will appended.",
"pagenetwork-basic-tab-label": "Basic Options",
"pagenetwork-advanced-tab-label": "Advanced Options"
"pagenetwork-advanced-tab-label": "Advanced Options",
"pagenetwork-AllowOnlyLinksToPages-field-label": "Allow Only Links To Pages",
"pagenetwork-AllowOnlyLinksToPages-field-help": "If true only specified pages will be displayed as nodes",
"pagenetwork-AllowLinkExpansion-field-label": "Allow Link Expansion",
"pagenetwork-AllowLinkExpansion-field-help": "If true Link Expansion when holding the node is possible"
}
29 changes: 26 additions & 3 deletions i18n/pl.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
{
"@metadata": {
"authors": [
"Rail"
"Rail",
"pw"
]
},
"network": "Sieć",
"network-name": "Sieć",
"network-desc": "Umożliwia dodawanie interaktywnych wizualizacji sieci do stron na wiki",
"network-aria": "Wizualizacja sieci pokazująca wychodzące i przychodzące połączenia dla {{PLURAL:$1|strony|stron}} $2"
}
"network-aria": "Wizualizacja sieci pokazująca wychodzące i przychodzące połączenia dla {{PLURAL:$1|strony|stron}} $2",
"pagenetwork-pages-field-label": "Strony",
"pagenetwork-pages-field-help": "Nazwa jednej lub wielu stron których połączenia mają zostać zwizualizowane, jedna na linię. Domyślnie to strona główna.",
"pagenetwork-exclude-field-label": "Wykluczone strony",
"pagenetwork-exclude-field-help": "Strony które mają zostać wykluczone z wizualizacji sieci połączeń, jedna na linię.",
"pagenetwork-excludedNamespaces-field-label": "Wykluczone przestrzenie nazw",
"pagenetwork-excludedNamespaces-field-help": "Przestrzenie nazw które mają zostać wykluczone z wizualizacji.",
"pagenetwork-class-field-label": "Klasy CSS",
"pagenetwork-class-field-help": "Dodatkowa klasa lub klasy które mają zostać dodane do wizualizacji, separowane znakiem spacji.",
"pagenetwork-options-field-label": "Opcje wizualizacji",
"pagenetwork-options-field-help": "Struktura JSON z opcjami wizualizacji vis.js.",
"pagenetwork-enableDisplayTitle-field-label": "Włącz wyświetlanie tytułu strony",
"pagenetwork-enableDisplayTitle-field-help": "Czy tytuł strony czy tytuł wyświetlania powinien być wyświetlany jako etykieta węzła?",
"pagenetwork-labelMaxLength-field-label": "Maksymalna długość etykiety",
"pagenetwork-labelMaxLength-field-help": "Maksymalna ilość znaków etykiety węzła lub zero dla braku ograniczenia. Jeżeli etkieta węzła zostanie obcięta to zostanie dodany wielokropek (…).",
"pagenetwork-basic-tab-label": "Opcje Podstawowe",
"pagenetwork-advanced-tab-label": "Opcje Zaawansowane",
"pagenetwork-AllowOnlyLinksToPages-field-label": "Wizualizuj tylko strony z listy",
"pagenetwork-AllowOnlyLinksToPages-field-help": "Wizualizuj tylko połączenia stron z listy",
"pagenetwork-AllowLinkExpansion-field-label": "Zezwalaj na dodawanie połączeń",
"pagenetwork-AllowLinkExpansion-field-help": "Umożliwia dodawanie połączeń ze strony poprzez przytrzymanie jej węzła"
}
17 changes: 11 additions & 6 deletions resources/js/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,38 @@ module.Network = (function (vis, NetworkData) {
* @param {module.PageExclusionManager} pageExclusionManager
* @param {object} options
* @param {int} labelMaxLength
* @param {string[]} pageNamesOrig
* @param {bool} startWithPageNamesOrigOnly
* @param {bool} allowNodeExpansion
*/
let Network = function(
divId,
pageConnectionRepo,
pageExclusionManager,
options,
labelMaxLength
labelMaxLength,
pageNamesOrig,
startWithPageNamesOrigOnly,
allowNodeExpansion
) {
this._pageConnectionRepo = pageConnectionRepo;
this._data = new NetworkData(pageExclusionManager, labelMaxLength);
this._data = new NetworkData(pageExclusionManager, labelMaxLength, pageNamesOrig, startWithPageNamesOrigOnly, allowNodeExpansion);
this._options = options;
this._network = this._newNetwork(divId);
this._lastZoomPosition = {x:0, y:0}

this._bindEvents();
};

/**
* @param {string[]} pageNames
* @return {Promise}
*/
Network.prototype.showPages = function(pageNames) {
Network.prototype.showPages = function(pageNames, allowOnly_pageNamesOrigList=true) {
let promise = this._pageConnectionRepo.addConnections(pageNames);

promise.then(
connections => {
this._data.addPages(connections.pages);
this._data.addPages(connections.pages, allowOnly_pageNamesOrigList);
this._data.addLinks(connections.links);
}
);
Expand All @@ -42,7 +47,7 @@ module.Network = (function (vis, NetworkData) {
};

Network.prototype._addPage = function(pageName) {
return this.showPages([pageName]);
return this.showPages([pageName], !this._data._allowNodeExpansion );
};

Network.prototype._newNetwork = function(divId) {
Expand Down
10 changes: 6 additions & 4 deletions resources/js/NetworkData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
*/
module.NetworkData = ( function ( vis, mw ) {
"use strict"

let NetworkData = function(pageExclusionManager, labelMaxLength) {
let NetworkData = function(pageExclusionManager, labelMaxLength, pageNamesOrig, startWithPageNamesOrigOnly, allowNodeExpansion) {
this.nodes = new vis.DataSet();
this.edges = new vis.DataSet();
this._pageExclusionManager = pageExclusionManager;
this._labelMaxLength = labelMaxLength;
this._pageNamesOrig = pageNamesOrig;
this._startWithPageNamesOrigOnly = startWithPageNamesOrigOnly;
this._allowNodeExpansion = allowNodeExpansion;
};

NetworkData.prototype.addPages = function(pages) {
NetworkData.prototype.addPages = function(pages, allowOnly_pageNamesOrigList=true) {
var maxlength = this._labelMaxLength;
this.nodes.update(
pages
.filter(page => this._pageTitleIsAllowed(page.title))
.filter(page => { return this._pageTitleIsAllowed(page.title) && (!allowOnly_pageNamesOrigList||this._pageNamesOrig.includes(page.title)) })
.map(function(page) {
if (maxlength > 0 && page.displayTitle.length > maxlength) {
page.label = page.displayTitle.slice(0, maxlength) + '\u2026';
Expand Down
30 changes: 29 additions & 1 deletion resources/js/SpecialForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,32 @@
helpInline: true
} );

let AllowOnlyLinksToPagesInput = new OO.ui.CheckboxInputWidget({
name: 'AllowOnlyLinksToPages',
selected: defaultValues['AllowOnlyLinksToPages'],
});
let AllowOnlyLinksToPagesField = new OO.ui.FieldLayout(
AllowOnlyLinksToPagesInput,
{
label: mw.message('pagenetwork-AllowOnlyLinksToPages-field-label').text(),
align: 'inline',
help: mw.message('pagenetwork-AllowOnlyLinksToPages-field-help').text(),
helpInline: true
} );

let AllowLinkExpansionInput = new OO.ui.CheckboxInputWidget({
name: 'AllowLinkExpansion',
selected: defaultValues['AllowLinkExpansion'],
});
let AllowLinkExpansionField = new OO.ui.FieldLayout(
AllowLinkExpansionInput,
{
label: mw.message('pagenetwork-AllowLinkExpansion-field-label').text(),
align: 'inline',
help: mw.message('pagenetwork-AllowLinkExpansion-field-help').text(),
helpInline: true
} );

let submitButton = new OO.ui.ButtonInputWidget( {
label: mw.message('htmlform-submit').text(),
type: 'submit',
Expand Down Expand Up @@ -159,7 +185,9 @@
classField,
optionsField,
enableDisplayTitleField,
labelMaxLengthField
labelMaxLengthField,
AllowOnlyLinksToPagesField,
AllowLinkExpansionField
]
} ),
] )
Expand Down
7 changes: 5 additions & 2 deletions resources/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
mw.config.get('networkExcludeTalkPages')
),
$this.data('options'),
$this.data('labelmaxlength')
$this.data('labelmaxlength'),
$this.data('pages'),
$this.data('allowonlylinkstopages'),
$this.data('allowlinkexpansion')
);

network.showPages($this.data('pages')).then(function() {
network.showPages($this.data('pages'),$this.data('allowonlylinkstopages')).then(function() {
$this.find('canvas:first').attr(
'aria-label',
mw.message(
Expand Down
2 changes: 2 additions & 0 deletions src/EntryPoints/NetworkFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public function handleParserFunctionCall( Parser $parser, string ...$arguments )
$requestModel->excludedNamespaces = $this->config->getExcludedNamespaces();
$requestModel->enableDisplayTitle = $this->config->getEnableDisplayTitle();
$requestModel->labelMaxLength = $this->config->getLabelMaxLength();
$requestModel->AllowOnlyLinksToPages = $this->config->getAllowOnlyLinksToPages();
$requestModel->AllowLinkExpansion = $this->config->getAllowLinkExpansion();

/**
* @psalm-suppress PossiblyNullReference
Expand Down
33 changes: 33 additions & 0 deletions src/EntryPoints/SpecialNetwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ private function parseParams( WebRequest $request, NetworkConfig $config ) : arr

$params['labelMaxLength'] = $request->getInt( 'labelMaxLength', $config->getLabelMaxLength() );

if ( $this->including() ) {
$params['AllowOnlyLinksToPages'] =
filter_var(
$request->getText( 'AllowOnlyLinksToPages', strval( $config->getAllowOnlyLinksToPages() ) ),
FILTER_VALIDATE_BOOL,
FILTER_NULL_ON_FAILURE
);
} elseif ( $request->getCheck( 'pages' ) ) {
$params['AllowOnlyLinksToPages'] = $request->getCheck('AllowOnlyLinksToPages');
} else {
$params['AllowOnlyLinksToPages'] = $config->getAllowOnlyLinksToPages();
}

if ( $this->including() ) {
$params['AllowLinkExpansion'] =
filter_var(
$request->getText( 'AllowLinkExpansion', strval( $config->getAllowLinkExpansion() ) ),
FILTER_VALIDATE_BOOL,
FILTER_NULL_ON_FAILURE
);
} elseif ( $request->getCheck( 'pages' ) ) {
$params['AllowLinkExpansion'] = $request->getCheck('AllowLinkExpansion');
} else {
$params['AllowLinkExpansion'] = $config->getAllowLinkExpansion();
}

return $params;
}

Expand Down Expand Up @@ -109,6 +135,10 @@ private function formatParams( array $params ) : array {
$formattedParams['enableDisplayTitle'] = 'enableDisplayTitle=' .
( $params['enableDisplayTitle'] ? 'true' : 'false' );
$formattedParams['labelMaxLength'] = 'labelMaxLength=' . strval( $params['labelMaxLength'] );
$formattedParams['AllowOnlyLinksToPages'] = 'AllowOnlyLinksToPages=' .
( $params['AllowOnlyLinksToPages'] ? 'true' : 'false' );
$formattedParams['AllowLinkExpansion'] = 'AllowLinkExpansion=' .
( $params['AllowLinkExpansion'] ? 'true' : 'false' );
return $formattedParams;
}

Expand All @@ -127,6 +157,9 @@ public function showGraph( array $arguments, NetworkConfig $config) : string {
$requestModel->excludedNamespaces = $config->getExcludedNamespaces();
$requestModel->enableDisplayTitle = $config->getEnableDisplayTitle();
$requestModel->labelMaxLength = $config->getLabelMaxLength();
$requestModel->AllowOnlyLinksToPages = $config->getAllowOnlyLinksToPages();
$requestModel->AllowLinkExpansion = $config->getAllowLinkExpansion();


/**
* @psalm-suppress PossiblyNullReference
Expand Down
2 changes: 2 additions & 0 deletions src/NetworkFunction/AbstractNetworkPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function setHtml( ResponseModel $viewModel ): void {
'data-options' => json_encode( $viewModel->visJsOptions ),
'data-enabledisplaytitle' => json_encode( $viewModel->enableDisplayTitle ),
'data-labelmaxlength' => json_encode( $viewModel->labelMaxLength ),
'data-allowonlylinkstopages' => json_encode( $viewModel->AllowOnlyLinksToPages),
'data-allowlinkexpansion' => json_encode( $viewModel->AllowLinkExpansion),
]
);
}
Expand Down
12 changes: 12 additions & 0 deletions src/NetworkFunction/NetworkConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class NetworkConfig {
* @var bool
*/
private $enableDisplayTitle;
private $AllowOnlyLinksToPages;
private $AllowLinkExpansion;

/**
* @var int
Expand All @@ -39,6 +41,8 @@ public function __construct() {
$this->excludedNamespaces = array_map( 'strval', $config->get( 'PageNetworkExcludedNamespaces' ) );
$this->enableDisplayTitle = (bool)$config->get( 'PageNetworkEnableDisplayTitle' );
$this->labelMaxLength = (int)$config->get( 'PageNetworkLabelMaxLength' );
$this->AllowOnlyLinksToPages = (bool)$config->get( 'PageNetworkAllowOnlyLinksToPages');
$this->AllowLinkExpansion = (bool)$config->get( 'PageNetworkAllowLinkExpansion');
}

public function getOptions(): array {
Expand All @@ -60,4 +64,12 @@ public function getEnableDisplayTitle(): bool {
public function getLabelMaxLength(): int {
return $this->labelMaxLength;
}

public function getAllowOnlyLinksToPages(): bool {
return $this->AllowOnlyLinksToPages;
}

public function getAllowLinkExpansion(): bool {
return $this->AllowLinkExpansion;
}
}
Loading