diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/skins/chameleon/src/Components/Modifications |
first commit
Diffstat (limited to 'www/wiki/skins/chameleon/src/Components/Modifications')
4 files changed, 367 insertions, 0 deletions
diff --git a/www/wiki/skins/chameleon/src/Components/Modifications/HideFor.php b/www/wiki/skins/chameleon/src/Components/Modifications/HideFor.php new file mode 100644 index 00000000..58d78a6c --- /dev/null +++ b/www/wiki/skins/chameleon/src/Components/Modifications/HideFor.php @@ -0,0 +1,71 @@ +<?php +/** + * File containing the HideFor class + * + * This file is part of the MediaWiki skin Chameleon. + * + * @copyright 2013 - 2014, Stephan Gambke + * @license GNU General Public License, version 3 (or any later version) + * + * The Chameleon skin 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 3 of the License, or (at your option) any + * later version. + * + * The Chameleon skin 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, see <http://www.gnu.org/licenses/>. + * + * @file + * @ingroup Skins + */ + +namespace Skins\Chameleon\Components\Modifications; +use Skins\Chameleon\Components\Silent; +use Skins\Chameleon\PermissionsHelper; + +/** + * HideFor class + * + * @author Stephan Gambke + * @since 1.1 + * @ingroup Skins + */ +class HideFor extends Modification { + + private $permissionsHelper; + + /** + * This method checks if the restriction is applicable and if necessary + * replaces the decorated component by a Silent component + */ + protected function applyModification() { + if ( $this->isHidden() ) { + $c = $this->getComponent(); + $this->setComponent( new Silent( $c->getSkinTemplate(), $c->getDomElement(), $c->getIndent() ) ); + } + } + + /** + * @return bool + */ + private function isHidden() { + $p = $this->getPermissionsHelper(); + return $p->userHasGroup( 'group' ) && $p->userHasPermission( 'permission' ) && $p->pageIsInNamespace( 'namespace' ) && $p->pageHasCategory( 'category' ); + } + + /** + * @return PermissionsHelper + */ + private function getPermissionsHelper() { + if ( $this->permissionsHelper === null ) { + $this->permissionsHelper = new PermissionsHelper( $this->getSkinTemplate()->getSkin(), $this->getDomElementOfModification(), true ); + } + + return $this->permissionsHelper; + } +} diff --git a/www/wiki/skins/chameleon/src/Components/Modifications/Modification.php b/www/wiki/skins/chameleon/src/Components/Modifications/Modification.php new file mode 100644 index 00000000..5fd34b19 --- /dev/null +++ b/www/wiki/skins/chameleon/src/Components/Modifications/Modification.php @@ -0,0 +1,174 @@ +<?php +/** + * File containing the Modification class + * + * This file is part of the MediaWiki skin Chameleon. + * + * @copyright 2013 - 2014, Stephan Gambke + * @license GNU General Public License, version 3 (or any later version) + * + * The Chameleon skin 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 3 of the License, or (at your option) any + * later version. + * + * The Chameleon skin 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, see <http://www.gnu.org/licenses/>. + * + * @file + * @ingroup Skins + */ + +namespace Skins\Chameleon\Components\Modifications; + +use Skins\Chameleon\ChameleonTemplate; +use Skins\Chameleon\Components\Component; + +/** + * Modification class + * + * This is the abstract base class of all modifications. + * + * Follows the Decorator pattern (Decorator role). + * + * @author Stephan Gambke + * @since 1.0 + * @ingroup Skins + */ +abstract class Modification extends Component { + + private $component = null; + + /** + * @param Component $component + * @param \DOMElement $domElement + */ + public function __construct( Component $component, \DOMElement $domElement = null ) { + + $this->component = $component; + parent::__construct( $component->getSkinTemplate(), $domElement, $component->getIndent() ); + } + + /** + * This method should apply any modifications to the decorated component + * available from the getComponent() method. + */ + abstract protected function applyModification(); + + /** + * @return \DOMElement|null + */ + public function getDomElementOfModification() { + return parent::getDomElement(); + } + + /** + * @return \DOMElement + */ + public function getDomElementOfComponent() { + return $this->getDomElement(); + } + + /** + * Sets the class string that should be assigned to the top-level html element of this component + * + * @param string | array | null $classes + * + */ + public function setClasses( $classes ) { + $this->getComponent()->setClasses( $classes ); + } + + /** + * @return Component + */ + public function getComponent() { + return $this->component; + } + + /** + * @param Component $component + * @since 1.1 + */ + protected function setComponent( Component $component ) { + $this->component = $component; + } + + /** + * Adds the given class to the class string that should be assigned to the top-level html element of this component + * + * @param string | array | null $classes + * + * @return string | array + */ + public function addClasses( $classes ) { + $this->getComponent()->addClasses( $classes ); + } + + /** + * @return ChameleonTemplate + */ + public function getSkinTemplate() { + return $this->getComponent()->getSkinTemplate(); + } + + /** + * Returns the current indentation level + * + * @return int + */ + public function getIndent() { + return $this->getComponent()->getIndent(); + } + + /** + * Returns the class string that should be assigned to the top-level html element of this component + * + * @return string + */ + public function getClassString() { + return $this->getComponent()->getClassString(); + } + + /** + * Removes the given class from the class string that should be assigned to the top-level html element of this component + * + * @param string | array | null $classes + * + * @return string + */ + public function removeClasses( $classes ) { + $this->getComponent()->removeClasses( $classes ); + } + + /** + * Returns the DOMElement from the description XML file associated with this element. + * + * @return \DOMElement + */ + public function getDomElement() { + return $this->getComponent()->getDomElement(); + } + + /** + * Builds the HTML code for this component + * + * @return String the HTML code + */ + public function getHtml() { + $this->applyModification(); + return $this->getComponent()->getHtml(); + } + + /** + * @return array the resource loader modules needed by this component + */ + public function getResourceLoaderModules() { + return $this->getComponent()->getResourceLoaderModules(); + } +} diff --git a/www/wiki/skins/chameleon/src/Components/Modifications/ShowOnlyFor.php b/www/wiki/skins/chameleon/src/Components/Modifications/ShowOnlyFor.php new file mode 100644 index 00000000..7c137d81 --- /dev/null +++ b/www/wiki/skins/chameleon/src/Components/Modifications/ShowOnlyFor.php @@ -0,0 +1,71 @@ +<?php +/** + * File containing the ShowOnlyFor class + * + * This file is part of the MediaWiki skin Chameleon. + * + * @copyright 2013 - 2014, Stephan Gambke + * @license GNU General Public License, version 3 (or any later version) + * + * The Chameleon skin 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 3 of the License, or (at your option) any + * later version. + * + * The Chameleon skin 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, see <http://www.gnu.org/licenses/>. + * + * @file + * @ingroup Skins + */ + +namespace Skins\Chameleon\Components\Modifications; +use Skins\Chameleon\Components\Silent; +use Skins\Chameleon\PermissionsHelper; + +/** + * ShowOnlyFor class + * + * @author Stephan Gambke + * @since 1.1 + * @ingroup Skins + */ +class ShowOnlyFor extends Modification { + + private $permissionsHelper; + + /** + * This method checks if the restriction is applicable and if necessary + * replaces the decorated component by a Silent component + */ + protected function applyModification() { + if ( ! $this->isShown() ) { + $c = $this->getComponent(); + $this->setComponent( new Silent( $c->getSkinTemplate(), $c->getDomElement(), $c->getIndent() ) ); + } + } + + /** + * @return bool + */ + private function isShown() { + $p = $this->getPermissionsHelper(); + return $p->userHasGroup( 'group' ) || $p->userHasPermission( 'permission' ) || $p->pageIsInNamespace( 'namespace' ) || $p->pageHasCategory( 'category' ); + } + + /** + * @return PermissionsHelper + */ + private function getPermissionsHelper() { + if ( $this->permissionsHelper === null ) { + $this->permissionsHelper = new PermissionsHelper( $this->getSkinTemplate()->getSkin(), $this->getDomElementOfModification(), false ); + } + + return $this->permissionsHelper; + } +} diff --git a/www/wiki/skins/chameleon/src/Components/Modifications/Sticky.php b/www/wiki/skins/chameleon/src/Components/Modifications/Sticky.php new file mode 100644 index 00000000..cbac2107 --- /dev/null +++ b/www/wiki/skins/chameleon/src/Components/Modifications/Sticky.php @@ -0,0 +1,51 @@ +<?php +/** + * File containing the Sticky class + * + * This file is part of the MediaWiki skin Chameleon. + * + * @copyright 2013 - 2014, Stephan Gambke + * @license GNU General Public License, version 3 (or any later version) + * + * The Chameleon skin 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 3 of the License, or (at your option) any + * later version. + * + * The Chameleon skin 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, see <http://www.gnu.org/licenses/>. + * + * @file + * @ingroup Skins + */ + +namespace Skins\Chameleon\Components\Modifications; + +/** + * Class Sticky + * + * @author Stephan Gambke + * @since 1.0 + * @ingroup Skins + */ +class Sticky extends Modification { + + protected function applyModification() { + $this->getComponent()->addClasses( 'sticky' ); + } + + /** + * @return string[] the resource loader modules needed by this component + */ + public function getResourceLoaderModules() { + $modules = parent::getResourceLoaderModules(); + $modules[] = 'skin.chameleon.jquery-sticky'; + return $modules; + } + +} |