Extension talk:Book

Latest comment: 12 years ago by Wingsofcourage in topic Fix for subcategories and Mediawiki 1.17

Hi, I cannot get this to work, I get the book.pdf file but it is not looking into the sub categories of the category I am adding action=bookpdf to.

Any ideas why this isn't working ? thanks Mark

Fix for subcategories and Mediawiki 1.17

edit

There are 2 changes needed to get it working.

Replace function setBook in file BookTree.php

   /**
    * Creates the book.
    * @param Node $root
    */
       private function setBook($root = null){
           if($root == null){
               $root = $this->getRoot();
           }
           $title = $root->getHeading();
           $this->text .= $root->view()."\n"; //fetching the text out of the nodes
           foreach($this->getArticles($title) as $article){
               $node = new Node($article);
               $root->addChild($node);
               if($node->isCategory()){
                   $this->setBook($node); // Call by reference
               } else {
		    $this->text .= $node->view()."\n"; //fetching the text out of the nodes
               }
	    }
       }

Replace function format in Node.php

       /**
        * This method fixes a few issues like image location and tables 
        * and comments.
        * @return String
        */
       private function format(){
           global $wgOut, $wgUser, $wgParser, $wgServer;
     
           $opt = ParserOptions::newFromUser($wgUser);
           $title = $this->getContent()->getTitle();
       
           $text = $this->content->fetchContent();
           $text = preg_replace('//s','@@'.'@@$1@@'.'@@',$text); # preserve HTML comments
           $text .= ;
           $opt->setEditSection(false);    # remove section-edit links
           $wgOut->setHTMLTitle($title->getText());   # use this so DISPLAYTITLE magic works
           $out  = $wgParser->parse($text,$title,$opt,true,true);
           $text = $out->getText();
           $text = preg_replace('|(<img[^>]+?src=")(/.+?>)|',"$1$wgServer$2",$text);
           $text = preg_replace('|@{4}([^@]+?)@{4}|s',,$text); # HTML comments hack
           $text = preg_replace('|<table|','<table border borderwidth=2 cellpadding=3 cellspacing=0',$text);
           
           //Increment <h> tags for good structure
           //TODO: May be anyone can find a cool regex here HINT: preg_replace ('|h([0-9]+)>|e','$1+1',$text); don't work complete
           $text = preg_replace('|h8>|','h9>',$text);
           $text = preg_replace('|h7>|','h8>',$text);
           $text = preg_replace('|h6>|','h7>',$text);
           $text = preg_replace('|h5>|','h6>',$text);
           $text = preg_replace('|h4>|','h5>',$text);
           $text = preg_replace('|h3>|','h4>',$text);
           $text = preg_replace('|h2>|','h3>',$text);
           $text = preg_replace('|h1>|','h2>',$text);
           $text = utf8_decode("$text\n");
     
           return $text;
       }

Happy PDF'ing ... --Wingsofcourage (talk) 14:13, 7 November 2012 (UTC)Reply

Return to "Book" page.