Handle multiple warnings correctly in ApiBase::setWarning(). Calling this function...
[lhc/web/wiklou.git] / includes / JobQueue.php
index 499e415..23fabd7 100644 (file)
@@ -1,13 +1,16 @@
 <?php
+/**
+ * @defgroup JobQueue JobQueue
+ */
 
 if ( !defined( 'MEDIAWIKI' ) ) {
        die( "This file is part of MediaWiki, it is not a valid entry point\n" );
 }
 
-require_once('UserMailer.php');
-
 /**
  * Class to both describe a background job and handle jobs.
+ *
+ * @ingroup JobQueue
  */
 abstract class Job {
        var $command,
@@ -39,8 +42,8 @@ abstract class Job {
         */
 
        /**
-        * Pop a job of a certain type.  This tries less hard than pop() to 
-        * actually find a job; it may be adversely affected by concurrent job 
+        * Pop a job of a certain type.  This tries less hard than pop() to
+        * actually find a job; it may be adversely affected by concurrent job
         * runners.
         */
        static function pop_type($type) {
@@ -80,7 +83,7 @@ abstract class Job {
 
        /**
         * Pop a job off the front of the queue
-        * @static
+        *
         * @param $offset Number of jobs to skip
         * @return Job or false if there's no jobs
         */
@@ -89,11 +92,11 @@ abstract class Job {
 
                $dbr = wfGetDB( DB_SLAVE );
 
-               /* Get a job from the slave, start with an offset, 
+               /* Get a job from the slave, start with an offset,
                        scan full set afterwards, avoid hitting purged rows
 
-                       NB: If random fetch previously was used, offset 
-                               will always be ahead of few entries 
+                       NB: If random fetch previously was used, offset
+                               will always be ahead of few entries
                */
 
                $row = $dbr->selectRow( 'job', '*', "job_id >= ${offset}", __METHOD__,
@@ -167,30 +170,21 @@ abstract class Job {
        }
 
        /**
-        * Create an object of a subclass
+        * Create the appropriate object to handle a specific job
+        *
+        * @param $command String: Job command
+        * @param $title Title: Associated title
+        * @param $params Array: Job parameters
+        * @param $id Int: Job identifier
+        * @return Job
         */
        static function factory( $command, $title, $params = false, $id = 0 ) {
-               switch ( $command ) {
-                       case 'refreshLinks':
-                               return new RefreshLinksJob( $title, $params, $id );
-                       case 'htmlCacheUpdate':
-                       case 'html_cache_update': # BC
-                               return new HTMLCacheUpdateJob( $title, $params['table'], $params['start'], $params['end'], $id );
-                       case 'sendMail':
-                               return new EmaillingJob( $params );
-                       case 'enotifNotify':
-                               return new EnotifNotifyJob( $title, $params );
-               }
-               // OK, check if this is a custom job
-               global $wgCustomJobs;
-               wfLoadAllExtensions(); // This may be for an extension
-
-               if( isset($wgCustomJobs[$command]) ) {
-                       $class = $wgCustomJobs[$command];
-                       return new $class($title, $params, $id);
-               } else {
-                       throw new MWException( "Invalid job command \"$command\"" );
+               global $wgJobClasses;
+               if( isset( $wgJobClasses[$command] ) ) {
+                       $class = $wgJobClasses[$command];
+                       return new $class( $title, $params, $id );
                }
+               throw new MWException( "Invalid job command `{$command}`" );
        }
 
        static function makeBlob( $params ) {
@@ -298,77 +292,3 @@ abstract class Job {
                return $this->error;
        }
 }
-
-
-/**
- * Background job to update links for a given title.
- */
-class RefreshLinksJob extends Job {
-       function __construct( $title, $params = '', $id = 0 ) {
-               parent::__construct( 'refreshLinks', $title, $params, $id );
-       }
-
-       /**
-        * Run a refreshLinks job
-        * @return boolean success
-        */
-       function run() {
-               global $wgParser;
-               wfProfileIn( __METHOD__ );
-
-               $linkCache =& LinkCache::singleton();
-               $linkCache->clear();
-
-               if ( is_null( $this->title ) ) {
-                       $this->error = "refreshLinks: Invalid title";
-                       wfProfileOut( __METHOD__ );
-                       return false;
-               }
-
-               $revision = Revision::newFromTitle( $this->title );
-               if ( !$revision ) {
-                       $this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"';
-                       wfProfileOut( __METHOD__ );
-                       return false;
-               }
-
-               wfProfileIn( __METHOD__.'-parse' );
-               $options = new ParserOptions;
-               $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options, true, true, $revision->getId() );
-               wfProfileOut( __METHOD__.'-parse' );
-               wfProfileIn( __METHOD__.'-update' );
-               $update = new LinksUpdate( $this->title, $parserOutput, false );
-               $update->doUpdate();
-               wfProfileOut( __METHOD__.'-update' );
-               wfProfileOut( __METHOD__ );
-               return true;
-       }
-}
-
-class EmaillingJob extends Job {
-       function __construct($params) {
-               parent::__construct('sendMail', Title::newMainPage(), $params);
-       }
-
-       function run() {
-               userMailer($this->params['to'], $this->params['from'], $this->params['subj'],
-                               $this->params['body'], $this->params['replyto']);
-       }
-}
-
-class EnotifNotifyJob extends Job {
-       function __construct($title, $params) {
-               parent::__construct('enotifNotify', $title, $params);
-       }
-
-       function run() {
-               $enotif = new EmailNotification();
-               $enotif->actuallyNotifyOnPageChange( User::newFromName($this->params['editor'], false),
-                               $this->title, $this->params['timestamp'],
-                               $this->params['summary'], $this->params['minorEdit'],
-                               $this->params['oldid']);
-       }
-}
-
-
-?>