r58871 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58870‎ | r58871 | r58872 >
Date:20:12, 10 November 2009
Author:ialex
Status:deferred
Tags:
Comment:
* added $wgBreadCrumbsShowAnons to control whether anons will have the links
* removed extension function, define hooks when including the file
* use tabs for indentation, not spaces
Modified paths:
  • /trunk/extensions/BreadCrumbs/BreadCrumbs.php (modified) (history)
  • /trunk/extensions/BreadCrumbs/BreadCrumbsFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/BreadCrumbs/BreadCrumbsFunctions.php
@@ -14,64 +14,67 @@
1515 }
1616
1717 function fnBreadCrumbsShowHook( &$m_pageObj ) {
18 - global $wgTitle;
19 - global $wgOut;
20 - global $wgUser;
21 - global $wgBreadCrumbsDelimiter;
22 - global $wgBreadCrumbsCount;
23 -
24 - # deserialize data from session into array:
25 - $m_BreadCrumbs = array();
26 - if( isset( $_SESSION['BreadCrumbs'] ) ) $m_BreadCrumbs = $_SESSION['BreadCrumbs'];
27 - # cache index of last element:
28 - $m_count = count( $m_BreadCrumbs ) - 1;
 18+ global $wgTitle, $wgOut, $wgUser;
 19+ global $wgBreadCrumbsDelimiter, $wgBreadCrumbsCount, $wgBreadCrumbsShowAnons;
2920
30 - # check for doubles:
31 - if( $m_count < 1 || $m_BreadCrumbs[ $m_count ] != $wgTitle->getPrefixedText() ) {
32 - if( $m_count >= 1) {
33 - # reduce the array set, remove older elements:
34 - $m_BreadCrumbs = array_slice( $m_BreadCrumbs, ( 1 - $wgBreadCrumbsCount ) );
35 - }
36 - # add new page:
37 - array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText() );
38 - }
39 - # serialize data from array to session:
40 - $_SESSION['BreadCrumbs'] = $m_BreadCrumbs;
41 - # update cache:
42 - $m_count = count( $m_BreadCrumbs ) - 1;
 21+ if ( !$wgBreadCrumbsShowAnons && $wgUser->isAnon() )
 22+ return true;
4323
44 - # acquire a skin object:
45 - $m_skin =& $wgUser->getSkin();
46 - # build the breadcrumbs trail:
47 - $m_trail = '<div id="BreadCrumbsTrail">';
48 - for( $i = 0; $i <= $m_count; $i++ ) {
49 - $m_trail .= $m_skin->makeLink( $m_BreadCrumbs[$i] );
50 - if( $i < $m_count ) $m_trail .= $wgBreadCrumbsDelimiter;
51 - }
52 - $m_trail .= '</div>';
53 - $wgOut->addHTML( $m_trail );
 24+ # deserialize data from session into array:
 25+ $m_BreadCrumbs = array();
 26+ if( isset( $_SESSION['BreadCrumbs'] ) ) $m_BreadCrumbs = $_SESSION['BreadCrumbs'];
 27+ # cache index of last element:
 28+ $m_count = count( $m_BreadCrumbs ) - 1;
5429
55 - # invalidate internal MediaWiki cache:
56 - $wgTitle->invalidateCache();
57 - $wgUser->invalidateCache();
 30+ # check for doubles:
 31+ if( $m_count < 1 || $m_BreadCrumbs[ $m_count ] != $wgTitle->getPrefixedText() ) {
 32+ if( $m_count >= 1) {
 33+ # reduce the array set, remove older elements:
 34+ $m_BreadCrumbs = array_slice( $m_BreadCrumbs, ( 1 - $wgBreadCrumbsCount ) );
 35+ }
 36+ # add new page:
 37+ array_push( $m_BreadCrumbs, $wgTitle->getPrefixedText() );
 38+ }
 39+ # serialize data from array to session:
 40+ $_SESSION['BreadCrumbs'] = $m_BreadCrumbs;
 41+ # update cache:
 42+ $m_count = count( $m_BreadCrumbs ) - 1;
5843
59 - # Return true to let the rest work:
60 - return true;
 44+ # acquire a skin object:
 45+ $m_skin =& $wgUser->getSkin();
 46+ # build the breadcrumbs trail:
 47+ $m_trail = '<div id="BreadCrumbsTrail">';
 48+ for( $i = 0; $i <= $m_count; $i++ ) {
 49+ $m_trail .= $m_skin->makeLink( $m_BreadCrumbs[$i] );
 50+ if( $i < $m_count ) $m_trail .= $wgBreadCrumbsDelimiter;
 51+ }
 52+ $m_trail .= '</div>';
 53+ $wgOut->addHTML( $m_trail );
 54+
 55+ # invalidate internal MediaWiki cache:
 56+ $wgTitle->invalidateCache();
 57+ $wgUser->invalidateCache();
 58+
 59+ # Return true to let the rest work:
 60+ return true;
6161 }
6262
6363 ## Entry point for the hook for printing the CSS:
6464 function fnBreadCrumbsOutputHook( &$m_pageObj, $m_parserOutput ) {
65 - global $wgScriptPath;
 65+ global $wgScriptPath, $wgBreadCrumbsShowAnons, $wgUser;
6666
67 - # Register CSS file for our select box:
68 - $m_pageObj->addLink(
69 - array(
70 - 'rel' => 'stylesheet',
71 - 'type' => 'text/css',
72 - 'href' => $wgScriptPath . '/extensions/BreadCrumbs/BreadCrumbs.css'
73 - )
74 - );
 67+ if ( !$wgBreadCrumbsShowAnons && $wgUser->isAnon() )
 68+ return true;
7569
76 - # Be nice:
77 - return true;
 70+ # Register CSS file for our select box:
 71+ $m_pageObj->addLink(
 72+ array(
 73+ 'rel' => 'stylesheet',
 74+ 'type' => 'text/css',
 75+ 'href' => $wgScriptPath . '/extensions/BreadCrumbs/BreadCrumbs.css'
 76+ )
 77+ );
 78+
 79+ # Be nice:
 80+ return true;
7881 }
Index: trunk/extensions/BreadCrumbs/BreadCrumbs.php
@@ -19,11 +19,12 @@
2020 $wgBreadCrumbsDelimiter = ' &gt; ';
2121 # $wgBreadCrumbsCount - number of breadcrumbs to use
2222 $wgBreadCrumbsCount = 5;
 23+# Whether to provide the links also for anonymous users
 24+$wgBreadCrumbsShowAnons = true;
2325
2426 $wgExtensionMessagesFiles['Breadcrumbs'] = dirname(__FILE__) . '/BreadCrumbs.i18n.php';
2527
26 -## Register extension setup hook and credits:
27 -$wgExtensionFunctions[] = 'fnBreadCrumbs';
 28+## Register extension credits:
2829 $wgExtensionCredits['parserhook'][] = array(
2930 'path' => __FILE__,
3031 'name' => 'BreadCrumbs',
@@ -34,17 +35,14 @@
3536 );
3637
3738 ## Set Hook:
38 -function fnBreadCrumbs() {
39 - global $wgHooks;
4039
41 - ## Showing and updating the breadcrumbs trail
42 - # Hook when viewing article header:
43 - $wgHooks['ArticleViewHeader'][] = 'fnBreadCrumbsShowHook';
 40+## Showing and updating the breadcrumbs trail
 41+# Hook when viewing article header:
 42+$wgHooks['ArticleViewHeader'][] = 'fnBreadCrumbsShowHook';
4443
45 - ## Infrastructure
46 - # Hook our own CSS:
47 - $wgHooks['OutputPageParserOutput'][] = 'fnBreadCrumbsOutputHook';
48 -}
 44+## Infrastructure
 45+# Hook our own CSS:
 46+$wgHooks['OutputPageParserOutput'][] = 'fnBreadCrumbsOutputHook';
4947
5048 ## Load the file containing the hook functions:
5149 require_once( 'BreadCrumbsFunctions.php' );

Status & tagging log