From: Tim Starling Date: Sat, 22 Oct 2005 09:03:03 +0000 (+0000) Subject: --redirects option X-Git-Tag: 1.6.0~1377 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=3c4585c1f373762544f0200f688129cf490ec073;p=lhc%2Fweb%2Fwiklou.git --redirects option --- diff --git a/maintenance/dumpHTML.inc b/maintenance/dumpHTML.inc index 6025802002..8697f0434a 100644 --- a/maintenance/dumpHTML.inc +++ b/maintenance/dumpHTML.inc @@ -183,6 +183,27 @@ class DumpHTML { print "\n"; } + function doRedirects() { + global $wgLinkCache; + + print "Doing redirects...\n"; + $fname = 'DumpHTML::doRedirects'; + $this->setupGlobals(); + $dbr =& wfGetDB( DB_SLAVE ); + + $res = $dbr->select( 'page', array( 'page_namespace', 'page_title' ), + array( 'page_is_redirect' => 1 ), $fname ); + $num = $dbr->numRows( $res ); + print "$num redirects to do...\n"; + $i = 0; + while ( $row = $dbr->fetchObject( $res ) ) { + $title = Title::makeTitle( $row->page_namespace, $row->page_title ); + if ( !(++$i % (REPORTING_INTERVAL*10) ) ) { + print "Done $i of $num\n"; + } + $this->doArticle( $title ); + } + } /** Write an article specified by title */ function doArticle( $title ) { @@ -190,6 +211,7 @@ class DumpHTML { global $wgUploadDirectory; $text = $this->getArticleHTML( $title ); + if ( $text === false ) { return; } @@ -285,10 +307,6 @@ class DumpHTML { function getArticleHTML( &$title ) { global $wgOut, $wgTitle, $wgArticle, $wgUser, $wgUseCategoryMagic, $wgLinkCache; - $wgOut = new OutputPage; - $wgOut->setParserOptions( new ParserOptions ); - $wgLinkCache = new LinkCache; - $wgTitle = $title; if ( is_null( $wgTitle ) ) { return false; @@ -307,10 +325,12 @@ class DumpHTML { } $rt = Title::newFromRedirect( $wgArticle->fetchContent() ); if ( $rt != NULL ) { - $wgOut->addMeta( 'http:Refresh', '3;url=' . $rt->escapeLocalURL() ); - $wgOut->setPageTitle( $wgTitle->getPrefixedText() ); - $wgOut->addWikiText( wfMsg( 'redirectingto', $rt->getPrefixedText() ) ); + return $this->getRedirect( $rt ); } else { + $wgOut = new OutputPage; + $wgOut->setParserOptions( new ParserOptions ); + $wgLinkCache = new LinkCache; + $wgArticle->view(); } } @@ -324,6 +344,23 @@ class DumpHTML { return $text; } + function getRedirect( $rt ) { + $url = $rt->escapeLocalURL(); + $text = $rt->getPrefixedText(); + return << + + + + + + +

Redirecting to $text

+ + +ENDTEXT; + } + /** Returns image paths used in an XHTML document */ function findImages( $text ) { global $wgOutputEncoding, $wgDumpImages; @@ -394,6 +431,7 @@ class DumpHTML { $rel = substr( $image, $mathPathLength + 1 ); // +1 for slash $source = "$wgMathDirectory/$rel"; $dest = "{$this->dest}/math/$rel"; + @mkdir( "{$this->dest}/math", 0755 ); if ( !file_exists( $dest ) ) { copy( $source, $dest ); } diff --git a/maintenance/dumpHTML.php b/maintenance/dumpHTML.php index 8f52f1cd63..f8d7b3b61c 100644 --- a/maintenance/dumpHTML.php +++ b/maintenance/dumpHTML.php @@ -14,6 +14,7 @@ * -e end ID * --images only do image description pages * --categories only do category pages + * --redirects only do redirects * --special only do miscellaneous stuff * --force-copy copy commons instead of symlink, needed for Wikimedia * --interlang allow interlanguage links @@ -73,6 +74,8 @@ if ( $options['special'] ) { $d->doImageDescriptions(); } elseif ( $options['categories'] ) { $d->doCategories(); +} elseif ( $options['redirects'] ) { + $d->doRedirects(); } else { print("Creating static HTML dump in directory $dest. \n". "Starting from page_id $start of $end.\n");