Index: trunk/extensions/BookManager/BookManager.body.php |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | private static $chapterList; |
10 | 10 | /** |
11 | 11 | * Get Title |
12 | | - * @param $text String Text for title of current page |
| 12 | + * @param $text String Text for title of current page |
13 | 13 | * @return Object |
14 | 14 | */ |
15 | 15 | protected static function newTitleObject( &$parser, $text = null ) { |
— | — | @@ -102,20 +102,20 @@ |
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
106 | | - * Get the book or chapter name from page title |
107 | | - * @param $text String Text for title of current page |
| 106 | + * Get the book or chapter name from page title |
| 107 | + * @param $text String Text for title of current page |
108 | 108 | * @param $part Integer. Title like 'Foo/Bar/Baz' "0" is Foo , the book name, and "1" is Bar/Baz, the chapter name. |
109 | 109 | * @return String with book or chapter |
110 | 110 | */ |
111 | | - protected static function bookparts( &$parser, $text = null, $part = 1 ) { |
112 | | - $t = self::newTitleObject( $parser, $text ); |
| 111 | + protected static function bookParts( &$parser, $text = null, $part = 1 ) { |
| 112 | + $t = self::newTitleObject( $parser, $text )->getText(); |
113 | 113 | // No book should have '/' in it's name, so... |
114 | | - $book = explode( "/", $t->getText(), 2 ); |
| 114 | + $book = explode( "/", $t , 2 ); |
115 | 115 | if ( count( $book ) > 1 ) { |
116 | 116 | return $book[$part]; |
117 | 117 | } |
118 | 118 | else { |
119 | | - return $t->getText(); |
| 119 | + return $t; |
120 | 120 | } |
121 | 121 | |
122 | 122 | } |
— | — | @@ -126,30 +126,30 @@ |
127 | 127 | * @return String The prefixed title or empty string if not found or found but not valid |
128 | 128 | */ |
129 | 129 | protected static function pageText( &$parser, $text = null, $p = 0 ) { |
130 | | - $pagetitle = self::newTitleObject( $parser, $text ); |
| 130 | + $pageTitle = self::newTitleObject( $parser, $text ); |
131 | 131 | $prefixes = self::getBookPagePrefixes(); |
132 | | - $booktitle = Title::newFromText( $prefixes['community-prefix'] . self::bookparts( $parser, $text, 0 ) ); // ...the book name will be 'Foo'. |
| 132 | + $bookTitle = Title::newFromText( $prefixes['community-prefix'] . self::bookParts( $parser, $text, 0 ) ); // ...the book name will be 'Foo'. |
133 | 133 | |
134 | 134 | if ( !self::$chapterList ) { |
135 | | - self::$chapterList = self::loadListFromCollection( $booktitle ); |
| 135 | + self::$chapterList = self::loadListFromCollection( $bookTitle ); |
136 | 136 | } |
137 | 137 | if ( self::$chapterList === false ) { |
138 | 138 | return ''; |
139 | 139 | } |
140 | | - $current = array_search( $pagetitle, self::$chapterList ); |
| 140 | + $current = array_search( $pageTitle, self::$chapterList ); |
141 | 141 | if ( $current === false || !isset( self::$chapterList[ $current + $p ] ) ) { |
142 | 142 | return ''; |
143 | 143 | } |
144 | | - $otherpagetitle = Title::newFromText( self::$chapterList[ $current + $p ] ); |
145 | | - if ( is_null( $otherpagetitle ) ) { |
| 144 | + $otherPageTitle = Title::newFromText( self::$chapterList[ $current + $p ] ); |
| 145 | + if ( is_null( $otherPageTitle ) ) { |
146 | 146 | return ''; |
147 | 147 | } |
148 | | - if ( $p == 'rand' ){ |
| 148 | + if ( $p == 'rand' ) { |
149 | 149 | $limit = count( self::$chapterList ) - 1; |
150 | 150 | $randPosition = rand( 0, $limit ); |
151 | | - return Title::newFromText( self::$chapterList[ $randPosition ] )->getText(); |
| 151 | + $otherPageTitle = Title::newFromText( self::$chapterList[ $randPosition ] ); |
152 | 152 | } |
153 | | - return wfEscapeWikiText( $otherpagetitle->getText() ); |
| 153 | + return wfEscapeWikiText( $otherPageTitle->getText() ); |
154 | 154 | } |
155 | 155 | } |
156 | 156 | /** |
— | — | @@ -208,19 +208,19 @@ |
209 | 209 | return wfUrlEncode( $t ); |
210 | 210 | } |
211 | 211 | static function rootpagename( &$parser, $text = null ) { |
212 | | - $t = self::bookparts( $parser, $text, 0 ); |
| 212 | + $t = self::bookParts( $parser, $text, 0 ); |
213 | 213 | return $t; |
214 | 214 | } |
215 | 215 | static function rootpagenamee( &$parser, $text = null ) { |
216 | | - $t = self::bookparts( $parser, $text, 0 ); |
| 216 | + $t = self::bookParts( $parser, $text, 0 ); |
217 | 217 | return wfUrlEncode( $t ); |
218 | 218 | } |
219 | 219 | static function chaptername( &$parser, $text = null ) { |
220 | | - $t = self::bookparts( $parser, $text, 1 ); |
| 220 | + $t = self::bookParts( $parser, $text, 1 ); |
221 | 221 | return $t; |
222 | 222 | } |
223 | 223 | static function chapternamee( &$parser, $text = null ) { |
224 | | - $t = self::bookparts( $parser, $text, 1 ); |
| 224 | + $t = self::bookParts( $parser, $text, 1 ); |
225 | 225 | return wfUrlEncode( $t ); |
226 | 226 | } |
227 | 227 | static function randomchapter( &$parser, $text = null ) { |
— | — | @@ -278,9 +278,9 @@ |
279 | 279 | |
280 | 280 | class BookManagerNavBar extends BookManagerCore { |
281 | 281 | |
282 | | - private static function camDisplayNavBar( &$out ) { |
| 282 | + private static function camDisplayNavBar( $title ) { |
283 | 283 | global $wgRequest, $wgBookManagerNamespaces, $wgBookManagerNavBar; |
284 | | - $ns = $out->getTitle()->getNamespace(); |
| 284 | + $ns = $title->getNamespace(); |
285 | 285 | $action = $wgRequest->getVal( 'action', 'view' ); |
286 | 286 | $isViewAction = ( $action == 'view' || $action == 'purge' || $action == 'submit' ); |
287 | 287 | $t = ( $wgBookManagerNavBar && in_array( $ns, $wgBookManagerNamespaces ) && $isViewAction ); |
— | — | @@ -288,40 +288,41 @@ |
289 | 289 | } |
290 | 290 | static function addNavBar( &$out, &$sk ) { |
291 | 291 | global $wgParser; |
292 | | - if ( !BookManagerNavBar::camDisplayNavBar( $out ) ) { |
| 292 | + $title = $out->getTitle(); |
| 293 | + if ( !BookManagerNavBar::camDisplayNavBar( $title ) ) { |
293 | 294 | return true; |
294 | 295 | } |
295 | 296 | $opt = array( |
296 | 297 | 'parseinline', |
297 | 298 | ); |
298 | 299 | # Get $out title |
299 | | - $currenttitletext = $out->getTitle()->getText(); |
| 300 | + $currentTitleText = $title->getText(); |
300 | 301 | # Get: prev, next and base chapter from the list |
301 | | - $prev = self::pageText( $wgParser, $currenttitletext, - 1 ); |
302 | | - $base = Title::newFromText( $currenttitletext )->getBaseText(); |
303 | | - $next = self::pageText( $wgParser, $currenttitletext, + 1 ); |
| 302 | + $prev = self::pageText( $wgParser, $currentTitleText, - 1 ); |
| 303 | + $base = Title::newFromText( $currentTitleText )->getBaseText(); |
| 304 | + $next = self::pageText( $wgParser, $currentTitleText, + 1 ); |
304 | 305 | if ( $prev === '' && $next === '' ) { |
305 | 306 | return true; |
306 | 307 | } |
307 | 308 | # Generate HTML or system messages values( $1 for $prev, $2 for $prevtext, $3 for $base, $4 for $basetext, $5 for $next and $6 for $nexttext ). |
308 | | - $prevtext = ( $prev !== '' ) ? Title::newFromText( $prev )->getSubpageText(): '' ; |
309 | | - $basetext = Title::newFromText( $base )->getSubpageText(); |
310 | | - $nexttext = ( $next !== '' ) ? Title::newFromText( $next )->getSubpageText(): '' ; |
| 309 | + $prevText = ( $prev !== '' ) ? Title::newFromText( $prev )->getSubpageText(): '' ; |
| 310 | + $baseText = Title::newFromText( $base )->getSubpageText(); |
| 311 | + $nextText = ( $next !== '' ) ? Title::newFromText( $next )->getSubpageText(): '' ; |
311 | 312 | $defaultBar = Xml::openElement( 'ul', array( 'class' => 'mw-book-navigation' ) ); |
312 | 313 | if ( $prev !== '' ) { |
313 | | - $prevlink = Title::newFromText( $prev )->getLocalURL(); |
| 314 | + $prevLink = Title::newFromText( $prev )->getLocalURL(); |
314 | 315 | $defaultBar .= Xml::openElement( 'li', array( 'class' => 'mw-prev' ) ); |
315 | | - $defaultBar .= Xml::element( 'a', array( 'href' => $prevlink, 'title' => $prev ), $prevtext ); |
| 316 | + $defaultBar .= Xml::element( 'a', array( 'href' => $prevLink, 'title' => $prev ), $prevText ); |
316 | 317 | $defaultBar .= Xml::closeElement( 'li' ); |
317 | 318 | } |
318 | | - $baselink = Title::newFromText( $base )->getLocalURL(); |
| 319 | + $baseLink = Title::newFromText( $base )->getLocalURL(); |
319 | 320 | $defaultBar .= Xml::openElement( 'li', array( 'class' => 'mw-index' ) ); |
320 | | - $defaultBar .= Xml::element( 'a', array( 'href' => $baselink, 'title' => $base ), $basetext ); |
| 321 | + $defaultBar .= Xml::element( 'a', array( 'href' => $baseLink, 'title' => $base ), $baseText ); |
321 | 322 | $defaultBar .= Xml::closeElement( 'li' ); |
322 | 323 | if ( $next !== '' ) { |
323 | | - $nextlink = Title::newFromText( $next )->getLocalURL(); |
| 324 | + $nextLink = Title::newFromText( $next )->getLocalURL(); |
324 | 325 | $defaultBar .= Xml::openElement( 'li', array( 'class' => 'mw-next' ) ); |
325 | | - $defaultBar .= Xml::element( 'a', array( 'href' => $nextlink, 'title' => $next ), $nexttext ); |
| 326 | + $defaultBar .= Xml::element( 'a', array( 'href' => $nextLink, 'title' => $next ), $nextText ); |
326 | 327 | $defaultBar .= Xml::closeElement( 'li' ); |
327 | 328 | } |
328 | 329 | $defaultBar .= Xml::closeElement( 'ul' ); |
— | — | @@ -333,13 +334,13 @@ |
334 | 335 | 'parseinline', |
335 | 336 | ); |
336 | 337 | if ( $customTop ) { |
337 | | - $top = wfMsgExt( $customTop, $opt, $prev, $prevtext, $base, $basetext, $next, $nexttext ); |
| 338 | + $top = wfMsgExt( $customTop, $opt, $prev, $prevText, $base, $baseText, $next, $nextText ); |
338 | 339 | } |
339 | 340 | else { |
340 | 341 | $top = $defaultBar; |
341 | 342 | } |
342 | 343 | if ( $customBottom ) { |
343 | | - $bottom = wfMsgExt( $customBottom, $opt, $prev, $prevtext, $base, $basetext, $next, $nexttext ); |
| 344 | + $bottom = wfMsgExt( $customBottom, $opt, $prev, $prevText, $base, $baseText, $next, $nextText ); |
344 | 345 | } |
345 | 346 | else { |
346 | 347 | $bottom = $defaultBar; |
— | — | @@ -352,39 +353,58 @@ |
353 | 354 | $out->addModules( 'ext.BookManager' ); |
354 | 355 | return true; |
355 | 356 | } |
356 | | - //known BUG: The category appears more than once when action is not 'view' |
| 357 | + // @bug The category appears more than once when action is not 'view' |
357 | 358 | static function CatByPrefix( &$parser, &$text ) { |
358 | | - global $wgOut, $wgCategorizationByPrefix ; |
359 | | - if ( $wgCategorizationByPrefix && BookManagerNavBar::camDisplayNavBar( $wgOut ) ) { |
360 | | - $catTitle = Title::newFromText( self::bookparts( $parser, $text, 0 )); |
| 359 | + global $wgCategorizeSubPages, $wgCategorizeRootPages; |
| 360 | + if ( BookManagerNavBar::camDisplayNavBar( $parser->getTitle() ) ) { |
| 361 | + $opt = array( |
| 362 | + 'parseinline', |
| 363 | + ); |
361 | 364 | $parserOutput = $parser->getOutput(); |
362 | | - $parserOutput->addCategory( $catTitle->getDBkey() , $catTitle->getText() ); |
| 365 | + $rootTitle = Title::newFromText( self::bookParts( $parser, $text, 0 ) ); |
| 366 | + if ( $wgCategorizeRootPages && $rootTitle->getText() == $parser->getTitle()->getText() && !wfEmptyMsg( 'bm-allrootpages' ) ) { |
| 367 | + $rootPagesCat = Title::newFromText( wfMsgExt( 'bm-allrootpages', $opt ) ); |
| 368 | + $parserOutput->addCategory( $rootPagesCat->getDBkey() , $rootPagesCat->getText() ); |
| 369 | + } |
| 370 | + if ( $wgCategorizeSubPages ) { |
| 371 | + $subPagesCat = $rootTitle; |
| 372 | + $parserOutput->addCategory( $subPagesCat->getDBkey() , $subPagesCat->getText() ); |
| 373 | + } |
| 374 | + |
363 | 375 | } |
364 | 376 | return true; |
365 | 377 | } |
366 | 378 | |
367 | 379 | static function bookToolboxSection( &$sk, &$toolbox ) { |
368 | | - global $wgTitle, $wgParser, $wgBookSidebarSection ; |
369 | | - $currenttitletext = $wgTitle->getText(); |
370 | | - $randchapter = self::pageText( $wgParser, $currenttitletext, 'rand' ); |
371 | | - # Add book tools section and all your items |
372 | | - if ( $wgBookSidebarSection && $randchapter ){ |
373 | | - ?><div class="portal" id='p-tb'><?php |
374 | | - ?><h5><?php $sk->msg( 'bm-booktools-section' ); ?></h5><?php |
375 | | - ?><div class="body"><?php |
376 | | - ?><ul><?php |
377 | | - ?><li id="t-rating"><?php |
378 | | - ?><a href="<?php echo htmlspecialchars( Title::newFromText( $randchapter )->getLocalURL() ) ?>"><?php |
379 | | - echo $sk->msg( 'bm-randomchapter-link' ); |
380 | | - ?></a><?php |
381 | | - ?></li><?php |
382 | | - ?></ul><?php |
383 | | - ?></div><?php |
384 | | - ?></div><?php |
| 380 | + global $wgParser, $wgBookSidebarSection ; |
| 381 | + $currentTitleText = $sk->data['title']; |
| 382 | + $randChapter = self::pageText( $wgParser, $currentTitleText, 'rand' ); |
| 383 | + # Add book tools section and all your items |
| 384 | + if ( $wgBookSidebarSection && $randChapter ) { |
| 385 | + $opt = array( |
| 386 | + 'parseinline', |
| 387 | + ); |
| 388 | + $bookSection = wfMsgExt( 'bm-booktools-section', $opt ); |
| 389 | + $randLink = Title::newFromText( $randChapter )->getLocalURL(); |
| 390 | + $randTitle = wfMsgExt( 'bm-randomchapter-link', $opt ); |
| 391 | + $toolBox = Xml::openElement( 'div', array( 'class' => 'portal', 'id' => 'p-tb' ) ); |
| 392 | + $toolBox .= Xml::openElement( 'h5' ); |
| 393 | + $toolBox .= $bookSection; |
| 394 | + $toolBox .= Xml::closeElement( 'h5' ); |
| 395 | + $toolBox .= Xml::openElement( 'div', array( 'class' => 'body' ) ); |
| 396 | + $toolBox .= Xml::openElement( 'ul' ); |
| 397 | + $toolBox .= Xml::openElement( 'li' , array( 'id' => 't-booktools' ) ); |
| 398 | + $toolBox .= Xml::element( 'a', array( 'href' => $randLink ) , $randTitle ); |
| 399 | + $toolBox .= Xml::closeElement( 'li' ); |
| 400 | + $toolBox .= Xml::closeElement( 'ul' ); |
| 401 | + $toolBox .= Xml::closeElement( 'div' ); |
| 402 | + $toolBox .= Xml::closeElement( 'div' ); |
| 403 | + echo $toolBox; |
385 | 404 | } |
386 | 405 | return true; |
387 | 406 | } |
388 | 407 | } |
| 408 | + |
389 | 409 | /** |
390 | 410 | * BookManager Functions [PrintVersion] |
391 | 411 | */ |
— | — | @@ -394,31 +414,31 @@ |
395 | 415 | parent::__construct( 'PrintVersion' ); |
396 | 416 | } |
397 | 417 | function execute( $book ) { |
398 | | - global $wgOut, $wgRequest; |
399 | | - |
| 418 | + $request = $this->getRequest(); |
| 419 | + $out = $this->getOutput(); |
400 | 420 | $this->setHeaders(); |
401 | 421 | $this->outputHeader(); |
402 | | - |
403 | | - $book = !is_null( $book ) ? $book : $wgRequest->getVal( 'book' ); |
| 422 | + $book = !is_null( $book ) ? $book : $request->getVal( 'book' ); |
404 | 423 | if ( !isset( $book ) ) { |
405 | | - $wgOut->addWikiMsg( 'bm-printversion-no-book' ); |
| 424 | + $out->addWikiMsg( 'bm-printversion-no-book' ); |
406 | 425 | return; |
407 | 426 | } |
408 | 427 | $prefixes = self::getBookPagePrefixes(); |
409 | | - $booktitle = Title::newFromText( $prefixes['community-prefix'] . $book ); |
410 | | - $chapterList = self::loadListFromCollection( $booktitle ); |
| 428 | + $bookTitle = Title::newFromText( $prefixes['community-prefix'] . $book ); |
| 429 | + $chapterList = self::loadListFromCollection( $bookTitle ); |
411 | 430 | if ( $chapterList === false ) { |
412 | | - $wgOut->addWikiMsg( 'bm-printversion-inexistent-book' ); |
| 431 | + $out->addWikiMsg( 'bm-printversion-inexistent-book' ); |
413 | 432 | return; |
414 | 433 | } |
415 | 434 | $text = ''; |
416 | 435 | foreach ( $chapterList as $chapter ) { |
417 | | - $chaptertitle = Title::newFromText( $chapter ); |
418 | | - $sectionname = $chaptertitle->getSubpageText(); |
| 436 | + $chapterTitle = Title::newFromText( $chapter ); |
| 437 | + $chapterPage = new Article( $chapterTitle ); |
| 438 | + $sectionname = $chapterTitle->getSubpageText(); |
419 | 439 | $text .= "= $sectionname =\n"; |
420 | | - $text .= "{{:$chapter}}\n\n"; |
| 440 | + $text .= $chapterPage->getContent() . "\n\n"; |
421 | 441 | } |
422 | | - $wgOut->addWikiText( $text ); |
| 442 | + $out->addWikiText( $text ); |
423 | 443 | } |
424 | 444 | |
425 | 445 | } |
Index: trunk/extensions/BookManager/BookManager.php |
— | — | @@ -12,18 +12,28 @@ |
13 | 13 | * - CHAPTERNAME (get chapter) |
14 | 14 | * - CHAPTERNAMEE (get chapter encode) |
15 | 15 | * - RANDOMCHAPTER (get random page) |
16 | | - * - RANDOMCHAPTERE (get random page encode) |
| 16 | + * - RANDOMCHAPTERE (get random page encode) |
17 | 17 | * @addtogroup Extensions |
18 | 18 | * @author Raylton P. Sousa |
19 | 19 | * @author Helder.wiki |
20 | 20 | * @copyright Copyright © 2011 Raylton P. Sousa <raylton.sousa@gmail.com> |
21 | | - * @copyright Copyright © 2011 Helder.wiki |
| 21 | + * @copyright Copyright © 2011 Helder.wiki |
22 | 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 3.0 or later |
23 | 23 | */ |
24 | 24 | |
25 | 25 | if ( !defined( 'MEDIAWIKI' ) ) { |
26 | 26 | die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
27 | 27 | } |
| 28 | +$wgBookSidebarSection = true; |
| 29 | +$wgBookManagerNamespaces = array( NS_MAIN ); |
| 30 | +$wgBookManagerVariables = true ; |
| 31 | +$wgBookManagerNavBar = true; |
| 32 | +$wgCategorizeSubPages = true; |
| 33 | +$wgCategorizeRootPages = true; |
| 34 | +/* Copyied from extensions/Collection/Collection.php */ |
| 35 | +/** Namespace for "community books" */ |
| 36 | +$wgBookManagerPrefixNamespace = NS_PROJECT; |
| 37 | + |
28 | 38 | $dir = dirname( __FILE__ ); |
29 | 39 | $wgParserTestFiles[] = $dir . "/BookManagerParserTests.txt"; |
30 | 40 | $wgAutoloadClasses['BookManagerCore'] = $dir . '/BookManager.body.php'; |
— | — | @@ -53,17 +63,10 @@ |
54 | 64 | 'styles' => 'bookmanager.css', |
55 | 65 | 'messages' => array( 'BookManager', 'BookManager-top', 'BookManager-bottom' ), |
56 | 66 | 'dependencies' => array( 'jquery', 'mediawiki.util' ), |
57 | | - 'localBasePath' => $dir. '/client', |
| 67 | + 'localBasePath' => $dir . '/client', |
58 | 68 | 'remoteExtPath' => 'BookManager/client' |
59 | 69 | ); |
60 | 70 | |
61 | | -$wgBookManagerNamespaces = array( NS_MAIN ); |
62 | | -$wgBookManagerVariables = true ; |
63 | | -$wgBookManagerNavBar = true; |
64 | | -$wgCategorizationByPrefix = true; |
65 | | -/* Copyied from extensions/Collection/Collection.php */ |
66 | | -/** Namespace for "community books" */ |
67 | | -$wgBookManagerPrefixNamespace = NS_PROJECT; |
68 | 71 | /**** Register magic words ****/ |
69 | 72 | if ( $wgBookManagerVariables ) { |
70 | 73 | $wgAutoloadClasses['BookManagerVariables'] = $dir . '/BookManager.body.php'; |
— | — | @@ -77,8 +80,9 @@ |
78 | 81 | /**** Navbar ****/ |
79 | 82 | |
80 | 83 | $wgHooks['BeforePageDisplay'][] = 'BookManagerNavBar::addNavBar'; |
81 | | -/**** Toolbox Section ***/ |
| 84 | +/**** Toolbox Section ***/ |
| 85 | +// $wgHooks['SkinTemplateToolboxEnd'][] = 'BookManagerNavBar::bookToolboxSection'; |
82 | 86 | $wgHooks['BaseTemplateToolbox'][] = 'BookManagerNavBar::bookToolboxSection'; |
83 | | - |
| 87 | +/*** Cat ***/ |
84 | 88 | $wgHooks['ParserAfterTidy'][] = 'BookManagerNavBar::CatByPrefix'; |
85 | 89 | |