Updates to Finnish localization from patch in bug 1403, with fixes so it actually...
[mediawiki.git] / maintenance / refreshLinks.inc
blob743293f01ee2bc12d1cb6d43546f1e5d6ead753a
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 );
44                 
45                 global $wgLinkHolders;
46                 $wgLinkHolders = array(
47                         'namespaces' => array(),
48                         'dbkeys' => array(),
49                         'queries' => array(),
50                         'texts' => array(),
51                         'titles' => array()
52                 );
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();
62                 if ( $wgEnablePersistentLC ) {
63                         $wgLinkCache->saveToLinkscc( $id, $dbw->strencode( $wgTitle->getPrefixedDBkey() ) );
64                 }
66                 $linksUpdate = new LinksUpdate( $id, $wgTitle->getPrefixedDBkey() );
67                 /** FIXME 
68                  * In ./includes/LinksUpdate.php doDumbUpdate is commented with:
69                  * "Old inefficient update function"
70                  * Probably need to call doUpdate instead.
71                 */
72                 $linksUpdate->doDumbUpdate();
73                 $linksUpdate->fixBrokenLinks();
74                 $dbw->query("COMMIT");
75         }