A little refactoring of the input splitting/expansion:
[lhc/web/wiklou.git] / includes / HTMLCacheUpdate.php
index cc392d9..050005d 100644 (file)
@@ -25,6 +25,7 @@ class HTMLCacheUpdate
 {
        public $mTitle, $mTable, $mPrefix;
        public $mRowsPerJob, $mRowsPerQuery;
+       public $mResult;
 
        function __construct( $titleTo, $table ) {
                global $wgUpdateRowsPerJob, $wgUpdateRowsPerQuery;
@@ -40,15 +41,14 @@ class HTMLCacheUpdate
                $cond = $this->getToCondition();
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( $this->mTable, $this->getFromField(), $cond, __METHOD__ );
-               $resWrap = new ResultWrapper( $dbr, $res );
+               $this->mResult = $res;
                if ( $dbr->numRows( $res ) != 0 ) {
                        if ( $dbr->numRows( $res ) > $this->mRowsPerJob ) {
-                               $this->insertJobs( $resWrap );
+                               $this->insertJobs( $res );
                        } else {
-                               $this->invalidateIDs( $resWrap );
+                               $this->invalidateIDs( $res );
                        }
                }
-               $dbr->freeResult( $res );
        }
 
        function insertJobs( ResultWrapper $res ) {
@@ -67,13 +67,13 @@ class HTMLCacheUpdate
                                        break;
                                }
                        }
-                       if ( $id !== false ) {
-                               // One less on the end to avoid duplicating the boundary
-                               $job = new HTMLCacheUpdateJob( $this->mTitle, $this->mTable, $start, $id - 1 );
-                       } else {
-                               $job = new HTMLCacheUpdateJob( $this->mTitle, $this->mTable, $start, false );
-                       }
-                       $jobs[] = $job;
+                       
+                       $params = array(
+                               'table' => $this->mTable,
+                               'start' => $start,
+                               'end' => ( $id !== false ? $id - 1 : false ),
+                       );
+                       $jobs[] = new HTMLCacheUpdateJob( $this->mTitle, $params );
 
                        $start = $id;
                } while ( $start );
@@ -87,6 +87,7 @@ class HTMLCacheUpdate
                        'imagelinks' => 'il',
                        'categorylinks' => 'cl',
                        'templatelinks' => 'tl',
+                       'redirect' => 'rd',
                        
                        # Not needed
                        # 'externallinks' => 'el',
@@ -107,16 +108,14 @@ class HTMLCacheUpdate
        }
 
        function getToCondition() {
+               $prefix = $this->getPrefix();
                switch ( $this->mTable ) {
                        case 'pagelinks':
-                               return array( 
-                                       'pl_namespace' => $this->mTitle->getNamespace(),
-                                       'pl_title' => $this->mTitle->getDBkey()
-                               );
                        case 'templatelinks':
-                               return array(
-                                       'tl_namespace' => $this->mTitle->getNamespace(),
-                                       'tl_title' => $this->mTitle->getDBkey()
+                       case 'redirect':
+                               return array( 
+                                       "{$prefix}_namespace" => $this->mTitle->getNamespace(),
+                                       "{$prefix}_title" => $this->mTitle->getDBkey()
                                );
                        case 'imagelinks':
                                return array( 'il_to' => $this->mTitle->getDBkey() );
@@ -184,26 +183,23 @@ class HTMLCacheUpdate
        }
 }
 
+/**
+ * @todo document (e.g. one-sentence top-level class description).
+ */
 class HTMLCacheUpdateJob extends Job {
        var $table, $start, $end;
 
        /**
         * Construct a job
         * @param Title $title The title linked to
-        * @param string $table The name of the link table.
-        * @param integer $start Beginning page_id or false for open interval
-        * @param integer $end End page_id or false for open interval
+        * @param array $params Job parameters (table, start and end page_ids)
         * @param integer $id job_id
         */
-       function __construct( $title, $table, $start, $end, $id = 0 ) {
-               $params = array(
-                       'table' => $table, 
-                       'start' => $start, 
-                       'end' => $end );
+       function __construct( $title, $params, $id = 0 ) {
                parent::__construct( 'htmlCacheUpdate', $title, $params, $id );
-               $this->table = $table;
-               $this->start = intval( $start );
-               $this->end = intval( $end );
+               $this->table = $params['table'];
+               $this->start = $params['start'];
+               $this->end = $params['end'];
        }
 
        function run() {
@@ -221,9 +217,8 @@ class HTMLCacheUpdateJob extends Job {
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->select( $this->table, $fromField, $conds, __METHOD__ );
                $update->invalidateIDs( new ResultWrapper( $dbr, $res ) );
-               $dbr->freeResult( $res );
 
                return true;
        }
 }
-?>
+