r25135 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25134‎ | r25135 | r25136 >
Date:15:23, 25 August 2007
Author:brion
Status:old
Tags:
Comment:
* (bug 11015) Handle HTTP errors for CategoryTree ajax request more gracefully. Instead of dumping the entire error page's HTML inline, display a nice clean bit of text with a functional retry link.
* Added $wgCategoryTreeVersion variable to bump JS and CSS URLs on update
Modified paths:
  • /trunk/extensions/CategoryTree/CategoryTree.i18n.php (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTree.js (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTree.php (modified) (history)
  • /trunk/extensions/CategoryTree/CategoryTreeFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryTree/CategoryTree.php
@@ -51,6 +51,7 @@
5252 $wgCategoryTreeExtPath = '/extensions/CategoryTree';
5353 $wgCategoryTreeDefaultMode = CT_MODE_CATEGORIES;
5454 $wgCategoryTreeCategoryPageMode = CT_MODE_CATEGORIES;
 55+$wgCategoryTreeVersion = '1';
5556
5657 /**
5758 * Register extension setup hook and credits
Index: trunk/extensions/CategoryTree/CategoryTree.i18n.php
@@ -33,6 +33,8 @@
3434 $messages['categorytree-no-subcategories']= 'no subcategories';
3535 $messages['categorytree-no-pages']= 'no pages or subcategories';
3636 $messages['categorytree-not-found']= "Category <i>$1</i> not found";
 37+$messages['categorytree-error'] = 'Problem loading data.';
 38+$messages['categorytree-retry'] = 'Please wait a moment and try again.';
3739
3840 $messages['categorytree-show-list'] = "Show as list";
3941 $messages['categorytree-show-tree'] = "Show as tree";
Index: trunk/extensions/CategoryTree/CategoryTree.js
@@ -8,7 +8,11 @@
99 * @copyright © 2006 Daniel Kinzler
1010 * @licence GNU General Public Licence 2.0 or later
1111 */
12 -
 12+
 13+// Default messages if new code loaded with old cached page
 14+var categoryTreeErrorMsg = "Problem loading data.";
 15+var categoryTreeRetryMsg = "Please wait a moment and try again.";
 16+
1317 function categoryTreeNextDiv(e) {
1418 var n= e.nextSibling;
1519 while ( n && ( n.nodeType != 1 || n.nodeName != 'DIV') ) {
@@ -55,10 +59,19 @@
5660 div.innerHTML= '<i class="CategoryTreeNotice">' + categoryTreeLoadingMsg + '</i>';
5761
5862 function f( request ) {
 63+ if (request.status != 200) {
 64+ div.innerHTML = '<i class="CategoryTreeNotice">' + categoryTreeErrorMsg + ' </i>';
 65+ var retryLink = document.createElement('a');
 66+ retryLink.innerHTML = categoryTreeRetryMsg;
 67+ retryLink.onclick = function() {
 68+ categoryTreeLoadChildren(cat, mode, div);
 69+ }
 70+ div.appendChild(retryLink);
 71+ return;
 72+ }
 73+
5974 result= request.responseText;
6075 result= result.replace(/^\s+|\s+$/, '');
61 -
62 - if (request.status != 200) result= "<div class='error'> " + request.status + " " + request.statusText + ": " + result + "</div>";
6376
6477 if ( result == '' ) {
6578 result= '<i class="CategoryTreeNotice">';
Index: trunk/extensions/CategoryTree/CategoryTreeFunctions.php
@@ -23,7 +23,7 @@
2424 * @param OutputPage $outputPage
2525 */
2626 static function setHeaders( &$outputPage ) {
27 - global $wgJsMimeType, $wgScriptPath, $wgContLang, $wgCategoryTreeExtPath;
 27+ global $wgJsMimeType, $wgScriptPath, $wgContLang, $wgCategoryTreeExtPath, $wgCategoryTreeVersion;
2828 efInjectCategoryTreeMessages();
2929
3030 # Register css file for CategoryTree
@@ -31,7 +31,7 @@
3232 array(
3333 'rel' => 'stylesheet',
3434 'type' => 'text/css',
35 - 'href' => $wgScriptPath . $wgCategoryTreeExtPath . '/CategoryTree.css'
 35+ 'href' => "$wgScriptPath$wgCategoryTreeExtPath/CategoryTree.css?$wgCategoryTreeVersion",
3636 )
3737 );
3838
@@ -41,14 +41,14 @@
4242 array(
4343 'rel' => 'stylesheet',
4444 'type' => 'text/css',
45 - 'href' => $wgScriptPath . $wgCategoryTreeExtPath . '/CategoryTree.rtl.css'
 45+ 'href' => "$wgScriptPath$wgCategoryTreeExtPath/CategoryTree.rtl.css?$wgCategoryTreeVersion"
4646 )
4747 );
4848 }
4949
5050 # Register main js file for CategoryTree
5151 $outputPage->addScript(
52 - "<script type=\"{$wgJsMimeType}\" src=\"{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTree.js\">" .
 52+ "<script type=\"{$wgJsMimeType}\" src=\"{$wgScriptPath}{$wgCategoryTreeExtPath}/CategoryTree.js?{$wgCategoryTreeVersion}\">" .
5353 "</script>\n"
5454 );
5555
@@ -62,6 +62,8 @@
6363 var categoryTreeNothingFoundMsg = \"".Xml::escapeJsString(self::msg('nothing-found'))."\";
6464 var categoryTreeNoSubcategoriesMsg = \"".Xml::escapeJsString(self::msg('no-subcategories'))."\";
6565 var categoryTreeNoPagesMsg = \"".Xml::escapeJsString(self::msg('no-pages'))."\";
 66+ var categoryTreeErrorMsg = \"".Xml::escapeJsString(self::msg('error'))."\";
 67+ var categoryTreeRetryMsg = \"".Xml::escapeJsString(self::msg('retry'))."\";
6668 </script>\n"
6769 );
6870 }

Status & tagging log