Index: trunk/extensions/BookManager/PrintVersion.alias.php |
— | — | @@ -0,0 +1,19 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Aliases for Special:PrintVersion |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$specialPageAliases = array(); |
| 11 | + |
| 12 | +/** English */ |
| 13 | +$specialPageAliases['en'] = array( |
| 14 | + 'PrintVersion' => array( 'PrintVersion' ), |
| 15 | +); |
| 16 | + |
| 17 | +/** Portuguese (Português) */ |
| 18 | +$specialPageAliases['pt'] = array( |
| 19 | + 'PrintVersion' => array( 'Versão para impressão' ), |
| 20 | +); |
Index: trunk/extensions/BookManager/PrintVersion.i18n.php |
— | — | @@ -0,0 +1,24 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation file for ExpandTemplates extension. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +$messages['en'] = array( |
| 13 | + 'printversion' => 'Print version', |
| 14 | + 'printversion-desc' => '[[Special:PrintVersion|Generates a print version of a book.', |
| 15 | + 'printversion-no-book' => 'Please inform the name of a book to get its print version.', |
| 16 | + 'printversion-inexistent-book' => 'Book not found. Please inform the name of an existing book to get its print version.', |
| 17 | +); |
| 18 | + |
| 19 | +/** Portuguese (Português) */ |
| 20 | +$messages['pt'] = array( |
| 21 | + 'printversion' => 'Versão para impressão', |
| 22 | + 'printversion-desc' => '[[Special:PrintVersion|Gera uma versão para impressão de um livro', |
| 23 | + 'printversion-no-book' => 'Por favor informe o nome de um livro para obter sua versão para impressão.', |
| 24 | + 'printversion-inexistent-book' => 'Livro não encontrado. Por favor informe o nome de um livro existente para obter sua versão para impressão.', |
| 25 | +); |
Index: trunk/extensions/BookManager/BookManager.body.php |
— | — | @@ -1,15 +1,15 @@ |
2 | 2 | <?php |
3 | | -class BookManagerFunctions { |
4 | 3 | /** |
5 | | -* BookManager private functions [Core] |
| 4 | +* BookManager protected functions [Core] |
6 | 5 | */ |
| 6 | +class BookManagerCore extends SpecialPage { |
7 | 7 | const VERSION = "0.1.6 "; |
8 | 8 | private static $chapterList; |
9 | 9 | /** |
10 | 10 | * Get Title |
11 | 11 | * @return Object |
12 | 12 | */ |
13 | | - private static function newTitleObject( &$parser, $text = null ) { |
| 13 | + protected static function newTitleObject( &$parser, $text = null ) { |
14 | 14 | $t = Title::newFromText( $text ); |
15 | 15 | if ( is_null( $t ) ) { |
16 | 16 | return $parser->getTitle(); |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | * Adaptation of the function "getBookPagePrefixes" from collection extension |
24 | 24 | * (http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Collection/Collection.body.php?revision=79895&view=markup#l440) |
25 | 25 | */ |
26 | | - private static function getBookPagePrefixes() { |
| 26 | + protected static function getBookPagePrefixes() { |
27 | 27 | // global $wgUser; |
28 | 28 | global $wgCommunityCollectionNamespace; |
29 | 29 | |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | * Simplification of the function "parseCollectionLine" from collection extension |
57 | 57 | * (http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Collection/Collection.body.php?revision=79895&view=markup#l709) |
58 | 58 | */ |
59 | | - private static function parseCollectionLine( /* Sem uso por enquanto: &$collection, */ $line ) { |
| 59 | + protected static function parseCollectionLine( /* Sem uso por enquanto: &$collection, */ $line ) { |
60 | 60 | $line = trim( $line ); |
61 | 61 | if ( substr( $line, 0, 1 ) == ':' ) { // article |
62 | 62 | $pagename = trim( substr( $line, 1 ) ); |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | * Adaptation of the function "loadCollection" from collection extension |
84 | 84 | * (http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Collection/Collection.body.php?revision=79895&view=markup#l780) |
85 | 85 | */ |
86 | | - private static function loadListFromCollection( $collectiontitle ) { |
| 86 | + protected static function loadListFromCollection( $collectiontitle ) { |
87 | 87 | if ( is_null( $collectiontitle ) || !$collectiontitle->exists() ) { |
88 | 88 | return false; |
89 | 89 | } |
— | — | @@ -101,7 +101,7 @@ |
102 | 102 | /** |
103 | 103 | * Get the book or chapter name |
104 | 104 | */ |
105 | | - private static function bookparts( &$parser, $text = null, $part = 1 ) { |
| 105 | + protected static function bookparts( &$parser, $text = null, $part = 1 ) { |
106 | 106 | $t = self::newTitleObject( $parser, $text ); |
107 | 107 | // No book should have '/' in it's name, so... |
108 | 108 | $book = explode( "/", $t->getText(), 2 ); // ...given a page with title like 'Foo/Bar/Baz'... |
— | — | @@ -119,8 +119,7 @@ |
120 | 120 | * @param $n Integer Position of wanted page. Next page is +1; Previous page is -1 |
121 | 121 | * @return String The prefixed title or empty string if not found or found but not valid |
122 | 122 | */ |
123 | | - |
124 | | - private static function pageText( &$parser, $text = null, $n = 0 ) { |
| 123 | + protected static function pageText( &$parser, $text = null, $n = 0 ) { |
125 | 124 | $pagetitle = self::newTitleObject( $parser, $text ); |
126 | 125 | $prefixes = self::getBookPagePrefixes(); |
127 | 126 | $booktitle = Title::newFromText( $prefixes['community-prefix'] . self::bookparts( $parser, $text, 0 ) ); // ...the book name will be 'Foo'. |
— | — | @@ -141,9 +140,11 @@ |
142 | 141 | } |
143 | 142 | return wfEscapeWikiText( $otherpagetitle->getText() ); |
144 | 143 | } |
| 144 | +} |
145 | 145 | /** |
146 | 146 | * BookManager Functions [Variables] |
147 | 147 | */ |
| 148 | +class BookManagerVariables extends BookManagerCore { |
148 | 149 | static function register( $parser ) { |
149 | 150 | # optional SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}} |
150 | 151 | # instead of {{#int:...}}) |
— | — | @@ -235,40 +236,39 @@ |
236 | 237 | static function AssignAValue( &$parser, &$cache, &$magicWordId, &$ret ) { |
237 | 238 | switch( $magicWordId ) { |
238 | 239 | case 'prevpagename': |
239 | | - $ret = BookManagerFunctions::prevpagename( $parser ); |
| 240 | + $ret = BookManagerVariables::prevpagename( $parser ); |
240 | 241 | return true; |
241 | 242 | case 'prevpagenamee': |
242 | | - $ret = BookManagerFunctions::prevpagenamee( $parser ); |
| 243 | + $ret = BookManagerVariables::prevpagenamee( $parser ); |
243 | 244 | return true; |
244 | 245 | case 'nextpagename': |
245 | | - $ret = BookManagerFunctions::nextpagename( $parser ); |
| 246 | + $ret = BookManagerVariables::nextpagename( $parser ); |
246 | 247 | return true; |
247 | 248 | case 'nextpagenamee': |
248 | | - $ret = BookManagerFunctions::nextpagenamee( $parser ); |
| 249 | + $ret = BookManagerVariables::nextpagenamee( $parser ); |
249 | 250 | return true; |
250 | 251 | case 'rootpagename': |
251 | | - $ret = BookManagerFunctions::rootpagename( $parser ); |
| 252 | + $ret = BookManagerVariables::rootpagename( $parser ); |
252 | 253 | return true; |
253 | 254 | case 'rootpagenamee': |
254 | | - $ret = BookManagerFunctions::rootpagenamee( $parser ); |
| 255 | + $ret = BookManagerVariables::rootpagenamee( $parser ); |
255 | 256 | return true; |
256 | 257 | case 'chaptername': |
257 | | - $ret = BookManagerFunctions::chaptername( $parser ); |
| 258 | + $ret = BookManagerVariables::chaptername( $parser ); |
258 | 259 | return true; |
259 | 260 | case 'chapternamee': |
260 | | - $ret = BookManagerFunctions::chapternamee( $parser ); |
| 261 | + $ret = BookManagerVariables::chapternamee( $parser ); |
261 | 262 | return true; |
262 | 263 | } |
263 | 264 | return false; |
264 | 265 | } |
265 | | - |
| 266 | +} |
266 | 267 | /** |
267 | 268 | * BookManager Functions [Navigation Bar] |
268 | 269 | * inspired by PageNotice extension |
269 | 270 | * (http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/PageNotice/PageNotice.php&view=markup) |
270 | 271 | */ |
271 | | - |
272 | | - |
| 272 | +class BookManagerNavBar extends BookManagerCore { |
273 | 273 | static function addText( &$out, &$text ) { |
274 | 274 | global $wgRequest, $wgBookManagerNamespaces, $wgBookManagerNavBar; |
275 | 275 | $ns = $out->getTitle()->getNamespace(); |
— | — | @@ -349,3 +349,39 @@ |
350 | 350 | return true; |
351 | 351 | } |
352 | 352 | } |
| 353 | +/** |
| 354 | +* BookManager Functions [PrintVersion] |
| 355 | +*/ |
| 356 | +class PrintVersion extends BookManagerCore { |
| 357 | + |
| 358 | + function __construct() { |
| 359 | + parent::__construct( 'PrintVersion' ); |
| 360 | + } |
| 361 | + function execute( $book ) { |
| 362 | + global $wgOut, $wgRequest; |
| 363 | + |
| 364 | + $this->setHeaders(); |
| 365 | + $this->outputHeader(); |
| 366 | + |
| 367 | + $book = !is_null( $book ) ? $book : $wgRequest->getVal( 'book' ); |
| 368 | + if( !isset( $book ) ){ |
| 369 | + $wgOut->addWikiMsg( 'printversion-no-book' ); |
| 370 | + return; |
| 371 | + } |
| 372 | + $prefixes = self::getBookPagePrefixes(); |
| 373 | + $booktitle = Title::newFromText( $prefixes['community-prefix'] . $book ); |
| 374 | + $chapterList = self::loadListFromCollection( $booktitle ); |
| 375 | + if ( $chapterList === false ) { |
| 376 | + $wgOut->addWikiMsg( 'printversion-inexistent-book' ); |
| 377 | + return; |
| 378 | + } |
| 379 | + $text = ''; |
| 380 | + foreach ( $chapterList as $chapter ) { |
| 381 | + $chaptertitle = Title::newFromText( $chapter ); |
| 382 | + $sectionname = $chaptertitle->getSubpageText(); |
| 383 | + $text .= "= $sectionname =\n"; |
| 384 | + $text .= "{{:$chapter}}\n\n"; |
| 385 | + } |
| 386 | + $wgOut->addWikiText( $text ); |
| 387 | + } |
| 388 | +} |