Remove SearchResultPageIdentity interface
SearchResultPageIdentity and SearchResultPageIdentityValue were introduced as placeholders for PageIdentity and PageIdentityValues. They can now become aliases. Bug: T282091 Depends-On: I9b1ab02e0acf12ace107361ea2c443aa543c4880 Depends-On: Ie405ea9539cd18e15b0abb6db6df64ec0135825d Change-Id: I6eb55c78a0a72be66814f8bc854ba663e7c6f62b
This commit is contained in:
parent
b6fea99341
commit
7b832c1fa3
7 changed files with 55 additions and 94 deletions
|
|
@ -1096,6 +1096,8 @@ $wgAutoloadLocalClasses = [
|
|||
'MediaWiki\\Parser\\ParserCacheMetadata' => __DIR__ . '/includes/parser/ParserCacheMetadata.php',
|
||||
'MediaWiki\\Parser\\RevisionOutputCache' => __DIR__ . '/includes/parser/RevisionOutputCache.php',
|
||||
'MediaWiki\\ProcOpenError' => __DIR__ . '/includes/exception/ProcOpenError.php',
|
||||
'MediaWiki\\Rest\\Entity\\SearchResultPageIdentity' => __DIR__ . '/includes/page/ProperPageIdentity.php',
|
||||
'MediaWiki\\Rest\\Entity\\SearchResultPageIdentityValue' => __DIR__ . '/includes/page/PageIdentityValue.php',
|
||||
'MediaWiki\\ShellDisabledError' => __DIR__ . '/includes/exception/ShellDisabledError.php',
|
||||
'MediaWiki\\Skins\\Hook\\SkinAfterPortletHook' => __DIR__ . '/includes/skins/Hook/SkinAfterPortletHook.php',
|
||||
'MediaWiki\\Skins\\Hook\\SkinPageReadyConfigHook' => __DIR__ . '/includes/skins/Hook/SkinPageReadyConfigHook.php',
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
namespace MediaWiki\Rest\Entity;
|
||||
|
||||
use MediaWiki\Page\PageIdentity;
|
||||
|
||||
/**
|
||||
* Lightweight interface representing a page identity
|
||||
*
|
||||
* @unstable
|
||||
* @note This interface is temorary solution. It will be replaced by the one from:
|
||||
* https://phabricator.wikimedia.org/T208776
|
||||
*/
|
||||
interface SearchResultPageIdentity {
|
||||
/**
|
||||
* The numerical page ID.
|
||||
* At the moment it is equivalent to PageIdentity::getId()
|
||||
* @see PageIdentity::getId()
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int;
|
||||
|
||||
/**
|
||||
* Returns the page's namespace number.
|
||||
* At the moment it is equivalent to PageIdentity::getNamespace()
|
||||
* @see PageIdentity::getNamespace()
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNamespace(): int;
|
||||
|
||||
/**
|
||||
* Get the page title in DB key form.
|
||||
* At the moment it is equivalent to PageIdentity::getDBkey()
|
||||
* @see PageIdentity::getDBkey()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDBkey(): string;
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
namespace MediaWiki\Rest\Entity;
|
||||
|
||||
/**
|
||||
* Lightweight value class representing a page identity
|
||||
*
|
||||
* @unstable
|
||||
* @note This class is temorary solution. It will be replaced by the one from:
|
||||
* https://phabricator.wikimedia.org/T208776
|
||||
*/
|
||||
class SearchResultPageIdentityValue implements SearchResultPageIdentity {
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $id = 0;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dbKey = '';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $namespace = null;
|
||||
|
||||
public function __construct( int $id, int $namespace, string $dbKey ) {
|
||||
$this->id = $id;
|
||||
$this->namespace = $namespace;
|
||||
$this->dbKey = $dbKey;
|
||||
}
|
||||
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getNamespace(): int {
|
||||
return $this->namespace;
|
||||
}
|
||||
|
||||
public function getDBkey(): string {
|
||||
return $this->dbKey;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ namespace MediaWiki\Rest\Handler;
|
|||
use Config;
|
||||
use InvalidArgumentException;
|
||||
use ISearchResultSet;
|
||||
use MediaWiki\Rest\Entity\SearchResultPageIdentityValue;
|
||||
use MediaWiki\Page\ProperPageIdentity;
|
||||
use MediaWiki\Rest\Handler;
|
||||
use MediaWiki\Rest\LocalizedHttpException;
|
||||
use MediaWiki\Rest\Response;
|
||||
|
|
@ -16,6 +16,7 @@ use SearchEngineFactory;
|
|||
use SearchResult;
|
||||
use SearchSuggestion;
|
||||
use Status;
|
||||
use Title;
|
||||
use Wikimedia\Message\MessageValue;
|
||||
use Wikimedia\ParamValidator\ParamValidator;
|
||||
use Wikimedia\ParamValidator\TypeDef\IntegerDef;
|
||||
|
|
@ -267,7 +268,7 @@ class SearchHandler extends Handler {
|
|||
* The information about description should be provided by extension by implementing
|
||||
* 'SearchResultProvideDescription' hook. Description is set to null if no extensions
|
||||
* implement the hook.
|
||||
* @param array $pageIdentities
|
||||
* @param ProperPageIdentity[] $pageIdentities
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -288,7 +289,7 @@ class SearchHandler extends Handler {
|
|||
* 'SearchResultProvideThumbnail' hook. Thumbnail is set to null if no extensions implement
|
||||
* the hook.
|
||||
*
|
||||
* @param array $pageIdentities
|
||||
* @param ProperPageIdentity[] $pageIdentities
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -309,15 +310,18 @@ class SearchHandler extends Handler {
|
|||
public function execute() {
|
||||
$searchEngine = $this->createSearchEngine();
|
||||
$pageInfos = $this->doSearch( $searchEngine );
|
||||
|
||||
/** @var ProperPageIdentity[] $pageIdentities */
|
||||
$pageIdentities = array_map( static function ( $pageInfo ) {
|
||||
/** @var Title $title */
|
||||
list( $title ) = $pageInfo;
|
||||
return new SearchResultPageIdentityValue(
|
||||
$title->getArticleID(),
|
||||
$title->getNamespace(),
|
||||
$title->getDBkey()
|
||||
);
|
||||
return $title->exists() ? $title->toPageIdentity() : null;
|
||||
}, $pageInfos );
|
||||
|
||||
// Remove empty entries resulting from non-proper pages like e.g. special pages
|
||||
// in the search result.
|
||||
$pageIdentities = array_filter( $pageIdentities );
|
||||
|
||||
$result = array_map( "array_merge",
|
||||
$this->buildResultFromPageInfos( $pageInfos ),
|
||||
$this->buildDescriptionsFromPageIdentities( $pageIdentities ),
|
||||
|
|
|
|||
|
|
@ -88,3 +88,9 @@ class PageIdentityValue extends PageReferenceValue implements ProperPageIdentity
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
// Retain compatibility with usage in Wikibase and PageImages
|
||||
// along with SearchResultProvideDescriptionHook.
|
||||
// Note that the class was marked @unstable, so the alias can be removed
|
||||
// once the extensions have been updated.
|
||||
class_alias( PageIdentityValue::class, 'MediaWiki\Rest\Entity\SearchResultPageIdentityValue' );
|
||||
|
|
|
|||
|
|
@ -74,3 +74,9 @@ interface ProperPageIdentity extends PageIdentity {
|
|||
public function canExist(): bool;
|
||||
|
||||
}
|
||||
|
||||
// Retain compatibility with hook interface signature as
|
||||
// of SearchResultProvideDescriptionHook as used in Wikibase and PageImages.
|
||||
// Note that the interface was marked @unstable, so the alias can be removed
|
||||
// once the extensions have been updated.
|
||||
class_alias( ProperPageIdentity::class, 'MediaWiki\Rest\Entity\SearchResultPageIdentity' );
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Page\PageIdentity;
|
||||
use MediaWiki\Page\PageIdentityValue;
|
||||
use MediaWiki\Page\PageStoreRecord;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
trait MockTitleTrait {
|
||||
|
|
@ -80,6 +83,32 @@ trait MockTitleTrait {
|
|||
} );
|
||||
$title->method( '__toString' )->willReturn( "MockTitle:{$preText}" );
|
||||
|
||||
$title->method( 'toPageIdentity' )->willReturnCallback( static function () use ( $title ) {
|
||||
return new PageIdentityValue(
|
||||
$title->getId(),
|
||||
$title->getNamespace(),
|
||||
$title->getDBkey(),
|
||||
PageIdentity::LOCAL
|
||||
);
|
||||
} );
|
||||
|
||||
$title->method( 'toPageRecord' )->willReturnCallback( static function () use ( $title ) {
|
||||
return new PageStoreRecord(
|
||||
(object)[
|
||||
'page_id' => $title->getArticleID(),
|
||||
'page_namespace' => $title->getNamespace(),
|
||||
'page_title' => $title->getDBkey(),
|
||||
'page_wiki_id' => $title->getWikiId(),
|
||||
'page_latest' => $title->getLatestRevID(),
|
||||
'page_is_new' => $title->isNewPage(),
|
||||
'page_is_redirect' => $title->isRedirect(),
|
||||
'page_touched' => $title->getTouched(),
|
||||
'page_lang' => $title->getPageLanguage() ?: null,
|
||||
],
|
||||
PageIdentity::LOCAL
|
||||
);
|
||||
} );
|
||||
|
||||
return $title;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue