Index: trunk/extensions/Collection/Collection.body.php |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | global $wgCollectionMaxArticles; |
49 | 49 | |
50 | 50 | wfLoadExtensionMessages( 'Collection' ); |
51 | | - |
| 51 | + |
52 | 52 | switch ( $par ) { |
53 | 53 | case 'add_article/': |
54 | 54 | if ( self::countArticles() >= $wgCollectionMaxArticles ) { |
— | — | @@ -220,7 +220,7 @@ |
221 | 221 | if ( !self::hasSession() ) { |
222 | 222 | self::startSession(); |
223 | 223 | } |
224 | | - |
| 224 | + |
225 | 225 | $this->setHeaders(); |
226 | 226 | $wgOut->addInlineScript( "var wgCollectionVersion = \"$wgCollectionVersion\";" ); |
227 | 227 | $wgOut->addScript( "<script type=\"$wgJsMimeType\" src=\"$wgScriptPath/extensions/Collection/collection/jquery.js?$wgCollectionStyleVersion\"></script>" ); |
— | — | @@ -1086,26 +1086,32 @@ |
1087 | 1087 | */ |
1088 | 1088 | static function getPortlet( $ajaxHint='' ) { |
1089 | 1089 | global $wgArticle; |
1090 | | - global $wgRequest; |
1091 | 1090 | global $wgTitle; |
1092 | 1091 | global $wgOut; |
| 1092 | + global $wgRequest; |
1093 | 1093 | 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 | + |
1102 | 1095 | 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 | + } |
1103 | 1107 | |
1104 | 1108 | $addArticle = wfMsgHtml( 'coll-add_page' ); |
1105 | 1109 | $removeArticle = wfMsgHtml( 'coll-remove_page' ); |
1106 | 1110 | $addCategory = wfMsgHtml( 'coll-add_category' ); |
1107 | 1111 | $loadCollection = wfMsgHtml( 'coll-load_collection' ); |
| 1112 | + $namespace = $wgTitle->getNamespace(); |
1108 | 1113 | |
1109 | 1114 | $numArticles = self::countArticles(); |
| 1115 | + $showShowAndClearLinks = true; |
1110 | 1116 | |
1111 | 1117 | $out = "<ul id=\"collectionPortletList\">"; |
1112 | 1118 | |
— | — | @@ -1116,97 +1122,87 @@ |
1117 | 1123 | 'load_collection/', |
1118 | 1124 | $params ) ); |
1119 | 1125 | $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 |
1135 | 1135 | <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> |
1137 | 1137 | </li> |
1138 | 1138 | 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 | + ; |
1152 | 1140 | |
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 |
1159 | 1156 | <li> |
1160 | 1157 | <a href="$href" onclick="collectionCall('AddArticle', [wgNamespaceNumber, wgTitle, $oldid]); return false;" rel="nofollow">$addArticle</a> |
1161 | 1158 | </li> |
1162 | 1159 | 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 |
1170 | 1167 | <li> |
1171 | 1168 | <a href="$href" onclick="collectionCall('RemoveArticle', [wgNamespaceNumber, wgTitle, $oldid]); return false;" rel="nofollow">$removeArticle</a> |
1172 | 1169 | </li> |
1173 | 1170 | EOS |
1174 | | - ; |
1175 | | - } |
1176 | | - } |
| 1171 | + ; |
| 1172 | + } |
| 1173 | + } |
1177 | 1174 | |
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 |
1184 | 1181 | <li><a href="$showURL" rel="nofollow">$showCollection<br /> |
1185 | 1182 | ($articles)</a></li> |
1186 | 1183 | 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 |
1197 | 1194 | <li> |
1198 | 1195 | <a href="$href" onclick="if (confirm('$msg')) return true; else return false;" rel="nofollow">$clearCollection</a> |
1199 | 1196 | </li> |
1200 | 1197 | 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 |
1207 | 1204 | <li><a href="$helpURL">$helpCollections</a></li> |
1208 | 1205 | EOS |
1209 | | - ; |
1210 | | - } |
| 1206 | + ; |
1211 | 1207 | |
1212 | 1208 | $out .= "</ul>"; |
1213 | 1209 | |