X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fwidget%2Fsearch%2FInterwikiSearchResultSetWidget.php;h=6d942de1ab9a9f628f5b61ca24d1242d9c629bfb;hb=36127c29c2d564cc723b6e1cfccca9ba1a0240c8;hp=b1b8c730c04e00cda4fa865119e9bfb820f928d7;hpb=49748181dd56ec97e7ba7c13e684a16abceb3cc0;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/widget/search/InterwikiSearchResultSetWidget.php b/includes/widget/search/InterwikiSearchResultSetWidget.php index b1b8c730c0..6d942de1ab 100644 --- a/includes/widget/search/InterwikiSearchResultSetWidget.php +++ b/includes/widget/search/InterwikiSearchResultSetWidget.php @@ -8,6 +8,7 @@ use SearchResultSet; use SpecialSearch; use Title; use Html; +use OOUI; /** * Renders one or more SearchResultSets into a sidebar grouped by @@ -27,23 +28,22 @@ class InterwikiSearchResultSetWidget implements SearchResultSetWidget { protected $iwLookup; /** @var $output */ protected $output; - /** @var $iwPrefixDisplayTypes */ - protected $iwPrefixDisplayTypes; + /** @var bool $showMultimedia */ + protected $showMultimedia; public function __construct( SpecialSearch $specialSearch, SearchResultWidget $resultWidget, LinkRenderer $linkRenderer, - InterwikiLookup $iwLookup + InterwikiLookup $iwLookup, + $showMultimedia = false ) { $this->specialSearch = $specialSearch; $this->resultWidget = $resultWidget; $this->linkRenderer = $linkRenderer; $this->iwLookup = $iwLookup; $this->output = $specialSearch->getOutput(); - $this->iwPrefixDisplayTypes = $specialSearch->getConfig()->get( - 'InterwikiPrefixDisplayTypes' - ); + $this->showMultimedia = $showMultimedia; } /** * @param string $term User provided search term @@ -58,7 +58,9 @@ class InterwikiSearchResultSetWidget implements SearchResultSetWidget { $this->loadCustomCaptions(); - $this->output->addModules( 'mediawiki.special.search.commonsInterwikiWidget' ); + if ( $this->showMultimedia ) { + $this->output->addModules( 'mediawiki.special.search.commonsInterwikiWidget' ); + } $this->output->addModuleStyles( 'mediawiki.special.search.interwikiwidget.styles' ); $iwResults = []; @@ -80,22 +82,17 @@ class InterwikiSearchResultSetWidget implements SearchResultSetWidget { $position = 0; $iwResultItemOutput = ''; - $iwDisplayType = isset( $this->iwPrefixDisplayTypes[$iwPrefix] ) - ? $this->iwPrefixDisplayTypes[$iwPrefix] - : ""; - foreach ( $results as $result ) { $iwResultItemOutput .= $this->resultWidget->render( $result, $term, $position++ ); } - $headerHtml = $this->headerHtml( $term, $iwPrefix ); $footerHtml = $this->footerHtml( $term, $iwPrefix ); $iwResultListOutput .= Html::rawElement( 'li', [ - 'class' => 'iw-resultset iw-resultset--' . $iwDisplayType, + 'class' => 'iw-resultset', 'data-iw-resultset-pos' => $iwResultSetPos ], - $headerHtml . + $iwResultItemOutput . $footerHtml ); @@ -117,34 +114,6 @@ class InterwikiSearchResultSetWidget implements SearchResultSetWidget { ); } - /** - * Generates an appropriate HTML header for the given interwiki prefix - * - * @param string $term User provided search term - * @param string $iwPrefix Interwiki prefix of wiki to show header for - * @return string HTML - */ - protected function headerHtml( $term, $iwPrefix ) { - - $iwDisplayType = isset( $this->iwPrefixDisplayTypes[$iwPrefix] ) - ? $this->iwPrefixDisplayTypes[$iwPrefix] - : ""; - - if ( isset( $this->customCaptions[$iwPrefix] ) ) { - /* customCaptions composed by loadCustomCaptions() with pre-escaped content.*/ - $caption = $this->customCaptions[$iwPrefix]; - } else { - $interwiki = $this->iwLookup->fetch( $iwPrefix ); - $parsed = wfParseUrl( wfExpandUrl( $interwiki ? $interwiki->getURL() : '/' ) ); - $caption = $this->specialSearch->msg( 'search-interwiki-default', $parsed['host'] )->escaped(); - } - - return Html::rawElement( 'div', [ 'class' => 'iw-result__header' ], - Html::rawElement( 'span', [ 'class' => 'iw-result__icon iw-result__icon--' . $iwDisplayType ] ) - . $caption - ); - } - /** * Generates an HTML footer for the given interwiki prefix * @@ -158,13 +127,22 @@ class InterwikiSearchResultSetWidget implements SearchResultSetWidget { [ 'search' => $term, 'fulltext' => 1 ] ); - $searchLink = Html::rawElement( - 'a', - [ 'href' => $href ], - $this->specialSearch->msg( 'search-interwiki-more-results' )->escaped() + $interwiki = $this->iwLookup->fetch( $iwPrefix ); + $parsed = wfParseUrl( wfExpandUrl( $interwiki ? $interwiki->getURL() : '/' ) ); + + if ( isset( $this->customCaptions[$iwPrefix] ) ) { + $caption = $this->customCaptions[$iwPrefix]; + } else { + $caption = $this->specialSearch->msg( 'search-interwiki-default', $parsed['host'] )->escaped(); + } + + $searchLink = Html::rawElement( 'em', null, + Html::rawElement( 'a', [ 'href' => $href, 'target' => '_blank' ], $caption ) ); - return Html::rawElement( 'div', [ 'class' => 'iw-result__footer' ], $searchLink ); + return Html::rawElement( 'div', + [ 'class' => 'iw-result__footer' ], + $this->iwIcon( $iwPrefix ) . $searchLink ); } protected function loadCustomCaptions() { @@ -181,4 +159,33 @@ class InterwikiSearchResultSetWidget implements SearchResultSetWidget { } } } + + /** + * Generates a custom OOUI icon element with a favicon as the image. + * The favicon image URL is generated by parsing the interwiki URL + * and returning the default location of the favicon for that domain, + * which is assumed to be '/favicon.ico'. + * + * @param string $iwPrefix Interwiki prefix + * @return OOUI\IconWidget + **/ + protected function iwIcon( $iwPrefix ) { + + $interwiki = $this->iwLookup->fetch( $iwPrefix ); + $parsed = wfParseUrl( wfExpandUrl( $interwiki ? $interwiki->getURL() : '/' ) ); + + $iwIconUrl = $parsed['scheme'] . + $parsed['delimiter'] . + $parsed['host'] . + ( $parsed['port'] ? ':' . $parsed['port'] : '' ) . + '/favicon.ico'; + + $iwIcon = new OOUI\IconWidget( [ + 'icon' => 'favicon' + ] ); + + $iwIcon->setAttributes( [ 'style' => "background-image:url($iwIconUrl);" ] ); + + return $iwIcon; + } }