-
- $wgArticle = new Article( $wgTitle );
- $text = $wgArticle->getContent( true );
- $wgLinkCache = new LinkCache;
- $wgLinkCache->forUpdate( true );
- $wgOut->addWikiText( $text );
-
- if ( $wgEnablePersistentLC ) {
- $wgLinkCache->saveToLinkscc( $id, $dbw->strencode( $wgTitle->getPrefixedDBkey() ) );
+ print("Starting from page_id $start of $end.\n");
+
+ for ($id = $start; $id <= $end; $id++) {
+
+ if ( !($id % $reportingInterval) ) {
+ print "$id\n";
+ wfWaitForSlaves( $maxLag );
+ }
+ 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, $wgParser;
+
+ $wgTitle = Title::newFromID( $id );
+ $dbw = wfGetDB( DB_MASTER );
+
+ $linkCache =& LinkCache::singleton();
+ $linkCache->clear();
+
+ if ( is_null( $wgTitle ) ) {
+ return;
+ }
+ $dbw->begin();
+
+ $revision = Revision::newFromTitle( $wgTitle );
+ if ( !$revision ) {
+ return;
+ }
+
+ $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_MASTER );
+
+ $linksTables = array(
+ 'pagelinks' => 'pl_from',
+ 'imagelinks' => 'il_from',
+ 'categorylinks' => 'cl_from',
+ 'templatelinks' => 'tl_from',
+ 'externallinks' => 'el_from',
+ );
+
+ $page = $dbw->tableName( 'page' );
+
+
+ foreach ( $linksTables as $table => $field ) {
+ if ( !$dbw->ping() ) {
+ print "DB disconnected, reconnecting...";
+ while ( !$dbw->ping() ) {
+ print ".";
+ sleep(10);
+ }
+ print "\n";