r66794 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66793‎ | r66794 | r66795 >
Date:14:22, 23 May 2010
Author:ialex
Status:deferred
Tags:
Comment:
* Use OutputPage::addScriptFile() and $wgExtensionAssetsPath
* Define hook and ajax function in main file
* Use OutputPage::setVal() instead of hacking $_GET
Modified paths:
  • /trunk/extensions/AjaxQueryPages/AjaxQueryPages.php (modified) (history)
  • /trunk/extensions/AjaxQueryPages/Hooks.php (modified) (history)
  • /trunk/extensions/AjaxQueryPages/Response.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AjaxQueryPages/AjaxQueryPages.php
@@ -14,6 +14,9 @@
1515
1616 $wgExtensionMessagesFiles['AjaxQueryPages'] = $dir . 'AjaxQueryPages.i18n.php';
1717
 18+$wgHooks['AjaxAddScript'][] = 'wfAjaxQueryPagesAddJS';
 19+$wgAjaxExportList[] = 'wfAjaxQueryPages';
 20+
1821 // Load hooks
1922 require_once( $dir . 'Hooks.php' );
2023
Index: trunk/extensions/AjaxQueryPages/Response.php
@@ -2,33 +2,26 @@
33 if ( !defined( 'MEDIAWIKI' ) )
44 die( 1 );
55
6 -// Ajax actions registration
7 -$wgAjaxExportList[] = "wfAjaxQueryPages";
8 -
96 /**
107 * Ajax responder entry point
118 */
129 function wfAjaxQueryPages( $specialpagename, $offset, $limit, $dir = false ) {
 10+ global $wgRequest, $wgOut;
 11+
1312 // Make sure we requested an existing special page
1413 if ( !$spObj = SpecialPage::getPageByAlias( $specialpagename ) ) {
1514 return null;
1615 }
1716
1817 // Alter the GET request.
19 - $_GET['offset'] = $offset;
20 - $_GET['limit'] = (int) $limit;
 18+ $wgRequest->setVal( 'offset', $offset );
 19+ $wgRequest->setVal( 'limit', $limit );
2120
2221 if ( $dir == 'prev' || $dir == 'next' ) {
23 - $_GET['dir'] = $dir ;
24 - } else {
25 - unset( $_GET['dir'] );
 22+ $wgRequest->setVal( 'dir', $dir );
2623 }
27 - // HACK : rebuild the webrequest object so it knows about offset & limit
28 - global $wgRequest ;
29 - $wgRequest->__construct();
3024
3125 $spObj->execute( null );
3226
33 - global $wgOut;
3427 return $wgOut->getHTML();
3528 }
Index: trunk/extensions/AjaxQueryPages/Hooks.php
@@ -2,26 +2,15 @@
33 if ( !defined( 'MEDIAWIKI' ) )
44 die( 1 );
55
6 -// Hooks registration:
7 -global $wgHooks;
8 -$wgHooks['AjaxAddScript'][] = 'wfAjaxQueryPagesAddJS';
9 -
106 // Insert our javascript only for QueryPages
117 function wfAjaxQueryPagesAddJS( $out ) {
12 - global $wgTitle;
13 - if ( $wgTitle->getNamespace() != NS_SPECIAL ) {
14 - return true;
15 - }
16 - global $wgQueryPages;
17 - if ( !$spObj = SpecialPage::getPageByAlias( $wgTitle->getDBkey() )
18 -// or !(isset($wgQueryPages) )
 8+ global $wgExtensionAssetsPath;
 9+
 10+ if ( $out->getTitle()->getNamespace() == NS_SPECIAL &&
 11+ SpecialPage::getPageByAlias( $out->getTitle()->getDBkey() )
1912 ) {
20 - return true;
 13+ $out->addScriptFile( "$wgExtensionAssetsPath/AjaxQueryPages/AjaxQueryPages.js" );
2114 }
2215
23 - global $wgJsMimeType, $wgScriptPath ;
24 - $out->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/AjaxQueryPages/AjaxQueryPages.js\"></script>\n" );
2516 return true;
2617 }
27 -
28 -

Status & tagging log