r94476 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94475‎ | r94476 | r94477 >
Date:19:54, 14 August 2011
Author:ialex
Status:ok
Tags:
Comment:
Use local context instead of global variables
Modified paths:
  • /trunk/phase3/includes/specials/SpecialLockdb.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUnlockdb.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialLockdb.php
@@ -34,12 +34,10 @@
3535 }
3636
3737 public function execute( $par ) {
38 - global $wgUser, $wgRequest;
39 -
4038 $this->setHeaders();
4139
4240 # Permission check
43 - if( !$this->userCanExecute( $wgUser ) ) {
 41+ if( !$this->userCanExecute( $this->getUser() ) ) {
4442 $this->displayRestrictionError();
4543 return;
4644 }
@@ -49,17 +47,18 @@
5048 # If the lock file isn't writable, we can do sweet bugger all
5149 global $wgReadOnlyFile;
5250 if( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
53 - self::notWritable();
 51+ $this->getOutput()->addWikiMsg( 'lockfilenotwritable' );
5452 return;
5553 }
5654
57 - $action = $wgRequest->getVal( 'action' );
58 - $this->reason = $wgRequest->getVal( 'wpLockReason', '' );
 55+ $request = $this->getRequest();
 56+ $action = $request->getVal( 'action' );
 57+ $this->reason = $request->getVal( 'wpLockReason', '' );
5958
6059 if ( $action == 'success' ) {
6160 $this->showSuccess();
62 - } elseif ( $action == 'submit' && $wgRequest->wasPosted() &&
63 - $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
 61+ } elseif ( $action == 'submit' && $request->wasPosted() &&
 62+ $this->getUser()->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
6463 $this->doSubmit();
6564 } else {
6665 $this->showForm();
@@ -67,16 +66,15 @@
6867 }
6968
7069 private function showForm( $err = '' ) {
71 - global $wgOut, $wgUser;
 70+ $out = $this->getOutput();
 71+ $out->addWikiMsg( 'lockdbtext' );
7272
73 - $wgOut->addWikiMsg( 'lockdbtext' );
74 -
7573 if ( $err != '' ) {
76 - $wgOut->setSubtitle( wfMsg( 'formerror' ) );
77 - $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
 74+ $out->setSubtitle( wfMsg( 'formerror' ) );
 75+ $out->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
7876 }
7977
80 - $wgOut->addHTML(
 78+ $out->addHTML(
8179 Html::openElement( 'form', array( 'id' => 'lockdb', 'method' => 'POST',
8280 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ). "\n" .
8381 wfMsgHtml( 'enterlockreason' ) . ":\n" .
@@ -98,17 +96,16 @@
9997 </td>
10098 </tr>
10199 </table>\n" .
102 - Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
 100+ Html::hidden( 'wpEditToken', $this->getUser()->editToken() ) . "\n" .
103101 Html::closeElement( 'form' )
104102 );
105103
106104 }
107105
108106 private function doSubmit() {
109 - global $wgOut, $wgUser, $wgContLang, $wgRequest;
110 - global $wgReadOnlyFile;
 107+ global $wgContLang, $wgReadOnlyFile;
111108
112 - if ( ! $wgRequest->getCheck( 'wpLockConfirm' ) ) {
 109+ if ( !$this->getRequest()->getCheck( 'wpLockConfirm' ) ) {
113110 $this->showForm( wfMsg( 'locknoconfirm' ) );
114111 return;
115112 }
@@ -121,7 +118,7 @@
122119 # This used to show a file not found error, but the likeliest reason for fopen()
123120 # to fail at this point is insufficient permission to write to the file...good old
124121 # is_writable() is plain wrong in some cases, it seems...
125 - self::notWritable();
 122+ $this->getOutput()->addWikiMsg( 'lockfilenotwritable' );
126123 return;
127124 }
128125 fwrite( $fp, $this->reason );
@@ -129,25 +126,19 @@
130127 fwrite( $fp, "\n<p>" . wfMsgExt(
131128 'lockedbyandtime',
132129 array( 'content', 'parsemag' ),
133 - $wgUser->getName(),
 130+ $this->getUser()->getName(),
134131 $wgContLang->date( $timestamp ),
135132 $wgContLang->time( $timestamp )
136133 ) . "</p>\n" );
137134 fclose( $fp );
138135
139 - $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
 136+ $this->getOutput()->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
140137 }
141138
142139 private function showSuccess() {
143 - global $wgOut;
144 -
145 - $wgOut->setPagetitle( wfMsg( 'lockdb' ) );
146 - $wgOut->setSubtitle( wfMsg( 'lockdbsuccesssub' ) );
147 - $wgOut->addWikiMsg( 'lockdbsuccesstext' );
 140+ $out = $this->getOutput();
 141+ $out->setPagetitle( wfMsg( 'lockdb' ) );
 142+ $out->setSubtitle( wfMsg( 'lockdbsuccesssub' ) );
 143+ $out->addWikiMsg( 'lockdbsuccesstext' );
148144 }
149 -
150 - public static function notWritable() {
151 - global $wgOut;
152 - $wgOut->showErrorPage( 'lockdb', 'lockfilenotwritable' );
153 - }
154145 }
Index: trunk/phase3/includes/specials/SpecialUnlockdb.php
@@ -33,24 +33,23 @@
3434 }
3535
3636 public function execute( $par ) {
37 - global $wgUser, $wgRequest;
38 -
3937 $this->setHeaders();
4038
4139 # Permission check
42 - if( !$this->userCanExecute( $wgUser ) ) {
 40+ if( !$this->userCanExecute( $this->getUser() ) ) {
4341 $this->displayRestrictionError();
4442 return;
4543 }
4644
4745 $this->outputHeader();
4846
49 - $action = $wgRequest->getVal( 'action' );
 47+ $request = $this->getRequest();
 48+ $action = $request->getVal( 'action' );
5049
5150 if ( $action == 'success' ) {
5251 $this->showSuccess();
53 - } elseif ( $action == 'submit' && $wgRequest->wasPosted() &&
54 - $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
 52+ } elseif ( $action == 'submit' && $request->wasPosted() &&
 53+ $this->getUser()->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
5554 $this->doSubmit();
5655 } else {
5756 $this->showForm();
@@ -58,22 +57,23 @@
5958 }
6059
6160 private function showForm( $err = '' ) {
62 - global $wgOut, $wgUser;
63 -
6461 global $wgReadOnlyFile;
 62+
 63+ $out = $this->getOutput();
 64+
6565 if( !file_exists( $wgReadOnlyFile ) ) {
66 - $wgOut->addWikiMsg( 'databasenotlocked' );
 66+ $out->addWikiMsg( 'databasenotlocked' );
6767 return;
6868 }
6969
70 - $wgOut->addWikiMsg( 'unlockdbtext' );
 70+ $out->addWikiMsg( 'unlockdbtext' );
7171
7272 if ( $err != '' ) {
73 - $wgOut->setSubtitle( wfMsg( 'formerror' ) );
74 - $wgOut->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
 73+ $out->setSubtitle( wfMsg( 'formerror' ) );
 74+ $out->addHTML( '<p class="error">' . htmlspecialchars( $err ) . "</p>\n" );
7575 }
7676
77 - $wgOut->addHTML(
 77+ $out->addHTML(
7878 Html::openElement( 'form', array( 'id' => 'unlockdb', 'method' => 'POST',
7979 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) ) . "
8080 <table>
@@ -93,17 +93,16 @@
9494 </td>
9595 </tr>
9696 </table>\n" .
97 - Html::hidden( 'wpEditToken', $wgUser->editToken() ) . "\n" .
 97+ Html::hidden( 'wpEditToken', $this->getUser()->editToken() ) . "\n" .
9898 Html::closeElement( 'form' )
9999 );
100100
101101 }
102102
103103 private function doSubmit() {
104 - global $wgOut, $wgRequest, $wgReadOnlyFile;
 104+ global $wgReadOnlyFile;
105105
106 - $wpLockConfirm = $wgRequest->getCheck( 'wpLockConfirm' );
107 - if ( !$wpLockConfirm ) {
 106+ if ( !$this->getRequest()->getCheck( 'wpLockConfirm' ) ) {
108107 $this->showForm( wfMsg( 'locknoconfirm' ) );
109108 return;
110109 }
@@ -112,18 +111,16 @@
113112 $res = unlink( $wgReadOnlyFile );
114113 wfRestoreWarnings();
115114
116 - if ( !$res ) {
117 - $wgOut->showFileDeleteError( $wgReadOnlyFile );
118 - return;
 115+ if ( $res ) {
 116+ $this->getOutput()->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
 117+ } else {
 118+ $this->getOutput()->addWikiMsg( 'filedeleteerror', $wgReadOnlyFile );
119119 }
120 -
121 - $wgOut->redirect( $this->getTitle()->getFullURL( 'action=success' ) );
122120 }
123121
124122 private function showSuccess() {
125 - global $wgOut;
126 -
127 - $wgOut->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) );
128 - $wgOut->addWikiMsg( 'unlockdbsuccesstext' );
 123+ $out = $this->getOutput();
 124+ $out->setSubtitle( wfMsg( 'unlockdbsuccesssub' ) );
 125+ $out->addWikiMsg( 'unlockdbsuccesstext' );
129126 }
130127 }

Status & tagging log