r38744 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38743‎ | r38744 | r38745 >
Date:21:50, 6 August 2008
Author:brion
Status:old
Tags:
Comment:
Couple of changes:
* Support the sidebar extension hooks in current MediaWiki for the little Collections portlet.
** NOTE: We seem to end up with a phantom empty portlet for non-article views if a 'COLLECTION' line is explicitly added to MediaWiki:Sidebar
** It probably doesn't play very well with sidebar caching
** I disabled this for anonymous visitors to ensure that weird unexpected things don't creep into the general HTTP caches. Not sure how best to handle this?
* Changed the cache invalidation on add/remove/etc from the page to the user
** This ensures that the portlet stays consistent when you go to another page you've already been to
** But it doesn't currently stick anything in the session data for anons :( (Currently disabled anyway)
Modified paths:
  • /trunk/extensions/Collection/Collection.body.php (modified) (history)
  • /trunk/extensions/Collection/Collection.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Collection/Collection.php
@@ -87,7 +87,9 @@
8888 $wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = 'Collection::createNavURLs';
8989 $wgHooks['MonoBookTemplateToolboxEnd'][] = 'Collection::insertMonoBookToolboxLink';
9090
 91+$wgHooks['SkinBuildSidebar'][] = 'Collection::buildSidebar';
9192
 93+
9294 function collectionLocalizedPageName(&$specialPageArray, $code) {
9395 wfLoadExtensionMessages( 'Collection' );
9496 $text = wfMsg( 'coll-collection' );
Index: trunk/extensions/Collection/Collection.body.php
@@ -69,7 +69,7 @@
7070 } else {
7171 $redirectURL = $title->getFullURL( 'oldid=' . $oldid );
7272 }
73 - $title->invalidateCache();
 73+ $wgUser->invalidateCache();
7474 $wgOut->redirect( $redirectURL );
7575 return;
7676 } else if ( $par == 'remove_article/' ) {
@@ -82,7 +82,7 @@
8383 } else {
8484 $redirectURL = $title->getFullURL( 'oldid=' . $oldid );
8585 }
86 - $title->invalidateCache();
 86+ $wgUser->invalidateCache();
8787 $wgOut->redirect( $redirectURL );
8888 return;
8989 } else if ( $par == 'add_category/' ) {
@@ -93,7 +93,7 @@
9494 } else {
9595 $wgOut->redirect( $title->getFullURL() );
9696 }
97 - $title->invalidateCache();
 97+ $wgUser->invalidateCache();
9898 return;
9999 } else if ( $par == 'load_collection/' ) {
100100 $title = Title::newFromText( $wgRequest->getVal( 'colltitle', '' ) );
@@ -1045,6 +1045,24 @@
10461046 return true;
10471047 }
10481048
 1049+
 1050+ static function buildSidebar( $skin, &$bar ) {
 1051+ global $wgArticle, $wgUser;
 1052+ if( $wgUser->isLoggedIn() ) {
 1053+ // We don't want this sidebar gadget polluting the HTTP caches.
 1054+ // To stay on the safe side for now, we'll show this only for
 1055+ // logged-in users.
 1056+ //
 1057+ // In theory this could be managed properly for open sessions,
 1058+ // but you'd have to inject something for non-open sessions or
 1059+ // it would be very confusing.
 1060+ if( $wgArticle && $wgArticle->exists() ) {
 1061+ $bar['COLLECTION'] = self::printPortlet();
 1062+ }
 1063+ }
 1064+ return true;
 1065+ }
 1066+
10491067 /**
10501068 * Return HTML-code to be inserted as portlet
10511069 */
@@ -1067,13 +1085,7 @@
10681086 $loadCollection = wfMsgHtml( 'coll-load_collection' );
10691087 $tooBigCat = wfMsgHtml( 'coll-too_big_cat' );
10701088
1071 - print <<<EOS
1072 - <div id="p-collection" class="portlet">
1073 - <h5>$portletTitle</h5>
1074 - <div class="pBody">
1075 - <ul>
1076 -EOS
1077 - ;
 1089+ $out = "<ul>";
10781090 if ( is_null( $wgArticle ) || !$wgArticle->exists() ) {
10791091 // no op
10801092 } else if ( self::isCollectionPage( $wgTitle, $wgArticle) ) {
@@ -1082,7 +1094,7 @@
10831095 'Collection',
10841096 'load_collection/'
10851097 ), $params ) );
1086 - print "<li><a href=\"$href\">$loadCollection</a></li>";
 1098+ $out .= "<li><a href=\"$href\">$loadCollection</a></li>";
10871099 } else if ( $wgTitle->getNamespace() == NS_MAIN ) { // TODO: only NS_MAIN?
10881100 $params = "arttitle=" . $wgTitle->getPrefixedUrl() . "&oldid=" . $wgArticle->getOldID();
10891101
@@ -1091,13 +1103,13 @@
10921104 'Collection',
10931105 'add_article/'
10941106 ), $params ) );
1095 - print "<li><a href=\"$href\">$addArticle</a></li>";
 1107+ $out .= "<li><a href=\"$href\">$addArticle</a></li>";
10961108 } else {
10971109 $href = htmlspecialchars( wfAppendQuery( SkinTemplate::makeSpecialUrlSubpage(
10981110 'Collection',
10991111 'remove_article/'
11001112 ), $params ) );
1101 - print "<li><a href=\"$href\">$removeArticle</a></li>";
 1113+ $out .= "<li><a href=\"$href\">$removeArticle</a></li>";
11021114 }
11031115 } else if ( $wgTitle->getNamespace() == NS_CATEGORY ) {
11041116 $params = "cattitle=" . $wgTitle->getPartialURL();
@@ -1105,7 +1117,7 @@
11061118 'Collection',
11071119 'add_category/'
11081120 ), $params ) );
1109 - print "<li><a href=\"$href\">$addCategory</a></li>";
 1121+ $out .= "<li><a href=\"$href\">$addCategory</a></li>";
11101122 }
11111123
11121124 $numArticles = self::countArticles();
@@ -1121,21 +1133,20 @@
11221134 }
11231135 $showCollection = wfMsgHtml( 'coll-show_collection' );
11241136 $showURL = htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Collection') );
1125 - print <<<EOS
 1137+ $out .= <<<EOS
11261138 <li><a href="$showURL">$showCollection<br />
11271139 ($articles)</a></li>
11281140 EOS
11291141 ;
11301142 $helpCollections = wfMsgHtml( 'coll-help_collections' );
11311143 $helpURL = htmlspecialchars( Title::makeTitle( NS_HELP, wfMsgForContent( 'coll-collections' ) )->getFullURL() );
1132 - print <<<EOS
 1144+ $out .= <<<EOS
11331145 <li><a href="$helpURL">$helpCollections</a></li>
11341146 </ul>
1135 - </div>
1136 - </div>
11371147 <span id="tooBigCategoryText" style="display:none">$tooBigCat</span>
11381148 EOS
11391149 ;
 1150+ return $out;
11401151 }
11411152
11421153 static function pdfServerCommand( $command, $args, $timeout=true, $toFile=null ) {

Status & tagging log