Index: trunk/extensions/BookManager/BookManager.body.php |
— | — | @@ -1,9 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | /**** All the BookManager Variables Functions ****/ |
4 | 4 | class BookManagerFunctions { |
| 5 | + const VERSION = "0.1.6 - unstable"; |
5 | 6 | |
6 | | - const VERSION = "0.1.5 - unstable"; |
7 | | - |
8 | 7 | static function register( ) { |
9 | 8 | global $wgParser; |
10 | 9 | |
— | — | @@ -18,7 +17,7 @@ |
19 | 18 | $wgParser->setFunctionHook( 'chaptername', array( __CLASS__, 'chaptername' ), SFH_NO_HASH ); |
20 | 19 | $wgParser->setFunctionHook( 'chapternamee', array( __CLASS__, 'chapternamee' ), SFH_NO_HASH ); |
21 | 20 | } |
22 | | - |
| 21 | + /**** All the BookManager functions to declare magicword id ****/ |
23 | 22 | static function DeclareVarIds( &$aCustomVariableIds ) { |
24 | 23 | # aCustomVariableIds is where MediaWiki wants to store its |
25 | 24 | # list of custom variable ids. We oblige by adding ours: |
— | — | @@ -32,7 +31,7 @@ |
33 | 32 | $aCustomVariableIds[] = MAG_CHAPTERNAMEE; |
34 | 33 | return true; |
35 | 34 | } |
36 | | - |
| 35 | + /**** All the BookManager functions to declare magicwords ****/ |
37 | 36 | static function LanguageGetMagic( &$magicWords, $langCode = "en" ) { |
38 | 37 | switch ( $langCode ) { |
39 | 38 | default: |
— | — | @@ -63,17 +62,27 @@ |
64 | 63 | } |
65 | 64 | return true; |
66 | 65 | } |
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 | + */ |
68 | 73 | private static function isViewAction() { |
69 | 74 | global $wgRequest; |
70 | 75 | $action = $wgRequest->getVal( 'action', 'view' ); |
71 | | - if( $action == 'view' || $action == 'purge'){ |
| 76 | + if( $action == 'view' || $action == 'purge' ){ |
72 | 77 | return true; |
73 | 78 | } |
74 | 79 | else{ |
75 | 80 | return false; |
76 | 81 | } |
77 | 82 | } |
| 83 | + |
| 84 | + /* |
| 85 | + * Get Title |
| 86 | + */ |
78 | 87 | private static function newTitleObject( &$parser, $text = null ) { |
79 | 88 | $t = Title::newFromText( $text ); |
80 | 89 | if ( is_null( $t ) ) { |
— | — | @@ -84,7 +93,7 @@ |
85 | 94 | |
86 | 95 | |
87 | 96 | /* |
88 | | - * Cópia da função "getBookPagePrefixes" da extensão Collection |
| 97 | + * Adaptation of the function "getBookPagePrefixes" from collection extension |
89 | 98 | * (http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Collection/Collection.body.php?revision=79895&view=markup#l440) |
90 | 99 | */ |
91 | 100 | private static function getBookPagePrefixes() { |
— | — | @@ -117,7 +126,7 @@ |
118 | 127 | } |
119 | 128 | |
120 | 129 | /* |
121 | | - * Simplificação da função "parseCollectionLine" da extensão Collection |
| 130 | + * Simplification of the function "parseCollectionLine" from collection extension |
122 | 131 | * (http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Collection/Collection.body.php?revision=79895&view=markup#l709) |
123 | 132 | */ |
124 | 133 | private static function parseCollectionLine( /* Sem uso por enquanto: &$collection, */ $line ) { |
— | — | @@ -144,7 +153,7 @@ |
145 | 154 | } |
146 | 155 | |
147 | 156 | /* |
148 | | - * Adaptação da função "loadCollection" da extensão Collection |
| 157 | + * Adaptation of the function "loadCollection" from collection extension |
149 | 158 | * (http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Collection/Collection.body.php?revision=79895&view=markup#l780) |
150 | 159 | */ |
151 | 160 | private static function loadListFromCollection( $collectiontitle ) { |
— | — | @@ -164,7 +173,7 @@ |
165 | 174 | return $caps; |
166 | 175 | } |
167 | 176 | |
168 | | - |
| 177 | + #Get the book or chapter name |
169 | 178 | private static function bookparts( &$parser, $text = null, $part = 1) { |
170 | 179 | $t = self::newTitleObject( $parser, $text ); |
171 | 180 | // No book should have '/' in it's name, so... |
— | — | @@ -183,12 +192,14 @@ |
184 | 193 | * @param $n Integer Position of wanted page. Next page is +1; Previous page is -1 |
185 | 194 | * @return String The prefixed title or empty string if not found or found but not valid |
186 | 195 | */ |
| 196 | + |
187 | 197 | private static function pageText( &$parser, $text = null, $n = 0 ) { |
188 | 198 | $pagetitle = self::newTitleObject( $parser, $text ); |
189 | 199 | $prefixes = self::getBookPagePrefixes(); |
190 | 200 | $booktitle = Title::newFromText( $prefixes['community-prefix'] . self::bookparts( $parser, $text, 0) ); // ...the book name will be 'Foo'. |
| 201 | + |
191 | 202 | $cap = self::loadListFromCollection( $booktitle ); |
192 | | - if ( $cap === false ) { |
| 203 | + if ( $cap ===false ) { |
193 | 204 | return ''; |
194 | 205 | } |
195 | 206 | $current = array_search( $pagetitle, $cap ); |
— | — | @@ -202,6 +213,10 @@ |
203 | 214 | return wfEscapeWikiText( $otherpagetitle->getText() ); |
204 | 215 | } |
205 | 216 | |
| 217 | + |
| 218 | +/**** All the BookManager values functions ****/ |
| 219 | + |
| 220 | + |
206 | 221 | static function prevpagename( &$parser, $text = null ) { |
207 | 222 | $t = self::pageText( $parser, $text, - 1 ); |
208 | 223 | return $t; |
— | — | @@ -213,6 +228,7 @@ |
214 | 229 | } |
215 | 230 | |
216 | 231 | static function nextpagename( &$parser, $text = null ) { |
| 232 | + |
217 | 233 | $t = self::pageText( $parser, $text, + 1 ); |
218 | 234 | return $t; |
219 | 235 | } |
— | — | @@ -273,7 +289,7 @@ |
274 | 290 | |
275 | 291 | /** |
276 | 292 | * Function that adds navigation bar |
277 | | -* inspired by extension PageNotice |
| 293 | +* inspired by PageNotice extension |
278 | 294 | * (http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/PageNotice/PageNotice.php) |
279 | 295 | */ |
280 | 296 | |
— | — | @@ -285,11 +301,27 @@ |
286 | 302 | ); |
287 | 303 | $currenttitletext = $wgTitle->getText(); |
288 | 304 | $prev = self::pageText( $wgParser, $currenttitletext, - 1 ); |
| 305 | + $base = Title::newFromText( $currenttitletext )->getBaseText(); |
289 | 306 | $next = self::pageText( $wgParser, $currenttitletext, + 1 ); |
290 | | - $base = Title::newFromText( $currenttitletext )->getBaseText(); |
| 307 | + $prevtext = ( $prev !== '' ) ? Title::newFromText( $prev )->getSubpageText(): '' ; |
291 | 308 | $basetext = ( $base !== '' ) ? Title::newFromText( $base )->getSubpageText(): '' ; |
292 | | - $prevtext = ( $prev !== '' ) ? Title::newFromText( $prev )->getSubpageText(): '' ; |
293 | 309 | $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 |
294 | 326 | if ( in_array($ns,$wgBookManagerNamespaces) && self::isViewAction() ) { |
295 | 327 | $BookManager = wfMsgExt( "BookManager", $opt, $prev, $prevtext, $base, $basetext, $next, $nexttext ); |
296 | 328 | $BookManagerTop = wfMsgExt( "BookManager-top", $opt, $prev, $prevtext, $base, $basetext, $next, $nexttext ); |
— | — | @@ -300,18 +332,26 @@ |
301 | 333 | elseif ( !wfEmptyMsg( "BookManager", $BookManager ) ) { |
302 | 334 | $text = "<div>$BookManager</div>\n$text"; |
303 | 335 | } |
| 336 | + #This part adds directly to the html by default when the messages are not defined ... |
| 337 | + else { |
| 338 | + $text = "$bar\n$text"; |
| 339 | + } |
304 | 340 | if ( !wfEmptyMsg( "BookManager-bottom", $BookManagerBottom ) ) { |
305 | 341 | $text = "$text\n<div>$BookManagerBottom</div>"; |
306 | 342 | } |
307 | 343 | elseif ( !wfEmptyMsg( "BookManager", $BookManager ) ) { |
308 | 344 | $text = "$text\n<div>$BookManager</div>"; |
309 | 345 | } |
| 346 | + #This part adds directly to the html by default when the messages are not defined ... |
| 347 | + else { |
| 348 | + $text = "$text\n$bar"; |
| 349 | + } |
310 | 350 | } |
311 | 351 | return true; |
312 | 352 | } |
313 | | - |
| 353 | + #adds CSS and JS to navigation bar |
314 | 354 | static function injectStyleAndJS( &$out, &$sk ) { |
315 | | - global $wgOut ; |
| 355 | + global $wgOut; |
316 | 356 | $wgOut->addModuleStyles('ext.BookManager'); |
317 | 357 | $wgOut->addModules( 'ext.BookManager'); |
318 | 358 | return true; |
Index: trunk/extensions/BookManager/BookManager.php |
— | — | @@ -84,4 +84,4 @@ |
85 | 85 | |
86 | 86 | $wgHooks['BeforePageDisplay'][] = 'BookManagerFunctions::injectStyleAndJS'; |
87 | 87 | |
88 | | -$wgExtensionMessagesFiles['BookManager'] = $dir . '/BookManager.i18n.php'; |
| 88 | +//$wgExtensionMessagesFiles['BookManager'] = $dir . '/BookManager.i18n.php'; |