public function execute($parameters) { $this->setHeaders(); $user = $this->getUser(); $request = $this->getRequest(); $target = $request->getText('target', $parameters); $revision = $request->getInt('revision', 0); $action = $request->getVal('do'); $out = $this->getOutput(); TranslateUtils::addSpecialHelpLink($out, 'Help:Extension:Translate/Page_translation_example'); // No specific page or invalid input $title = Title::newFromText($target); if (!$title) { if ($target !== '') { $out->addWikiMsg('tpt-badtitle'); } else { $this->listPages(); } return; } // Check permissions if (!$user->isAllowed('pagetranslation')) { throw new PermissionsError('pagetranslation'); } // Check permissions if ($request->wasPosted() && !$user->matchEditToken($request->getText('token'))) { throw new PermissionsError('pagetranslation'); } // We are processing some specific page if (!$title->exists()) { $out->addWikiMsg('tpt-nosuchpage', $title->getPrefixedText()); return; } if ($action === 'discourage' || $action === 'encourage') { $id = TranslatablePage::getMessageGroupIdFromTitle($title); $current = MessageGroups::getPriority($id); if ($action === 'encourage') { $new = ''; } else { $new = 'discouraged'; } if ($new !== $current) { MessageGroups::setPriority($id, $new); $entry = new ManualLogEntry('pagetranslation', $action); $entry->setPerformer($user); $entry->setTarget($title); $logid = $entry->insert(); $entry->publish($logid); } $this->listPages(); $group = MessageGroups::getGroup($id); $parents = MessageGroups::getSharedGroups($group); MessageGroupStats::clearGroup($parents); return; } if ($action === 'unlink') { if (!$request->wasPosted()) { $this->showUnlinkConfirmation($title); return; } else { $page = TranslatablePage::newFromTitle($title); $content = ContentHandler::makeContent(self::getStrippedSourcePageText($page->getParse()), $title); $status = WikiPage::factory($title)->doEditContent($content, $this->msg('tpt-unlink-summary')->inContentLanguage()->text(), EDIT_FORCE_BOT | EDIT_UPDATE); if (!$status->isOK()) { $out->wrapWikiMsg('<div class="errorbox">$1</div>', array('tpt-edit-failed', $status->getWikiText())); return; } $page = TranslatablePage::newFromTitle($title); $this->unmarkPage($page, $user); $out->wrapWikiMsg('<div class="successbox">$1</div>', array('tpt-unmarked', $title->getPrefixedText())); $this->listPages(); return; } } if ($action === 'unmark') { $page = TranslatablePage::newFromTitle($title); $this->unmarkPage($page, $user); $out->wrapWikiMsg('<div class="successbox">$1</div>', array('tpt-unmarked', $title->getPrefixedText())); $this->listPages(); return; } if ($revision === 0) { // Get the latest revision $revision = intval($title->getLatestRevID()); } $page = TranslatablePage::newFromRevision($title, $revision); if (!$page instanceof TranslatablePage) { $out->wrapWikiMsg('<div class="errorbox">$1</div>', array('tpt-notsuitable', $title->getPrefixedText(), $revision)); return; } if ($revision !== intval($title->getLatestRevID())) { // We do want to notify the reviewer if the underlying page changes during review $target = $title->getFullUrl(array('oldid' => $revision)); $link = "<span class='plainlinks'>[{$target} {$revision}]</span>"; $out->wrapWikiMsg('<div class="warningbox">$1</div>', array('tpt-oldrevision', $title->getPrefixedText(), $link)); $this->listPages(); return; } $lastrev = $page->getMarkedTag(); if ($lastrev !== false && $lastrev === $revision) { $out->wrapWikiMsg('<div class="warningbox">$1</div>', array('tpt-already-marked')); $this->listPages(); return; } // This will modify the sections to include name property $error = false; $sections = $this->checkInput($page, $error); // Non-fatal error which prevents saving if ($error === false && $request->wasPosted()) { // Check if user wants to translate title // If not, remove it from the list of sections if (!$request->getCheck('translatetitle')) { $sections = array_filter($sections, function ($s) { return $s->id !== 'Page display title'; }); } $err = $this->markForTranslation($page, $sections); if ($err) { call_user_func_array(array($out, 'addWikiMsg'), $err); } else { $this->showSuccess($page); $this->listPages(); } return; } $this->showPage($page, $sections); }