| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\Notifications; |
| 4 | |
| 5 | /** |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | * http://www.gnu.org/copyleft/gpl.html |
| 20 | * |
| 21 | * @file |
| 22 | */ |
| 23 | |
| 24 | use MediaWiki\ResourceLoader as RL; |
| 25 | use RuntimeException; |
| 26 | |
| 27 | /** |
| 28 | * A sibling of secret special sauce. |
| 29 | * @see RL\OOUIImageModule for familial resemblence |
| 30 | */ |
| 31 | class ResourceLoaderEchoImageModule extends RL\ImageModule { |
| 32 | protected function loadFromDefinition() { |
| 33 | if ( $this->definition === null ) { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | // Check to make sure icons are set |
| 38 | if ( !isset( $this->definition['icons'] ) ) { |
| 39 | throw new RuntimeException( 'Icons must be set.' ); |
| 40 | } |
| 41 | |
| 42 | $images = []; |
| 43 | foreach ( $this->definition['icons'] as $iconName => $definition ) { |
| 44 | // FIXME: We also have a 'site' icon which is "magical" |
| 45 | // and uses witchcraft and should be handled specifically |
| 46 | if ( isset( $definition[ 'path' ] ) && $definition[ 'path' ] ) { |
| 47 | // string or array, if array, has both rtl and ltr definitions |
| 48 | $images[ $iconName ][ 'file' ] = $definition[ 'path' ]; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | $this->definition[ 'images' ] = $images; |
| 53 | $this->definition[ 'selector' ] = '.oo-ui-icon-{name}'; |
| 54 | |
| 55 | parent::loadFromDefinition(); |
| 56 | } |
| 57 | } |