Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / includes / job / JobQueue.php
index 0ec1a52..7b7ec0c 100644 (file)
  * @defgroup JobQueue JobQueue
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       die( "This file is part of MediaWiki, it is not a valid entry point\n" );
-}
-
 /**
  * Class to both describe a background job and handle jobs.
  *
@@ -117,7 +113,6 @@ abstract class Job {
         * @return Job or false if there's no jobs
         */
        static function pop( $offset = 0 ) {
-               global $wgJobTypesExcludedFromDefaultQueue;
                wfProfileIn( __METHOD__ );
 
                $dbr = wfGetDB( DB_SLAVE );
@@ -128,12 +123,9 @@ abstract class Job {
                        NB: If random fetch previously was used, offset
                                will always be ahead of few entries
                */
-               $conditions = array();
-               if ( count( $wgJobTypesExcludedFromDefaultQueue ) != 0 ) {
-                       foreach ( $wgJobTypesExcludedFromDefaultQueue as $cmdType ) {
-                               $conditions[] = "job_cmd != " . $dbr->addQuotes( $cmdType );
-                       }
-               }
+
+               $conditions = self::defaultQueueConditions();
+
                $offset = intval( $offset );
                $options = array( 'ORDER BY' => 'job_id', 'USE INDEX' => 'PRIMARY' );
 
@@ -201,6 +193,12 @@ abstract class Job {
                $namespace = $row->job_namespace;
                $dbkey = $row->job_title;
                $title = Title::makeTitleSafe( $namespace, $dbkey );
+
+               if ( is_null( $title ) ) {
+                       wfProfileOut( __METHOD__ );
+                       return false;
+               }
+
                $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), $row->job_id );
 
                // Remove any duplicates it may have later in the queue
@@ -219,7 +217,7 @@ abstract class Job {
         * @param $id Int: Job identifier
         * @return Job
         */
-       static function factory( $command, $title, $params = false, $id = 0 ) {
+       static function factory( $command, Title $title, $params = false, $id = 0 ) {
                global $wgJobClasses;
                if( isset( $wgJobClasses[$command] ) ) {
                        $class = $wgJobClasses[$command];
@@ -317,6 +315,27 @@ abstract class Job {
                wfIncrStats( 'job-insert', count( $jobs ) );
        }
 
+
+       /**
+        * SQL conditions to apply on most JobQueue queries
+        *
+        * Whenever we exclude jobs types from the default queue, we want to make
+        * sure that queries to the job queue actually ignore them.
+        *
+        * @return array SQL conditions suitable for Database:: methods
+        */
+       static function defaultQueueConditions( ) {
+               global $wgJobTypesExcludedFromDefaultQueue;
+               $conditions = array();
+               if ( count( $wgJobTypesExcludedFromDefaultQueue ) > 0 ) {
+                       $dbr = wfGetDB( DB_SLAVE );
+                       foreach ( $wgJobTypesExcludedFromDefaultQueue as $cmdType ) {
+                               $conditions[] = "job_cmd != " . $dbr->addQuotes( $cmdType );
+                       }
+               }
+               return $conditions;
+       }
+
        /*-------------------------------------------------------------------------
         * Non-static functions
         *------------------------------------------------------------------------*/