r96127 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96126‎ | r96127 | r96128 >
Date:16:59, 2 September 2011
Author:ialex
Status:ok
Tags:
Comment:
Use local context instead of global variables
Modified paths:
  • /trunk/phase3/includes/specials/SpecialExport.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialExport.php
@@ -38,9 +38,8 @@
3939 }
4040
4141 public function execute( $par ) {
42 - global $wgOut, $wgRequest, $wgSitename, $wgExportAllowListContributors;
 42+ global $wgSitename, $wgExportAllowListContributors, $wgExportFromNamespaces;
4343 global $wgExportAllowHistory, $wgExportMaxHistory, $wgExportMaxLinkDepth;
44 - global $wgExportFromNamespaces;
4544
4645 $this->setHeaders();
4746 $this->outputHeader();
@@ -48,16 +47,17 @@
4948 // Set some variables
5049 $this->curonly = true;
5150 $this->doExport = false;
52 - $this->templates = $wgRequest->getCheck( 'templates' );
53 - $this->images = $wgRequest->getCheck( 'images' ); // Doesn't do anything yet
 51+ $request = $this->getRequest();
 52+ $this->templates = $request->getCheck( 'templates' );
 53+ $this->images = $request->getCheck( 'images' ); // Doesn't do anything yet
5454 $this->pageLinkDepth = $this->validateLinkDepth(
55 - $wgRequest->getIntOrNull( 'pagelink-depth' )
 55+ $request->getIntOrNull( 'pagelink-depth' )
5656 );
5757 $nsindex = '';
5858
59 - if ( $wgRequest->getCheck( 'addcat' ) ) {
60 - $page = $wgRequest->getText( 'pages' );
61 - $catname = $wgRequest->getText( 'catname' );
 59+ if ( $request->getCheck( 'addcat' ) ) {
 60+ $page = $request->getText( 'pages' );
 61+ $catname = $request->getText( 'catname' );
6262
6363 if ( $catname !== '' && $catname !== null && $catname !== false ) {
6464 $t = Title::makeTitleSafe( NS_MAIN, $catname );
@@ -74,9 +74,9 @@
7575 }
7676 }
7777 }
78 - elseif( $wgRequest->getCheck( 'addns' ) && $wgExportFromNamespaces ) {
79 - $page = $wgRequest->getText( 'pages' );
80 - $nsindex = $wgRequest->getText( 'nsindex', '' );
 78+ elseif( $request->getCheck( 'addns' ) && $wgExportFromNamespaces ) {
 79+ $page = $request->getText( 'pages' );
 80+ $nsindex = $request->getText( 'nsindex', '' );
8181
8282 if ( strval( $nsindex ) !== '' ) {
8383 /**
@@ -88,10 +88,10 @@
8989 }
9090 }
9191 }
92 - elseif( $wgRequest->wasPosted() && $par == '' ) {
93 - $page = $wgRequest->getText( 'pages' );
94 - $this->curonly = $wgRequest->getCheck( 'curonly' );
95 - $rawOffset = $wgRequest->getVal( 'offset' );
 92+ elseif( $request->wasPosted() && $par == '' ) {
 93+ $page = $request->getText( 'pages' );
 94+ $this->curonly = $request->getCheck( 'curonly' );
 95+ $rawOffset = $request->getVal( 'offset' );
9696
9797 if( $rawOffset ) {
9898 $offset = wfTimestamp( TS_MW, $rawOffset );
@@ -99,14 +99,14 @@
100100 $offset = null;
101101 }
102102
103 - $limit = $wgRequest->getInt( 'limit' );
104 - $dir = $wgRequest->getVal( 'dir' );
 103+ $limit = $request->getInt( 'limit' );
 104+ $dir = $request->getVal( 'dir' );
105105 $history = array(
106106 'dir' => 'asc',
107107 'offset' => false,
108108 'limit' => $wgExportMaxHistory,
109109 );
110 - $historyCheck = $wgRequest->getCheck( 'history' );
 110+ $historyCheck = $request->getCheck( 'history' );
111111
112112 if ( $this->curonly ) {
113113 $history = WikiExporter::CURRENT;
@@ -127,8 +127,8 @@
128128 }
129129 } else {
130130 // Default to current-only for GET requests.
131 - $page = $wgRequest->getText( 'pages', $par );
132 - $historyCheck = $wgRequest->getCheck( 'history' );
 131+ $page = $request->getText( 'pages', $par );
 132+ $historyCheck = $request->getCheck( 'history' );
133133
134134 if( $historyCheck ) {
135135 $history = WikiExporter::FULL;
@@ -146,23 +146,23 @@
147147 $history = WikiExporter::CURRENT;
148148 }
149149
150 - $list_authors = $wgRequest->getCheck( 'listauthors' );
 150+ $list_authors = $request->getCheck( 'listauthors' );
151151 if ( !$this->curonly || !$wgExportAllowListContributors ) {
152152 $list_authors = false ;
153153 }
154154
155155 if ( $this->doExport ) {
156 - $wgOut->disable();
 156+ $this->getOutput()->disable();
157157
158158 // Cancel output buffering and gzipping if set
159159 // This should provide safer streaming for pages with history
160160 wfResetOutputBuffers();
161 - $wgRequest->response()->header( "Content-type: application/xml; charset=utf-8" );
 161+ $request->response()->header( "Content-type: application/xml; charset=utf-8" );
162162
163 - if( $wgRequest->getCheck( 'wpDownload' ) ) {
 163+ if( $request->getCheck( 'wpDownload' ) ) {
164164 // Provide a sane filename suggestion
165165 $filename = urlencode( $wgSitename . '-' . wfTimestampNow() . '.xml' );
166 - $wgRequest->response()->header( "Content-disposition: attachment;filename={$filename}" );
 166+ $request->response()->header( "Content-disposition: attachment;filename={$filename}" );
167167 }
168168
169169 $this->doExport( $page, $history, $list_authors );
@@ -170,7 +170,8 @@
171171 return;
172172 }
173173
174 - $wgOut->addWikiMsg( 'exporttext' );
 174+ $out = $this->getOutput();
 175+ $out->addWikiMsg( 'exporttext' );
175176
176177 $form = Xml::openElement( 'form', array( 'method' => 'post',
177178 'action' => $this->getTitle()->getLocalUrl( 'action=submit' ) ) );
@@ -190,17 +191,17 @@
191192 wfMsg( 'exportcuronly' ),
192193 'curonly',
193194 'curonly',
194 - $wgRequest->wasPosted() ? $wgRequest->getCheck( 'curonly' ) : true
 195+ $request->wasPosted() ? $request->getCheck( 'curonly' ) : true
195196 ) . '<br />';
196197 } else {
197 - $wgOut->addHTML( wfMsgExt( 'exportnohistory', 'parse' ) );
 198+ $out->addHTML( wfMsgExt( 'exportnohistory', 'parse' ) );
198199 }
199200
200201 $form .= Xml::checkLabel(
201202 wfMsg( 'export-templates' ),
202203 'templates',
203204 'wpExportTemplates',
204 - $wgRequest->wasPosted() ? $wgRequest->getCheck( 'templates' ) : false
 205+ $request->wasPosted() ? $request->getCheck( 'templates' ) : false
205206 ) . '<br />';
206207
207208 if( $wgExportMaxLinkDepth || $this->userCanOverrideExportDepth() ) {
@@ -212,18 +213,17 @@
213214 wfMsg( 'export-download' ),
214215 'wpDownload',
215216 'wpDownload',
216 - $wgRequest->wasPosted() ? $wgRequest->getCheck( 'wpDownload' ) : true
 217+ $request->wasPosted() ? $request->getCheck( 'wpDownload' ) : true
217218 ) . '<br />';
218219
219220 $form .= Xml::submitButton( wfMsg( 'export-submit' ), Linker::tooltipAndAccesskeyAttribs( 'export' ) );
220221 $form .= Xml::closeElement( 'form' );
221222
222 - $wgOut->addHTML( $form );
 223+ $out->addHTML( $form );
223224 }
224225
225226 private function userCanOverrideExportDepth() {
226 - global $wgUser;
227 - return $wgUser->isAllowed( 'override-export-depth' );
 227+ return $this->getUser()->isAllowed( 'override-export-depth' );
228228 }
229229
230230 /**

Status & tagging log