protected function performAction() { $jobs = array(); $target = $this->title; $base = $this->title->getPrefixedText(); $translationPages = $this->getTranslationPages(); foreach ( $translationPages as $old ) { $jobs[$old->getPrefixedText()] = DeleteJob::newJob( $old, $base, !$this->singleLanguage(), $this->user ); } $sectionPages = $this->getSectionPages(); foreach ( $sectionPages as $old ) { $jobs[$old->getPrefixedText()] = DeleteJob::newJob( $old, $base, !$this->singleLanguage(), $this->user ); } if ( !$this->doSubpages ) { $subpages = $this->getSubpages(); foreach ( $subpages as $old ) { if ( TranslatablePage::isTranslationPage( $old ) ) { continue; } $jobs[$old->getPrefixedText()] = DeleteJob::newJob( $old, $base, !$this->singleLanguage(), $this->user ); } } Job::batchInsert( $jobs ); $cache = wfGetCache( CACHE_DB ); $cache->set( wfMemcKey( 'pt-base', $target->getPrefixedText() ), array_keys( $jobs ), 60 * 60 * 6 ); if ( !$this->singleLanguage() ) { $this->page->removeTags(); } MessageGroups::clearCache(); MessageIndexRebuildJob::newJob()->insert(); global $wgOut; $wgOut->addWikiMsg( 'pt-deletepage-started' ); }
protected function performAction() { $jobs = array(); $target = $this->newTitle; $base = $this->oldTitle->getPrefixedText(); $oldLatest = $this->oldTitle->getLatestRevId(); $params = array( 'base-source' => $this->oldTitle->getPrefixedText(), 'base-target' => $this->newTitle->getPrefixedText(), ); $translationPages = $this->getTranslationPages(); foreach ( $translationPages as $old ) { $to = $this->newPageTitle( $base, $old, $target ); $jobs[$old->getPrefixedText()] = MoveJob::newJob( $old, $to, $params, $this->user ); } $sectionPages = $this->getSectionPages(); foreach ( $sectionPages as $old ) { $to = $this->newPageTitle( $base, $old, $target ); $jobs[$old->getPrefixedText()] = MoveJob::newJob( $old, $to, $params, $this->user ); } if ( $this->moveSubpages ) { $subpages = $this->getSubpages(); foreach ( $subpages as $old ) { if ( TranslatablePage::isTranslationPage( $old ) ) { continue; } $to = $this->newPageTitle( $base, $old, $target ); $jobs[$old->getPrefixedText()] = MoveJob::newJob( $old, $to, $params, $this->user ); } } // This is used by MoveJob wfGetCache( CACHE_ANYTHING )->set( wfMemcKey( 'translate-pt-move', $base ), count( $jobs ) ); Job::batchInsert( $jobs ); MoveJob::forceRedirects( false ); $errors = $this->oldTitle->moveTo( $this->newTitle, true, $this->reason, false ); if ( is_array( $errors ) ) { $this->showErrors( $errors ); } MoveJob::forceRedirects( true ); $newTpage = TranslatablePage::newFromTitle( $this->newTitle ); $newTpage->addReadyTag( $this->newTitle->getLatestRevId( GAID_FOR_UPDATE ) ); if ( $newTpage->getMarkedTag() === $oldLatest ) { $newTpage->addMarkedTag( $this->newTitle->getLatestRevId( GAID_FOR_UPDATE ) ); } MessageGroups::clearCache(); MessageIndexRebuildJob::newJob()->insert(); global $wgOut; $wgOut->addWikiMsg( 'pt-movepage-started' ); }
* * @author Niklas Laxstrom * @copyright Copyright © 2008-2011, Niklas Laxström * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later * @file */ require( dirname( __FILE__ ) . '/cli.inc' ); function showUsage() { STDERR( <<<EOT Message index creation command line script Usage: php createMessageIndex.php [options...] Options: --help Show this help text --quiet Only output errors EOT ); exit( 1 ); } if ( isset( $options['help'] ) ) { showUsage(); } MessageGroups::clearCache(); MessageIndex::singleton()->rebuild();
/** * Adds a tag which indicates that this page is * suitable for translation. * @param $revision integer|Revision * @param $value string */ public function addMarkedTag($revision, $value = null) { $this->addTag('tp:mark', $revision, $value); MessageGroups::clearCache(); }
/** * This function does the heavy duty of marking a page. * - Updates the source page with section markers. * - Updates translate_sections table * - Updates revtags table * - Setups renderjobs to update the translation pages * - Invalidates caches * @param $page TranslatablePage * @param $sections array * @return array|bool */ public function markForTranslation( TranslatablePage $page, Array $sections ) { global $wgRequest; // Add the section markers to the source page $article = new Article( $page->getTitle(), 0 ); $status = $article->doEdit( $page->getParse()->getSourcePageText(), // Content wfMsgForContent( 'tpt-mark-summary' ), // Summary EDIT_FORCE_BOT | EDIT_UPDATE, // Flags $page->getRevision() // Based-on revision ); if ( !$status->isOK() ) { self::superDebug( __METHOD__, 'edit-fail', $this->user, $page->getTitle(), $status ); return array( 'tpt-edit-failed', $status->getWikiText() ); } $newrevision = $status->value['revision']; // In theory it is either null or Revision object, // never revision object with null id, but who knows if ( $newrevision instanceof Revision ) { $newrevision = $newrevision->getId(); } if ( $newrevision === null ) { // Probably a no-change edit, so no new revision was assigned. // Get the latest revision manually $newrevision = $page->getTitle()->getLatestRevId(); } self::superDebug( __METHOD__, 'latestrev', $page->getTitle(), $newrevision ); $inserts = array(); $changed = array(); $pageId = $page->getTitle()->getArticleId(); foreach ( array_values( $sections ) as $index => $s ) { if ( $s->type === 'changed' ) { // Allow silent changes to avoid fuzzying unnecessary. if ( !$wgRequest->getCheck( "tpt-sect-{$s->id}-action-nofuzzy" ) ) { $changed[] = $s->name; } } $inserts[] = array( 'trs_page' => $pageId, 'trs_key' => $s->name, 'trs_text' => $s->getText(), 'trs_order' => $index ); } // Don't add stuff if no changes, use the plain null instead for prettiness if ( !count( $changed ) ) { $changed = null; } $dbw = wfGetDB( DB_MASTER ); if ( !$dbw->fieldExists( 'translate_sections', 'trs_order', __METHOD__ ) ) { error_log( 'Field trs_order does not exist. Please run update.php.' ); foreach ( array_keys( $inserts ) as $index ) { unset( $inserts[$index]['trs_order'] ); } } $dbw->delete( 'translate_sections', array( 'trs_page' => $page->getTitle()->getArticleId() ), __METHOD__ ); $dbw->insert( 'translate_sections', $inserts, __METHOD__ ); /* Stores the names of changed sections in the database. * Used for calculating completion percentages for outdated messages */ $page->addMarkedTag( $newrevision, $changed ); $this->addFuzzyTags( $page, $changed ); global $wgUser; $logger = new LogPage( 'pagetranslation' ); $params = array( 'user' => $wgUser->getName(), 'revision' => $newrevision, 'changed' => count( $changed ), ); $logger->addEntry( 'mark', $page->getTitle(), null, array( serialize( $params ) ) ); $page->getTitle()->invalidateCache(); $this->setupRenderJobs( $page ); // Re-generate caches MessageGroups::clearCache(); MessageIndexRebuildJob::newJob()->insert(); return false; }