including the new Defines.php
[mediawiki.git] / maintenance / refreshLinks.inc
blob5a18a166a84d3f0c20640143b56a356e3568f2ff
1 <?php
3 define( "REPORTING_INTERVAL", 50 );
4 define( "PAUSE_INTERVAL", 50 );
6 function refreshLinks( $start ) {
7         global $wgUser, $wgTitle, $wgArticle, $wgEnablePersistentLC, $wgLinkCache, $wgOut;
9         $dbw =& wfGetDB( DB_MASTER );
10         
11         $end = $dbw->selectField( 'cur_id', 'max(cur_id)', false );
13         print("Refreshing link table. Starting from cur_id $start of $end.\n");
15         # Don't generate TeX PNGs (lack of a sensible current directory causes errors anyway)
16         $wgUser->setOption("math", 3);
17         
18         # Turn on link cache in skin
19         $sk =& $wgUser->getSkin();
20         $sk->postParseLinkColour( false );
22         for ($id = $start; $id <= $end; $id++) {
23                 if ( !($id % REPORTING_INTERVAL) ) {
24                         print "$id\n";
25                 }
27                 if ( !($id % PAUSE_INTERVAL) ) {
28                         sleep(1);
29                 }
30                 
31                 $wgTitle = Title::newFromID( $id );
32                 if ( is_null( $wgTitle ) ) {
33                         continue;
34                 }
35                 
36                 $wgArticle = new Article( $wgTitle );
37                 $text = $wgArticle->getContent( true );
38                 $wgLinkCache = new LinkCache;
39                 $wgLinkCache->forUpdate( true );
40                 $wgOut->addWikiText( $text );
42                 if ( $wgEnablePersistentLC ) {
43                         $wgLinkCache->saveToLinkscc( $id, $dbw->strencode( $wgTitle->getPrefixedDBkey() ) );
44                 }
46                 $linksUpdate = new LinksUpdate( $id, $wgTitle->getPrefixedDBkey() );
47                 $linksUpdate->doDumbUpdate();
48                 $linksUpdate->fixBrokenLinks();
49         }