http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88198

Revision: 88198
Author:   raylton.sousa
Date:     2011-05-15 17:24:10 +0000 (Sun, 15 May 2011)
Log Message:
-----------


Modified Paths:
--------------
    trunk/extensions/BookManager/BookManager.body.php
    trunk/extensions/BookManager/BookManager.php

Modified: trunk/extensions/BookManager/BookManager.body.php
===================================================================
--- trunk/extensions/BookManager/BookManager.body.php   2011-05-15 17:17:12 UTC 
(rev 88197)
+++ trunk/extensions/BookManager/BookManager.body.php   2011-05-15 17:24:10 UTC 
(rev 88198)
@@ -2,12 +2,13 @@
 /**
 * BookManager protected functions [Core]
 */
-$wgBookSidebarSection = false;
+
 class BookManagerCore extends SpecialPage {
        const VERSION = "0.1.6 ";
        private static $chapterList;
        /**
         * Get Title
+        * @param $text String Text for title of current page 
         * @return Object
         */
        protected static function newTitleObject( &$parser, $text = null ) {
@@ -99,18 +100,22 @@
                }
                return $caps;
        }
+
        /**
-       * Get the book or chapter name
+       * Get the book or chapter name from page title 
+       * @param $text String Text for title of current page 
+       * @param $part Integer. Title like 'Foo/Bar/Baz' "0" is Foo , the book 
name, and "1" is Bar/Baz, the chapter name.
+       * @return String with book or chapter
        */
        protected static function bookparts( &$parser, $text = null, $part = 1 
) {
                $t = self::newTitleObject( $parser, $text );
                // No book should have '/' in it's name, so...
-               $book = explode( "/", $t->getText(), 2 ); // ...given a page 
with title like 'Foo/Bar/Baz'...
+               $book = explode( "/", $t->getText(), 2 ); 
                if ( count( $book ) > 1 ) {
-                       return $book[$part];// ... $book[0] is Foo, the book 
name, and $book[1] is Bar/Baz, the chapter name.
+                       return $book[$part];
                }
                else {
-                       return $t;
+                       return $t->getText();
                }
 
        }
@@ -142,7 +147,7 @@
                if ( $p == 'rand' ){
                        $limit = count( self::$chapterList ) - 1;
                        $randPosition = rand( 0, $limit );
-                       return Title::newFromText( self::$chapterList[ 
$randPosition ] );
+                       return Title::newFromText( self::$chapterList[ 
$randPosition ] )->getText();
                }
                return wfEscapeWikiText( $otherpagetitle->getText() );
        }
@@ -347,24 +352,37 @@
                $out->addModules( 'ext.BookManager' );
                return true;
        }
+//known BUG: The category appears more than once when action is not 'view'
+       static function CatByPrefix( &$parser, &$text ) {
+               global $wgOut;
+               if ( !BookManagerNavBar::camDisplayNavBar( $wgOut ) ) {
+                       return true;
+               }
+               $catTitle = Title::newFromText( self::bookparts( $parser, 
$text, 0 ));
+               $parserOutput = $parser->getOutput();
+               $parserOutput->addCategory( $catTitle->getDBkey() , 
$catTitle->getText() );
+
+               return true;
+       }
+
        static function bookToolboxSection( &$sk, &$toolbox ) {
                global $wgTitle, $wgParser;
                $currenttitletext = $wgTitle->getText();
                $randchapter = self::pageText( $wgParser, $currenttitletext, 
'rand' );
-               # Add book tools section and all your items 
+               # Add book tools section and all yours itens 
                if ( $randchapter ){
                        ?><div class="portal" id='p-tb'><?php
                                        ?><h5><?php $sk->msg( 
'bm-booktools-section' ); ?></h5><?php
                                        ?><div class="body"><?php
                                                ?><ul><?php
                                                        ?><li 
id="t-rating"><?php
-                                                               ?><a 
href="<?php echo htmlspecialchars( $randchapter->getLocalURL() ) ?>"><?php
+                                                               ?><a 
href="<?php echo htmlspecialchars( Title::newFromText( $randchapter 
)->getLocalURL() ) ?>"><?php
                                                                echo $sk->msg( 
'bm-randomchapter-link' );
                                                                ?></a><?php
                                                        ?></li><?php
                                                ?></ul><?php
                                        ?></div><?php
-                               ?></div><?php
+                       ?></div><?php
                }
                return true;
        }
@@ -375,7 +393,7 @@
 class PrintVersion extends BookManagerCore {
 
        function __construct() {
-               parent::__construct( 'PrintVersion' );
+               parent::__construct( 'Book render' );
        }
        function execute( $book ) {
                global $wgOut, $wgRequest;

Modified: trunk/extensions/BookManager/BookManager.php
===================================================================
--- trunk/extensions/BookManager/BookManager.php        2011-05-15 17:17:12 UTC 
(rev 88197)
+++ trunk/extensions/BookManager/BookManager.php        2011-05-15 17:24:10 UTC 
(rev 88198)
@@ -9,28 +9,16 @@
  * - NEXTPAGENAMEE             (get next page encode)
  * - ROOTPAGENAME              (get root page)
  * - ROOTPAGENAMEE             (get root page encode)
- * - CHAPTERNAME               (get root page)
- * - CHAPTERNAMEE              (get root page encode)
+ * - CHAPTERNAME               (get chapter)
+ * - CHAPTERNAMEE              (get chapter encode)
+ * - RANDOMCHAPTER             (get random page)
+ * - RANDOMCHAPTERE            (get random page encode) 
  * @addtogroup Extensions
- * @author Raylton P. Sousa <[email protected]>
+ * @author Raylton P. Sousa
  * @author Helder.wiki
- * @license GNU General Public License 3.0 or later
-**
-**
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- http://www.gnu.org/copyleft/gpl.html
+ * @copyright Copyright © 2011 Raylton P. Sousa <[email protected]>
+ * @copyright Copyright © 2011 Helder.wiki 
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
3.0 or later
 */
 
 if ( !defined( 'MEDIAWIKI' ) ) {
@@ -87,6 +75,10 @@
 $wgHooks['ParserGetVariableValueSwitch'][] = 
'BookManagerVariables::AssignAValue';
 }
 /**** Navbar ****/
+
 $wgHooks['BeforePageDisplay'][] = 'BookManagerNavBar::addNavBar';
-# Rating link
+/****  Rating Toolbox Section ***/
 $wgHooks['BaseTemplateToolbox'][] = 'BookManagerNavBar::bookToolboxSection';
+
+$wgHooks['ParserAfterTidy'][] = 'BookManagerNavBar::CatByPrefix';
+


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to