r47446 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47445‎ | r47446 | r47447 >
Date:12:16, 18 February 2009
Author:jojo
Status:ok
Tags:
Comment:
refacotred getPortlet(). fix hiding of portlet when on Special:Book (w/out subpages). show help link when on saved book page.
Modified paths:
  • /trunk/extensions/Collection/Collection.body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Collection/Collection.body.php
@@ -47,7 +47,7 @@
4848 global $wgCollectionMaxArticles;
4949
5050 wfLoadExtensionMessages( 'Collection' );
51 -
 51+
5252 switch ( $par ) {
5353 case 'add_article/':
5454 if ( self::countArticles() >= $wgCollectionMaxArticles ) {
@@ -220,7 +220,7 @@
221221 if ( !self::hasSession() ) {
222222 self::startSession();
223223 }
224 -
 224+
225225 $this->setHeaders();
226226 $wgOut->addInlineScript( "var wgCollectionVersion = \"$wgCollectionVersion\";" );
227227 $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"$wgScriptPath/extensions/Collection/collection/jquery.js?$wgCollectionStyleVersion\"></script>" );
@@ -1086,26 +1086,32 @@
10871087 */
10881088 static function getPortlet( $ajaxHint='' ) {
10891089 global $wgArticle;
1090 - global $wgRequest;
10911090 global $wgTitle;
10921091 global $wgOut;
 1092+ global $wgRequest;
10931093 global $wgCollectionArticleNamespaces;
1094 -
1095 - // Note: we need to use $wgRequest, b/c there is apparently no way to get
1096 - // the subpage part of a Special page via $wgTitle.
1097 - $mainTitle = Title::makeTitle( NS_SPECIAL, 'Book' );
1098 - if ( $wgRequest->getRequestURL() == $mainTitle->getLocalURL() ) {
1099 - return;
1100 - }
1101 -
 1094+
11021095 wfLoadExtensionMessages( 'Collection' );
 1096+
 1097+ if (!$ajaxHint) {
 1098+ // we need to re-construct a title object from the request, because
 1099+ // the "subpage" (i.e. "par") part has been stripped of by SpecialPage.php
 1100+ // in $wgTitle.
 1101+ $origTitle = Title::newFromUrl($wgRequest->getVal('title'));
 1102+ if (!is_null($origTitle)
 1103+ && $origTitle->getLocalUrl() == SkinTemplate::makeSpecialUrl('Book')) {
 1104+ return;
 1105+ }
 1106+ }
11031107
11041108 $addArticle = wfMsgHtml( 'coll-add_page' );
11051109 $removeArticle = wfMsgHtml( 'coll-remove_page' );
11061110 $addCategory = wfMsgHtml( 'coll-add_category' );
11071111 $loadCollection = wfMsgHtml( 'coll-load_collection' );
 1112+ $namespace = $wgTitle->getNamespace();
11081113
11091114 $numArticles = self::countArticles();
 1115+ $showShowAndClearLinks = true;
11101116
11111117 $out = "<ul id=\"collectionPortletList\">";
11121118
@@ -1116,97 +1122,87 @@
11171123 'load_collection/',
11181124 $params ) );
11191125 $out .= "<li><a href=\"$href\" rel=\"nofollow\">$loadCollection</a></li>";
1120 - } else {
1121 -
1122 - // disable caching
1123 - $wgOut->setSquidMaxage( 0 );
1124 - $wgOut->enableClientCache( false );
1125 -
1126 - $namespace = $wgTitle->getNamespace();
1127 -
1128 - if ( $ajaxHint == 'AddCategory' || $namespace == NS_CATEGORY ) {
1129 - $params = "cattitle=" . $wgTitle->getPartialURL();
1130 - $href = htmlspecialchars( SkinTemplate::makeSpecialUrlSubpage(
1131 - 'Book',
1132 - 'add_category/',
1133 - $params ) );
1134 - $out .= <<<EOS
 1126+ $showShowAndClearLinks = false;
 1127+
 1128+ } else if ( $ajaxHint == 'AddCategory' || $namespace == NS_CATEGORY ) {
 1129+ $params = "cattitle=" . $wgTitle->getPartialURL();
 1130+ $href = htmlspecialchars( SkinTemplate::makeSpecialUrlSubpage(
 1131+ 'Book',
 1132+ 'add_category/',
 1133+ $params ) );
 1134+ $out .= <<<EOS
11351135 <li>
1136 - <a href="$href" onclick="collectionCall('AddCategory', [wgTitle]); return false;" rel="nofollow">$addCategory</a>
 1136+<a href="$href" onclick="collectionCall('AddCategory', [wgTitle]); return false;" rel="nofollow">$addCategory</a>
11371137 </li>
11381138 EOS
1139 - ;
1140 - } else if ( !$ajaxHint && (is_null( $wgArticle ) || !$wgArticle->exists()) ) {
1141 - if ( self::countArticles() == 0) {
1142 - return;
1143 - }
1144 - } else if ( $ajaxHint || in_array( $namespace, $wgCollectionArticleNamespaces ) ) {
1145 - $params = "arttitle=" . $wgTitle->getPrefixedUrl();
1146 - if ( !is_null( $wgArticle ) ) {
1147 - $oldid = $wgArticle->getOldID();
1148 - $params .= "&oldid=" . $oldid;
1149 - } else {
1150 - $oldid = null;
1151 - }
 1139+ ;
11521140
1153 - if ( $ajaxHint == "RemoveArticle" || self::findArticle( $wgTitle->getPrefixedText(), $oldid ) == -1 ) {
1154 - $href = htmlspecialchars( SkinTemplate::makeSpecialUrlSubpage(
1155 - 'Book',
1156 - 'add_article/',
1157 - $params ) );
1158 - $out .= <<<EOS
 1141+ } else if ( $ajaxHint || in_array( $namespace, $wgCollectionArticleNamespaces ) ) {
 1142+ $params = "arttitle=" . $wgTitle->getPrefixedUrl();
 1143+ if ( !is_null( $wgArticle ) ) {
 1144+ $oldid = $wgArticle->getOldID();
 1145+ $params .= "&oldid=" . $oldid;
 1146+ } else {
 1147+ $oldid = null;
 1148+ }
 1149+
 1150+ if ( $ajaxHint == "RemoveArticle" || self::findArticle( $wgTitle->getPrefixedText(), $oldid ) == -1 ) {
 1151+ $href = htmlspecialchars( SkinTemplate::makeSpecialUrlSubpage(
 1152+ 'Book',
 1153+ 'add_article/',
 1154+ $params ) );
 1155+ $out .= <<<EOS
11591156 <li>
11601157 <a href="$href" onclick="collectionCall('AddArticle', [wgNamespaceNumber, wgTitle, $oldid]); return false;" rel="nofollow">$addArticle</a>
11611158 </li>
11621159 EOS
1163 - ;
1164 - } else {
1165 - $href = htmlspecialchars( SkinTemplate::makeSpecialUrlSubpage(
1166 - 'Book',
1167 - 'remove_article/',
1168 - $params ) );
1169 - $out .= <<<EOS
 1160+ ;
 1161+ } else {
 1162+ $href = htmlspecialchars( SkinTemplate::makeSpecialUrlSubpage(
 1163+ 'Book',
 1164+ 'remove_article/',
 1165+ $params ) );
 1166+ $out .= <<<EOS
11701167 <li>
11711168 <a href="$href" onclick="collectionCall('RemoveArticle', [wgNamespaceNumber, wgTitle, $oldid]); return false;" rel="nofollow">$removeArticle</a>
11721169 </li>
11731170 EOS
1174 - ;
1175 - }
1176 - }
 1171+ ;
 1172+ }
 1173+ }
11771174
1178 - if ( $numArticles > 0 ) {
1179 - global $wgLang;
1180 - $articles = wfMsgExt( 'coll-n_pages', array( 'parsemag' ), $wgLang->formatNum( $numArticles ) );
1181 - $showCollection = wfMsgHtml( 'coll-show_collection' );
1182 - $showURL = htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Book') );
1183 - $out .= <<<EOS
 1175+ if ( $showShowAndClearLinks && $numArticles > 0 ) {
 1176+ global $wgLang;
 1177+ $articles = wfMsgExt( 'coll-n_pages', array( 'parsemag' ), $wgLang->formatNum( $numArticles ) );
 1178+ $showCollection = wfMsgHtml( 'coll-show_collection' );
 1179+ $showURL = htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Book') );
 1180+ $out .= <<<EOS
11841181 <li><a href="$showURL" rel="nofollow">$showCollection<br />
11851182 ($articles)</a></li>
11861183 EOS
1187 - ;
1188 -
1189 - $clearCollection = wfMsgHtml( 'coll-clear_collection' );
1190 - $params = 'return_to=' . $wgTitle->getFullURL();
1191 - $href = htmlspecialchars( SkinTemplate::makeSpecialUrlSubpage(
1192 - 'Book',
1193 - 'clear_collection/',
1194 - $params ) );
1195 - $msg = htmlspecialchars( wfMsg( 'coll-clear_collection_confirm' ) );
1196 - $out .= <<<EOS
 1184+ ;
 1185+
 1186+ $clearCollection = wfMsgHtml( 'coll-clear_collection' );
 1187+ $params = 'return_to=' . $wgTitle->getFullURL();
 1188+ $href = htmlspecialchars( SkinTemplate::makeSpecialUrlSubpage(
 1189+ 'Book',
 1190+ 'clear_collection/',
 1191+ $params ) );
 1192+ $msg = htmlspecialchars( wfMsg( 'coll-clear_collection_confirm' ) );
 1193+ $out .= <<<EOS
11971194 <li>
11981195 <a href="$href" onclick="if (confirm('$msg')) return true; else return false;" rel="nofollow">$clearCollection</a>
11991196 </li>
12001197 EOS
1201 - ;
1202 - }
1203 -
1204 - $helpCollections = wfMsgHtml( 'coll-help_collections' );
1205 - $helpURL = htmlspecialchars( Title::newFromText( wfMsgForContent( 'coll-helppage' ) )->getFullURL() );
1206 - $out .= <<<EOS
 1198+ ;
 1199+ }
 1200+
 1201+ $helpCollections = wfMsgHtml( 'coll-help_collections' );
 1202+ $helpURL = htmlspecialchars( Title::newFromText( wfMsgForContent( 'coll-helppage' ) )->getFullURL() );
 1203+ $out .= <<<EOS
12071204 <li><a href="$helpURL">$helpCollections</a></li>
12081205 EOS
1209 - ;
1210 - }
 1206+ ;
12111207
12121208 $out .= "</ul>";
12131209

Status & tagging log