mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-11 17:02:28 +00:00
c6c7dd2fb0
Why: - We want to allow extensions to register interactive menu items in the overflow menu. What: - Create a PHP hook to allow extensions to provide menu items for rendering in the overflow menu - The hook allows for registering resource loader modules required by the menu item - The hook passes in some contextual information, like the thread item data, context source object, and if the page is editable - Create a JS hook that fires when a user selects one of the menu items - Example implementation: Ie9afbedb4f24cbd75eb48bb21dc9f6d8d732d853 Misc: - Remove b/c code that existed to handle a transitional period where JSON encoded overflow menu data did not necessarily exist in the parser cache - Rename code instances of ellipsis button / data / menu to refer to "overflow menu" - Some renames will have to wait until parser cache is updated; these are noted with TODOs Bug: T342251 Change-Id: I5f2a51791f8ba7619d1399a4b93111e9bb44e172
60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools;
|
|
|
|
use JsonSerializable;
|
|
|
|
/**
|
|
* Item to go into the DiscussionTools overflow menu, as an OO.ui.MenuOptionWidget object.
|
|
*/
|
|
class OverflowMenuItem implements JsonSerializable {
|
|
|
|
private string $icon;
|
|
private string $label;
|
|
private array $data;
|
|
private string $id;
|
|
private int $weight;
|
|
|
|
/**
|
|
* @param string $id A unique identifier for the menu item, e.g. 'edit' or 'reportincident'
|
|
* @param string $icon An OOUI icon name.
|
|
* @param string $label A rendered string to use as the label for the item.
|
|
* @param int $weight Sorting weight. Higher values will push the item further up the menu.
|
|
* @param array $data Data to include with the menu item. Will be accessible via getData() on the
|
|
* OOUI MenuOptionWidget in client-side code.
|
|
*/
|
|
public function __construct(
|
|
string $id,
|
|
string $icon,
|
|
string $label,
|
|
int $weight = 0,
|
|
array $data = []
|
|
) {
|
|
$this->id = $id;
|
|
$this->icon = $icon;
|
|
$this->label = $label;
|
|
$this->weight = $weight;
|
|
$this->data = $data;
|
|
}
|
|
|
|
public function jsonSerialize(): array {
|
|
$data = $this->data;
|
|
// Add 'id' into the 'data' array, for easier access with OOUI's getData() method
|
|
$data['id'] = $this->id;
|
|
return [
|
|
'id' => $this->id,
|
|
'data' => $data,
|
|
'icon' => $this->icon,
|
|
'label' => $this->label,
|
|
];
|
|
}
|
|
|
|
public function getId(): string {
|
|
return $this->id;
|
|
}
|
|
|
|
public function getWeight(): int {
|
|
return $this->weight;
|
|
}
|
|
}
|