r73449 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73448‎ | r73449 | r73450 >
Date:05:20, 21 September 2010
Author:nad
Status:deferred (Comments)
Tags:
Comment:
Add Jacks changes for action tab and clean up
Modified paths:
  • /trunk/extensions/PdfBook/PdfBook.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PdfBook/PdfBook.php
@@ -14,36 +14,51 @@
1515 * @copyright © 2007 Aran Dunkley
1616 * @licence GNU General Public Licence 2.0 or later
1717 */
18 -if (!defined('MEDIAWIKI')) die('Not an entry point.');
 18+if( !defined( 'MEDIAWIKI' ) ) die( "Not an entry point." );
1919
20 -define('PDFBOOK_VERSION', '1.0.4, 2010-01-05');
 20+define( 'PDFBOOK_VERSION', "1.0.5, 2010-09-19" );
2121
2222 $wgExtensionFunctions[] = 'wfSetupPdfBook';
2323 $wgHooks['LanguageGetMagic'][] = 'wfPdfBookLanguageGetMagic';
2424
2525 $wgExtensionCredits['parserhook'][] = array(
2626 'path' => __FILE__,
27 - 'name' => 'PdfBook',
28 - 'author' => '[http://www.organicdesign.co.nz/nad User:Nad]',
29 - 'description' => 'Composes a book from articles in a category and exports as a PDF book',
30 - 'url' => 'http://www.mediawiki.org/wiki/Extension:PdfBook',
 27+ 'name' => "PdfBook",
 28+ 'author' => "[http://www.organicdesign.co.nz/nad User:Nad]",
 29+ 'description' => "Composes a book from articles in a category and exports as a PDF book",
 30+ 'url' => "http://www.mediawiki.org/wiki/Extension:PdfBook",
3131 'version' => PDFBOOK_VERSION
3232 );
3333
 34+# Set this to true in LocalSettings to add PdfBook to the action tabs
 35+$wgPdfBookTab = false;
 36+
 37+# The text displayed in the pdf tab, can be set to another value in Localsettings.
 38+$wgTabText = 'PDF';
 39+
 40+
3441 class PdfBook {
3542
3643 function __construct() {
3744 global $wgHooks, $wgParser, $wgPdfBookMagic;
38 - global $wgLogTypes, $wgLogNames, $wgLogHeaders, $wgLogActions;
 45+ global $wgLogTypes, $wgLogNames, $wgLogHeaders, $wgLogActions, $wgPdfBookTab;
3946 $wgHooks['UnknownAction'][] = $this;
4047
 48+ # Hooks for pre-Vector and Vector addtabs.
 49+ if ( $wgPdfBookTab ) {
 50+ $wgHooks['SkinTemplateTabs'][] = $this ;
 51+ $wgHooks['SkinTemplateNavigation'][] = $this;
 52+ }
 53+
4154 # Add a new pdf log type
4255 $wgLogTypes[] = 'pdf';
4356 $wgLogNames ['pdf'] = 'pdflogpage';
4457 $wgLogHeaders['pdf'] = 'pdflogpagetext';
4558 $wgLogActions['pdf/book'] = 'pdflogentry';
 59+
4660 }
4761
 62+
4863 /**
4964 * Perform the export operation
5065 */
@@ -51,13 +66,13 @@
5267 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgRequest;
5368 global $wgServer, $wgArticlePath, $wgScriptPath, $wgUploadPath, $wgUploadDirectory, $wgScript;
5469
55 - if ($action == 'pdfbook') {
 70+ if( $action == 'pdfbook' ) {
5671
5772 $title = $article->getTitle();
5873 $opt = ParserOptions::newFromUser( $wgUser );
5974
6075 # Log the export
61 - $msg = $wgUser->getUserPage()->getPrefixedText().' exported as a PDF book';
 76+ $msg = $wgUser->getUserPage()->getPrefixedText() . " exported as a PDF book";
6277 $log = new LogPage( 'pdf', false );
6378 $log->addEntry( 'book', $wgTitle, $msg );
6479
@@ -77,10 +92,10 @@
7893 $exclude = $this->setProperty( 'Exclude', array() );
7994 $width = $this->setProperty( 'Width', '' );
8095 $width = $width ? "--browserwidth $width" : '';
81 - if ( !is_array( $exclude ) ) $exclude = split( '\\s*,\\s*', $exclude );
 96+ if( !is_array( $exclude ) ) $exclude = split( '\\s*,\\s*', $exclude );
8297
8398 # Select articles from members if a category or links in content if not
84 - if ( $format == 'single' ) $articles = array( $title );
 99+ if( $format == 'single' ) $articles = array( $title );
85100 else {
86101 $articles = array();
87102 if ( $title->getNamespace() == NS_CATEGORY ) {
@@ -99,7 +114,7 @@
100115 else {
101116 $text = $article->fetchContent();
102117 $text = $wgParser->preprocess( $text, $title, $opt );
103 - if ( preg_match_all( '/^\\*\\s*\\[{2}\\s*([^\\|\\]]+)\\s*.*?\\]{2}/m', $text, $links ) )
 118+ if ( preg_match_all( "/^\\*\\s*\\[{2}\\s*([^\\|\\]]+)\\s*.*?\\]{2}/m", $text, $links ) )
104119 foreach ( $links[1] as $link ) $articles[] = Title::newFromText( $link );
105120 }
106121 }
@@ -116,25 +131,24 @@
117132 if ( !in_array( $ttext, $exclude ) ) {
118133 $article = new Article( $title );
119134 $text = $article->fetchContent();
120 - $text = preg_replace( '/<!--([^@]+?)-->/s', '@@'.'@@$1@@'.'@@', $text ); # preserve HTML comments
121 - if ( $format != 'single' ) $text .= '__NOTOC__';
 135+ $text = preg_replace( "/<!--([^@]+?)-->/s", "@@" . "@@$1@@" . "@@", $text ); # preserve HTML comments
 136+ if ( $format != 'single' ) $text .= "__NOTOC__";
122137 $opt->setEditSection( false ); # remove section-edit links
123138 $wgOut->setHTMLTitle( $ttext ); # use this so DISPLAYTITLE magic works
124139 $out = $wgParser->parse( $text, $title, $opt, true, true );
125140 $ttext = $wgOut->getHTMLTitle();
126141 $text = $out->getText();
127 - $text = preg_replace( '|(<img[^>]+?src=")(/.+?>)|', "$1$wgServer$2", $text ); # make image urls absolute
128 - $text = preg_replace( '|<div\s*class=[\'"]?noprint["\']?>.+?</div>|s', '', $text ); # non-printable areas
129 - $text = preg_replace( '|@{4}([^@]+?)@{4}|s', '<!--$1-->', $text ); # HTML comments hack
130 - #$text = preg_replace('|<table|', '<table border borderwidth=2 cellpadding=3 cellspacing=0', $text);
 142+ $text = preg_replace( "|(<img[^>]+?src=\")(/.+?>)|", "$1$wgServer$2", $text ); # make image urls absolute
 143+ $text = preg_replace( "|<div\s*class=['\"]?noprint[\"']?>.+?</div>|s", "", $text ); # non-printable areas
 144+ $text = preg_replace( "|@{4}([^@]+?)@{4}|s", "<!--$1-->", $text ); # HTML comments hack
131145 $ttext = basename($ttext);
132 - $h1 = $notitle ? '' : "<center><h1>$ttext</h1></center>";
133 - $html .= utf8_decode("$h1$text\n");
 146+ $h1 = $notitle ? "" : "<center><h1>$ttext</h1></center>";
 147+ $html .= utf8_decode( "$h1$text\n" );
134148 }
135149 }
136150
137151 # If format=html in query-string, return html content directly
138 - if ( $format == 'html' ) {
 152+ if( $format == 'html' ) {
139153 $wgOut->disable();
140154 header( "Content-Type: text/html" );
141155 header( "Content-Disposition: attachment; filename=\"$book.html\"" );
@@ -147,8 +161,8 @@
148162 fwrite( $fh, $html );
149163 fclose( $fh );
150164
151 - $footer = $format == 'single' ? '...' : '.1.';
152 - $toc = $format == 'single' ? '' : " --toclevels $levels";
 165+ $footer = $format == 'single' ? "..." : ".1.";
 166+ $toc = $format == 'single' ? "" : " --toclevels $levels";
153167
154168 # Send the file to the client via htmldoc converter
155169 $wgOut->disable();
@@ -165,10 +179,11 @@
166180 }
167181 return false;
168182 }
169 -
 183+
170184 return true;
171185 }
172186
 187+
173188 /**
174189 * Return a property for htmldoc using global, request or passed default
175190 */
@@ -179,12 +194,36 @@
180195 return $default;
181196 }
182197
 198+
183199 /**
184 - * Needed in some versions to prevent Special:Version from breaking
 200+ * Add PDF to actions tabs in MonoBook based skins
185201 */
186 - function __toString() { return 'PdfBook'; }
 202+ function onSkinTemplateTabs( &$skin, &$actions) {
 203+ global $wgTitle, $wgTabText;
 204+ $actions['pdfbook'] = array(
 205+ 'class' => false,
 206+ 'text' => $wgTabText,
 207+ 'href' => $wgTitle->getLocalURL( "action=pdfbook&format=single" ),
 208+ );
 209+ return true;
 210+ }
 211+
 212+
 213+ /**
 214+ * Add PDF to actions tabs in vector based skins
 215+ */
 216+ function onSkinTemplateNavigation( &$skin, &$actions ) {
 217+ global $wgTitle, $wgTabText;
 218+ $actions['views']['pdfbook'] = array(
 219+ 'class' => false,
 220+ 'text' => $wgTabText,
 221+ 'href' => $wgTitle->getLocalURL( "action=pdfbook&format=single" ),
 222+ );
 223+ return true;
 224+ }
187225 }
188226
 227+
189228 /**
190229 * Called from $wgExtensionFunctions array when initialising extensions
191230 */
@@ -193,6 +232,7 @@
194233 $wgPdfBook = new PdfBook();
195234 }
196235
 236+
197237 /**
198238 * Needed in MediaWiki >1.8.0 for magic word hooks to work properly
199239 */

Comments

#Comment by Nikerabbit (talk | contribs)   08:34, 21 September 2010

Why wgTabText a global and not a normal message?

#Comment by Nikerabbit (talk | contribs)   09:00, 21 September 2010

I also don't get it why half of the quotes had to be changed? Patch was based on older revision?

Status & tagging log