| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * http://www.gnu.org/copyleft/gpl.html |
| 18 | * |
| 19 | * @file |
| 20 | */ |
| 21 | |
| 22 | use MediaWiki\Html\HtmlHelper; |
| 23 | use Wikimedia\RemexHtml\Serializer\SerializerNode; |
| 24 | |
| 25 | /** |
| 26 | * SkinAuthenticationPopup is a "micro-skin" that omits most of the usual interface elements, |
| 27 | * making the page suitable to be displayed in a small popup window. |
| 28 | * |
| 29 | * It should not ever be available for normal use. It's only used directly by special pages |
| 30 | * related to authentication when this kind of interface is requested. |
| 31 | */ |
| 32 | class SkinAuthenticationPopup extends SkinMustache { |
| 33 | |
| 34 | private static function openLinksInNewWindow( string &$html ): void { |
| 35 | $html = HtmlHelper::modifyElements( |
| 36 | $html, |
| 37 | static function ( SerializerNode $node ): bool { |
| 38 | return $node->name === 'a' |
| 39 | && isset( $node->attrs['href'] ) |
| 40 | && !str_contains( $node->attrs['class'] ?? '', 'mw-authentication-popup-link' ); |
| 41 | }, |
| 42 | static function ( SerializerNode $node ): SerializerNode { |
| 43 | $node->attrs['target'] ??= '_blank'; |
| 44 | return $node; |
| 45 | } |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | public function getTemplateData() { |
| 50 | $data = parent::getTemplateData(); |
| 51 | |
| 52 | // This skin is intended to be shown in small popups, therefore open all links in new windows, |
| 53 | // except those explicitly marked. The CSS class can also be added by extensions. |
| 54 | self::openLinksInNewWindow( $data['html-body-content'] ); |
| 55 | foreach ( $data['data-footer'] as &$footerItems ) { |
| 56 | foreach ( $footerItems['array-items'] as &$item ) { |
| 57 | self::openLinksInNewWindow( $item['html'] ); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return $data; |
| 62 | } |
| 63 | |
| 64 | } |