Skip to content

Commit

Permalink
Compete jQuery rewrite; also added option to Update or Rebuild the index
Browse files Browse the repository at this point in the history
All JS rewritten to use jQuery
JS code now used revealing module pattern to reduce namespace repetition
Revised the instruction text and layout
New updating status message layout
2 options: Rebuild Index or Update Index only
Revised CSS
  • Loading branch information
MrBertie committed Jan 7, 2012
1 parent 05c9d6f commit 73c6efc
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 144 deletions.
12 changes: 7 additions & 5 deletions admin.php
Expand Up @@ -29,13 +29,15 @@ function handle() {
function html() { function html() {
echo $this->plugin_locale_xhtml('intro'); echo $this->plugin_locale_xhtml('intro');



echo '<div id="plugin__searchindex">'; echo '<div id="plugin__searchindex">';
echo $this->getLang('nojs'); echo '<div class="buttons" id="plugin__searchindex_buttons">' .
'<input type="button" class="button" id="plugin__searchindex_rebuild" value="' . $this->getLang('rebuild') . '"/>' .
'<p>' . $this->getLang('rebuild_tip') . '</p>' .
'<input type="button" class="button" id="plugin__searchindex_update" value="' . $this->getLang('update') . '"/>' .
'<p>' . $this->getLang('update_tip') . '</p>' .
'</div>';
echo '<div class="msg" id="plugin__searchindex_msg"></div>';
echo '</div>'; echo '</div>';

} }


} }
//Setup VIM: ex: et ts=4 enc=utf-8 : //Setup VIM: ex: et ts=4 enc=utf-8 :
4 changes: 2 additions & 2 deletions ajax.php
Expand Up @@ -125,14 +125,14 @@ function ajax_indexpage(){
} }


// do the work // do the work
idx_addPage($_POST['page'], false, true); $success = idx_addPage($_POST['page'], false, false);


// we're finished // we're finished
if(INDEXER_VERSION < 4){ if(INDEXER_VERSION < 4){
io_saveFile(metaFN($id,'.indexed'),''); io_saveFile(metaFN($id,'.indexed'),'');
@rmdir($lock); @rmdir($lock);
} }


print 1; print ($success !== false) ? 1 : 0;
} }


16 changes: 8 additions & 8 deletions lang/en/intro.txt
@@ -1,12 +1,12 @@
====== Searchindex Manager ====== ====== SearchIndex Manager ======


This page allows you to rebuild the index used by the fulltext search. This page allows you to update or rebuild the index used by the full-text search.
This isn't needed generally as the index builds and updates itself while This is generally not needed as the index builds and updates itself as
users browse your wiki. However if you just upgraded, added or removed users browse your wiki. However if you just upgraded, added or removed
a lot of files it may be a good idea to cleanup the the index. a lot of files it may be a good idea to clean up the index.


This manager needs a recent browser as it makes use of modern JavaScript Rebuilding the index **can take a long time**. You should leave the page open
to carry out multiple tasks in the background (using [[wp>AJAX]]).

Rebuilding the index takes a long time. You should leave the page open
until the indexing has finished. until the indexing has finished.

//NOTE: This manager needs a recent browser as it makes use of modern JavaScript
to carry out multiple tasks in the background (using [[wp>AJAX]]).//
12 changes: 7 additions & 5 deletions lang/en/lang.php
Expand Up @@ -5,13 +5,15 @@


$lang['menu'] = 'Searchindex Manager'; $lang['menu'] = 'Searchindex Manager';


$lang['nojs'] = 'JavaScript needs to be enabled to run this plugin'; $lang['update'] = 'Update Index';
$lang['update_tip'] = 'Just update the search index (usually quicker)';
$lang['rebuild'] = 'Rebuild Index';
$lang['rebuild_tip'] = 'Clear then completely rebuild the search index';


$lang['js']['rebuild'] = 'Rebuild Index'; $lang['js']['indexing'] = 'Indexed:';
$lang['js']['indexing'] = 'Now indexing:';
$lang['js']['done'] = 'Finished indexing.'; $lang['js']['done'] = 'Finished indexing.';
$lang['js']['pages'] = '%d pages found.'; $lang['js']['pages'] = '%d pages found.';
$lang['js']['clearing'] = 'Clearing index...'; $lang['js']['clearing'] = 'Clearing index...';
$lang['js']['finding'] = 'Finding pages...'; $lang['js']['finding'] = 'Finding pages...';

$lang['js']['notindexed'] = 'Skipped: Up-to-date';

$lang['js']['indexed'] = 'Updated';
233 changes: 114 additions & 119 deletions script.js
Expand Up @@ -2,155 +2,150 @@
* Javascript for searchindex manager plugin * Javascript for searchindex manager plugin
* *
* @author Andreas Gohr <andi@splitbrain.org> * @author Andreas Gohr <andi@splitbrain.org>
* @author Symon Bent <hendrybadao@gmail.com>
* Complete rewrite using jQuery and revealing module pattern
* Separate update and rebuild options
*/ */


var plugin_searchindex = { var plugin_searchindex = (function() {


// hold some values // public methods/properties
pages: null, var pub = {};
page: null,
sack: null, // private vars
done: 1, var pages = null,
count: 0, page = null,
output: null, url = null,
lang: null, done = 1,
count = 0,
$msg = null,
$buttons = null,
lang = null;


/** /**
* initialize everything * initialize everything
*/ */
init: function(){ pub.init = function() {
plugin_searchindex.output = $('plugin__searchindex'); $msg = jQuery('#plugin__searchindex_msg');
if(!plugin_searchindex.output) return; if( ! $msg) return;

plugin_searchindex.sack = new sack(DOKU_BASE + 'lib/plugins/searchindex/ajax.php');
plugin_searchindex.sack.AjaxFailedAlert = '';
plugin_searchindex.sack.encodeURIString = false;
plugin_searchindex.lang = LANG.plugins.searchindex;


// init interface lang = LANG.plugins.searchindex;
plugin_searchindex.status('<button id="plugin__searchindex_btn" class="button">'+plugin_searchindex.lang.rebuild+'</button>'); url = DOKU_BASE + 'lib/plugins/searchindex/ajax.php';
addEvent($('plugin__searchindex_btn'),'click',plugin_searchindex.go);
},


/** $buttons = jQuery('#plugin__searchindex_buttons');
* Gives textual feedback
*/
status: function(text){
plugin_searchindex.output.innerHTML = text;
},


/** // init interface events
* Callback. jQuery('#plugin__searchindex_update').click(pub.update);
* Executed when the index was cleared. jQuery('#plugin__searchindex_rebuild').click(pub.rebuild);
* Starts the indexing };
*/
cb_clear: function(){
var ok = this.response;
if(ok == 1){
// start indexing
window.setTimeout(plugin_searchindex.index,1000);
}else{
plugin_searchindex.status(ok);
// retry
window.setTimeout(plugin_searchindex.clear,5000);
}
},


/** /**
* Callback. * Gives textual feedback
* Executed when the list of pages came back.
* Starts the index clearing
*/
cb_pages: function(){
var data = this.response;
plugin_searchindex.pages = data.split("\n");
plugin_searchindex.count = plugin_searchindex.pages.length;
plugin_searchindex.status(plugin_searchindex.lang.pages.replace(/%d/,plugin_searchindex.pages.length));

// move the first page from the queue
plugin_searchindex.page = plugin_searchindex.pages.shift();

// start index cleaning
window.setTimeout(plugin_searchindex.clear,1000);
},

/**
* Callback.
* Returned after indexing one page
* Calls the next index run.
*/ */
cb_index: function(){ var message = function(text) {
var ok = this.response; if (text.charAt(0) !== '<') {
var wait = 500; text = '<p>' + text + '</p>'
if(ok == 1){
// next page from queue
plugin_searchindex.page = plugin_searchindex.pages.shift();
plugin_searchindex.done++;
}else{
// something went wrong, show message
plugin_searchindex.status(ok);
wait = 5000;
} }
// next index run $msg.html(text);
window.setTimeout(plugin_searchindex.index,500); };
},


/** /**
* Starts the indexing of a page. * Starts the indexing of a page.
*/ */
index: function(){ var index = function() {
if(plugin_searchindex.page){ if (page) {
plugin_searchindex.status(plugin_searchindex.lang.indexing+' <b>'+plugin_searchindex.page+'</b> ('+plugin_searchindex.done+'/'+plugin_searchindex.count+')'); jQuery.post(url, 'call=indexpage&page=' + encodeURI(page), function(response) {
plugin_searchindex.sack.onCompletion = plugin_searchindex.cb_index; var wait = 250;
plugin_searchindex.sack.URLString = ''; var status = lang.indexed;
plugin_searchindex.sack.runAJAX('call=indexpage&page='+encodeURI(plugin_searchindex.page)); if (response !== 1) {
}else{ // either up-to-date or error: skipped
// we're done status = '<p class="status">' + lang.notindexed + '</p>';
plugin_searchindex.throbber_off(); }
plugin_searchindex.status(plugin_searchindex.lang.done); // next page from queue
page = pages.shift();
done++;

message('<p>' + lang.indexing + ' ' + done + '/' + count + '</p><p class="name">' + page + '</p>' + status);
// next index run
window.setTimeout(index, wait);
});
} else {
finished();
} }
}, };


var finished = function() {
// we're done
throbber_off();
message(lang.done);
window.setTimeout(function() {
message('');
$buttons.show('slow');
}, 3000);
};
/** /**
* Cleans the index * Cleans the index (ready for complete rebuild)
*/ */
clear: function(){ var clear = function() {
plugin_searchindex.status(plugin_searchindex.lang.clearing); message(lang.clearing);
plugin_searchindex.sack.onCompletion = plugin_searchindex.cb_clear; jQuery.post(url, 'call=clearindex', function(response) {
plugin_searchindex.sack.URLString = ''; if (response !== 1) {
plugin_searchindex.sack.runAJAX('call=clearindex'); message(response);
}, // retry

window.setTimeout(clear,5000);
}
});
};

pub.rebuild = function() {
pub.update(true);
};
/** /**
* Starts the whole index rebuild process * Starts the index update
*/ */
go: function(){ pub.update = function(rebuild) {
plugin_searchindex.throbber_on(); rebuild = rebuild || false;
plugin_searchindex.status(plugin_searchindex.lang.finding); $buttons.hide('slow');
plugin_searchindex.sack.onCompletion = plugin_searchindex.cb_pages; throbber_on();
plugin_searchindex.sack.URLString = ''; message(lang.finding);
plugin_searchindex.sack.runAJAX('call=pagelist'); jQuery.post(url, 'call=pagelist', function(response) {
}, if (response != 1) {
pages = response.split("\n");
count = pages.length;
message(lang.pages.replace(/%d/, pages.length));

// move the first page from the queue
page = pages.shift();

// complete index rebuild?
if (rebuild === true) clear();

// start indexing
window.setTimeout(index,1000);
} else {
finished();
}
});
};


/** /**
* add a throbber image * add a throbber image
*/ */
throbber_on: function(){ var throbber_on = function() {
plugin_searchindex.output.style['background-image'] = "url('"+DOKU_BASE+'lib/images/throbber.gif'+"')"; $msg.addClass('updating');
plugin_searchindex.output.style['background-repeat'] = 'no-repeat'; };
},


/** /**
* Stop the throbber * Stop the throbber
*/ */
throbber_off: function(){ var throbber_off = function() {
plugin_searchindex.output.style['background-image'] = 'none'; $msg.removeClass('updating');
} };
};

addInitEvent(function(){
plugin_searchindex.init();
});


// return only public methods/properties
return pub;
})();


//Setup VIM: ex: et ts=4 enc=utf-8 : jQuery(function() {
plugin_searchindex.init();
});

0 comments on commit 73c6efc

Please sign in to comment.