| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Extension\Gadgets; |
| 22 |
|
| 23 |
use MediaWiki\Output\OutputPage; |
| 24 |
use MediaWiki\User\User; |
| 25 |
use Skin; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
class GadgetLoadConditions { |
| 31 |
|
| 32 |
private $user; |
| 33 |
|
| 34 |
private $skin; |
| 35 |
|
| 36 |
private $action; |
| 37 |
|
| 38 |
private $namespace; |
| 39 |
|
| 40 |
private $categories; |
| 41 |
|
| 42 |
private $contentModel; |
| 43 |
|
| 44 |
private $withGadgetParam; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public function __construct( OutputPage $out ) { |
| 50 |
$this->user = $out->getUser(); |
| 51 |
$this->skin = $out->getSkin(); |
| 52 |
$this->action = $out->getContext()->getActionName(); |
| 53 |
$this->namespace = $out->getTitle()->getNamespace(); |
| 54 |
$this->categories = $out->getCategories(); |
| 55 |
$this->contentModel = $out->getTitle()->getContentModel(); |
| 56 |
$this->withGadgetParam = $out->getRequest()->getRawVal( 'withgadget' ); |
| 57 |
} |
| 58 |
|
| 59 |
public function check( Gadget $gadget ): bool { |
| 60 |
$urlLoad = $this->withGadgetParam === $gadget->getName() && $gadget->supportsUrlLoad(); |
| 61 |
|
| 62 |
return ( $gadget->isEnabled( $this->user ) || $urlLoad ) |
| 63 |
&& $gadget->isAllowed( $this->user ) |
| 64 |
&& $gadget->isActionSupported( $this->action ) |
| 65 |
&& $gadget->isSkinSupported( $this->skin ) |
| 66 |
&& $gadget->isNamespaceSupported( $this->namespace ) |
| 67 |
&& $gadget->isCategorySupported( $this->categories ) |
| 68 |
&& $gadget->isContentModelSupported( $this->contentModel ); |
| 69 |
} |
| 70 |
} |