r62310 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62309‎ | r62310 | r62311 >
Date:16:47, 11 February 2010
Author:ialex
Status:deferred
Tags:
Comment:
* restrict Special:InspectCache only to users having inspect cache right (given to sysops)
* fixed possible XSS errors
* removed $wgTitle, now using $this->getTitle()
* removed useless global declarations
* removed unused 'inspectcache-ok' message
* whitespaces fixes
Modified paths:
  • /trunk/extensions/InspectCache/InspectCache.i18n.php (modified) (history)
  • /trunk/extensions/InspectCache/InspectCache.php (modified) (history)
  • /trunk/extensions/InspectCache/InspectCache_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/InspectCache/InspectCache.php
@@ -24,4 +24,9 @@
2525 $wgExtensionMessagesFiles['InspectCache'] = $dir . 'InspectCache.i18n.php';
2626 $wgExtensionAliasesFiles['InspectCache'] = $dir . 'InspectCache.alias.php';
2727 $wgAutoloadClasses['SpecialInspectCache'] = $dir . 'InspectCache_body.php';
 28+
2829 $wgSpecialPages['InspectCache'] = 'SpecialInspectCache';
 30+$wgSpecialPageGroups['InspectCache'] = 'wiki';
 31+
 32+$wgAvailableRights[] = 'inspectcache';
 33+$wgGroupPermissions['sysop']['inspectcache'] = true;
Index: trunk/extensions/InspectCache/InspectCache_body.php
@@ -5,35 +5,37 @@
66 exit(1);
77 }
88
9 -class SpecialInspectCache extends SpecialPage
10 -{
 9+class SpecialInspectCache extends SpecialPage {
1110 function __construct() {
12 - SpecialPage::SpecialPage( 'InspectCache' );
 11+ SpecialPage::SpecialPage( 'InspectCache', 'inspectcache' );
1312 }
1413
1514 function execute( $par ) {
16 - global $wgRequest, $wgOut, $wgTitle, $inspectcacheget, $inspectcachedelete;
 15+ global $wgRequest, $wgOut, $wgUser;
1716
1817 wfLoadExtensionMessages( 'InspectCache' );
1918
20 - $inspectcacheget = wfMsgHtml('inspectcache-get');
21 - $inspectcachedelete = wfMsgHtml('inspectcache-delete');
22 - $inspectcachelist = wfMsgHtml('inspectcache-list');
2319 $this->setHeaders();
2420
 21+ if ( !$this->userCanExecute( $wgUser ) ) {
 22+ $this->displayRestrictionError();
 23+ return;
 24+ }
 25+
 26+ $this->outputHeader();
 27+
2528 $key = $wgRequest->getVal( 'key' );
2629 $delete = $wgRequest->getBool( 'delete' ) && $wgRequest->wasPosted();
2730 $list = $wgRequest->getBool( 'list' );
2831 $group = $wgRequest->getVal( 'group' );
2932
3033 $encQ = htmlspecialchars( $key );
31 - $action = $wgTitle->escapeLocalUrl();
32 - $ok = htmlspecialchars( wfMsg( 'inspectcache-ok' ) );
 34+ $action = $this->getTitle()->escapeLocalUrl();
3335
3436 $groups = array(
35 - 'main' => array( wfMsg('inspectcache-general'), 'wfGetMainCache' ),
36 - 'parser' => array( wfMsg('inspectcache-parser'), 'wfGetParserCacheStorage' ),
37 - 'message' => array( wfMsg('inspectcache-message'), 'wfGetMessageCacheStorage' ),
 37+ 'main' => array( wfMsg( 'inspectcache-general' ), 'wfGetMainCache' ),
 38+ 'parser' => array( wfMsg( 'inspectcache-parser' ), 'wfGetParserCacheStorage' ),
 39+ 'message' => array( wfMsg( 'inspectcache-message' ), 'wfGetMessageCacheStorage' ),
3840 );
3941 if( !isset( $groups[$group] ) ) {
4042 $group = 'main';
@@ -45,16 +47,20 @@
4648 list( $desc ) = $bits;
4749 $radios .=
4850 Xml::radioLabel( $desc, 'group', $type, "mw-cache-$type",
49 - $group == $type ) . " ";
 51+ $group == $type ) . ' ';
5052 }
5153
 54+ $inspectcacheget = wfMsgHtml( 'inspectcache-get' );
 55+ $inspectcachedelete = wfMsgHtml( 'inspectcache-delete' );
 56+ $inspectcachelist = wfMsgHtml( 'inspectcache-list' );
 57+
5258 $wgOut->addHTML( <<<END
5359 <form name="ucf" method="post" action="$action">
5460 <input type="text" size="80" name="key" value="$encQ"/><br />
5561 <div>$radios</div>
56 -<input type="submit" name="submit" value={$inspectcacheget} />
57 -<input type="submit" name="delete" value={$inspectcachedelete} />
58 -<input type="submit" name="list" value={$inspectcachelist} />
 62+<input type="submit" name="submit" value="{$inspectcacheget}" />
 63+<input type="submit" name="delete" value="{$inspectcachedelete}" />
 64+<input type="submit" name="list" value="{$inspectcachelist}" />
5965 <br /><br />
6066 </form>
6167 END
@@ -62,13 +68,13 @@
6369
6470 if ( $delete && !is_null( $key ) ) {
6571 $cache->delete( $key );
66 - $wgOut->addHTML( wfMsg('inspectcache-deleted')."\n" );
 72+ $wgOut->addWikiMsg( 'inspectcache-deleted' );
6773 } else if ( $list ) {
6874 $list = $cache->keys();
6975 $str = "<ul>\n";
7076 foreach( $list as $li ) {
7177 $keyEncoded = urlencode( $li );
72 - $url = $wgTitle->getFullUrl( "key={$keyEncoded}&group={$group}" );
 78+ $url = $this->getTitle()->getFullUrl( "key={$keyEncoded}&group={$group}" );
7379 $urlEncoded = htmlspecialchars( $url );
7480 $liEncoded = htmlspecialchars( $li );
7581 $str .= "<li><a href=\"{$urlEncoded}\">{$liEncoded}</a></li>\n";
@@ -80,7 +86,7 @@
8187 if ( !is_string( $value ) ) {
8288 $value = var_export( $value, true );
8389 }
84 - $wgOut->addHTML( "<pre>" . htmlspecialchars( $value ) . "</pre>" );
 90+ $wgOut->addHTML( '<pre>' . htmlspecialchars( $value ) . '</pre>' );
8591 }
8692 }
8793 }
Index: trunk/extensions/InspectCache/InspectCache.i18n.php
@@ -10,7 +10,6 @@
1111 $messages['en'] = array(
1212 'inspectcache' => 'Inspect cache',
1313 'inspectcache-desc' => 'A simple debugging tool to inspect the contents of the shared cache',
14 - 'inspectcache-ok' => 'OK',
1514 'inspectcache-general' => 'General cache',
1615 'inspectcache-parser' => 'Parser cache',
1716 'inspectcache-message' => 'Message cache',
@@ -18,6 +17,7 @@
1918 'inspectcache-delete' => 'Delete',
2019 'inspectcache-deleted' => 'Deleted cache',
2120 'inspectcache-list' => 'List',
 21+ 'right-inspectcache' => 'View and delete cache entries',
2222 );
2323
2424 /** Message documentation (Message documentation)

Status & tagging log