No point in fetching the result in Database::unlock() if we're not using it anyway.
[lhc/web/wiklou.git] / maintenance / refreshLinks.inc
index e89db8a..e52d101 100644 (file)
@@ -1,15 +1,16 @@
 <?php
 /**
  * @todo document
- * @addtogroup Maintenance
+ * @file
+ * @ingroup Maintenance
  */
 
 /** */
 define( "REPORTING_INTERVAL", 100 );
 #define( "REPORTING_INTERVAL", 1 );
 
-function refreshLinks( $start, $newOnly = false, $maxLag = false, $end = 0, $redirectsOnly = false ) {
-       global $wgUser, $wgParser, $wgUseImageResize, $wgUseTidy;
+function refreshLinks( $start, $newOnly = false, $maxLag = false, $end = 0, $redirectsOnly = false, $oldRedirectsOnly = false ) {
+       global $wgUser, $wgParser, $wgUseTidy;
 
        $fname = 'refreshLinks';
        $dbr = wfGetDB( DB_SLAVE );
@@ -21,19 +22,39 @@ function refreshLinks( $start, $newOnly = false, $maxLag = false, $end = 0, $red
        # Don't generate extension images (e.g. Timeline)
        $wgParser->clearTagHooks();
 
-       # Don't generate thumbnail images
-       $wgUseImageResize = false;
+       # Don't use HTML tidy
        $wgUseTidy = false;
 
-       $what = ($redirectsOnly)? "redirects" : "links";
+       $what = $redirectsOnly ? "redirects" : "links";
+
+       if( $oldRedirectsOnly ) {
+               # This entire code path is cut-and-pasted from below.  Hurrah.
+               $res = $dbr->query(
+                       "SELECT page_id ".
+                       "FROM page ".
+                       "LEFT JOIN redirect ON page_id=rd_from ".
+                       "WHERE page_is_redirect=1 AND rd_from IS NULL AND ".
+                       ($end == 0 ? "page_id >= $start"
+                                  : "page_id BETWEEN $start AND $end"),
+                       $fname
+               );
+               $num = $dbr->numRows( $res );
+               print "Refreshing $num old redirects from $start...\n";
 
-       if ( $newOnly ) {
+               while( $row = $dbr->fetchObject( $res ) ) {
+                       if ( !( ++$i % REPORTING_INTERVAL ) ) {
+                               print "$i\n";
+                               wfWaitForSlaves( $maxLag );
+                       }
+                       fixRedirect( $row->page_id );
+               }
+       } elseif( $newOnly ) {
                print "Refreshing $what from ";
                $res = $dbr->select( 'page',
                        array( 'page_id' ),
                        array(
                                'page_is_new' => 1,
-                               "page_id > $start" ),
+                               "page_id >= $start" ),
                        $fname
                );
                $num = $dbr->numRows( $res );
@@ -121,7 +142,7 @@ function deleteLinksFromNonexistent( $maxLag = 0 ) {
 
        wfWaitForSlaves( $maxLag );
 
-       $dbw = wfGetDB( DB_WRITE );
+       $dbw = wfGetDB( DB_MASTER );
 
        $linksTables = array(
                'pagelinks' => 'pl_from',