function run()
 {
     // Initialization
     $title = $this->title;
     list(, $code) = TranslateUtils::figureMessage($title->getPrefixedText());
     // Return the actual translation page...
     $page = TranslatablePage::isTranslationPage($title);
     if (!$page) {
         var_dump($this->params);
         var_dump($title);
         throw new MWException("Oops, this should not happen!");
     }
     $group = $page->getMessageGroup();
     $collection = $group->initCollection($code);
     $text = $page->getParse()->getTranslationPageText($collection);
     // Other stuff
     $user = $this->getUser();
     $summary = $this->getSummary();
     $flags = $this->getFlags();
     $page = WikiPage::factory($title);
     // @todo FuzzyBot hack
     PageTranslationHooks::$allowTargetEdit = true;
     $content = ContentHandler::makeContent($text, $page->getTitle());
     $page->doEditContent($content, $summary, $flags, false, $user);
     PageTranslationHooks::$allowTargetEdit = false;
     return true;
 }
Exemplo n.º 2
0
	function run() {
		// Initialization
		$title = $this->title;
		list( , $code ) = TranslateUtils::figureMessage( $title->getPrefixedText() );

		// Return the actual translation page...
		$page = TranslatablePage::isTranslationPage( $title );
		if ( !$page ) {
			var_dump( $this->params );
			var_dump( $title );
			throw new MWException( "Oops, this should not happen!" );
		}

		$group = $page->getMessageGroup();
		$collection = $group->initCollection( $code );
		$collection->loadTranslations( DB_MASTER );

		$text = $page->getParse()->getTranslationPageText( $collection );

		// Other stuff
		$user    = $this->getUser();
		$summary = $this->getSummary();
		$flags   = $this->getFlags();

		$article = new Article( $title, 0 );

		// @todo FuzzyBot hack
		PageTranslationHooks::$allowTargetEdit = true;

		// Do the edit
		$status = $article->doEdit( $text, $summary, $flags, false, $user );
		SpecialPageTranslation::superDebug( __METHOD__, 'edit', $user, $title, $flags, $status );

		PageTranslationHooks::$allowTargetEdit = false;

		// purge cache
		$page->getTranslationPercentages( true );

		return true;
	}
	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->title;
     $base = $this->title->getPrefixedText();
     $translationPages = $this->getTranslationPages();
     $user = $this->getUser();
     foreach ($translationPages as $old) {
         $jobs[$old->getPrefixedText()] = TranslateDeleteJob::newJob($old, $base, !$this->singleLanguage(), $user);
     }
     $sectionPages = $this->getSectionPages();
     foreach ($sectionPages as $old) {
         $jobs[$old->getPrefixedText()] = TranslateDeleteJob::newJob($old, $base, !$this->singleLanguage(), $user);
     }
     if (!$this->doSubpages) {
         $subpages = $this->getSubpages();
         foreach ($subpages as $old) {
             if (TranslatablePage::isTranslationPage($old)) {
                 continue;
             }
             $jobs[$old->getPrefixedText()] = TranslateDeleteJob::newJob($old, $base, !$this->singleLanguage(), $user);
         }
     }
     JobQueueGroup::singleton()->push($jobs);
     $cache = wfGetCache(CACHE_DB);
     $cache->set(wfMemcKey('pt-base', $target->getPrefixedText()), array_keys($jobs), 60 * 60 * 6);
     if (!$this->singleLanguage()) {
         $this->page->unmarkTranslatablePage();
     }
     $this->clearMetadata();
     MessageGroups::singleton()->recache();
     MessageIndexRebuildJob::newJob()->insert();
     $this->getOutput()->addWikiMsg('pt-deletepage-started');
 }
	protected function checkMoveBlockers() {
		$blockers = array();

		$target = $this->newTitle;

		if ( !$target ) {
			$blockers[] = array( 'pt-movepage-block-base-invalid' );
			return $blockers;
		}

		if ( $target->getNamespace() == NS_MEDIAWIKI || $target->getNamespace() == NS_TRANSLATIONS ) {
			$blockers[] = array( 'immobile-target-namespace', $target->getNsText() );
			return $blockers;
		}

		$base = $this->oldTitle->getPrefixedText();

		if ( $target->exists() ) {
			$blockers[] = array( 'pt-movepage-block-base-exists', $target->getPrefixedText() );
		} else {
			$errors = $this->oldTitle->isValidMoveOperation( $target, true, $this->reason );
			if ( is_array( $errors ) ) $blockers = array_merge( $blockers, $errors );
		}

		// Don't spam the same errors for all pages if base page fails
		if ( $blockers ) return $blockers;

		$translationPages = $this->getTranslationPages();
		foreach ( $translationPages as $old ) {
			$new = $this->newPageTitle( $base, $old, $target );
			if ( !$new ) {
				$blockers[] = array( 'pt-movepage-block-tp-invalid', $old->getPrefixedText() );
			} elseif ( $new->exists() ) {
				$blockers[] = array( 'pt-movepage-block-tp-exists', $old->getPrefixedText(), $new->getPrefixedText() );
			} else {
				$errors = $old->isValidMoveOperation( $target, false );
				if ( is_array( $errors ) ) $blockers = array_merge( $blockers, $errors );
			}
		}

		$sections = $this->getSectionPages();
		foreach ( $sections as $old ) {
			$new = $this->newPageTitle( $base, $old, $target );
			if ( !$new ) {
				$blockers[] = array( 'pt-movepage-block-section-invalid', $old->getPrefixedText() );
			} elseif ( $new->exists() ) {
				$blockers[] = array( 'pt-movepage-block-section-exists', $old->getPrefixedText(), $new->getPrefixedText() );
			} else {
				$errors = $old->isValidMoveOperation( $target, false );
				if ( is_array( $errors ) ) $blockers = array_merge( $blockers, $errors );
			}
		}

		if ( $this->moveSubpages ) {
			$subpages = $this->getSubpages();
			foreach ( $subpages as $old ) {
				if ( TranslatablePage::isTranslationPage( $old ) ) {
					continue;
				}

				$new = $this->newPageTitle( $base, $old, $target );

				if ( !$new ) {
					$blockers[] = array( 'pt-movepage-block-subpage-invalid', $old->getPrefixedText() );
				} elseif ( $new->exists() ) {
					$blockers[] = array( 'pt-movepage-block-subpage-exists', $old->getPrefixedText(), $new->getPrefixedText() );
				} else {
					$errors = $old->isValidMoveOperation( $target, false );
					if ( is_array( $errors ) ) $blockers = array_merge( $blockers, $errors );
				}
			}
		}

		return $blockers;
	}
 /**
  * Converts the edit tab (if exists) for translation pages to translate tab.
  * Hook: SkinTemplateNavigation
  * @since 2013.06
  */
 static function translateTab(Skin $skin, array &$tabs)
 {
     $title = $skin->getTitle();
     $handle = new MessageHandle($title);
     $code = $handle->getCode();
     $page = TranslatablePage::isTranslationPage($title);
     if (!$page) {
         return true;
     }
     // The source language has a subpage too, but cannot be translated
     if ($page->getSourceLanguageCode() === $code) {
         return true;
     }
     if (isset($tabs['views']['edit'])) {
         $tabs['views']['edit']['text'] = $skin->msg('tpt-tab-translate')->text();
         $tabs['views']['edit']['href'] = $page->getTranslationUrl($code);
     }
     return true;
 }
Exemplo n.º 7
0
 public static function replaceSubtitle(&$subpages, $skin = null, $out = null)
 {
     global $wgOut;
     // $out was only added in some MW version
     if ($out === null) {
         $out = $wgOut;
     }
     $linker = class_exists('DummyLinker') ? new DummyLinker() : new Linker();
     if (!TranslatablePage::isTranslationPage($out->getTitle()) && !TranslatablePage::isSourcePage($out->getTitle())) {
         return true;
     }
     // Copied from Skin::subPageSubtitle()
     if ($out->isArticle() && MWNamespace::hasSubpages($out->getTitle()->getNamespace())) {
         $ptext = $out->getTitle()->getPrefixedText();
         if (preg_match('/\\//', $ptext)) {
             $links = explode('/', $ptext);
             array_pop($links);
             // Also pop of one extra for language code is needed
             if (TranslatablePage::isTranslationPage($out->getTitle())) {
                 array_pop($links);
             }
             $c = 0;
             $growinglink = '';
             $display = '';
             foreach ($links as $link) {
                 $growinglink .= $link;
                 $display .= $link;
                 $linkObj = Title::newFromText($growinglink);
                 if (is_object($linkObj) && $linkObj->exists()) {
                     $getlink = $linker->linkKnown(SpecialPage::getTitleFor('MyLanguage', $growinglink), htmlspecialchars($display));
                     $c++;
                     if ($c > 1) {
                         $subpages .= wfMsgExt('pipe-separator', 'escapenoentities');
                     } else {
                         // This one is stupid imho, doesn't work with chihuahua
                         // $subpages .= '< ';
                     }
                     $subpages .= $getlink;
                     $display = '';
                 } else {
                     $display .= '/';
                 }
                 $growinglink .= '/';
             }
         }
         return false;
     }
     return true;
 }
 protected function checkMoveBlockers()
 {
     $blockers = array();
     $target = $this->newTitle;
     if (!$target) {
         $blockers[] = array('pt-movepage-block-base-invalid');
         return $blockers;
     }
     if ($target->getNamespace() == NS_MEDIAWIKI || $target->getNamespace() == NS_TRANSLATIONS) {
         $blockers[] = array('immobile-target-namespace', $target->getNsText());
         return $blockers;
     }
     $base = $this->oldTitle->getPrefixedText();
     if ($target->exists()) {
         $blockers[] = array('pt-movepage-block-base-exists', $target->getPrefixedText());
     } else {
         $errors = $this->oldTitle->isValidMoveOperation($target, true, $this->reason);
         if (is_array($errors)) {
             $blockers = array_merge($blockers, $errors);
         }
     }
     // Don't spam the same errors for all pages if base page fails
     if ($blockers) {
         return $blockers;
     }
     // Collect all the old and new titles for checcks
     $titles = array();
     $pages = $this->getTranslationPages();
     foreach ($pages as $old) {
         $titles['tp'][] = array($old, $this->newPageTitle($base, $old, $target));
     }
     $pages = $this->getSectionPages();
     foreach ($pages as $old) {
         $titles['section'][] = array($old, $this->newPageTitle($base, $old, $target));
     }
     $subpages = array();
     if ($this->moveSubpages) {
         $subpages = $this->getSubpages();
     }
     foreach ($subpages as $old) {
         if (!TranslatablePage::isTranslationPage($old)) {
             $titles['subpage'][] = array($old, $this->newPageTitle($base, $old, $target));
         }
     }
     // Check that all new titles are valid
     $lb = new LinkBatch();
     foreach ($titles as $type => $list) {
         // Give grep a chance to find the usages:
         // pt-movepage-block-tp-invalid, pt-movepage-block-section-invalid,
         // pt-movepage-block-subpage-invalid
         foreach ($list as $pair) {
             list($old, $new) = $pair;
             if ($new === null) {
                 $blockers[] = array("pt-movepage-block-{$type}-invalid", $old->getPrefixedText());
                 continue;
             }
             $lb->addObj($old);
             $lb->addObj($new);
         }
     }
     if ($blockers) {
         return $blockers;
     }
     // Check that there are no move blockers
     $lb->execute();
     foreach ($titles as $type => $list) {
         // Give grep a chance to find the usages:
         // pt-movepage-block-tp-exists, pt-movepage-block-section-exists,
         // pt-movepage-block-subpage-exists
         foreach ($list as $pair) {
             list($old, $new) = $pair;
             if ($new->exists()) {
                 $blockers[] = array("pt-movepage-block-{$type}-exists", $old->getPrefixedText(), $new->getPrefixedText());
             } else {
                 /* This method has terrible performance:
                  * - 2 queries by core
                  * - 3 queries by lqt
                  * - and no obvious way to preload the data! */
                 $errors = $old->isValidMoveOperation($target, false);
                 if (is_array($errors)) {
                     $blockers = array_merge($blockers, $errors);
                 }
                 /* Because of the above, check only one of the possibly thousands
                  * of section pages and assume rest are fine. */
                 if ($type === 'section') {
                     break;
                 }
             }
         }
     }
     return $blockers;
 }