use SpecialSearch;
use Title;
use Html;
+use OOUI;
/**
* Renders one or more SearchResultSets into a sidebar grouped by
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
$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 = [];
$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
);
);
}
- /**
- * 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
*
[ '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() {
}
}
}
+
+ /**
+ * 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'] .
+ ( isset ( $parsed['port'] ) ? ':' . $parsed['port'] : '' ) .
+ '/favicon.ico';
+
+ $iwIcon = new OOUI\IconWidget( [
+ 'icon' => 'favicon'
+ ] );
+
+ $iwIcon->setAttributes( [ 'style' => "background-image:url($iwIconUrl);" ] );
+
+ return $iwIcon;
+ }
}