Added handling of moving pages

This commit is contained in:
Yaron Koren 2008-11-05 20:33:38 +00:00
parent b1be1c743a
commit a544abbe88
Notes: Yaron Koren 2009-07-20 18:49:29 +00:00

View file

@ -25,32 +25,44 @@ class ReplaceTextJob extends Job {
return false;
}
$article = new Article($this->title);
if ( !$article ) {
$this->error = 'replaceText: Article not found "' . $this->title->getPrefixedDBkey() . '"';
wfProfileOut( __METHOD__ );
return false;
}
wfProfileIn( __METHOD__.'-replace' );
$article_text = $article->fetchContent();
$target_str = $this->params['target_str'];
$replacement_str = $this->params['replacement_str'];
$num_matches;
$new_text = str_replace($target_str, $replacement_str, $article_text, $num_matches);
// if there's at least one replacement, modify the page,
// using the passed-in edit summary
if ($num_matches > 0) {
// change global $wgUser variable to the one
// specified by the job only for the extent of this
// replacement
if (array_key_exists('move_page', $this->params)) {
global $wgUser;
$actual_user = $wgUser;
$wgUser = User::newFromId($this->params['user_id']);
$edit_summary = $this->params['edit_summary'];
$flags = EDIT_MINOR;
$article->doEdit($new_text, $edit_summary, $flags);
$cur_page_name = $this->title->getText();
$new_page_name = str_replace($this->params['target_str'], $this->params['replacement_str'], $cur_page_name);
$new_title = Title::newFromText($new_page_name, $this->title->getNamespace());
$reason = $this->params['edit_summary'];
$this->title->moveTo($new_title, true, $reason);
$wgUser = $actual_user;
} else {
$article = new Article($this->title);
if ( !$article ) {
$this->error = 'replaceText: Article not found "' . $this->title->getPrefixedDBkey() . '"';
wfProfileOut( __METHOD__ );
return false;
}
wfProfileIn( __METHOD__.'-replace' );
$article_text = $article->fetchContent();
$target_str = $this->params['target_str'];
$replacement_str = $this->params['replacement_str'];
$num_matches;
$new_text = str_replace($target_str, $replacement_str, $article_text, $num_matches);
// if there's at least one replacement, modify the page,
// using the passed-in edit summary
if ($num_matches > 0) {
// change global $wgUser variable to the one
// specified by the job only for the extent of this
// replacement
global $wgUser;
$actual_user = $wgUser;
$wgUser = User::newFromId($this->params['user_id']);
$edit_summary = $this->params['edit_summary'];
$flags = EDIT_MINOR;
$article->doEdit($new_text, $edit_summary, $flags);
$wgUser = $actual_user;
}
}
wfProfileOut( __METHOD__.'-replace' );
wfProfileOut( __METHOD__ );