1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
<?php
namespace MediaWiki\Deferred\LinksUpdate;
use MediaWiki\Page\PageReferenceValue;
use MediaWiki\Title\Title;
/**
* An abstract base class for tables that link to local titles.
*
* @stable to extend
* @since 1.38
*/
abstract class TitleLinksTable extends LinksTable {
/**
* Convert a link ID to a PageReferenceValue
*
* @param mixed $linkId
* @return PageReferenceValue
*/
abstract protected function makePageReferenceValue( $linkId ): PageReferenceValue;
/**
* Convert a link ID to a Title
*
* @stable to override
* @param mixed $linkId
* @return Title
*/
protected function makeTitle( $linkId ): Title {
return Title::newFromPageReference( $this->makePageReferenceValue( $linkId ) );
}
/**
* Given an iterator over link IDs, remove links which go to the same
* title, leaving only one link per title.
*
* @param iterable<mixed> $linkIds
* @return iterable<mixed>
*/
abstract protected function deduplicateLinkIds( $linkIds );
/**
* Get link IDs for a given set type, filtering out duplicate links to the
* same title.
*
* @param int $setType
* @return iterable<mixed>
*/
protected function getDeduplicatedLinkIds( $setType ) {
$linkIds = $this->getLinkIDs( $setType );
// Only the CHANGED set type should have duplicates
if ( $setType === self::CHANGED ) {
$linkIds = $this->deduplicateLinkIds( $linkIds );
}
return $linkIds;
}
/**
* Get a link set as an array of Title objects. This is memory-inefficient.
*
* @deprecated since 1.38, hard-deprecated since 1.43
* @param int $setType
* @return Title[]
*/
public function getTitleArray( $setType ) {
wfDeprecated( __METHOD__, '1.43' );
$linkIds = $this->getDeduplicatedLinkIds( $setType );
$titles = [];
foreach ( $linkIds as $linkId ) {
$titles[] = $this->makeTitle( $linkId );
}
return $titles;
}
/**
* Get a link set as an iterator over PageReferenceValue objects.
*
* @param int $setType
* @return iterable<PageReferenceValue>
* @phan-return \Traversable
*/
public function getPageReferenceIterator( $setType ) {
$linkIds = $this->getDeduplicatedLinkIds( $setType );
foreach ( $linkIds as $linkId ) {
yield $this->makePageReferenceValue( $linkId );
}
}
}
|