strip profile name in case it exceeds db storage size (at 255 mark)
[mediawiki.git] / maintenance / refreshLinks.inc
blob1aac42ec156e7eec5572150372bc32491268cd0f
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', '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         
19         for ($id = $start; $id <= $end; $id++) {
20                 if ( !($id % REPORTING_INTERVAL) ) {
21                         print "$id\n";
22                 }
24                 if ( !($id % PAUSE_INTERVAL) ) {
25                         sleep(1);
26                 }
27                 
28                 $wgTitle = Title::newFromID( $id );
29                 if ( is_null( $wgTitle ) ) {
30                         continue;
31                 }
32                 $dbw->query("BEGIN");
34                 $wgArticle = new Article( $wgTitle );
35                 $text = $wgArticle->getContent( true );
36                 $wgLinkCache = new LinkCache;
37                 $wgLinkCache->forUpdate( true );
39                 # Parse the text and replace links with placeholders
40                 $wgOut->addWikiText( $text );
41                 
42                 # Look up the links in the DB and add them to the link cache
43                 $wgOut->transformBuffer( RLH_FOR_UPDATE );
45                 if ( $wgEnablePersistentLC ) {
46                         $wgLinkCache->saveToLinkscc( $id, $dbw->strencode( $wgTitle->getPrefixedDBkey() ) );
47                 }
49                 $linksUpdate = new LinksUpdate( $id, $wgTitle->getPrefixedDBkey() );
50                 $linksUpdate->doDumbUpdate();
51                 $linksUpdate->fixBrokenLinks();
52                 $dbw->query("COMMIT");
53         }