replaceLinkHolders -> transformBuffer
[lhc/web/wiklou.git] / maintenance / refreshLinks.inc
1 <?php
2
3 define( "REPORTING_INTERVAL", 50 );
4 define( "PAUSE_INTERVAL", 50 );
5
6 function refreshLinks( $start ) {
7 global $wgUser, $wgTitle, $wgArticle, $wgEnablePersistentLC, $wgLinkCache, $wgOut;
8
9 $dbw =& wfGetDB( DB_MASTER );
10
11 $end = $dbw->selectField( 'cur', 'max(cur_id)', false );
12
13 print("Refreshing link table. Starting from cur_id $start of $end.\n");
14
15 # Don't generate TeX PNGs (lack of a sensible current directory causes errors anyway)
16 $wgUser->setOption("math", 3);
17
18
19 for ($id = $start; $id <= $end; $id++) {
20 if ( !($id % REPORTING_INTERVAL) ) {
21 print "$id\n";
22 }
23
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");
33
34 $wgArticle = new Article( $wgTitle );
35 $text = $wgArticle->getContent( true );
36 $wgLinkCache = new LinkCache;
37 $wgLinkCache->forUpdate( true );
38
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 );
44
45 if ( $wgEnablePersistentLC ) {
46 $wgLinkCache->saveToLinkscc( $id, $dbw->strencode( $wgTitle->getPrefixedDBkey() ) );
47 }
48
49 $linksUpdate = new LinksUpdate( $id, $wgTitle->getPrefixedDBkey() );
50 $linksUpdate->doDumbUpdate();
51 $linksUpdate->fixBrokenLinks();
52 $dbw->query("COMMIT");
53 }
54 }
55 ?>