TranslateRenderJob.php

Go to the documentation of this file.
00001 <?php
00015 class TranslateRenderJob extends Job {
00016 
00021     public static function newJob( Title $target ) {
00022         $job = new self( $target );
00023         $job->setUser( FuzzyBot::getUser() );
00024         $job->setFlags( EDIT_FORCE_BOT );
00025         $job->setSummary( wfMessage( 'tpt-render-summary' )->inContentLanguage()->text() );
00026 
00027         return $job;
00028     }
00029 
00030     function __construct( $title, $params = array(), $id = 0 ) {
00031         parent::__construct( __CLASS__, $title, $params, $id );
00032         $this->params = $params;
00033         $this->removeDuplicates = true;
00034     }
00035 
00036     function run() {
00037         // Initialization
00038         $title = $this->title;
00039         list( , $code ) = TranslateUtils::figureMessage( $title->getPrefixedText() );
00040 
00041         // Return the actual translation page...
00042         $page = TranslatablePage::isTranslationPage( $title );
00043         if ( !$page ) {
00044             var_dump( $this->params );
00045             var_dump( $title );
00046             throw new MWException( "Oops, this should not happen!" );
00047         }
00048 
00049         $group = $page->getMessageGroup();
00050         $collection = $group->initCollection( $code );
00051 
00052         $text = $page->getParse()->getTranslationPageText( $collection );
00053 
00054         // Other stuff
00055         $user = $this->getUser();
00056         $summary = $this->getSummary();
00057         $flags = $this->getFlags();
00058 
00059         $article = new Article( $title, 0 );
00060 
00061         // @todo FuzzyBot hack
00062         PageTranslationHooks::$allowTargetEdit = true;
00063         $article->doEdit( $text, $summary, $flags, false, $user );
00064         PageTranslationHooks::$allowTargetEdit = false;
00065 
00066         return true;
00067     }
00068 
00069     public function setFlags( $flags ) {
00070         $this->params['flags'] = $flags;
00071     }
00072 
00073     public function getFlags() {
00074         return $this->params['flags'];
00075     }
00076 
00077     public function setSummary( $summary ) {
00078         $this->params['summary'] = $summary;
00079     }
00080 
00081     public function getSummary() {
00082         return $this->params['summary'];
00083     }
00084 
00088     public function setUser( $user ) {
00089         if ( $user instanceof User ) {
00090             $this->params['user'] = $user->getName();
00091         } else {
00092             $this->params['user'] = $user;
00093         }
00094     }
00095 
00101     public function getUser() {
00102         return User::newFromName( $this->params['user'], false );
00103     }
00104 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3