r38905 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38904‎ | r38905 | r38906 >
Date:15:20, 8 August 2008
Author:jojo
Status:old
Tags:
Comment:
added "Start collection" feature as preparation to solve the caching issue of the navbar
Modified paths:
  • /trunk/extensions/Collection/Collection.body.php (modified) (history)
  • /trunk/extensions/Collection/Collection.i18n.php (modified) (history)
  • /trunk/extensions/Collection/Collection.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Collection/Collection.i18n.php
@@ -25,6 +25,7 @@
2626
2727 $messages['en'] = array(
2828 'coll-desc' => '[[Special:Collection|Collect pages]], generate PDFs',
 29+ 'coll-collection' => 'Collection',
2930 'coll-collections' => 'Collections',
3031 'coll-portlet_title' => 'My collection',
3132 'coll-add_page' => 'Add page',
@@ -121,6 +122,17 @@
122123 'coll-invalid_podpartner_msg' => 'The supplied POD partner is invalid.
123124 Please contact your MediaWiki administrator.',
124125 '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]]",
125137 );
126138
127139 /** Faeag Rotuma (Faeag Rotuma)
Index: trunk/extensions/Collection/Collection.php
@@ -37,6 +37,9 @@
3838
3939 # Configuration:
4040
 41+/** Title of Start Collection page */
 42+$wgCollectionStartPage = 'Start collection';
 43+
4144 /** URL of PDF server */
4245 $wgCollectionMWServeURL = 'http://tools.pediapress.com/mw-serve/';
4346
Index: trunk/extensions/Collection/Collection.body.php
@@ -41,7 +41,7 @@
4242 function getDescription() {
4343 return wfMsg( 'coll-collection' );
4444 }
45 -
 45+
4646 function execute( $par ) {
4747 global $wgOut;
4848 global $wgRequest;
@@ -54,8 +54,16 @@
5555 global $wgCollectionVersion;
5656
5757 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/' ) {
6068 if ( self::countArticles() >= $wgCollectionMaxArticles ) {
6169 $this->limitExceeded();
6270 return;
@@ -243,6 +251,65 @@
244252 return -1;
245253 }
246254
 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+
247314 function addArticle( $title, $oldid=0 ) {
248315 $article = new Article( $title, $oldid );
249316 $latest = $article->getLatest();
@@ -1056,8 +1123,9 @@
10571124 // In theory this could be managed properly for open sessions,
10581125 // but you'd have to inject something for non-open sessions or
10591126 // 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;
10621130 }
10631131 }
10641132 return true;
@@ -1068,14 +1136,17 @@
10691137 */
10701138 static function printPortlet() {
10711139 global $wgArticle;
 1140+ global $wgRequest;
10721141 global $wgTitle;
10731142 global $wgOut;
10741143
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() ) {
10771148 return;
10781149 }
1079 -
 1150+
10801151 wfLoadExtensionMessages( 'Collection' );
10811152
10821153 $portletTitle = wfMsgHtml( 'coll-portlet_title' );
@@ -1084,66 +1155,101 @@
10851156 $addCategory = wfMsgHtml( 'coll-add_category' );
10861157 $loadCollection = wfMsgHtml( 'coll-load_collection' );
10871158 $tooBigCat = wfMsgHtml( 'coll-too_big_cat' );
1088 -
 1159+
 1160+ $numArticles = self::countArticles();
 1161+
10891162 $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) ) {
10931165 $params = "colltitle=" . $wgTitle->getPrefixedUrl();
10941166 $href = htmlspecialchars( wfAppendQuery( SkinTemplate::makeSpecialUrlSubpage(
10951167 'Collection',
10961168 'load_collection/'
10971169 ), $params ) );
10981170 $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();
11011208
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();
11031224 $href = htmlspecialchars( wfAppendQuery( SkinTemplate::makeSpecialUrlSubpage(
11041225 'Collection',
1105 - 'add_article/'
 1226+ 'add_category/'
11061227 ), $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' );
11081233 } 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' );
11141235 }
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+ ;
11221249 }
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+
11371251 $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>
11461252 </ul>
1147 - <span id="tooBigCategoryText" style="display:none">$tooBigCat</span>
 1253+ <span id="tooBigCategoryText" style="display:none">$tooBigCat</span>
11481254 EOS
11491255 ;
11501256 return $out;
@@ -1211,7 +1317,6 @@
12121318 if ( is_object( $wgTitle ) ) {
12131319 curl_setopt( $c, CURLOPT_REFERER, $wgTitle->getFullURL() );
12141320 }
1215 - #curl_setopt( $c, CURLOPT_HEADER, true );
12161321 if ( $timeout ) {
12171322 curl_setopt( $c, CURLOPT_TIMEOUT, $wgHTTPTimeout );
12181323 }

Status & tagging log