2022-03-19 16:49:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\Gadgets;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
* @author Siddharth VP
|
|
|
|
* @file
|
|
|
|
*/
|
|
|
|
|
|
|
|
use OutputPage;
|
|
|
|
use Skin;
|
|
|
|
use User;
|
|
|
|
|
|
|
|
class GadgetLoadConditions {
|
|
|
|
/** @var User */
|
|
|
|
private $user;
|
|
|
|
/** @var Skin */
|
|
|
|
private $skin;
|
|
|
|
/** @var string */
|
|
|
|
private $action;
|
2020-09-04 03:42:31 +00:00
|
|
|
/** @var int */
|
|
|
|
private $namespace;
|
2023-05-22 08:41:15 +00:00
|
|
|
/** @var string */
|
|
|
|
private $contentModel;
|
2023-06-29 00:57:04 +00:00
|
|
|
/** @var bool */
|
|
|
|
private $isMobileView;
|
2022-03-19 16:49:41 +00:00
|
|
|
/** @var string|null */
|
|
|
|
private $withGadgetParam;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param OutputPage $out
|
|
|
|
*/
|
2023-06-29 00:57:04 +00:00
|
|
|
public function __construct( OutputPage $out, bool $isMobileView = false ) {
|
2022-03-19 16:49:41 +00:00
|
|
|
$this->user = $out->getUser();
|
|
|
|
$this->skin = $out->getSkin();
|
2022-03-26 16:49:48 +00:00
|
|
|
$this->action = $out->getContext()->getActionName();
|
2020-09-04 03:42:31 +00:00
|
|
|
$this->namespace = $out->getTitle()->getNamespace();
|
2023-05-22 08:41:15 +00:00
|
|
|
$this->contentModel = $out->getTitle()->getContentModel();
|
2022-03-19 16:49:41 +00:00
|
|
|
$this->withGadgetParam = $out->getRequest()->getRawVal( 'withgadget' );
|
2023-06-29 00:57:04 +00:00
|
|
|
$this->isMobileView = $isMobileView;
|
2022-03-19 16:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Gadget $gadget
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function check( Gadget $gadget ) {
|
|
|
|
$urlLoad = $this->withGadgetParam === $gadget->getName() && $gadget->supportsUrlLoad();
|
|
|
|
|
|
|
|
return ( $gadget->isEnabled( $this->user ) || $urlLoad )
|
|
|
|
&& $gadget->isAllowed( $this->user )
|
|
|
|
&& $gadget->isActionSupported( $this->action )
|
|
|
|
&& $gadget->isSkinSupported( $this->skin )
|
2020-09-04 03:42:31 +00:00
|
|
|
&& $gadget->isNamespaceSupported( $this->namespace )
|
2023-05-22 08:41:15 +00:00
|
|
|
&& $gadget->isContentModelSupported( $this->contentModel )
|
2023-06-29 00:57:04 +00:00
|
|
|
&& $gadget->isTargetSupported( $this->isMobileView );
|
2022-03-19 16:49:41 +00:00
|
|
|
}
|
|
|
|
}
|