Carsonoid has uploaded a new change for review.
https://gerrit.wikimedia.org/r/241087
Change subject: add htmltoc format mode add nothumbs option
......................................................................
add htmltoc format mode
add nothumbs option
Change-Id: Id0701eb6265af892cb9b83c2b6eb71814db4fd45
---
M PdfBook.hooks.php
1 file changed, 34 insertions(+), 23 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PdfBook
refs/changes/87/241087/1
diff --git a/PdfBook.hooks.php b/PdfBook.hooks.php
index 34a07d4..6618c93 100644
--- a/PdfBook.hooks.php
+++ b/PdfBook.hooks.php
@@ -20,22 +20,23 @@
$log->addEntry( 'book', $article->getTitle(), $msg );
// Initialise PDF variables
- $format = $wgRequest->getText( 'format' );
- $notitle = $wgRequest->getText( 'notitle' );
- $layout = $format == 'single' ? '--webpage' :
'--firstpage toc';
- $charset = self::setProperty( 'Charset',
'iso-8859-1' );
- $left = self::setProperty( 'LeftMargin', '1cm' );
- $right = self::setProperty( 'RightMargin', '1cm' );
- $top = self::setProperty( 'TopMargin', '1cm' );
- $bottom = self::setProperty( 'BottomMargin','1cm' );
- $font = self::setProperty( 'Font', 'Arial' );
- $size = self::setProperty( 'FontSize', '8' );
- $ls = self::setProperty( 'LineSpacing', 1 );
- $linkcol = self::setProperty( 'LinkColour', '217A28' );
- $levels = self::setProperty( 'TocLevels', '2' );
- $exclude = self::setProperty( 'Exclude', array() );
- $width = self::setProperty( 'Width', '' );
- $width = $width ? "--browserwidth $width" : '';
+ $format = $wgRequest->getText( 'format' );
+ $nothumbs = $wgRequest->getText( 'nothumbs' );
+ $notitle = $wgRequest->getText( 'notitle' );
+ $layout = $format == 'single' ? '--webpage' :
'--firstpage toc';
+ $charset = self::setProperty( 'Charset',
'iso-8859-1' );
+ $left = self::setProperty( 'LeftMargin', '1cm' );
+ $right = self::setProperty( 'RightMargin', '1cm' );
+ $top = self::setProperty( 'TopMargin', '1cm' );
+ $bottom = self::setProperty( 'BottomMargin','1cm' );
+ $font = self::setProperty( 'Font', 'Arial' );
+ $size = self::setProperty( 'FontSize', '8' );
+ $ls = self::setProperty( 'LineSpacing', 1 );
+ $linkcol = self::setProperty( 'LinkColour', '217A28'
);
+ $levels = self::setProperty( 'TocLevels', '2' );
+ $exclude = self::setProperty( 'Exclude', array() );
+ $width = self::setProperty( 'Width', '' );
+ $width = $width ? "--browserwidth $width" : '';
if( !is_array( $exclude ) ) $exclude = split(
'\\s*,\\s*', $exclude );
// Select articles from members if a category or links
in content if not
@@ -81,9 +82,10 @@
$opt->setEditSection( false ); #
remove section-edit links
$out = $wgParser->parse( $text,
$title, $opt, true, true );
$text = $out->getText();
- $text = preg_replace(
"|(<img[^>]+?src=\")(/.+?>)|", "$1$wgServer$2", $text ); # make image urls
absolute
- $text = preg_replace(
"|<div\s*class=['\"]?noprint[\"']?>.+?</div>|s", "", $text ); # non-printable
areas
- $text = preg_replace(
"|@{4}([^@]+?)@{4}|s", "<!--$1-->", $text ); # HTML comments
hack
+ $text = preg_replace(
"|(<img[^>]+?src=\")(/.+?>)|", "$1$wgServer$2", $text );
# make image urls absolute
+ if ( $nothumbs == 'true') $text =
preg_replace( "|images/thumb/(\w+/\w+/[\w\.\-]+).*\"|", "images/$1\"", $text );
# Convert image links from thumbnail to full-size
+ $text = preg_replace(
"|<div\s*class=['\"]?noprint[\"']?>.+?</div>|s", "", $text );
# non-printable areas
+ $text = preg_replace(
"|@{4}([^@]+?)@{4}|s", "<!--$1-->", $text );
# HTML comments hack
$ttext = basename( $ttext );
$h1 = $notitle ? "" :
"<center><h1>$ttext</h1></center>";
$html .= utf8_decode( "$h1$text\n" );
@@ -108,13 +110,22 @@
// Send the file to the client via htmldoc
converter
$wgOut->disable();
- header( "Content-Type: application/pdf" );
- header( "Content-Disposition: attachment;
filename=\"$book.pdf\"" );
$cmd = "--left $left --right $right --top $top
--bottom $bottom";
$cmd .= " --header ... --footer $footer
--headfootsize 8 --quiet --jpeg --color";
$cmd .= " --bodyfont $font --fontsize $size
--fontspacing $ls --linkstyle plain --linkcolor $linkcol";
- $cmd .= "$toc --no-title --format pdf14
--numbered $layout $width";
- $cmd = "htmldoc -t pdf --charset $charset $cmd
$file";
+ $cmd .= "$toc --no-title --numbered $layout
$width";
+
+ if ( $format == 'htmltoc' ) {
+ header( "Content-Type: text/html" );
+ header( "Content-Disposition:
attachment; filename=\"$book.html\"" );
+ $cmd = "htmldoc -t html --format html
--charset $charset $cmd $file";
+ }
+ else {
+ header( "Content-Type: application/pdf"
);
+ header( "Content-Disposition:
attachment; filename=\"$book.pdf\"" );
+ $cmd = "htmldoc -t pdf --format pdf14
--charset $charset $cmd $file";
+ }
+
putenv( "HTMLDOC_NOCGI=1" );
passthru( $cmd );
@unlink( $file );
--
To view, visit https://gerrit.wikimedia.org/r/241087
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id0701eb6265af892cb9b83c2b6eb71814db4fd45
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PdfBook
Gerrit-Branch: master
Gerrit-Owner: Carsonoid <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits