MessageUpdateJob.php
Go to the documentation of this file.00001 <?php
00016 class MessageUpdateJob extends Job {
00017 public static function newJob( Title $target, $content, $fuzzy = false ) {
00018 $params = array(
00019 'content' => $content,
00020 'fuzzy' => $fuzzy,
00021 );
00022 $job = new self( $target, $params );
00023
00024 return $job;
00025 }
00026
00027 function __construct( $title, $params = array(), $id = 0 ) {
00028 parent::__construct( __CLASS__, $title, $params, $id );
00029 $this->params = $params;
00030 }
00031
00032 function run() {
00033 global $wgTranslateDocumentationLanguageCode;
00034
00035 $title = $this->title;
00036 $params = $this->params;
00037 $user = FuzzyBot::getUser();
00038 $flags = EDIT_DEFER_UPDATES | EDIT_FORCE_BOT;
00039
00040 $wikiPage = WikiPage::factory( $title );
00041 $summary = wfMessage( 'translate-manage-import-summary' )
00042 ->inContentLanguage()->plain();
00043 $wikiPage->doEdit( $params['content'], $summary, $flags, false, $user );
00044
00045
00046 if ( $params['fuzzy'] ) {
00047 $handle = new MessageHandle( $title );
00048 $key = $handle->getKey();
00049
00050 $languages = TranslateUtils::getLanguageNames( 'en' );
00051 unset( $languages[$wgTranslateDocumentationLanguageCode] );
00052 $languages = array_keys( $languages );
00053
00054 $dbw = wfGetDB( DB_MASTER );
00055 $fields = array( 'page_id', 'page_latest' );
00056 $conds = array( 'page_namespace' => $title->getNamespace() );
00057
00058 $pages = array();
00059 foreach ( $languages as $code ) {
00060 $otherTitle = Title::makeTitleSafe( $title->getNamespace(), "$key/$code" );
00061 $pages[$otherTitle->getDBKey()] = true;
00062 }
00063 unset( $pages[$title->getDBKey()] );
00064 if ( count( $pages ) === 0 ) {
00065 return true;
00066 }
00067
00068 $conds['page_title'] = array_keys( $pages );
00069
00070 $res = $dbw->select( 'page', $fields, $conds, __METHOD__ );
00071 $inserts = array();
00072 foreach ( $res as $row ) {
00073 $inserts[] = array(
00074 'rt_type' => RevTag::getType( 'fuzzy' ),
00075 'rt_page' => $row->page_id,
00076 'rt_revision' => $row->page_latest,
00077 );
00078 }
00079
00080 $dbw->replace(
00081 'revtag',
00082 array( array( 'rt_type', 'rt_page', 'rt_revision' ) ),
00083 $inserts,
00084 __METHOD__
00085 );
00086 }
00087
00088 return true;
00089 }
00090 }