r84378 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84377‎ | r84378 | r84379 >
Date:13:01, 20 March 2011
Author:raylton.sousa
Status:deferred (Comments)
Tags:
Comment:
*Creating printable version, for books (based on patch sent from e-mail by Helder.wiki)
*Begin to use inheritance in classes to eventually separate them into different files
Modified paths:
  • /trunk/extensions/BookManager/BookManager.body.php (modified) (history)
  • /trunk/extensions/BookManager/PrintVersion.alias.php (added) (history)
  • /trunk/extensions/BookManager/PrintVersion.i18n.php (added) (history)

Diff [purge]

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 @@
22 <?php
3 -class BookManagerFunctions {
43 /**
5 -* BookManager private functions [Core]
 4+* BookManager protected functions [Core]
65 */
 6+class BookManagerCore extends SpecialPage {
77 const VERSION = "0.1.6 ";
88 private static $chapterList;
99 /**
1010 * Get Title
1111 * @return Object
1212 */
13 - private static function newTitleObject( &$parser, $text = null ) {
 13+ protected static function newTitleObject( &$parser, $text = null ) {
1414 $t = Title::newFromText( $text );
1515 if ( is_null( $t ) ) {
1616 return $parser->getTitle();
@@ -22,7 +22,7 @@
2323 * Adaptation of the function "getBookPagePrefixes" from collection extension
2424 * (http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Collection/Collection.body.php?revision=79895&view=markup#l440)
2525 */
26 - private static function getBookPagePrefixes() {
 26+ protected static function getBookPagePrefixes() {
2727 // global $wgUser;
2828 global $wgCommunityCollectionNamespace;
2929
@@ -55,7 +55,7 @@
5656 * Simplification of the function "parseCollectionLine" from collection extension
5757 * (http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Collection/Collection.body.php?revision=79895&view=markup#l709)
5858 */
59 - private static function parseCollectionLine( /* Sem uso por enquanto: &$collection, */ $line ) {
 59+ protected static function parseCollectionLine( /* Sem uso por enquanto: &$collection, */ $line ) {
6060 $line = trim( $line );
6161 if ( substr( $line, 0, 1 ) == ':' ) { // article
6262 $pagename = trim( substr( $line, 1 ) );
@@ -82,7 +82,7 @@
8383 * Adaptation of the function "loadCollection" from collection extension
8484 * (http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Collection/Collection.body.php?revision=79895&view=markup#l780)
8585 */
86 - private static function loadListFromCollection( $collectiontitle ) {
 86+ protected static function loadListFromCollection( $collectiontitle ) {
8787 if ( is_null( $collectiontitle ) || !$collectiontitle->exists() ) {
8888 return false;
8989 }
@@ -101,7 +101,7 @@
102102 /**
103103 * Get the book or chapter name
104104 */
105 - private static function bookparts( &$parser, $text = null, $part = 1 ) {
 105+ protected static function bookparts( &$parser, $text = null, $part = 1 ) {
106106 $t = self::newTitleObject( $parser, $text );
107107 // No book should have '/' in it's name, so...
108108 $book = explode( "/", $t->getText(), 2 ); // ...given a page with title like 'Foo/Bar/Baz'...
@@ -119,8 +119,7 @@
120120 * @param $n Integer Position of wanted page. Next page is +1; Previous page is -1
121121 * @return String The prefixed title or empty string if not found or found but not valid
122122 */
123 -
124 - private static function pageText( &$parser, $text = null, $n = 0 ) {
 123+ protected static function pageText( &$parser, $text = null, $n = 0 ) {
125124 $pagetitle = self::newTitleObject( $parser, $text );
126125 $prefixes = self::getBookPagePrefixes();
127126 $booktitle = Title::newFromText( $prefixes['community-prefix'] . self::bookparts( $parser, $text, 0 ) ); // ...the book name will be 'Foo'.
@@ -141,9 +140,11 @@
142141 }
143142 return wfEscapeWikiText( $otherpagetitle->getText() );
144143 }
 144+}
145145 /**
146146 * BookManager Functions [Variables]
147147 */
 148+class BookManagerVariables extends BookManagerCore {
148149 static function register( $parser ) {
149150 # optional SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}}
150151 # instead of {{#int:...}})
@@ -235,40 +236,39 @@
236237 static function AssignAValue( &$parser, &$cache, &$magicWordId, &$ret ) {
237238 switch( $magicWordId ) {
238239 case 'prevpagename':
239 - $ret = BookManagerFunctions::prevpagename( $parser );
 240+ $ret = BookManagerVariables::prevpagename( $parser );
240241 return true;
241242 case 'prevpagenamee':
242 - $ret = BookManagerFunctions::prevpagenamee( $parser );
 243+ $ret = BookManagerVariables::prevpagenamee( $parser );
243244 return true;
244245 case 'nextpagename':
245 - $ret = BookManagerFunctions::nextpagename( $parser );
 246+ $ret = BookManagerVariables::nextpagename( $parser );
246247 return true;
247248 case 'nextpagenamee':
248 - $ret = BookManagerFunctions::nextpagenamee( $parser );
 249+ $ret = BookManagerVariables::nextpagenamee( $parser );
249250 return true;
250251 case 'rootpagename':
251 - $ret = BookManagerFunctions::rootpagename( $parser );
 252+ $ret = BookManagerVariables::rootpagename( $parser );
252253 return true;
253254 case 'rootpagenamee':
254 - $ret = BookManagerFunctions::rootpagenamee( $parser );
 255+ $ret = BookManagerVariables::rootpagenamee( $parser );
255256 return true;
256257 case 'chaptername':
257 - $ret = BookManagerFunctions::chaptername( $parser );
 258+ $ret = BookManagerVariables::chaptername( $parser );
258259 return true;
259260 case 'chapternamee':
260 - $ret = BookManagerFunctions::chapternamee( $parser );
 261+ $ret = BookManagerVariables::chapternamee( $parser );
261262 return true;
262263 }
263264 return false;
264265 }
265 -
 266+}
266267 /**
267268 * BookManager Functions [Navigation Bar]
268269 * inspired by PageNotice extension
269270 * (http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/PageNotice/PageNotice.php&view=markup)
270271 */
271 -
272 -
 272+class BookManagerNavBar extends BookManagerCore {
273273 static function addText( &$out, &$text ) {
274274 global $wgRequest, $wgBookManagerNamespaces, $wgBookManagerNavBar;
275275 $ns = $out->getTitle()->getNamespace();
@@ -349,3 +349,39 @@
350350 return true;
351351 }
352352 }
 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+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r84382fix r84378 (add wgParser, and solve bug with class name)raylton.sousa14:03, 20 March 2011

Comments

#Comment by He7d3r (talk | contribs)   13:42, 20 March 2011

Fatal error: Class 'BookManagerFunctions' not found in /var/www/wikilocal/extensions/BookManager/BookManager.php on line 52

Status & tagging log