r102668 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102667‎ | r102668 | r102669 >
Date:17:22, 10 November 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
killed globals
Modified paths:
  • /trunk/extensions/Nuke/Nuke_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Nuke/Nuke_body.php
@@ -7,9 +7,7 @@
88 }
99
1010 public function execute( $par ){
11 - global $wgUser, $wgRequest;
12 -
13 - if( !$this->userCanExecute( $wgUser ) ){
 11+ if( !$this->userCanExecute( $this->getUser() ) ){
1412 $this->displayRestrictionError();
1513 return;
1614 }
@@ -17,15 +15,17 @@
1816 $this->setHeaders();
1917 $this->outputHeader();
2018
21 - $target = trim( $wgRequest->getText( 'target', $par ) );
 19+ $req = $this->getRequest();
2220
 21+ $target = trim( $req->getText( 'target', $par ) );
 22+
2323 // Normalise name
2424 if ( $target !== '' ) {
2525 $user = User::newFromName( $target );
2626 if ( $user ) $target = $user->getName();
2727 }
2828
29 - $reason = $wgRequest->getText(
 29+ $reason = $req->getText(
3030 'wpReason',
3131 wfMsgForContent(
3232 'nuke-defaultreason',
@@ -33,19 +33,18 @@
3434 )
3535 );
3636
37 - if( $wgRequest->wasPosted()
38 - && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
 37+ if( $req->wasPosted()
 38+ && $this->getUser()->matchEditToken( $req->getVal( 'wpEditToken' ) ) ) {
3939
40 -
41 - if ( $wgRequest->getVal( 'action' ) == 'delete' ) {
42 - $pages = $wgRequest->getArray( 'pages' );
 40+ if ( $req->getVal( 'action' ) == 'delete' ) {
 41+ $pages = $req->getArray( 'pages' );
4342
4443 if( $pages ) {
4544 return $this->doDelete( $pages, $reason );
4645 }
4746 }
48 - else if ( $wgRequest->getVal( 'action' ) == 'submit' ) {
49 - $this->listForm( $target, $reason, $wgRequest->getInt( 'limit', 500 ) );
 47+ else if ( $req->getVal( 'action' ) == 'submit' ) {
 48+ $this->listForm( $target, $reason, $req->getInt( 'limit', 500 ) );
5049 }
5150 else {
5251 $this->promptForm();
@@ -55,7 +54,7 @@
5655 $this->promptForm();
5756 }
5857 else {
59 - $this->listForm( $target, $reason, $wgRequest->getInt( 'limit', 500 ) );
 58+ $this->listForm( $target, $reason, $req->getInt( 'limit', 500 ) );
6059 }
6160 }
6261
@@ -63,11 +62,11 @@
6463 * Prompt for a username or IP address.
6564 */
6665 protected function promptForm( $userName = '' ) {
67 - global $wgOut, $wgUser;
 66+ $out = $this->getOutput();
 67+
 68+ $out->addWikiMsg( 'nuke-tools' );
6869
69 - $wgOut->addWikiMsg( 'nuke-tools' );
70 -
71 - $wgOut->addHTML(
 70+ $out->addHTML(
7271 Xml::openElement(
7372 'form',
7473 array(
@@ -88,7 +87,7 @@
8988 . '<td></td>'
9089 . '<td>' . Xml::submitButton( wfMsg( 'nuke-submit-user' ) ) . '</td>'
9190 .'</tr></table>'
92 - . Html::hidden( 'wpEditToken', $wgUser->editToken() )
 91+ . Html::hidden( 'wpEditToken', $this->getUser()->editToken() )
9392 . Xml::closeElement( 'form' )
9493 );
9594 }
@@ -101,25 +100,25 @@
102101 * @param integer $limit
103102 */
104103 protected function listForm( $username, $reason, $limit ) {
105 - global $wgUser, $wgOut, $wgLang;
106 -
 104+ $out = $this->getOutput();
 105+
107106 $pages = $this->getNewPages( $username, $limit );
108107
109108 if( count( $pages ) == 0 ) {
110109 if ( $username === '' ) {
111 - $wgOut->addWikiMsg( 'nuke-nopages-global' );
 110+ $out->addWikiMsg( 'nuke-nopages-global' );
112111 }
113112 else {
114 - $wgOut->addWikiMsg( 'nuke-nopages', $username );
 113+ $out->addWikiMsg( 'nuke-nopages', $username );
115114 }
116115
117116 return $this->promptForm( $username );
118117 }
119118
120119 if ( $username === '' ) {
121 - $wgOut->addWikiMsg( 'nuke-list-multiple' );
 120+ $out->addWikiMsg( 'nuke-list-multiple' );
122121 } else {
123 - $wgOut->addWikiMsg( 'nuke-list', $username );
 122+ $out->addWikiMsg( 'nuke-list', $username );
124123 }
125124
126125 $nuke = $this->getTitle();
@@ -136,15 +135,15 @@
137136 }
138137 </script>
139138 JAVASCRIPT;
140 - $wgOut->addScript( $script );
 139+ $out->addScript( $script );
141140
142 - $wgOut->addHTML(
 141+ $out->addHTML(
143142 Xml::openElement( 'form', array(
144143 'action' => $nuke->getLocalURL( 'action=delete' ),
145144 'method' => 'post',
146145 'name' => 'nukelist')
147146 ) .
148 - Html::hidden( 'wpEditToken', $wgUser->editToken() ) .
 147+ Html::hidden( 'wpEditToken', $this->getUser()->editToken() ) .
149148 Xml::tags( 'p',
150149 null,
151150 Xml::inputLabel(
@@ -159,28 +158,28 @@
160159 wfMsg( 'powersearch-toggleall' ) . '</a>';
161160 $links[] = '<a href="#" onclick="selectPages( false ); return false;">' .
162161 wfMsg( 'powersearch-togglenone' ) . '</a>';
163 - $wgOut->addHTML(
 162+ $out->addHTML(
164163 Xml::tags( 'p',
165164 null,
166 - wfMsg( 'nuke-select', $wgLang->commaList( $links ) )
 165+ wfMsg( 'nuke-select', $this->getLang()->commaList( $links ) )
167166 )
168167 );
169168
170169 // Delete button
171 - $wgOut->addHTML(
 170+ $out->addHTML(
172171 Xml::submitButton( wfMsg( 'nuke-submit-delete' ) )
173172 );
174173
175 - $wgOut->addHTML( '<ul>' );
 174+ $out->addHTML( '<ul>' );
176175
177176 foreach( $pages as $info ) {
178177 list( $title, $edits, $userName ) = $info;
179178 $image = $title->getNamespace() == NS_IMAGE ? wfLocalFile( $title ) : false;
180179 $thumb = $image && $image->exists() ? $image->transform( array( 'width' => 120, 'height' => 120 ), 0 ) : false;
181180
182 - $changes = wfMsgExt( 'nchanges', 'parsemag', $wgLang->formatNum( $edits ) );
 181+ $changes = wfMsgExt( 'nchanges', 'parsemag', $this->getLang()->formatNum( $edits ) );
183182
184 - $wgOut->addHTML( '<li>' .
 183+ $out->addHTML( '<li>' .
185184 Xml::check( 'pages[]', true,
186185 array( 'value' => $title->getPrefixedDbKey() )
187186 ) .
@@ -193,7 +192,7 @@
194193 ")</li>\n" );
195194 }
196195
197 - $wgOut->addHTML(
 196+ $out->addHTML(
198197 "</ul>\n" .
199198 Xml::submitButton( wfMsg( 'nuke-submit-delete' ) ) .
200199 "</form>"
@@ -262,9 +261,8 @@
263262 * @param string $reason
264263 */
265264 protected function doDelete( array $pages, $reason ) {
266 - global $wgOut;
267 -
268265 $res = array();
 266+
269267 foreach( $pages as $page ) {
270268 $title = Title::newFromURL( $page );
271269 $file = $title->getNamespace() == NS_FILE ? wfLocalFile( $title ) : false;
@@ -282,9 +280,9 @@
283281 }
284282 }
285283
286 - $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $res ) . "</li>\n</ul>\n" );
 284+ $this->getOutput()->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $res ) . "</li>\n</ul>\n" );
287285
288 - $wgOut->addWikiMsg( 'nuke-delete-more' );
 286+ $this->getOutput()->addWikiMsg( 'nuke-delete-more' );
289287 }
290288
291289 }

Status & tagging log