Index: trunk/extensions/Collection/Collection.i18n.php |
— | — | @@ -25,6 +25,7 @@ |
26 | 26 | |
27 | 27 | $messages['en'] = array( |
28 | 28 | 'coll-desc' => '[[Special:Collection|Collect pages]], generate PDFs', |
| 29 | + 'coll-collection' => 'Collection', |
29 | 30 | 'coll-collections' => 'Collections', |
30 | 31 | 'coll-portlet_title' => 'My collection', |
31 | 32 | 'coll-add_page' => 'Add page', |
— | — | @@ -121,6 +122,17 @@ |
122 | 123 | 'coll-invalid_podpartner_msg' => 'The supplied POD partner is invalid. |
123 | 124 | Please contact your MediaWiki administrator.', |
124 | 125 | 'coll-license' => 'License', |
| 126 | + 'coll-start_title' => "Start collection", |
| 127 | + 'coll-start_text' => " |
| 128 | +You can collect articles, generate and download a document in one of severa from article collections or from single articles, order books from a print-on-demand partner and save article collections for later use or to share them. |
| 129 | + |
| 130 | +See the [[{{MediaWiki:Coll-helppage}}|help page about collections]] for more information. |
| 131 | +", |
| 132 | + 'coll-start_add_box_title' => "Start collection right now", |
| 133 | + 'coll-start_add_link' => "Click to start your collection.", |
| 134 | + 'coll-start_add_page_text' => "$1 will be the first article.", |
| 135 | + 'coll-start_add_page_category' => "The articles in category $1 will be added.", |
| 136 | + 'coll-return_to' => "Return to [[:$1]]", |
125 | 137 | ); |
126 | 138 | |
127 | 139 | /** Faeag Rotuma (Faeag Rotuma) |
Index: trunk/extensions/Collection/Collection.php |
— | — | @@ -37,6 +37,9 @@ |
38 | 38 | |
39 | 39 | # Configuration: |
40 | 40 | |
| 41 | +/** Title of Start Collection page */ |
| 42 | +$wgCollectionStartPage = 'Start collection'; |
| 43 | + |
41 | 44 | /** URL of PDF server */ |
42 | 45 | $wgCollectionMWServeURL = 'http://tools.pediapress.com/mw-serve/'; |
43 | 46 | |
Index: trunk/extensions/Collection/Collection.body.php |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | function getDescription() { |
43 | 43 | return wfMsg( 'coll-collection' ); |
44 | 44 | } |
45 | | - |
| 45 | + |
46 | 46 | function execute( $par ) { |
47 | 47 | global $wgOut; |
48 | 48 | global $wgRequest; |
— | — | @@ -54,8 +54,16 @@ |
55 | 55 | global $wgCollectionVersion; |
56 | 56 | |
57 | 57 | wfLoadExtensionMessages( 'Collection' ); |
58 | | - |
59 | | - if ( $par == 'add_article/' ) { |
| 58 | + |
| 59 | + if ( $par == 'start_collection/' ) { |
| 60 | + $art_url = $wgRequest->getVal( 'arttitle', '' ); |
| 61 | + $oldid = $wgRequest->getInt( 'oldid', 0 ); |
| 62 | + $art_title = Title::newFromURL( $art_url ); |
| 63 | + $cat_url = $wgRequest->getVal( 'cattitle', '' ); |
| 64 | + $cat_title = Title::makeTitleSafe( NS_CATEGORY, $cat_url ); |
| 65 | + $this->startCollection( $art_title, $olid, $cat_title ); |
| 66 | + return; |
| 67 | + } else if ( $par == 'add_article/' ) { |
60 | 68 | if ( self::countArticles() >= $wgCollectionMaxArticles ) { |
61 | 69 | $this->limitExceeded(); |
62 | 70 | return; |
— | — | @@ -243,6 +251,65 @@ |
244 | 252 | return -1; |
245 | 253 | } |
246 | 254 | |
| 255 | + function startCollection( $title, $oldid, $cat_title ) { |
| 256 | + global $wgOut; |
| 257 | + global $wgCollectionStartPage; |
| 258 | + |
| 259 | + $wgOut->setPageTitle( wfMsg( 'coll-collection' ) ); |
| 260 | + |
| 261 | + if ( !is_null( $title ) or !is_null( $cat_title ) ) { |
| 262 | + if ( !is_null( $title ) ) { |
| 263 | + $params = 'arttitle=' . $title->getPrefixedURL(); |
| 264 | + if ( $oldid ) { |
| 265 | + $params .= '&oldid=' . $oldid; |
| 266 | + } |
| 267 | + $addLinkURL = htmlspecialchars( wfAppendQuery( SkinTemplate::makeSpecialUrlSubpage( |
| 268 | + 'Collection', |
| 269 | + 'add_article/' |
| 270 | + ), $params ) ); |
| 271 | + $addText = wfMsg( "coll-start_add_page_text", $title->getPrefixedText() ); |
| 272 | + } else { |
| 273 | + $params = 'cattitle=' . $cat_title->getPartialURL(); |
| 274 | + $addLinkURL = htmlspecialchars( wfAppendQuery( SkinTemplate::makeSpecialUrlSubpage( |
| 275 | + 'Collection', |
| 276 | + 'add_category/' |
| 277 | + ), $params ) ); |
| 278 | + $addText = wfMsg( "coll-start_add_category_text", $link ); |
| 279 | + } |
| 280 | + $addLinkLabel = wfMsg( "coll-start_add_link", $title->getPrefixedText() ); |
| 281 | + $wgOut->addHTML( <<<EOS |
| 282 | +<table align="center" margin-bottom: 10px;" class="toccolours" width="50%"> |
| 283 | + <tr> |
| 284 | + <td align="center"> |
| 285 | + <a href="$addLinkURL"><strong>$addLinkLabel</strong></a><br/> |
| 286 | + $addText |
| 287 | + </td> |
| 288 | + </tr> |
| 289 | +</table> |
| 290 | +EOS |
| 291 | + ); |
| 292 | + } |
| 293 | + |
| 294 | + $fallback = true; |
| 295 | + $startPageTitle = Title::newFromText( $wgCollectionStartPage ); |
| 296 | + if ( !is_null( $startPageTitle ) ) { |
| 297 | + $startPage = new Article( $startPageTitle ); |
| 298 | + if ( $startPage->exists() ) { |
| 299 | + $wgOut->addWikiText( "{{:$wgCollectionStartPage}}" ); |
| 300 | + $fallback = false; |
| 301 | + } |
| 302 | + } |
| 303 | + if ( $fallback ) { |
| 304 | + $wgOut->addWikiText( wfMsg( 'coll-start_text' ) ); |
| 305 | + } |
| 306 | + |
| 307 | + if ( $title ) { |
| 308 | + $wgOut->addWikiText( wfMsg( 'coll-return_to', $title->getPrefixedText() ) ); |
| 309 | + } else if ( $cat_title ) { |
| 310 | + $wgOut->addWikiText( wfMsg( 'coll-return_to', $cat_title->getPrefixedText() ) ); |
| 311 | + } |
| 312 | + } |
| 313 | + |
247 | 314 | function addArticle( $title, $oldid=0 ) { |
248 | 315 | $article = new Article( $title, $oldid ); |
249 | 316 | $latest = $article->getLatest(); |
— | — | @@ -1056,8 +1123,9 @@ |
1057 | 1124 | // In theory this could be managed properly for open sessions, |
1058 | 1125 | // but you'd have to inject something for non-open sessions or |
1059 | 1126 | // it would be very confusing. |
1060 | | - if( $wgArticle && $wgArticle->exists() ) { |
1061 | | - $bar['COLLECTION'] = self::printPortlet(); |
| 1127 | + $html = self::printPortlet(); |
| 1128 | + if ( $html ) { |
| 1129 | + $bar['COLLECTION'] = $html; |
1062 | 1130 | } |
1063 | 1131 | } |
1064 | 1132 | return true; |
— | — | @@ -1068,14 +1136,17 @@ |
1069 | 1137 | */ |
1070 | 1138 | static function printPortlet() { |
1071 | 1139 | global $wgArticle; |
| 1140 | + global $wgRequest; |
1072 | 1141 | global $wgTitle; |
1073 | 1142 | global $wgOut; |
1074 | 1143 | |
1075 | | - $myTitle = Title::makeTitle( NS_SPECIAL, 'Collection' ); |
1076 | | - if ( $wgTitle->getPrefixedText() == $myTitle->getPrefixedText() ) { |
| 1144 | + // Note: we need to use $wgRequest, b/c there is apparently no way to get |
| 1145 | + // the subpage part of a Special page via $wgTitle. |
| 1146 | + $mainTitle = Title::makeTitle( NS_SPECIAL, 'Collection' ); |
| 1147 | + if ( $wgRequest->getRequestURL() == $mainTitle->getLocalURL() ) { |
1077 | 1148 | return; |
1078 | 1149 | } |
1079 | | - |
| 1150 | + |
1080 | 1151 | wfLoadExtensionMessages( 'Collection' ); |
1081 | 1152 | |
1082 | 1153 | $portletTitle = wfMsgHtml( 'coll-portlet_title' ); |
— | — | @@ -1084,66 +1155,101 @@ |
1085 | 1156 | $addCategory = wfMsgHtml( 'coll-add_category' ); |
1086 | 1157 | $loadCollection = wfMsgHtml( 'coll-load_collection' ); |
1087 | 1158 | $tooBigCat = wfMsgHtml( 'coll-too_big_cat' ); |
1088 | | - |
| 1159 | + |
| 1160 | + $numArticles = self::countArticles(); |
| 1161 | + |
1089 | 1162 | $out = "<ul>"; |
1090 | | - if ( is_null( $wgArticle ) || !$wgArticle->exists() ) { |
1091 | | - // no op |
1092 | | - } else if ( self::isCollectionPage( $wgTitle, $wgArticle) ) { |
| 1163 | + |
| 1164 | + if ( self::isCollectionPage( $wgTitle, $wgArticle) ) { |
1093 | 1165 | $params = "colltitle=" . $wgTitle->getPrefixedUrl(); |
1094 | 1166 | $href = htmlspecialchars( wfAppendQuery( SkinTemplate::makeSpecialUrlSubpage( |
1095 | 1167 | 'Collection', |
1096 | 1168 | 'load_collection/' |
1097 | 1169 | ), $params ) ); |
1098 | 1170 | $out .= "<li><a href=\"$href\">$loadCollection</a></li>"; |
1099 | | - } else if ( $wgTitle->getNamespace() == NS_MAIN ) { // TODO: only NS_MAIN? |
1100 | | - $params = "arttitle=" . $wgTitle->getPrefixedUrl() . "&oldid=" . $wgArticle->getOldID(); |
| 1171 | + } else if ( $numArticles == 0) { |
| 1172 | + $startURL = SkinTemplate::makeSpecialUrlSubpage( |
| 1173 | + 'Collection', |
| 1174 | + 'start_collection/' |
| 1175 | + ); |
| 1176 | + if ( $wgRequest->getRequestURL() == $startURL ) { |
| 1177 | + return; |
| 1178 | + } |
| 1179 | + $params = null; |
| 1180 | + if ( !is_null($wgArticle) && $wgArticle->exists() ) { |
| 1181 | + if ( $wgTitle->getNamespace() == NS_MAIN ) { // TODO: only NS_MAIN? |
| 1182 | + $params = "arttitle=" . $wgTitle->getPrefixedUrl() |
| 1183 | + . "&oldid=" . $wgArticle->getOldID(); |
| 1184 | + } else if ( $wgTitle->getNamespace() == NS_CATEGORY ) { |
| 1185 | + $params = "cattitle=" . $wgTitle->getPartialURL(); |
| 1186 | + } |
| 1187 | + } |
| 1188 | + $startURL = SkinTemplate::makeSpecialUrlSubpage( |
| 1189 | + 'Collection', |
| 1190 | + 'start_collection/' |
| 1191 | + ); |
| 1192 | + if ( $params ) { |
| 1193 | + $startURL = wfAppendQuery( $startURL, $params ); |
| 1194 | + } |
| 1195 | + $startURL = htmlspecialchars( $startURL ); |
| 1196 | + $startLabel = 'Start collection'; |
| 1197 | + $out .= "<li><a href=\"$startURL\">$startLabel</a></li>"; |
| 1198 | + } else { |
| 1199 | + |
| 1200 | + // disable caching |
| 1201 | + $wgOut->setSquidMaxage( 0 ); |
| 1202 | + $wgOut->enableClientCache( false ); |
| 1203 | + |
| 1204 | + if ( is_null( $wgArticle ) || !$wgArticle->exists() ) { |
| 1205 | + // no op |
| 1206 | + } else if ( $wgTitle->getNamespace() == NS_MAIN ) { // TODO: only NS_MAIN? |
| 1207 | + $params = "arttitle=" . $wgTitle->getPrefixedUrl() . "&oldid=" . $wgArticle->getOldID(); |
1101 | 1208 | |
1102 | | - if ( self::findArticle( $wgTitle->getPrefixedText(), $wgArticle->getOldID() ) == -1 ) { |
| 1209 | + if ( self::findArticle( $wgTitle->getPrefixedText(), $wgArticle->getOldID() ) == -1 ) { |
| 1210 | + $href = htmlspecialchars( wfAppendQuery( SkinTemplate::makeSpecialUrlSubpage( |
| 1211 | + 'Collection', |
| 1212 | + 'add_article/' |
| 1213 | + ), $params ) ); |
| 1214 | + $out .= "<li><a href=\"$href\">$addArticle</a></li>"; |
| 1215 | + } else { |
| 1216 | + $href = htmlspecialchars( wfAppendQuery( SkinTemplate::makeSpecialUrlSubpage( |
| 1217 | + 'Collection', |
| 1218 | + 'remove_article/' |
| 1219 | + ), $params ) ); |
| 1220 | + $out .= "<li><a href=\"$href\">$removeArticle</a></li>"; |
| 1221 | + } |
| 1222 | + } else if ( $wgTitle->getNamespace() == NS_CATEGORY ) { |
| 1223 | + $params = "cattitle=" . $wgTitle->getPartialURL(); |
1103 | 1224 | $href = htmlspecialchars( wfAppendQuery( SkinTemplate::makeSpecialUrlSubpage( |
1104 | 1225 | 'Collection', |
1105 | | - 'add_article/' |
| 1226 | + 'add_category/' |
1106 | 1227 | ), $params ) ); |
1107 | | - $out .= "<li><a href=\"$href\">$addArticle</a></li>"; |
| 1228 | + $out .= "<li><a href=\"$href\">$addCategory</a></li>"; |
| 1229 | + } |
| 1230 | + |
| 1231 | + if ( $numArticles == 1 ){ |
| 1232 | + $articles = $numArticles . ' ' . wfMsgHtml( 'coll-page' ); |
1108 | 1233 | } else { |
1109 | | - $href = htmlspecialchars( wfAppendQuery( SkinTemplate::makeSpecialUrlSubpage( |
1110 | | - 'Collection', |
1111 | | - 'remove_article/' |
1112 | | - ), $params ) ); |
1113 | | - $out .= "<li><a href=\"$href\">$removeArticle</a></li>"; |
| 1234 | + $articles = $numArticles . ' ' . wfMsgHtml( 'coll-pages' ); |
1114 | 1235 | } |
1115 | | - } else if ( $wgTitle->getNamespace() == NS_CATEGORY ) { |
1116 | | - $params = "cattitle=" . $wgTitle->getPartialURL(); |
1117 | | - $href = htmlspecialchars( wfAppendQuery( SkinTemplate::makeSpecialUrlSubpage( |
1118 | | - 'Collection', |
1119 | | - 'add_category/' |
1120 | | - ), $params ) ); |
1121 | | - $out .= "<li><a href=\"$href\">$addCategory</a></li>"; |
| 1236 | + $showCollection = wfMsgHtml( 'coll-show_collection' ); |
| 1237 | + $showURL = htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Collection') ); |
| 1238 | + $out .= <<<EOS |
| 1239 | + <li><a href="$showURL">$showCollection<br /> |
| 1240 | + ($articles)</a></li> |
| 1241 | +EOS |
| 1242 | + ; |
| 1243 | + $helpCollections = wfMsgHtml( 'coll-help_collections' ); |
| 1244 | + $helpURL = htmlspecialchars( Title::makeTitle( NS_HELP, wfMsgForContent( 'coll-collections' ) )->getFullURL() ); |
| 1245 | + $out .= <<<EOS |
| 1246 | + <li><a href="$helpURL">$helpCollections</a></li> |
| 1247 | +EOS |
| 1248 | + ; |
1122 | 1249 | } |
1123 | | - |
1124 | | - $numArticles = self::countArticles(); |
1125 | | - if ( $numArticles > 0 ) { |
1126 | | - # disable caching |
1127 | | - $wgOut->setSquidMaxage( 0 ); |
1128 | | - $wgOut->enableClientCache( false ); |
1129 | | - } |
1130 | | - if ( $numArticles == 1 ){ |
1131 | | - $articles = $numArticles . ' ' . wfMsgHtml( 'coll-page' ); |
1132 | | - } else { |
1133 | | - $articles = $numArticles . ' ' . wfMsgHtml( 'coll-pages' ); |
1134 | | - } |
1135 | | - $showCollection = wfMsgHtml( 'coll-show_collection' ); |
1136 | | - $showURL = htmlspecialchars( SkinTemplate::makeSpecialUrl( 'Collection') ); |
| 1250 | + |
1137 | 1251 | $out .= <<<EOS |
1138 | | - <li><a href="$showURL">$showCollection<br /> |
1139 | | - ($articles)</a></li> |
1140 | | -EOS |
1141 | | - ; |
1142 | | - $helpCollections = wfMsgHtml( 'coll-help_collections' ); |
1143 | | - $helpURL = htmlspecialchars( Title::makeTitle( NS_HELP, wfMsgForContent( 'coll-collections' ) )->getFullURL() ); |
1144 | | - $out .= <<<EOS |
1145 | | - <li><a href="$helpURL">$helpCollections</a></li> |
1146 | 1252 | </ul> |
1147 | | - <span id="tooBigCategoryText" style="display:none">$tooBigCat</span> |
| 1253 | + <span id="tooBigCategoryText" style="display:none">$tooBigCat</span> |
1148 | 1254 | EOS |
1149 | 1255 | ; |
1150 | 1256 | return $out; |
— | — | @@ -1211,7 +1317,6 @@ |
1212 | 1318 | if ( is_object( $wgTitle ) ) { |
1213 | 1319 | curl_setopt( $c, CURLOPT_REFERER, $wgTitle->getFullURL() ); |
1214 | 1320 | } |
1215 | | - #curl_setopt( $c, CURLOPT_HEADER, true ); |
1216 | 1321 | if ( $timeout ) { |
1217 | 1322 | curl_setopt( $c, CURLOPT_TIMEOUT, $wgHTTPTimeout ); |
1218 | 1323 | } |