From: jenkins-bot Date: Sat, 7 Jan 2017 17:58:30 +0000 (+0000) Subject: Merge "Make RefreshLinksJob handle LinksUpdateConstructed hooks doing DB writes" X-Git-Tag: 1.31.0-rc.0~4369 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;h=6ce0b82f713f8731c04b28d27ac2637d6749dc70;hp=2d4ed16bd8cc70de1742c8b06ec65928971b6b8e;p=lhc%2Fweb%2Fwiklou.git Merge "Make RefreshLinksJob handle LinksUpdateConstructed hooks doing DB writes" --- diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29 index 3630abc47a..8b1020788d 100644 --- a/RELEASE-NOTES-1.29 +++ b/RELEASE-NOTES-1.29 @@ -163,6 +163,10 @@ changes to languages because of Phabricator reports. * Hook UnknownAction (deprecated in 1.19) was actually deprecated (it will now emit warnings). Create a subclass of Action, and add it to $wgActions instead. * WikiRevision:getText() (deprecated since 1.21) is no longer marked deprecated. +* Linker:getInterwikiLinkAttributes (deprecated since 1.25) was removed. +* Linker:getInternalLinkAttributes (deprecated since 1.25) was removed. +* Linker:getInternalLinkAttributesObj (deprecated since 1.25) was removed. +* Linker:getLinkAttributesInternal (deprecated since 1.25) was removed. == Compatibility == diff --git a/autoload.php b/autoload.php index a38fca2655..c8033cf951 100644 --- a/autoload.php +++ b/autoload.php @@ -932,6 +932,9 @@ $wgAutoloadLocalClasses = [ 'MediaWiki\\Widget\\DateTimeInputWidget' => __DIR__ . '/includes/widget/DateTimeInputWidget.php', 'MediaWiki\\Widget\\NamespaceInputWidget' => __DIR__ . '/includes/widget/NamespaceInputWidget.php', 'MediaWiki\\Widget\\SearchInputWidget' => __DIR__ . '/includes/widget/SearchInputWidget.php', + 'MediaWiki\\Widget\\Search\\FullSearchResultWidget' => __DIR__ . '/includes/widget/search/FullSearchResultWidget.php', + 'MediaWiki\\Widget\\Search\\SearchResultWidget' => __DIR__ . '/includes/widget/search/SearchResultWidget.php', + 'MediaWiki\\Widget\\Search\\SimpleSearchResultWidget' => __DIR__ . '/includes/widget/search/SimpleSearchResultWidget.php', 'MediaWiki\\Widget\\TitleInputWidget' => __DIR__ . '/includes/widget/TitleInputWidget.php', 'MediaWiki\\Widget\\UserInputWidget' => __DIR__ . '/includes/widget/UserInputWidget.php', 'MemCachedClientforWiki' => __DIR__ . '/includes/compat/MemcachedClientCompat.php', diff --git a/docs/hooks.txt b/docs/hooks.txt index 2f99fffdb0..1da39cf61b 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -2877,7 +2877,7 @@ $terms: Search terms, for highlighting function returned false. 'ShowSearchHitTitle': Customise display of search hit title/link. -&$title: Title to link to +$title: Title to link to &$text: Text to use for the link $result: The search result $terms: The search terms entered diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index a56c8dfaa8..ffa5c2128e 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -443,7 +443,6 @@ $wgImgAuthUrlPathMap = []; * Properties required for all repos: * - class The class name for the repository. May come from the core or an extension. * The core repository classes are FileRepo, LocalRepo, ForeignDBRepo. - * FSRepo is also supported for backwards compatibility. * * - name A unique name for the repository (but $wgLocalFileRepo should be 'local'). * The name should consist of alpha-numeric characters. diff --git a/includes/DummyLinker.php b/includes/DummyLinker.php index fc94a63b74..9aa6aeb056 100644 --- a/includes/DummyLinker.php +++ b/includes/DummyLinker.php @@ -5,48 +5,6 @@ */ class DummyLinker { - /** - * @deprecated since 1.27 - */ - public function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) { - wfDeprecated( __METHOD__, '1.27' ); - return Linker::getInterwikiLinkAttributes( - $title, - $unused, - $class - ); - } - - /** - * @deprecated since 1.27 - */ - public function getInternalLinkAttributes( $title, $unused = null, $class = '' ) { - wfDeprecated( __METHOD__, '1.27' ); - return Linker::getInternalLinkAttributes( - $title, - $unused, - $class - ); - } - - /** - * @deprecated since 1.27 - */ - public function getInternalLinkAttributesObj( - $nt, - $unused = null, - $class = '', - $title = false - ) { - wfDeprecated( __METHOD__, '1.27' ); - return Linker::getInternalLinkAttributesObj( - $nt, - $unused, - $class, - $title - ); - } - /** * @deprecated since 1.28, use LinkRenderer::getLinkClasses() instead */ diff --git a/includes/Linker.php b/includes/Linker.php index d3d1f389af..794e2e9171 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -38,102 +38,6 @@ class Linker { const TOOL_LINKS_NOBLOCK = 1; const TOOL_LINKS_EMAIL = 2; - /** - * Get the appropriate HTML attributes to add to the "a" element of an interwiki link. - * - * @since 1.16.3 - * @deprecated since 1.25 - * - * @param string $title The title text for the link, URL-encoded (???) but - * not HTML-escaped - * @param string $unused Unused - * @param string $class The contents of the class attribute; if an empty - * string is passed, which is the default value, defaults to 'external'. - * @return string - */ - static function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) { - global $wgContLang; - - wfDeprecated( __METHOD__, '1.25' ); - - # @todo FIXME: We have a whole bunch of handling here that doesn't happen in - # getExternalLinkAttributes, why? - $title = urldecode( $title ); - $title = $wgContLang->checkTitleEncoding( $title ); - $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title ); - - return self::getLinkAttributesInternal( $title, $class ); - } - - /** - * Get the appropriate HTML attributes to add to the "a" element of an internal link. - * - * @since 1.16.3 - * @deprecated since 1.25 - * - * @param string $title The title text for the link, URL-encoded (???) but - * not HTML-escaped - * @param string $unused Unused - * @param string $class The contents of the class attribute, default none - * @return string - */ - static function getInternalLinkAttributes( $title, $unused = null, $class = '' ) { - wfDeprecated( __METHOD__, '1.25' ); - - $title = urldecode( $title ); - $title = strtr( $title, '_', ' ' ); - return self::getLinkAttributesInternal( $title, $class ); - } - - /** - * Get the appropriate HTML attributes to add to the "a" element of an internal - * link, given the Title object for the page we want to link to. - * - * @since 1.16.3 - * @deprecated since 1.25 - * - * @param Title $nt - * @param string $unused Unused - * @param string $class The contents of the class attribute, default none - * @param string|bool $title Optional (unescaped) string to use in the title - * attribute; if false, default to the name of the page we're linking to - * @return string - */ - static function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) { - wfDeprecated( __METHOD__, '1.25' ); - - if ( $title === false ) { - $title = $nt->getPrefixedText(); - } - return self::getLinkAttributesInternal( $title, $class ); - } - - /** - * Common code for getLinkAttributesX functions - * - * @since 1.16.3 - * @deprecated since 1.25 - * - * @param string $title - * @param string $class - * - * @return string - */ - private static function getLinkAttributesInternal( $title, $class ) { - wfDeprecated( __METHOD__, '1.25' ); - - $title = htmlspecialchars( $title ); - $class = htmlspecialchars( $class ); - $r = ''; - if ( $class != '' ) { - $r .= " class=\"$class\""; - } - if ( $title != '' ) { - $r .= " title=\"$title\""; - } - return $r; - } - /** * Return the CSS colour of a known link * diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 727179af7d..255e618806 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -740,8 +740,12 @@ class SpecialSearch extends SpecialPage { } $out .= "\n"; @@ -752,181 +756,6 @@ class SpecialSearch extends SpecialPage { return $out; } - /** - * Format a single hit result - * - * @param SearchResult $result - * @param array $terms Terms to highlight - * @param int $position Position within the search results, including offset. - * - * @return string - */ - protected function showHit( SearchResult $result, $terms, $position ) { - if ( $result->isBrokenTitle() ) { - return ''; - } - - $title = $result->getTitle(); - - $titleSnippet = $result->getTitleSnippet(); - - if ( $titleSnippet == '' ) { - $titleSnippet = null; - } - - $link_t = clone $title; - $query = []; - - Hooks::run( 'ShowSearchHitTitle', - [ &$link_t, &$titleSnippet, $result, $terms, $this, &$query ] ); - - $linkRenderer = $this->getLinkRenderer(); - - if ( $titleSnippet !== null ) { - $titleSnippet = new HtmlArmor( $titleSnippet ); - } - - $link = $linkRenderer->makeKnownLink( - $link_t, - $titleSnippet, - [ 'data-serp-pos' => $position ], // HTML attributes - $query - ); - - // If page content is not readable, just return the title. - // This is not quite safe, but better than showing excerpts from non-readable pages - // Note that hiding the entry entirely would screw up paging. - if ( !$title->userCan( 'read', $this->getUser() ) ) { - return "
  • {$link}
  • \n"; - } - - // If the page doesn't *exist*... our search index is out of date. - // The least confusing at this point is to drop the result. - // You may get less results, but... oh well. :P - if ( $result->isMissingRevision() ) { - return ''; - } - - // format redirects / relevant sections - $redirectTitle = $result->getRedirectTitle(); - $redirectText = $result->getRedirectSnippet(); - $sectionTitle = $result->getSectionTitle(); - $sectionText = $result->getSectionSnippet(); - $categorySnippet = $result->getCategorySnippet(); - - $redirect = ''; - if ( !is_null( $redirectTitle ) ) { - if ( $redirectText == '' ) { - $redirectText = null; - } - - if ( $redirectText !== null ) { - $redirectText = new HtmlArmor( $redirectText ); - } - - $redirect = "" . - $this->msg( 'search-redirect' )->rawParams( - $linkRenderer->makeKnownLink( $redirectTitle, $redirectText ) )->text() . - ""; - } - - $section = ''; - if ( !is_null( $sectionTitle ) ) { - if ( $sectionText == '' ) { - $sectionText = null; - } - - if ( $sectionText !== null ) { - $sectionText = new HtmlArmor( $sectionText ); - } - - $section = "" . - $this->msg( 'search-section' )->rawParams( - $linkRenderer->makeKnownLink( $sectionTitle, $sectionText ) )->text() . - ""; - } - - $category = ''; - if ( $categorySnippet ) { - $category = "" . - $this->msg( 'search-category' )->rawParams( $categorySnippet )->text() . - ""; - } - - // format text extract - $extract = "
    " . $result->getTextSnippet( $terms ) . "
    "; - - $lang = $this->getLanguage(); - - // format description - $byteSize = $result->getByteSize(); - $wordCount = $result->getWordCount(); - $timestamp = $result->getTimestamp(); - $size = $this->msg( 'search-result-size', $lang->formatSize( $byteSize ) ) - ->numParams( $wordCount )->escaped(); - - if ( $title->getNamespace() == NS_CATEGORY ) { - $cat = Category::newFromTitle( $title ); - $size = $this->msg( 'search-result-category-size' ) - ->numParams( $cat->getPageCount(), $cat->getSubcatCount(), $cat->getFileCount() ) - ->escaped(); - } - - $date = $lang->userTimeAndDate( $timestamp, $this->getUser() ); - - $fileMatch = ''; - // Include a thumbnail for media files... - if ( $title->getNamespace() == NS_FILE ) { - $img = $result->getFile(); - $img = $img ?: wfFindFile( $title ); - if ( $result->isFileMatch() ) { - $fileMatch = "" . - $this->msg( 'search-file-match' )->escaped() . ""; - } - if ( $img ) { - $thumb = $img->transform( [ 'width' => 120, 'height' => 120 ] ); - if ( $thumb ) { - $desc = $this->msg( 'parentheses' )->rawParams( $img->getShortDesc() )->escaped(); - // Float doesn't seem to interact well with the bullets. - // Table messes up vertical alignment of the bullets. - // Bullets are therefore disabled (didn't look great anyway). - return "
  • " . - '' . - '' . - '' . - '' . - '' . - '
    ' . - $thumb->toHtml( [ 'desc-link' => true ] ) . - '' . - "{$link} {$redirect} {$category} {$section} {$fileMatch}" . - $extract . - "
    {$desc} - {$date}
    " . - '
    ' . - "
  • \n"; - } - } - } - - $html = null; - - $score = ''; - $related = ''; - if ( Hooks::run( 'ShowSearchHit', [ - $this, $result, $terms, - &$link, &$redirect, &$section, &$extract, - &$score, &$size, &$date, &$related, - &$html - ] ) ) { - $html = "
  • " . - "{$link} {$redirect} {$category} {$section} {$fileMatch}
    {$extract}\n" . - "
    {$size} - {$date}
    " . - "
  • \n"; - } - - return $html; - } - /** * Extract custom captions from search-interwiki-custom message */ @@ -948,17 +777,13 @@ class SpecialSearch extends SpecialPage { * Show results from other wikis * * @param SearchResultSet|array $matches - * @param string $query + * @param string $terms * * @return string */ - protected function showInterwiki( $matches, $query ) { + protected function showInterwiki( $matches, $terms ) { global $wgContLang; - $out = "
    " . - $this->msg( 'search-interwiki-caption' )->text() . "
    \n"; - $out .= "
    \n"; + $out = ''; + $widget = new MediaWiki\Widget\Search\SimpleSearchResultWidget( + $this, + $this->getLinkRenderer() + ); + foreach ( $iwResults as $iwPrefix => $results ) { + $out .= $this->iwHeaderHtml( $iwPrefix, $terms ); + $out .= ""; + } - // convert the whole thing to desired language variant - $out = $wgContLang->convert( $out ); + $out = + "
    " . + "
    " . + $this->msg( 'search-interwiki-caption' )->escaped() . + "
    " . + $out . + "
    "; - return $out; + // convert the whole thing to desired language variant + return $wgContLang->convert( $out ); } /** - * Show single interwiki link - * - * @param SearchResult $result - * @param string $lastInterwiki - * @param string $query - * - * @return string + * @param string $iwPrefix The interwiki prefix to render a header for + * @param string $terms The user-provided search terms */ - protected function showInterwikiHit( $result, $lastInterwiki, $query ) { - if ( $result->isBrokenTitle() ) { - return ''; - } - - $linkRenderer = $this->getLinkRenderer(); - - $title = $result->getTitle(); - - $titleSnippet = $result->getTitleSnippet(); - - if ( $titleSnippet == '' ) { - $titleSnippet = null; - } - - if ( $titleSnippet !== null ) { - $titleSnippet = new HtmlArmor( $titleSnippet ); - } - - $link = $linkRenderer->makeKnownLink( - $title, - $titleSnippet + protected function iwHeaderHtml( $iwPrefix, $terms ) { + if ( isset( $this->customCaptions[$iwPrefix] ) ) { + $caption = $this->customCaptions[$iwPrefix]; + } else { + $iwLookup = MediaWiki\MediaWikiServices::getInstance()->getInterwikiLookup(); + $interwiki = $iwLookup->fetch( $iwPrefix ); + $parsed = wfParseUrl( wfExpandUrl( $interwiki ? $interwiki->getURL() : '/' ) ); + $caption = $this->msg( 'search-interwiki-default', $parsed['host'] )->text(); + } + $searchLink = Linker::linkKnown( + Title::newFromText( "$iwPrefix:Special:Search" ), + $this->msg( 'search-interwiki-more' )->text(), + [], + [ + 'search' => $terms, + 'fulltext' => 1, + ] ); - - // format redirect if any - $redirectTitle = $result->getRedirectTitle(); - $redirectText = $result->getRedirectSnippet(); - $redirect = ''; - if ( !is_null( $redirectTitle ) ) { - if ( $redirectText == '' ) { - $redirectText = null; - } - - if ( $redirectText !== null ) { - $redirectText = new HtmlArmor( $redirectText ); - } - - $redirect = "" . - $this->msg( 'search-redirect' )->rawParams( - $linkRenderer->makeKnownLink( $redirectTitle, $redirectText ) )->text() . - ""; - } - - $out = ""; - // display project name - if ( is_null( $lastInterwiki ) || $lastInterwiki != $title->getInterwiki() ) { - if ( array_key_exists( $title->getInterwiki(), $this->customCaptions ) ) { - // captions from 'search-interwiki-custom' - $caption = $this->customCaptions[$title->getInterwiki()]; - } else { - // default is to show the hostname of the other wiki which might suck - // if there are many wikis on one hostname - $parsed = wfParseUrl( $title->getFullURL() ); - $caption = $this->msg( 'search-interwiki-default', $parsed['host'] )->text(); - } - // "more results" link (special page stuff could be localized, but we might not know target lang) - $searchTitle = Title::newFromText( $title->getInterwiki() . ":Special:Search" ); - $searchLink = $linkRenderer->makeKnownLink( - $searchTitle, - $this->msg( 'search-interwiki-more' )->text(), - [], - [ - 'search' => $query, - 'fulltext' => 'Search' - ] - ); - $out .= "
    - {$searchLink}{$caption}
    \n