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