Index: trunk/extensions/AjaxQueryPages/AjaxQueryPages.js |
— | — | @@ -0,0 +1,54 @@ |
| 2 | +var wgAjaxQueryPages = {}; |
| 3 | + |
| 4 | +wgAjaxQueryPages.onLoad = function() { |
| 5 | + wgAjaxQueryPages.replacelinks( document ); |
| 6 | +} |
| 7 | + |
| 8 | +wgAjaxQueryPages.replacelinks = function( target ) { |
| 9 | + var elsPrev = getElementsByClassName(target, "a", "mw-prevlink"); |
| 10 | + var elsNext = getElementsByClassName(target, "a", "mw-nextlink"); |
| 11 | + var elsNums = getElementsByClassName(target, "a", "mw-numlink"); |
| 12 | + var els = elsPrev.concat( elsNext, elsNums ); |
| 13 | + |
| 14 | + var reoff = /offset=(\d+)/ ; |
| 15 | + var relim = /limit=(\d+)/ ; |
| 16 | + |
| 17 | + var nEls = els.length ; |
| 18 | + for (var i=0; i<nEls;i++) { |
| 19 | + var offset = reoff.exec( els[i].getAttribute("href") )[1]; |
| 20 | + var limit = relim.exec( els[i].getAttribute("href") )[1]; |
| 21 | + |
| 22 | + els[i].setAttribute("href", "javascript:wgAjaxQueryPages.call(" + offset + "," + limit + ")"); |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +wgAjaxQueryPages.call = function( offset, limit) { |
| 27 | + sajax_do_call( |
| 28 | + "wfAjaxQueryPages", |
| 29 | + [wgCanonicalSpecialPageName, offset, limit], |
| 30 | + wgAjaxQueryPages.processResult |
| 31 | + ); |
| 32 | + |
| 33 | +} |
| 34 | + |
| 35 | +html2dom = function( html ) { |
| 36 | + var ret = document.createDocumentFragment(); |
| 37 | + var tmp = document.createElement("div"); |
| 38 | + tmp.innerHTML = html |
| 39 | + |
| 40 | + while( tmp.firstChild ) { |
| 41 | + ret.appendChild( tmp.firstChild ); |
| 42 | + } |
| 43 | + return ret; |
| 44 | +} |
| 45 | + |
| 46 | +wgAjaxQueryPages.processResult = function(request) { |
| 47 | + // convert html to dom, need to merge branches/hashar@21917 to use the responseXML |
| 48 | + var response = html2dom( request.responseText ); |
| 49 | + var spcontent = getElementsByClassName(document, "div", "mw-spcontent"); |
| 50 | + wgAjaxQueryPages.replacelinks( response.firstChild ); |
| 51 | + |
| 52 | + spcontent[0].innerHTML = response.firstChild.innerHTML ; |
| 53 | +} |
| 54 | + |
| 55 | +hookEvent( "load", wgAjaxQueryPages.onLoad ); |
Index: trunk/extensions/AjaxQueryPages/Response.php |
— | — | @@ -0,0 +1,27 @@ |
| 2 | +<?php |
| 3 | +if( !defined( 'MEDIAWIKI' ) ) |
| 4 | + die( 1 ); |
| 5 | + |
| 6 | +// Ajax actions registration |
| 7 | +$wgAjaxExportList[] = "wfAjaxQueryPages"; |
| 8 | + |
| 9 | +/** |
| 10 | + * Ajax responder entry point |
| 11 | + */ |
| 12 | +function wfAjaxQueryPages( $specialpagename, $offset, $limit ) { |
| 13 | + |
| 14 | + // Make sure we requested an existing special page |
| 15 | + if( !$spObj = SpecialPage::getPage( $specialpagename ) ) { |
| 16 | + return null; |
| 17 | + } |
| 18 | + |
| 19 | + // todo check values |
| 20 | + $_REQUEST['offset'] = (int) $offset; |
| 21 | + $_REQUEST['limit'] = (int) $limit; |
| 22 | + |
| 23 | + $spObj->execute( null ); |
| 24 | + |
| 25 | + global $wgOut; |
| 26 | + return $wgOut->getHTML(); |
| 27 | +} |
| 28 | +?> |
Index: trunk/extensions/AjaxQueryPages/Load.php |
— | — | @@ -0,0 +1,26 @@ |
| 2 | +<?php |
| 3 | +// Common credits entries: |
| 4 | +$aqpCredits = array( |
| 5 | + 'name' => 'Ajax Query Pages', |
| 6 | + 'author' => 'Ashar Voultoiz', |
| 7 | +); |
| 8 | + |
| 9 | +// We require 1.11alpha or later: |
| 10 | +if( version_compare( $wgVersion, '1.11alpha', '<' ) ) { |
| 11 | + $wgExtensionCredits['other'][] = $aqpCredits + array( |
| 12 | + 'description' => "Add some AJAX to QueryPages such as [[Special:Shortpages]].<br/>'''Disabled''', requires MediaWiki 1.11alpha or later.", |
| 13 | + ); |
| 14 | +} else { |
| 15 | + $wgExtensionCredits['other'][] = array( |
| 16 | + 'name' => 'Ajax Query Pages', |
| 17 | + 'author' => 'Ashar Voultoiz', |
| 18 | + 'description' => 'Add some AJAX to QueryPages such as [[Special:Shortpages]]', |
| 19 | + ); |
| 20 | + |
| 21 | + // Load hooks |
| 22 | + require_once('extensions/AjaxQueryPages/Hooks.php'); |
| 23 | + |
| 24 | + // Set up AJAX entry point: |
| 25 | + require_once('extensions/AjaxQueryPages/Response.php'); |
| 26 | +} |
| 27 | +?> |
Index: trunk/extensions/AjaxQueryPages/Hooks.php |
— | — | @@ -0,0 +1,23 @@ |
| 2 | +<?php |
| 3 | +if( !defined( 'MEDIAWIKI' ) ) |
| 4 | + die( 1 ); |
| 5 | + |
| 6 | +// Hooks registration: |
| 7 | +global $wgHooks; |
| 8 | +$wgHooks['AjaxAddScript'][] = 'wfAjaxQueryPagesAddJS'; |
| 9 | + |
| 10 | +function wfAjaxQueryPagesAddJS( $out ) { |
| 11 | + global $wgTitle; |
| 12 | + if( $wgTitle->getNamespace() != NS_SPECIAL ) { |
| 13 | + return true; |
| 14 | + } |
| 15 | + if( !$spObj = SpecialPage::getPage( $wgTitle->getDBKey() ) ) { |
| 16 | + return true; |
| 17 | + } |
| 18 | + |
| 19 | + global $wgJsMimeType, $wgScriptPath ; |
| 20 | + $out->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/AjaxQueryPages/AjaxQueryPages.js\"></script>\n" ); |
| 21 | + return true; |
| 22 | +} |
| 23 | + |
| 24 | +?> |