22 public static function newJob(
26 bool $isTranslatableBundle,
31 'translation' => $isTranslatableBundle,
33 'bundleType' => $bundleType,
34 'performer' => $performer->getName(),
38 return new self( $target, $params );
41 public function __construct( Title $title, array $params = [] ) {
42 parent::__construct(
'DeleteTranslatableBundleJob', $title, $params );
45 public function run() {
46 $title = $this->title;
47 $fuzzyBot = FuzzyBot::getUser();
48 $summary = $this->getSummary();
49 $base = $this->getBase();
50 $performer = $this->getPerformer();
51 $reason = $this->getReason();
52 $mwInstance = MediaWikiServices::getInstance();
54 Hooks::$allowTargetEdit =
true;
55 Hooks::$jobQueueRunning =
true;
57 $wikipage = $mwInstance->getWikiPageFactory()->newFromTitle( $title );
58 $deletePage = $mwInstance->getDeletePageFactory()->newDeletePage( $wikipage, $fuzzyBot );
59 $status = $deletePage->setSuppress(
false )
60 ->forceImmediate(
true )
61 ->deleteUnsafe(
"{$summary}: $reason" );
63 $bundleFactory = Services::getInstance()->getTranslatableBundleFactory();
65 $bundle = $bundleFactory->getBundleFromClass( Title::newFromText( $base ), $this->getBundleType() );
66 $logger = $bundleFactory->getPageDeleteLogger( $bundle );
68 if ( !$status->isGood() ) {
69 if ( $this->isTranslation() ) {
70 $logger->logPageError( $performer, $reason, $status );
72 $logger->logBundleError( $performer, $reason, $status );
76 Hooks::$allowTargetEdit =
false;
78 $cache = $mwInstance->getMainObjectStash();
79 $pageKey = $cache->makeKey(
'pt-base', $base );
80 $pages = (array)$cache->get( $pageKey );
81 $lastitem = array_pop( $pages );
82 if ( $title->getPrefixedText() === $lastitem ) {
83 $cache->delete( $pageKey );
85 if ( $this->isTranslation() ) {
86 $logger->logPageSuccess( $performer, $reason );
88 $logger->logBundleSuccess( $performer, $reason );
91 $title->invalidateCache();
92 Hooks::$jobQueueRunning =
false;
98 public function getSummary():
string {
99 $base = $this->getBase();
100 if ( $this->isTranslation() ) {
101 $msg = wfMessage(
'pt-deletepage-lang-logreason', $base )->inContentLanguage()->text();
103 $msg = wfMessage(
'pt-deletepage-full-logreason', $base )->inContentLanguage()->text();
109 public function getReason():
string {
110 return $this->params[
'reason'];
113 private function isTranslation():
bool {
117 return $this->params[
'translation'] ?? !$this->params[
'full'];
120 public function getPerformer(): User {
121 $userFactory = MediaWikiServices::getInstance()->getUserFactory();
122 return $userFactory->newFromName( $this->params[
'performer'] );
125 public function getBase():
string {
126 return $this->params[
'base'];
129 private function getBundleType():
string {
131 return $this->params[
'bundleType'] ?? TranslatablePage::class;