Re-enable message transformations when we're done building the message list.
[mediawiki.git] / maintenance / refreshLinks.inc
blobc57acf3ef48a2ffc284d0cb8dbfbbc191495941d
1 <?php
2 /**
3  * @todo document
4  * @package MediaWiki
5  * @subpackage Maintenance
6  */
8 /** */
9 define( "REPORTING_INTERVAL", 50 );
10 define( "PAUSE_INTERVAL", 50 );
12 function refreshLinks( $start ) {
13         global $wgUser, $wgTitle, $wgArticle, $wgEnablePersistentLC, $wgLinkCache, $wgOut;
15         $dbw =& wfGetDB( DB_MASTER );
16         
17         $end = $dbw->selectField( 'cur', 'max(cur_id)', false );
19         print("Refreshing link table. Starting from cur_id $start of $end.\n");
21         # Don't generate TeX PNGs (lack of a sensible current directory causes errors anyway)
22         $wgUser->setOption("math", 3);
23         
25         for ($id = $start; $id <= $end; $id++) {
26                 if ( !($id % REPORTING_INTERVAL) ) {
27                         print "$id\n";
28                 }
30                 if ( !($id % PAUSE_INTERVAL) ) {
31                         sleep(1);
32                 }
33                 
34                 $wgTitle = Title::newFromID( $id );
35                 if ( is_null( $wgTitle ) ) {
36                         continue;
37                 }
38                 $dbw->query("BEGIN");
40                 $wgArticle = new Article( $wgTitle );
41                 $text = $wgArticle->getContent( true );
42                 $wgLinkCache = new LinkCache;
43                 $wgLinkCache->forUpdate( true );
45                 # Parse the text and replace links with placeholders
46                 $wgOut->addWikiText( $text );
47                 
48                 # Look up the links in the DB and add them to the link cache
49                 $wgOut->transformBuffer( RLH_FOR_UPDATE );
51                 if ( $wgEnablePersistentLC ) {
52                         $wgLinkCache->saveToLinkscc( $id, $dbw->strencode( $wgTitle->getPrefixedDBkey() ) );
53                 }
55                 $linksUpdate = new LinksUpdate( $id, $wgTitle->getPrefixedDBkey() );
56                 $linksUpdate->doDumbUpdate();
57                 $linksUpdate->fixBrokenLinks();
58                 $dbw->query("COMMIT");
59         }