Applied changes from BUG#748, attachment http://bugzilla.wikipedia.org/attachment...
[mediawiki.git] / maintenance / refreshLinks.inc
blob82bf29a590804f954ce560f2c5352a1903c5c9ca
1 <?php
2 /**
3  * @todo document
4  * @package MediaWiki
5  * @subpackage Maintenance
6  * @version $Id$
7  */
9 /** */
10 define( "REPORTING_INTERVAL", 50 );
11 define( "PAUSE_INTERVAL", 50 );
13 function refreshLinks( $start ) {
14         global $wgUser, $wgTitle, $wgArticle, $wgEnablePersistentLC, $wgLinkCache, $wgOut;
16         $dbw =& wfGetDB( DB_MASTER );
17         
18         $end = $dbw->selectField( 'cur', 'max(cur_id)', false );
20         print("Refreshing link table. Starting from cur_id $start of $end.\n");
22         # Don't generate TeX PNGs (lack of a sensible current directory causes errors anyway)
23         $wgUser->setOption("math", 3);
24         
26         for ($id = $start; $id <= $end; $id++) {
27                 if ( !($id % REPORTING_INTERVAL) ) {
28                         print "$id\n";
29                 }
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");
41                 $wgArticle = new Article( $wgTitle );
42                 $text = $wgArticle->getContent( true );
43                 $wgLinkCache = new LinkCache;
44                 $wgLinkCache->forUpdate( true );
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();
53                 if ( $wgEnablePersistentLC ) {
54                         $wgLinkCache->saveToLinkscc( $id, $dbw->strencode( $wgTitle->getPrefixedDBkey() ) );
55                 }
57                 $linksUpdate = new LinksUpdate( $id, $wgTitle->getPrefixedDBkey() );
58                 /** FIXME 
59                  * In ./includes/LinksUpdate.php doDumbUpdate is commented with:
60                  * "Old inefficient update function"
61                  * Probably need to call doUpdate instead.
62                 */
63                 $linksUpdate->doDumbUpdate();
64                 $linksUpdate->fixBrokenLinks();
65                 $dbw->query("COMMIT");
66         }