TranslateDeleteJob.php
Go to the documentation of this file.00001 <?php
00016 class TranslateDeleteJob extends Job {
00025 public static function newJob( Title $target, $base, $full, $performer ) {
00026 $job = new self( $target );
00027 $job->setUser( FuzzyBot::getUser() );
00028 $job->setFull( $full );
00029 $job->setBase( $base );
00030 $msg = $job->getFull() ? 'pt-deletepage-full-logreason' : 'pt-deletepage-lang-logreason';
00031 $job->setSummary( wfMessage( $msg, $base )->inContentLanguage()->text() );
00032 $job->setPerformer( $performer );
00033
00034 return $job;
00035 }
00036
00037 function __construct( $title, $params = array(), $id = 0 ) {
00038 parent::__construct( __CLASS__, $title, $params, $id );
00039 }
00040
00041 function run() {
00042
00043 $title = $this->title;
00044
00045 $user = $this->getUser();
00046 $summary = $this->getSummary();
00047 $base = $this->getBase();
00048 $doer = User::newFromName( $this->getPerformer() );
00049
00050 PageTranslationHooks::$allowTargetEdit = true;
00051
00052 $error = '';
00053 $wikipage = new WikiPage( $title );
00054 $ok = $wikipage->doDeleteArticle( $summary, false, 0, true, $error, $user );
00055 if ( !$ok ) {
00056 $params = array(
00057 'target' => $base,
00058 'error' => $ok,
00059 );
00060
00061 $type = $this->getFull() ? 'deletefnok' : 'deletelnok';
00062 $entry = new ManualLogEntry( 'pagetranslation', $type );
00063 $entry->setPerformer( $doer );
00064 $entry->setTarget( $title );
00065 $entry->setParameters( $params );
00066 $logid = $entry->insert();
00067 $entry->publish( $logid );
00068 }
00069
00070 PageTranslationHooks::$allowTargetEdit = false;
00071
00072 $cache = wfGetCache( CACHE_DB );
00073 $pages = (array)$cache->get( wfMemcKey( 'pt-base', $base ) );
00074 $lastitem = array_pop( $pages );
00075 if ( $title->getPrefixedText() === $lastitem ) {
00076 $cache->delete( wfMemcKey( 'pt-base', $base ) );
00077
00078 $type = $this->getFull() ? 'deletefok' : 'deletelok';
00079 $entry = new ManualLogEntry( 'pagetranslation', $type );
00080 $entry->setPerformer( $doer );
00081 $entry->setTarget( Title::newFromText( $base ) );
00082 $logid = $entry->insert();
00083 $entry->publish( $logid );
00084
00085 $tpage = TranslatablePage::newFromTitle( $title );
00086 $tpage->getTranslationPercentages( true );
00087 foreach ( $tpage->getTranslationPages() as $page ) {
00088 $page->invalidateCache();
00089 }
00090 $title->invalidateCache();
00091 }
00092
00093 return true;
00094 }
00095
00096 public function setSummary( $summary ) {
00097 $this->params['summary'] = $summary;
00098 }
00099
00100 public function getSummary() {
00101 return $this->params['summary'];
00102 }
00103
00104 public function setFull( $full ) {
00105 $this->params['full'] = $full;
00106 }
00107
00108 public function getFull() {
00109 return $this->params['full'];
00110 }
00111
00115 public function setPerformer( $performer ) {
00116 if ( is_object( $performer ) ) {
00117 $this->params['performer'] = $performer->getName();
00118 } else {
00119 $this->params['performer'] = $performer;
00120 }
00121 }
00122
00123 public function getPerformer() {
00124 return $this->params['performer'];
00125 }
00126
00130 public function setUser( $user ) {
00131 if ( is_object( $user ) ) {
00132 $this->params['user'] = $user->getName();
00133 } else {
00134 $this->params['user'] = $user;
00135 }
00136 }
00137
00138 public function setBase( $base ) {
00139 $this->params['base'] = $base;
00140 }
00141
00142 public function getBase() {
00143 return $this->params['base'];
00144 }
00145
00150 public function getUser() {
00151 return User::newFromName( $this->params['user'], false );
00152 }
00153 }