Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
TranslatableBundleDeleter.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\PageTranslation;
5
6use JobQueueGroup;
12use MediaWiki\Title\Title;
13use MediaWiki\User\UserIdentity;
14use Wikimedia\ObjectCache\BagOStuff;
15
23 private BagOStuff $mainCache;
24 private JobQueueGroup $jobQueueGroup;
25 private SubpageListBuilder $subpageBuilder;
26 private TranslatableBundleFactory $bundleFactory;
27
28 public function __construct(
29 BagOStuff $mainCache,
30 JobQueueGroup $jobQueueGroup,
31 SubpageListBuilder $subpageBuilder,
32 TranslatableBundleFactory $bundleFactory
33 ) {
34 $this->mainCache = $mainCache;
35 $this->jobQueueGroup = $jobQueueGroup;
36 $this->subpageBuilder = $subpageBuilder;
37 $this->bundleFactory = $bundleFactory;
38 }
39
48 public function getPagesForDeletion( Title $title, ?string $languageCode, bool $isTranslationPage ): array {
49 if ( $isTranslationPage ) {
50 $resultSet = $this->subpageBuilder->getEmptyResultSet();
51
52 [ $titleKey, ] = Utilities::figureMessage( $title->getPrefixedDBkey() );
53 $translatablePage = TranslatablePage::newFromTitle( Title::newFromText( $titleKey ) );
54
55 $resultSet['translationPages'] = [ $title ];
56 $resultSet['translationUnitPages'] = $translatablePage->getTranslationUnitPages( $languageCode );
57 return $resultSet;
58 } else {
59 $bundle = $this->bundleFactory->getValidBundle( $title );
60 return $this->subpageBuilder->getSubpagesPerType( $bundle, false );
61 }
62 }
63
65 public function deleteAsynchronously(
66 Title $title,
67 bool $isTranslation,
68 UserIdentity $user,
69 array $subpageList,
70 bool $deleteSubpages,
71 string $reason,
72 array $userSessionInfo,
73 ): void {
74 $jobs = [];
75 $base = $title->getPrefixedText();
76 $bundle = $this->getValidBundleFromTitle( $title, $isTranslation );
77 $bundleType = get_class( $bundle );
78
79 foreach ( $subpageList[ 'translationPages' ] as $old ) {
80 $jobs[$old->getPrefixedText()] = DeleteTranslatableBundleJob::newJob(
81 $old, $base, $bundleType, $isTranslation, $user, $reason, $userSessionInfo
82 );
83 }
84
85 foreach ( $subpageList[ 'translationUnitPages' ] as $old ) {
86 $jobs[$old->getPrefixedText()] = DeleteTranslatableBundleJob::newJob(
87 $old, $base, $bundleType, $isTranslation, $user, $reason, $userSessionInfo
88 );
89 }
90
91 if ( $deleteSubpages ) {
92 foreach ( $subpageList[ 'normalSubpages' ] as $old ) {
93 $jobs[$old->getPrefixedText()] = DeleteTranslatableBundleJob::newJob(
94 $old, $base, $bundleType, $isTranslation, $user, $reason, $userSessionInfo
95 );
96 }
97 }
98
99 if ( !$isTranslation ) {
100 $jobs[$title->getPrefixedText()] = DeleteTranslatableBundleJob::newJob(
101 $title, $base, $bundleType, false, $user, $reason, $userSessionInfo
102 );
103 }
104
105 $this->jobQueueGroup->push( $jobs );
106
107 $this->mainCache->set(
108 $this->mainCache->makeKey( 'pt-base', $title->getPrefixedText() ),
109 array_keys( $jobs ),
110 6 * $this->mainCache::TTL_HOUR
111 );
112
113 if ( !$isTranslation ) {
114 $this->bundleFactory->getStore( $bundle )->delete( $title );
115 }
116 }
117
118 private function getValidBundleFromTitle( Title $bundleTitle, bool $isTranslation ): TranslatableBundle {
119 if ( $isTranslation ) {
120 [ $key, ] = Utilities::figureMessage( $bundleTitle->getPrefixedDBkey() );
121 $bundleTitle = Title::newFromText( $key );
122 }
123
124 return $this->bundleFactory->getValidBundle( $bundleTitle );
125 }
126}
Generates list of subpages for the translatable bundle that can be moved or deleted.
Create instances of various classes based on the type of TranslatableBundle.
Translatable bundle represents a message group where its translatable content is defined on a wiki pa...
figureMessage()
Recommended to use getCode and getKey instead.
Contains the core logic to delete translatable bundles or translation pages.
deleteAsynchronously(Title $title, bool $isTranslation, UserIdentity $user, array $subpageList, bool $deleteSubpages, string $reason, array $userSessionInfo,)
Creates the necessary jobs required to delete translation, translatable pages or message bundles.
getPagesForDeletion(Title $title, ?string $languageCode, bool $isTranslationPage)
Returns list of pages to be deleted based on whether the page being deleted is a translation page,...
static newFromTitle(PageIdentity $title)
Constructs a translatable page from title.
Essentially random collection of helper functions, similar to GlobalFunctions.php.
Definition Utilities.php:29