r83706 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83705‎ | r83706 | r83707 >
Date:18:30, 11 March 2011
Author:raylton.sousa
Status:deferred (Comments)
Tags:
Comment:
adding html by default when the system message is not set, and commenting code
Modified paths:
  • /trunk/extensions/BookManager/BookManager.body.php (modified) (history)
  • /trunk/extensions/BookManager/BookManager.php (modified) (history)

Diff [purge]

Index: trunk/extensions/BookManager/BookManager.body.php
@@ -1,9 +1,8 @@
22 <?php
33 /**** All the BookManager Variables Functions ****/
44 class BookManagerFunctions {
 5+ const VERSION = "0.1.6 - unstable";
56
6 - const VERSION = "0.1.5 - unstable";
7 -
87 static function register( ) {
98 global $wgParser;
109
@@ -18,7 +17,7 @@
1918 $wgParser->setFunctionHook( 'chaptername', array( __CLASS__, 'chaptername' ), SFH_NO_HASH );
2019 $wgParser->setFunctionHook( 'chapternamee', array( __CLASS__, 'chapternamee' ), SFH_NO_HASH );
2120 }
22 -
 21+ /**** All the BookManager functions to declare magicword id ****/
2322 static function DeclareVarIds( &$aCustomVariableIds ) {
2423 # aCustomVariableIds is where MediaWiki wants to store its
2524 # list of custom variable ids. We oblige by adding ours:
@@ -32,7 +31,7 @@
3332 $aCustomVariableIds[] = MAG_CHAPTERNAMEE;
3433 return true;
3534 }
36 -
 35+ /**** All the BookManager functions to declare magicwords ****/
3736 static function LanguageGetMagic( &$magicWords, $langCode = "en" ) {
3837 switch ( $langCode ) {
3938 default:
@@ -63,17 +62,27 @@
6463 }
6564 return true;
6665 }
67 -/**** All the BookManager values functions ****/
 66+/**** All the BookManager private functions ****/
 67+
 68+
 69+ /*
 70+ * Check if action is suported
 71+ * @return Bool
 72+ */
6873 private static function isViewAction() {
6974 global $wgRequest;
7075 $action = $wgRequest->getVal( 'action', 'view' );
71 - if( $action == 'view' || $action == 'purge'){
 76+ if( $action == 'view' || $action == 'purge' ){
7277 return true;
7378 }
7479 else{
7580 return false;
7681 }
7782 }
 83+
 84+ /*
 85+ * Get Title
 86+ */
7887 private static function newTitleObject( &$parser, $text = null ) {
7988 $t = Title::newFromText( $text );
8089 if ( is_null( $t ) ) {
@@ -84,7 +93,7 @@
8594
8695
8796 /*
88 - * Cópia da função "getBookPagePrefixes" da extensão Collection
 97+ * Adaptation of the function "getBookPagePrefixes" from collection extension
8998 * (http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Collection/Collection.body.php?revision=79895&view=markup#l440)
9099 */
91100 private static function getBookPagePrefixes() {
@@ -117,7 +126,7 @@
118127 }
119128
120129 /*
121 - * Simplificação da função "parseCollectionLine" da extensão Collection
 130+ * Simplification of the function "parseCollectionLine" from collection extension
122131 * (http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Collection/Collection.body.php?revision=79895&view=markup#l709)
123132 */
124133 private static function parseCollectionLine( /* Sem uso por enquanto: &$collection, */ $line ) {
@@ -144,7 +153,7 @@
145154 }
146155
147156 /*
148 - * Adaptação da função "loadCollection" da extensão Collection
 157+ * Adaptation of the function "loadCollection" from collection extension
149158 * (http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Collection/Collection.body.php?revision=79895&view=markup#l780)
150159 */
151160 private static function loadListFromCollection( $collectiontitle ) {
@@ -164,7 +173,7 @@
165174 return $caps;
166175 }
167176
168 -
 177+ #Get the book or chapter name
169178 private static function bookparts( &$parser, $text = null, $part = 1) {
170179 $t = self::newTitleObject( $parser, $text );
171180 // No book should have '/' in it's name, so...
@@ -183,12 +192,14 @@
184193 * @param $n Integer Position of wanted page. Next page is +1; Previous page is -1
185194 * @return String The prefixed title or empty string if not found or found but not valid
186195 */
 196+
187197 private static function pageText( &$parser, $text = null, $n = 0 ) {
188198 $pagetitle = self::newTitleObject( $parser, $text );
189199 $prefixes = self::getBookPagePrefixes();
190200 $booktitle = Title::newFromText( $prefixes['community-prefix'] . self::bookparts( $parser, $text, 0) ); // ...the book name will be 'Foo'.
 201+
191202 $cap = self::loadListFromCollection( $booktitle );
192 - if ( $cap === false ) {
 203+ if ( $cap ===false ) {
193204 return '';
194205 }
195206 $current = array_search( $pagetitle, $cap );
@@ -202,6 +213,10 @@
203214 return wfEscapeWikiText( $otherpagetitle->getText() );
204215 }
205216
 217+
 218+/**** All the BookManager values functions ****/
 219+
 220+
206221 static function prevpagename( &$parser, $text = null ) {
207222 $t = self::pageText( $parser, $text, - 1 );
208223 return $t;
@@ -213,6 +228,7 @@
214229 }
215230
216231 static function nextpagename( &$parser, $text = null ) {
 232+
217233 $t = self::pageText( $parser, $text, + 1 );
218234 return $t;
219235 }
@@ -273,7 +289,7 @@
274290
275291 /**
276292 * Function that adds navigation bar
277 -* inspired by extension PageNotice
 293+* inspired by PageNotice extension
278294 * (http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/PageNotice/PageNotice.php)
279295 */
280296
@@ -285,11 +301,27 @@
286302 );
287303 $currenttitletext = $wgTitle->getText();
288304 $prev = self::pageText( $wgParser, $currenttitletext, - 1 );
 305+ $base = Title::newFromText( $currenttitletext )->getBaseText();
289306 $next = self::pageText( $wgParser, $currenttitletext, + 1 );
290 - $base = Title::newFromText( $currenttitletext )->getBaseText();
 307+ $prevtext = ( $prev !== '' ) ? Title::newFromText( $prev )->getSubpageText(): '' ;
291308 $basetext = ( $base !== '' ) ? Title::newFromText( $base )->getSubpageText(): '' ;
292 - $prevtext = ( $prev !== '' ) ? Title::newFromText( $prev )->getSubpageText(): '' ;
293309 $nexttext = ( $next !== '' ) ? Title::newFromText( $next )->getSubpageText(): '' ;
 310+ $prevlink = ( $prev !== '' ) ? Title::newFromText( $prev )->getLocalURL(): '' ;
 311+ $baselink = ( $base !== '' ) ? Title::newFromText( $base )->getLocalURL(): '' ;
 312+ $nextlink = ( $next !== '' ) ? Title::newFromText( $next )->getLocalURL(): '' ;
 313+ $bar = Xml::openElement('ul',array('class'=>'mw-book-navigation') );
 314+ $bar .= Xml::openElement('li',array('class'=>'mw-prev') );
 315+ $bar .= Xml::element('a',array('href'=>$prevlink,'title'=>$prev ),$prevtext);
 316+ $bar .= Xml::closeElement('li');
 317+ $bar .= Xml::openElement('li',array('class'=>'mw-index') );
 318+ $bar .= Xml::element('a',array('href'=>$baselink,'title'=>$base ),$basetext);
 319+ $bar .= Xml::closeElement('li');
 320+ $bar .= Xml::openElement('li',array('class'=>'mw-next') );
 321+ $bar .= Xml::element('a',array('href'=>$nextlink,'title'=>$next ),$nexttext);
 322+ $bar .= Xml::closeElement('li');
 323+ $bar .= Xml::closeElement('ul');
 324+
 325+ #adds system messages or html
294326 if ( in_array($ns,$wgBookManagerNamespaces) && self::isViewAction() ) {
295327 $BookManager = wfMsgExt( "BookManager", $opt, $prev, $prevtext, $base, $basetext, $next, $nexttext );
296328 $BookManagerTop = wfMsgExt( "BookManager-top", $opt, $prev, $prevtext, $base, $basetext, $next, $nexttext );
@@ -300,18 +332,26 @@
301333 elseif ( !wfEmptyMsg( "BookManager", $BookManager ) ) {
302334 $text = "<div>$BookManager</div>\n$text";
303335 }
 336+ #This part adds directly to the html by default when the messages are not defined ...
 337+ else {
 338+ $text = "$bar\n$text";
 339+ }
304340 if ( !wfEmptyMsg( "BookManager-bottom", $BookManagerBottom ) ) {
305341 $text = "$text\n<div>$BookManagerBottom</div>";
306342 }
307343 elseif ( !wfEmptyMsg( "BookManager", $BookManager ) ) {
308344 $text = "$text\n<div>$BookManager</div>";
309345 }
 346+ #This part adds directly to the html by default when the messages are not defined ...
 347+ else {
 348+ $text = "$text\n$bar";
 349+ }
310350 }
311351 return true;
312352 }
313 -
 353+ #adds CSS and JS to navigation bar
314354 static function injectStyleAndJS( &$out, &$sk ) {
315 - global $wgOut ;
 355+ global $wgOut;
316356 $wgOut->addModuleStyles('ext.BookManager');
317357 $wgOut->addModules( 'ext.BookManager');
318358 return true;
Index: trunk/extensions/BookManager/BookManager.php
@@ -84,4 +84,4 @@
8585
8686 $wgHooks['BeforePageDisplay'][] = 'BookManagerFunctions::injectStyleAndJS';
8787
88 -$wgExtensionMessagesFiles['BookManager'] = $dir . '/BookManager.i18n.php';
 88+//$wgExtensionMessagesFiles['BookManager'] = $dir . '/BookManager.i18n.php';

Follow-up revisions

RevisionCommit summaryAuthorDate
r83722fix r83706raylton.sousa21:02, 11 March 2011

Comments

#Comment by Nikerabbit (talk | contribs)   20:49, 11 March 2011

+//$wgExtensionMessagesFiles['BookManager'] = $dir . '/BookManager.i18n.php';

?

#Comment by Raylton P. Sousa (talk | contribs)   21:08, 11 March 2011

Done in r83722

#Comment by He7d3r (talk | contribs)   13:39, 12 March 2011

For consistency, since the default $bar doesn't wrap the list in a <div>, the content of messages MediaWiki:BookManager, MediaWiki:BookManager-top and MediaWiki:BookManager-bottom shouldn't be wrapped either.

Status & tagging log