r112862 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112861‎ | r112862 | r112863 >
Date:00:40, 2 March 2012
Author:aaron
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.19wmf1/extensions (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/CategoryTree (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/CategoryTree/CategoryTreeFunctions.php (modified) (history)
  • /branches/wmf/1.19wmf1/extensions/CategoryTree/modules/ext.categoryTree.js (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/extensions/CategoryTree/modules/ext.categoryTree.js
@@ -27,7 +27,7 @@
2828 */
2929 handleNode: function( e ) {
3030 var $link = $( this );
31 - if ( $link.data( 'ctState' ) === 'collapsed' ) {
 31+ if ( $link.data( 'ct-state' ) === 'collapsed' ) {
3232 categoryTree.expandNode( $link );
3333 } else {
3434 categoryTree.collapseNode( $link );
@@ -48,9 +48,9 @@
4949 $link
5050 .html( mw.msg( 'categorytree-collapse-bullet' ) )
5151 .attr( 'title', mw.msg( 'categorytree-collapse' ) )
52 - .data( 'ctState', 'expanded' );
 52+ .data( 'ct-state', 'expanded' );
5353
54 - if ( !$link.data( 'ctLoaded' ) ) {
 54+ if ( !$link.data( 'ct-loaded' ) ) {
5555 categoryTree.loadChildren( $link, $children );
5656 }
5757 },
@@ -68,7 +68,7 @@
6969 $link
7070 .html( mw.msg( 'categorytree-expand-bullet' ) )
7171 .attr( 'title', mw.msg( 'categorytree-expand' ) )
72 - .data( 'ctState', 'collapsed' );
 72+ .data( 'ct-state', 'collapsed' );
7373 },
7474
7575 /**
@@ -78,26 +78,55 @@
7979 * @param {jQuery} $children
8080 */
8181 loadChildren: function( $link, $children ) {
82 - $link.data( 'ctLoaded', true );
 82+ var $linkParentCTTag, ctTitle, ctMode, ctOptions;
 83+
 84+ /**
 85+ * Error callback
 86+ */
 87+ function error() {
 88+ var $retryLink;
 89+
 90+ $retryLink = $( '<a>' )
 91+ .text( mw.msg( 'categorytree-retry' ) )
 92+ .attr( 'href', '#' )
 93+ .click( function ( e ) {
 94+ e.preventDefault();
 95+ categoryTree.loadChildren( $link, $children );
 96+ } );
 97+
 98+ $children
 99+ .text( mw.msg( 'categorytree-error' ) + ' ' )
 100+ .append( $retryLink );
 101+ }
 102+
 103+ $link.data( 'ct-loaded', true );
 104+
83105 $children.html(
84106 $( '<i class="CategoryTreeNotice"></i>' )
85107 .text( mw.msg( 'categorytree-loading' ) )
86108 );
87109
88 - var $parentTag = $link.parents( '.CategoryTreeTag' );
 110+ $linkParentCTTag = $link.parents( '.CategoryTreeTag' );
89111
90 - if ( $parentTag.length === 0 ) {
91 - // Probably a CategoryPage
92 - $parentTag = $( '<div />' )
93 - .hide()
94 - .data( 'ctOptions', mw.config.get( 'wgCategoryTreePageCategoryOptions' ) );
 112+ // Element may not have a .CategoryTreeTag parent, fallback to defauls
 113+ // Probably a CategoryPage (@todo: based on what?)
 114+ ctTitle = $link.data( 'ct-title' );
 115+ ctMode = $linkParentCTTag.data( 'ct-mode' );
 116+ ctMode = typeof ctMode === 'number' ? ctMode : undefined;
 117+ ctOptions = $linkParentCTTag.data( 'ct-options' ) || mw.config.get( 'wgCategoryTreePageCategoryOptions' );
 118+
 119+ // Mode and options have defaults or fallbacks, title does not.
 120+ // Don't make a request if there is no title.
 121+ if ( typeof ctTitle !== 'string' ) {
 122+ error();
 123+ return;
95124 }
96125
97126 $.get(
98127 mw.util.wikiScript(), {
99128 action: 'ajax',
100129 rs: 'efCategoryTreeAjaxWrapper',
101 - rsargs: [$link.data( 'ctTitle' ), $parentTag.data( 'ctOptions' ), 'json'] // becomes &rsargs[]=arg1&rsargs[]=arg2...
 130+ rsargs: [ctTitle, ctOptions, 'json'] // becomes &rsargs[]=arg1&rsargs[]=arg2...
102131 }
103132 )
104133 .success( function ( data ) {
@@ -105,16 +134,20 @@
106135 data = data.replace(/##LOAD##/g, mw.msg( 'categorytree-expand' ) );
107136
108137 if ( data === '' ) {
109 - switch ( $parentTag.data( 'ctMode' ) ) {
 138+ switch ( ctMode ) {
 139+ // CT_MODE_CATEGORIES = 0
110140 case 0:
111141 data = mw.msg( 'categorytree-no-subcategories' );
112142 break;
 143+ // CT_MODE_PAGES = 10
113144 case 10:
114145 data = mw.msg( 'categorytree-no-pages' );
115146 break;
 147+ // CT_MODE_PARENTS = 100
116148 case 100:
117149 data = mw.msg( 'categorytree-no-parent-categories' );
118150 break;
 151+ // CT_MODE_ALL = 20
119152 default:
120153 data = mw.msg( 'categorytree-nothing-found' );
121154 }
@@ -126,17 +159,10 @@
127160 .html( data )
128161 .find( '.CategoryTreeToggle' )
129162 .click( categoryTree.handleNode );
 163+
130164 categoryTree.showToggles();
131165 } )
132 - .error( function() {
133 - var $retryLink = $( '<a />' )
134 - .text( mw.msg( 'categorytree-retry' ) )
135 - .attr( 'href', '#' )
136 - .click( function() { categoryTree.loadChildren( $link, $children ); } );
137 - $children
138 - .text( mw.msg( 'categorytree-error' ) )
139 - .append( $retryLink );
140 - } );
 166+ .error( error );
141167 }
142168 };
143169
Index: branches/wmf/1.19wmf1/extensions/CategoryTree/CategoryTreeFunctions.php
@@ -315,19 +315,19 @@
316316 }
317317
318318 $attr['data-ct-mode'] = $this->mOptions['mode'];
319 - $attr['data-ct-options'] = Xml::escapeTagsOnly( $this->getOptionsAsJsStructure() );
 319+ $attr['data-ct-options'] = $this->getOptionsAsJsStructure();
320320
321321 $html = '';
322 - $html .= Xml::openElement( 'div', $attr );
 322+ $html .= Html::openElement( 'div', $attr );
323323
324324 if ( !$allowMissing && !$title->getArticleID() ) {
325 - $html .= Xml::openElement( 'span', array( 'class' => 'CategoryTreeNotice' ) );
 325+ $html .= Html::openElement( 'span', array( 'class' => 'CategoryTreeNotice' ) );
326326 if ( $parser ) {
327327 $html .= $parser->recursiveTagParse( wfMsgNoTrans( 'categorytree-not-found', $category ) );
328328 } else {
329329 $html .= wfMsgExt( 'categorytree-not-found', 'parseinline', htmlspecialchars( $category ) );
330330 }
331 - $html .= Xml::closeElement( 'span' );
 331+ $html .= Html::closeElement( 'span' );
332332 }
333333 else {
334334 if ( !$hideroot ) {
Property changes on: branches/wmf/1.19wmf1/extensions/CategoryTree/CategoryTreeFunctions.php
___________________________________________________________________
Modified: svn:mergeinfo
335335 Merged /trunk/extensions/CategoryTree/CategoryTreeFunctions.php:r112856,112859
Property changes on: branches/wmf/1.19wmf1/extensions/CategoryTree
___________________________________________________________________
Modified: svn:mergeinfo
336336 Merged /trunk/extensions/CategoryTree:r112849,112851,112856,112859
Property changes on: branches/wmf/1.19wmf1/extensions
___________________________________________________________________
Modified: svn:mergeinfo
337337 Merged /trunk/extensions:r112849,112851,112856,112859

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r112849[CategoryTree] clean up JS, fix undefined bug...krinkle23:04, 1 March 2012
r112851[CategoryTree] clean up JS...krinkle23:43, 1 March 2012
r112856[CategoryTree] Fix "bad json errors on options= {&quot;:" that are populating...krinkle00:18, 2 March 2012
r112859[CategoryTree]...krinkle00:31, 2 March 2012

Status & tagging log