* links and brokenlinks tables merged to pagelinks; this will reduce pain
[lhc/web/wiklou.git] / maintenance / refreshLinks.inc
1 <?php
2 /**
3 * @todo document
4 * @package MediaWiki
5 * @subpackage Maintenance
6 */
7
8 /** */
9 define( "REPORTING_INTERVAL", 50 );
10 define( "PAUSE_INTERVAL", 50 );
11
12 function refreshLinks( $start ) {
13 global $wgUser, $wgTitle, $wgArticle, $wgEnablePersistentLC, $wgLinkCache, $wgOut;
14
15 $dbw =& wfGetDB( DB_MASTER );
16
17 $end = $dbw->selectField( 'page', 'max(page_id)', false );
18
19 print("Refreshing link table. Starting from page_id $start of $end.\n");
20
21 # Don't generate TeX PNGs (lack of a sensible current directory causes errors anyway)
22 $wgUser->setOption("math", 3);
23
24
25 for ($id = $start; $id <= $end; $id++) {
26 if ( !($id % REPORTING_INTERVAL) ) {
27 print "$id\n";
28 }
29
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");
39
40 $wgArticle = new Article( $wgTitle );
41 $text = $wgArticle->getContent( true );
42 $wgLinkCache = new LinkCache;
43 $wgLinkCache->forUpdate( true );
44
45 global $wgLinkHolders;
46 $wgLinkHolders = array(
47 'namespaces' => array(),
48 'dbkeys' => array(),
49 'queries' => array(),
50 'texts' => array(),
51 'titles' => array()
52 );
53
54
55 # Parse the text and replace links with placeholders
56 $wgOut->addWikiText( $text );
57
58 # Look up the links in the DB and add them to the link cache
59 $wgOut->transformBuffer( RLH_FOR_UPDATE );
60 $wgOut->clearHTML();
61
62 if ( $wgEnablePersistentLC ) {
63 $wgLinkCache->saveToLinkscc( $id, $dbw->strencode( $wgTitle->getPrefixedDBkey() ) );
64 }
65
66 $linksUpdate = new LinksUpdate( $id, $wgTitle->getPrefixedDBkey() );
67 $linksUpdate->doDumbUpdate();
68 $dbw->query("COMMIT");
69 }
70 }
71 ?>