X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=maintenance%2FrefreshLinks.inc;h=48d99712afd4f6da44c0a970118d7687c2078225;hb=63a6b8e0a3740660912c6052549933ac6e1cc277;hp=feb91ef214b231d3ee0371393ec133607ae4bd61;hpb=87cdeb11e83cbface41e1b0a380243cbfb36e5b3;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/refreshLinks.inc b/maintenance/refreshLinks.inc index feb91ef214..48d99712af 100644 --- a/maintenance/refreshLinks.inc +++ b/maintenance/refreshLinks.inc @@ -1,117 +1,154 @@ setOption('math', MW_MATH_SOURCE); # Don't generate extension images (e.g. Timeline) - $wgParser->mTagHooks = array(); - - # Don't generate thumbnail images - $wgUseImageResize = false; + $wgParser->clearTagHooks(); + + # Don't use HTML tidy + $wgUseTidy = false; + + $what = $redirectsOnly ? "redirects" : "links"; + + if( $oldRedirectsOnly ) { + # This entire code path is cut-and-pasted from below. Hurrah. + $res = $dbr->query( + "SELECT page_id ". + "FROM page ". + "LEFT JOIN redirect ON page_id=rd_from ". + "WHERE page_is_redirect=1 AND rd_from IS NULL AND ". + ($end == 0 ? "page_id >= $start" + : "page_id BETWEEN $start AND $end"), + $fname + ); + $num = $dbr->numRows( $res ); + print "Refreshing $num old redirects from $start...\n"; - if ( $newOnly ) { - print "Refreshing links from "; + while( $row = $dbr->fetchObject( $res ) ) { + if ( !( ++$i % REPORTING_INTERVAL ) ) { + print "$i\n"; + wfWaitForSlaves( $maxLag ); + } + fixRedirect( $row->page_id ); + } + } elseif( $newOnly ) { + print "Refreshing $what from "; $res = $dbr->select( 'page', - array( 'page_id' ), + array( 'page_id' ), array( 'page_is_new' => 1, - "page_id > $start" ), + "page_id >= $start" ), $fname ); $num = $dbr->numRows( $res ); print "$num new articles...\n"; - + $i = 0; while ( $row = $dbr->fetchObject( $res ) ) { if ( !( ++$i % REPORTING_INTERVAL ) ) { print "$i\n"; wfWaitForSlaves( $maxLag ); } - - fixLinksFromArticle( $row->page_id ); + if($redirectsOnly) + fixRedirect( $row->page_id ); + else + fixLinksFromArticle( $row->page_id ); } } else { - print "Refreshing link table.\n"; - $end = $dbr->selectField( 'page', 'max(page_id)', false ); + print "Refreshing $what table.\n"; + if ( !$end ) { + $end = $dbr->selectField( 'page', 'max(page_id)', false ); + } print("Starting from page_id $start of $end.\n"); for ($id = $start; $id <= $end; $id++) { - + if ( !($id % REPORTING_INTERVAL) ) { print "$id\n"; wfWaitForSlaves( $maxLag ); } - fixLinksFromArticle( $id ); + if($redirectsOnly) + fixRedirect( $id ); + else + fixLinksFromArticle( $id ); } - + } +} + +function fixRedirect( $id ){ + global $wgTitle, $wgArticle; + + $wgTitle = Title::newFromID( $id ); + $dbw = wfGetDB( DB_MASTER ); + if ( is_null( $wgTitle ) ) { + return; } + $wgArticle = new Article($wgTitle); + + $rt = $wgArticle->followRedirect(); + + if($rt == false || !is_object($rt)) + return; + + $wgArticle->updateRedirectOn($dbw,$rt); } function fixLinksFromArticle( $id ) { - global $wgTitle, $wgArticle, $wgLinkCache, $wgOut; + global $wgTitle, $wgParser; $wgTitle = Title::newFromID( $id ); - $dbw =& wfGetDB( DB_MASTER ); + $dbw = wfGetDB( DB_MASTER ); + + $linkCache =& LinkCache::singleton(); + $linkCache->clear(); if ( is_null( $wgTitle ) ) { return; } $dbw->begin(); - $wgArticle = new Article( $wgTitle ); - $text = $wgArticle->getContent( true ); - $wgLinkCache = new LinkCache; - $wgLinkCache->forUpdate( true ); - - global $wgLinkHolders; - $wgLinkHolders = array( - 'namespaces' => array(), - 'dbkeys' => array(), - 'queries' => array(), - 'texts' => array(), - 'titles' => array() - ); - - - # Parse the text and replace links with placeholders - $wgOut->addWikiText( $text ); - - # Look up the links in the DB and add them to the link cache - $wgOut->clearHTML(); + $revision = Revision::newFromTitle( $wgTitle ); + if ( !$revision ) { + return; + } - $linksUpdate = new LinksUpdate( $id, $wgTitle->getPrefixedDBkey() ); - $linksUpdate->doDumbUpdate(); + $options = new ParserOptions; + $parserOutput = $wgParser->parse( $revision->getText(), $wgTitle, $options, true, true, $revision->getId() ); + $update = new LinksUpdate( $wgTitle, $parserOutput, false ); + $update->doUpdate(); $dbw->immediateCommit(); } function deleteLinksFromNonexistent( $maxLag = 0 ) { $fname = 'deleteLinksFromNonexistent'; - + wfWaitForSlaves( $maxLag ); - $dbw =& wfGetDB( DB_WRITE ); - - $linksTables = array( + $dbw = wfGetDB( DB_MASTER ); + + $linksTables = array( 'pagelinks' => 'pl_from', 'imagelinks' => 'il_from', 'categorylinks' => 'cl_from', + 'templatelinks' => 'tl_from', + 'externallinks' => 'el_from', ); $page = $dbw->tableName( 'page' ); @@ -129,7 +166,7 @@ function deleteLinksFromNonexistent( $maxLag = 0 ) { $pTable = $dbw->tableName( $table ); $sql = "DELETE $pTable FROM $pTable LEFT JOIN $page ON page_id=$field WHERE page_id IS NULL"; - + print "Deleting $table from non-existent articles..."; $dbw->query( $sql, $fname ); print " fixed " .$dbw->affectedRows() . " row(s)\n";