19 private LinkBatchFactory $linkBatchFactory;
21 public function __construct(
23 LinkBatchFactory $linkBatchFactory
25 $this->bundleFactory = $bundleFactory;
26 $this->linkBatchFactory = $linkBatchFactory;
29 public function getSubpagesPerType(
TranslatableBundle $bundle,
bool $fetchTalkPages ): array {
30 $classifiedSubPages = $this->getEmptyResultSet();
37 $allSubpages = $bundle->
getTitle()->getSubpages();
40 $allSubpagesIndexed = [];
41 foreach ( $allSubpages as $page ) {
42 $allSubpagesIndexed[ $page->getPrefixedDBkey() ] = $page;
46 foreach ( $classifiedSubPages[
'translationPages' ] as $translationPage ) {
47 if ( isset( $allSubpagesIndexed[ $translationPage->getPrefixedDBkey() ] ) ) {
48 unset( $allSubpagesIndexed[ $translationPage->getPrefixedDBkey() ] );
53 foreach ( $allSubpagesIndexed as $index => $subpage ) {
54 if ( $this->bundleFactory->getBundle( $subpage ) ) {
55 $classifiedSubPages[
'translatableSubpages'][] = $subpage;
56 unset( $allSubpagesIndexed[$index] );
61 $allSubpagesIndexed = $this->filterOtherTranslationPages(
62 $allSubpagesIndexed, $classifiedSubPages[
'translatableSubpages']
65 $classifiedSubPages[
'normalSubpages'] = $allSubpagesIndexed;
67 if ( $fetchTalkPages && !$bundle->
getTitle()->isTalkPage() ) {
69 $talkPages = $this->getTalkPages(
72 $classifiedSubPages[
'translationPages'],
73 $classifiedSubPages[
'translationUnitPages'],
74 $classifiedSubPages[
'normalSubpages']
78 $translatableTalkPages = [];
79 foreach ( $talkPages as $key => $talkPage ) {
80 if ( $talkPage ===
null ) {
84 if ( $this->bundleFactory->getBundle( $talkPage ) ) {
85 $translatableTalkPages[] = $talkPage;
86 unset( $talkPages[$key] );
90 $classifiedSubPages[
'talkPages'] = $talkPages;
91 $classifiedSubPages[
'translatableTalkPages'] = $translatableTalkPages;
94 return $classifiedSubPages;
97 public function getEmptyResultSet(): array {
99 'translationPages' => [],
100 'translatableSubpages' => [],
101 'translationUnitPages' => [],
102 'normalSubpages' => [],
104 'translatableTalkPages' => []
113 private function filterOtherTranslationPages( array $allPages, array $translatablePages ): array {
114 $mappedTranslatablePages = [];
115 foreach ( $translatablePages as $index => $page ) {
116 $mappedTranslatablePages[ $page->getText() ] = $index;
119 foreach ( $allPages as $prefixedDbKeyTitle => $subpage ) {
121 if ( isset( $mappedTranslatablePages[ $key ] ) ) {
122 unset( $allPages[ $prefixedDbKeyTitle ] );
136 private function getTalkPages( array $pages ): array {
137 $lb = $this->linkBatchFactory->newLinkBatch();
140 foreach ( $pages as $page ) {
141 $talkPage = $page->getTalkPageIfDefined();
142 $talkPageList[ $page->getPrefixedDBkey() ] = $talkPage;
144 $lb->addObj( $talkPage );
148 $lb->setCaller( __METHOD__ )->execute();
149 foreach ( $talkPageList as $index => $talkPage ) {
150 if ( !$talkPage || !$talkPage->exists() ) {
151 $talkPageList[$index] =
null;
155 return $talkPageList;