diff options
Diffstat (limited to 'includes/job')
-rw-r--r-- | includes/job/DoubleRedirectJob.php | 31 | ||||
-rw-r--r-- | includes/job/EnotifNotifyJob.php | 3 | ||||
-rw-r--r-- | includes/job/JobQueue.php | 21 | ||||
-rw-r--r-- | includes/job/RefreshLinksJob.php | 12 | ||||
-rw-r--r-- | includes/job/UploadFromUrlJob.php | 16 |
5 files changed, 57 insertions, 26 deletions
diff --git a/includes/job/DoubleRedirectJob.php b/includes/job/DoubleRedirectJob.php index d7991f5e..2b7cd7c8 100644 --- a/includes/job/DoubleRedirectJob.php +++ b/includes/job/DoubleRedirectJob.php @@ -19,7 +19,7 @@ class DoubleRedirectJob extends Job { */ static $user; - /** + /** * Insert jobs into the job queue to fix redirects to the given title * @param $reason String: the reason for the fix, see message double-redirect-fixed-<reason> * @param $redirTitle Title: the title which has changed, redirects pointing to this title are fixed @@ -28,10 +28,10 @@ class DoubleRedirectJob extends Job { public static function fixRedirects( $reason, $redirTitle, $destTitle = false ) { # Need to use the master to get the redirect table updated in the same transaction $dbw = wfGetDB( DB_MASTER ); - $res = $dbw->select( - array( 'redirect', 'page' ), - array( 'page_namespace', 'page_title' ), - array( + $res = $dbw->select( + array( 'redirect', 'page' ), + array( 'page_namespace', 'page_title' ), + array( 'page_id = rd_from', 'rd_namespace' => $redirTitle->getNamespace(), 'rd_title' => $redirTitle->getDBkey() @@ -46,7 +46,7 @@ class DoubleRedirectJob extends Job { continue; } - $jobs[] = new self( $title, array( + $jobs[] = new self( $title, array( 'reason' => $reason, 'redirTitle' => $redirTitle->getPrefixedDBkey() ) ); # Avoid excessive memory usage @@ -65,6 +65,9 @@ class DoubleRedirectJob extends Job { $this->destTitleText = !empty( $params['destTitle'] ) ? $params['destTitle'] : ''; } + /** + * @return bool + */ function run() { if ( !$this->redirTitle ) { $this->setLastError( 'Invalid title' ); @@ -103,13 +106,13 @@ class DoubleRedirectJob extends Job { } # Preserve fragment (bug 14904) - $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(), + $newTitle = Title::makeTitle( $newTitle->getNamespace(), $newTitle->getDBkey(), $currentDest->getFragment() ); # Fix the text # Remember that redirect pages can have categories, templates, etc., # so the regex has to be fairly general - $newText = preg_replace( '/ \[ \[ [^\]]* \] \] /x', + $newText = preg_replace( '/ \[ \[ [^\]]* \] \] /x', '[[' . $newTitle->getFullText() . ']]', $text, 1 ); @@ -122,10 +125,10 @@ class DoubleRedirectJob extends Job { global $wgUser; $oldUser = $wgUser; $wgUser = $this->getUser(); - $article = new Article( $this->title ); - $reason = wfMsgForContent( 'double-redirect-fixed-' . $this->reason, + $article = WikiPage::factory( $this->title ); + $reason = wfMsgForContent( 'double-redirect-fixed-' . $this->reason, $this->redirTitle->getPrefixedText(), $newTitle->getPrefixedText() ); - $article->doEdit( $newText, $reason, EDIT_UPDATE | EDIT_SUPPRESS_RC ); + $article->doEdit( $newText, $reason, EDIT_UPDATE | EDIT_SUPPRESS_RC, false, $this->getUser() ); $wgUser = $oldUser; return true; @@ -152,10 +155,10 @@ class DoubleRedirectJob extends Job { } $seenTitles[$titleText] = true; - $row = $dbw->selectRow( + $row = $dbw->selectRow( array( 'redirect', 'page' ), array( 'rd_namespace', 'rd_title' ), - array( + array( 'rd_from=page_id', 'page_namespace' => $title->getNamespace(), 'page_title' => $title->getDBkey() @@ -172,10 +175,12 @@ class DoubleRedirectJob extends Job { /** * Get a user object for doing edits, from a request-lifetime cache + * @return User */ function getUser() { if ( !self::$user ) { self::$user = User::newFromName( wfMsgForContent( 'double-redirect-fixer' ), false ); + # FIXME: newFromName could return false on a badly configured wiki. if ( !self::$user->isLoggedIn() ) { self::$user->addToDatabase(); } diff --git a/includes/job/EnotifNotifyJob.php b/includes/job/EnotifNotifyJob.php index 5d2a08ea..eb154ece 100644 --- a/includes/job/EnotifNotifyJob.php +++ b/includes/job/EnotifNotifyJob.php @@ -20,10 +20,11 @@ class EnotifNotifyJob extends Job { function run() { $enotif = new EmailNotification(); // Get the user from ID (rename safe). Anons are 0, so defer to name. - if( isset($this->params['editorID']) && $this->params['editorID'] ) { + if( isset( $this->params['editorID'] ) && $this->params['editorID'] ) { $editor = User::newFromId( $this->params['editorID'] ); // B/C, only the name might be given. } else { + # FIXME: newFromName could return false on a badly configured wiki. $editor = User::newFromName( $this->params['editor'], false ); } $enotif->actuallyNotifyOnPageChange( diff --git a/includes/job/JobQueue.php b/includes/job/JobQueue.php index 0d917ba3..e7c66719 100644 --- a/includes/job/JobQueue.php +++ b/includes/job/JobQueue.php @@ -213,6 +213,10 @@ abstract class Job { throw new MWException( "Invalid job command `{$command}`" ); } + /** + * @param $params + * @return string + */ static function makeBlob( $params ) { if ( $params !== false ) { return serialize( $params ); @@ -221,6 +225,10 @@ abstract class Job { } } + /** + * @param $blob + * @return bool|mixed + */ static function extractBlob( $blob ) { if ( (string)$blob !== '' ) { return unserialize( $blob ); @@ -244,6 +252,10 @@ abstract class Job { } $dbw = wfGetDB( DB_MASTER ); $rows = array(); + + /** + * @var $job Job + */ foreach ( $jobs as $job ) { $rows[] = $job->insertFields(); if ( count( $rows ) >= 50 ) { @@ -323,13 +335,16 @@ abstract class Job { if ( $this->removeDuplicates ) { $res = $dbw->select( 'job', array( '1' ), $fields, __METHOD__ ); if ( $dbw->numRows( $res ) ) { - return; + return true; } } wfIncrStats( 'job-insert' ); return $dbw->insert( 'job', $fields, __METHOD__ ); } + /** + * @return array + */ protected function insertFields() { $dbw = wfGetDB( DB_MASTER ); return array( @@ -337,6 +352,7 @@ abstract class Job { 'job_cmd' => $this->command, 'job_namespace' => $this->title->getNamespace(), 'job_title' => $this->title->getDBkey(), + 'job_timestamp' => $dbw->timestamp(), 'job_params' => Job::makeBlob( $this->params ) ); } @@ -362,6 +378,9 @@ abstract class Job { } } + /** + * @return string + */ function toString() { $paramString = ''; if ( $this->params ) { diff --git a/includes/job/RefreshLinksJob.php b/includes/job/RefreshLinksJob.php index 910f0c58..1aa206f0 100644 --- a/includes/job/RefreshLinksJob.php +++ b/includes/job/RefreshLinksJob.php @@ -22,7 +22,7 @@ class RefreshLinksJob extends Job { * @return boolean success */ function run() { - global $wgParser; + global $wgParser, $wgContLang; wfProfileIn( __METHOD__ ); $linkCache = LinkCache::singleton(); @@ -42,7 +42,7 @@ class RefreshLinksJob extends Job { } wfProfileIn( __METHOD__.'-parse' ); - $options = new ParserOptions; + $options = ParserOptions::newFromUserAndLang( new User, $wgContLang ); $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options, true, true, $revision->getId() ); wfProfileOut( __METHOD__.'-parse' ); wfProfileIn( __METHOD__.'-update' ); @@ -71,7 +71,7 @@ class RefreshLinksJob2 extends Job { * @return boolean success */ function run() { - global $wgParser; + global $wgParser, $wgContLang; wfProfileIn( __METHOD__ ); @@ -88,8 +88,10 @@ class RefreshLinksJob2 extends Job { wfProfileOut( __METHOD__ ); return false; } + // Back compat for pre-r94435 jobs + $table = isset( $this->params['table'] ) ? $this->params['table'] : 'templatelinks'; $titles = $this->title->getBacklinkCache()->getLinks( - 'templatelinks', $this->params['start'], $this->params['end']); + $table, $this->params['start'], $this->params['end']); # Not suitable for page load triggered job running! # Gracefully switch to refreshLinks jobs if this happens. @@ -103,6 +105,7 @@ class RefreshLinksJob2 extends Job { wfProfileOut( __METHOD__ ); return true; } + $options = ParserOptions::newFromUserAndLang( new User, $wgContLang ); # Re-parse each page that transcludes this page and update their tracking links... foreach ( $titles as $title ) { $revision = Revision::newFromTitle( $title ); @@ -112,7 +115,6 @@ class RefreshLinksJob2 extends Job { return false; } wfProfileIn( __METHOD__.'-parse' ); - $options = new ParserOptions; $parserOutput = $wgParser->parse( $revision->getText(), $title, $options, true, true, $revision->getId() ); wfProfileOut( __METHOD__.'-parse' ); wfProfileIn( __METHOD__.'-update' ); diff --git a/includes/job/UploadFromUrlJob.php b/includes/job/UploadFromUrlJob.php index 3f915245..26f6e4ba 100644 --- a/includes/job/UploadFromUrlJob.php +++ b/includes/job/UploadFromUrlJob.php @@ -61,24 +61,24 @@ class UploadFromUrlJob extends Job { if ( !$this->params['ignoreWarnings'] ) { $warnings = $this->upload->checkWarnings(); if ( $warnings ) { - wfSetupSession( $this->params['sessionId'] ); + + # Stash the upload + $key = $this->upload->stashFile(); if ( $this->params['leaveMessage'] ) { $this->user->leaveUserMessage( wfMsg( 'upload-warning-subj' ), wfMsg( 'upload-warning-msg', - $this->params['sessionKey'], + $key, $this->params['url'] ) ); } else { + wfSetupSession( $this->params['sessionId'] ); $this->storeResultInSession( 'Warning', 'warnings', $warnings ); + session_write_close(); } - # Stash the upload in the session - $this->upload->stashSession( $this->params['sessionKey'] ); - session_write_close(); - return true; } } @@ -151,6 +151,10 @@ class UploadFromUrlJob extends Job { $$session['result'] = 'Queued'; } + /** + * @param $key + * @return mixed + */ public static function &getSessionData( $key ) { if ( !isset( $_SESSION[self::SESSION_KEYNAME][$key] ) ) { $_SESSION[self::SESSION_KEYNAME][$key] = array(); |