This is moderately messy. Process was principally: * xargs rg --files-with-matches '^use Title;' | grep 'php$' | \ xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1' * rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \ xargs rg --files-with-matches 'Title\b' | \ xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1' * composer fix Then manual fix-ups for a few files that don't have any use statements. Bug: T166010 Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
79 lines
1.8 KiB
PHP
79 lines
1.8 KiB
PHP
<?php
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
use MediaWiki\Title\Title;
|
|
use Wikimedia\Rdbms\IResultWrapper;
|
|
|
|
/**
|
|
* This class is used for different SQL-based search engines shipped with MediaWiki
|
|
* @ingroup Search
|
|
*/
|
|
class SqlSearchResultSet extends SearchResultSet {
|
|
/** @noinspection PhpMissingParentConstructorInspection */
|
|
|
|
/** @var IResultWrapper Result object from database */
|
|
protected $resultSet;
|
|
/** @var string[] Requested search query */
|
|
protected $terms;
|
|
/** @var int|null Total number of hits for $terms */
|
|
protected $totalHits;
|
|
|
|
/**
|
|
* @param IResultWrapper $resultSet
|
|
* @param string[] $terms
|
|
* @param int|null $total
|
|
*/
|
|
public function __construct( IResultWrapper $resultSet, array $terms, $total = null ) {
|
|
parent::__construct();
|
|
$this->resultSet = $resultSet;
|
|
$this->terms = $terms;
|
|
$this->totalHits = $total;
|
|
}
|
|
|
|
/**
|
|
* @return string[]
|
|
* @deprecated since 1.34
|
|
*/
|
|
public function termMatches() {
|
|
return $this->terms;
|
|
}
|
|
|
|
public function numRows() {
|
|
if ( $this->resultSet === false ) {
|
|
return 0;
|
|
}
|
|
|
|
return $this->resultSet->numRows();
|
|
}
|
|
|
|
public function extractResults() {
|
|
if ( $this->resultSet === false ) {
|
|
return [];
|
|
}
|
|
|
|
if ( $this->results === null ) {
|
|
$this->results = [];
|
|
$this->resultSet->rewind();
|
|
$terms = MediaWikiServices::getInstance()->getContentLanguage()
|
|
->convertForSearchResult( $this->terms );
|
|
while ( ( $row = $this->resultSet->fetchObject() ) !== false ) {
|
|
$result = new SqlSearchResult(
|
|
Title::makeTitle( $row->page_namespace, $row->page_title ),
|
|
$terms
|
|
);
|
|
$this->augmentResult( $result );
|
|
$this->results[] = $result;
|
|
}
|
|
}
|
|
return $this->results;
|
|
}
|
|
|
|
public function getTotalHits() {
|
|
if ( $this->totalHits !== null ) {
|
|
return $this->totalHits;
|
|
} else {
|
|
// Special:Search expects a number here.
|
|
return $this->numRows();
|
|
}
|
|
}
|
|
}
|