r44172 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44171‎ | r44172 | r44173 >
Date:14:48, 3 December 2008
Author:werdna
Status:ok (Comments)
Tags:
Comment:
Sexy new JS-based setting search!
Textbox at the top, you enter your query, some voodoo happens, and you get a list of matching settings. Click on a setting, and it opens it up in the view below. Whee!
Modified paths:
  • /trunk/extensions/Configure/Configure.i18n.php (modified) (history)
  • /trunk/extensions/Configure/Configure.js (modified) (history)
  • /trunk/extensions/Configure/Configure.page.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Configure/Configure.page.php
@@ -703,6 +703,7 @@
704704 'id' => 'configure-form' ) ) . "\n" :
705705 Xml::openElement( 'div', array( 'id' => 'configure-form' ) )
706706 ) .
 707+ $this->buildSearchForm() . "\n" .
707708 Xml::openElement( 'div', array( 'id' => 'configure' ) ) . "\n" .
708709 $this->buildAllSettings() . "\n" .
709710 ( $this->mCanEdit ?
@@ -727,6 +728,14 @@
728729 );
729730 $this->injectScriptsAndStyles();
730731 }
 732+
 733+ /** Show a hidden-by-default search form */
 734+ protected function buildSearchForm() {
 735+ $form = wfMsgExt( 'configure-js-search-prompt', 'parseinline' ) . ' ' . Xml::element( 'input', array( 'id' => 'configure-search-input', 'size' => 45 ) );
 736+ $form = Xml::tags( 'p', null, $form ) . "\n" . Xml::element( 'ul', array( 'id' => 'configure-search-results' ) );
 737+ $form = Xml::fieldset( wfMsg( 'configure-js-search-legend' ), $form, array( 'style' => 'display: none;', 'id' => 'configure-search-form' ) );
 738+ return $form;
 739+ }
731740
732741 /**
733742 * Inject JavaScripts and Stylesheets in page output
Index: trunk/extensions/Configure/Configure.i18n.php
@@ -50,6 +50,8 @@
5151 'configure-js-biglist-show' => '[show details]',
5252 'configure-js-biglist-hide' => '[hide details]',
5353 'configure-js-summary-none' => 'No settings',
 54+ 'configure-js-search-legend' => 'Search settings',
 55+ 'configure-js-search-prompt' => 'Query: ',
5456 'configure-no-diff' => 'There are no changes between selected versions.',
5557 'configure-no-directory' => 'The directory used to store the settings, <tt>$1</tt>, does not exist.
5658 Please create it or change it to use this extension.',
Index: trunk/extensions/Configure/Configure.js
@@ -3,6 +3,8 @@
44 * create JavaScript buttons to allow to modify the form to have more
55 * flexibility
66 */
 7+
 8+ var allSettings = undefined;
79
810 function setupConfigure(){
911
@@ -262,7 +264,87 @@
263265 summariseSetting( list, summary );
264266 list.parentNode.insertBefore( summary, list );
265267 }
 268+
 269+ /** Search box initialise */
 270+ buildSearchIndex();
 271+
 272+ // Insert a little search form just before the configuration form
 273+ document.getElementById( 'configure-search-form' ).style.display = 'block';
 274+ addHandler( document.getElementById( 'configure-search-input' ), 'keyup', function() { doSearch( this.value ); } )
266275 }
 276+
 277+function doSearch( query ) {
 278+ query = query.toLowerCase();
 279+
 280+ var results = document.getElementById( 'configure-search-results' );
 281+
 282+ // Empty the existing results
 283+ while(results.firstChild) {
 284+ results.removeChild(results.firstChild);
 285+ }
 286+
 287+ if (query == '') {
 288+ return;
 289+ }
 290+
 291+ var isMatch = function(element) { return element.description.indexOf( query ) !== -1; }
 292+ for( var i=0;i<allSettings.length;++i ) {
 293+ var data = allSettings[i];
 294+ if (isMatch( data )) {
 295+ var a = document.createElement( 'a' );
 296+ var li = document.createElement( 'li' );
 297+
 298+ a.href = '#config-head-'+data.fid+'-'+data.sid;
 299+ addHandler( a, 'click', configToggle );
 300+ a.confSec = data.fid;
 301+ a.confSub = data.sid;
 302+ a.appendChild( document.createTextNode( data.displayDescription ) );
 303+ li.appendChild( a );
 304+
 305+ results.appendChild( li );
 306+ }
 307+ }
 308+}
 309+
 310+function buildSearchIndex() {
 311+ allSettings = [];
 312+
 313+ // For each section...
 314+ var rootElement = document.getElementById( 'configure' );
 315+ var fieldsets = rootElement.getElementsByTagName( 'fieldset' );
 316+ for( var fid=0;fid<fieldsets.length;++fid ) {
 317+ // For each subsection...
 318+ var fieldset = fieldsets[fid];
 319+ var fieldset_title = getInnerText( fieldset.getElementsByTagName( 'legend' )[0] );
 320+ var subsections = getElementsByClassName( fieldset, 'table', 'configure-table' );
 321+ for( var sid=0;sid<subsections.length;++sid ) {
 322+ var subsection = subsections[sid].getElementsByTagName( 'tbody' )[0];
 323+ var heading = document.getElementById( subsection.parentNode.id.replace( 'config-table', 'config-head' ) );
 324+
 325+ // For each setting...
 326+ for( var i=0; i<subsection.childNodes.length;++i ) {
 327+ var row = subsection.childNodes[i];
 328+ if ( row.nodeType != row.ELEMENT_NODE || row.tagName != 'TR' ) {
 329+ continue;
 330+ }
 331+
 332+ var desc_cell = getElementsByClassName( row, 'td', 'configure-left-column' )[0];
 333+
 334+
 335+ var description;
 336+
 337+ if (desc_cell.getElementsByTagName( 'p' ).length) { // Ward off comments like "This setting has been customised"
 338+ description = getInnerText( desc_cell.getElementsByTagName( 'p' )[0] );
 339+ } else {
 340+ description = getInnerText( desc_cell );
 341+ }
 342+
 343+ allSettings.push( { 'description': description.toLowerCase(), 'fid':fid+1, 'sid':sid, 'displayDescription': description } );
 344+ }
 345+ }
 346+ }
 347+}
 348+
267349 // Summarise the setting contained in 'div' to the summary field 'summary'.
268350 function summariseSetting( div, summary ) {
269351 // Empty the existing summary
@@ -592,11 +674,7 @@
593675 var oldsecid = this.parentNode.parentNode.selectedid;
594676 var confSec = this.confSec;
595677 var confSub = this.confSub;
596 - if( confSub == -1 ){
597 - var toc = this.parentNode.parentNode;
598 - } else {
599 - var toc = this.parentNode.parentNode.parentNode.parentNode;
600 - }
 678+ var toc = document.getElementById( 'configtoc' );
601679 var oldSec = toc.confSec;
602680 var oldId = 'config-section-' + oldSec;
603681 document.getElementById( oldId ).style.display = "none";

Comments

#Comment by Aaron Schulz (talk | contribs)   21:27, 3 December 2008

That index functions is pretty messy. It would be nicer to do that in PHP and just export the final var to JS.

#Comment by Brion VIBBER (talk | contribs)   22:25, 3 December 2008

Voodooriffic!

I agree on the index bit, but that's not a blocker. :) Switching from fixme to todo tag.

Status & tagging log