Debian Codegraph @

extensions/Gadgets/includes/GadgetLoadConditions.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Extension\Gadgets;
22
23 use MediaWiki\Output\OutputPage;
24 use MediaWiki\User\User;
25 use Skin;
26
27 /**
28 * @author Siddharth VP
29 */
30 class GadgetLoadConditions {
31 /** @var User */
32 private $user;
33 /** @var Skin */
34 private $skin;
35 /** @var string */
36 private $action;
37 /** @var int */
38 private $namespace;
39 /** @var string[] */
40 private $categories;
41 /** @var string */
42 private $contentModel;
43 /** @var string|null */
44 private $withGadgetParam;
45
46 /**
47 * @param OutputPage $out
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 }