r98143 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98142‎ | r98143 | r98144 >
Date:16:40, 26 September 2011
Author:robin
Status:ok
Tags:
Comment:
Use new logging system and kill all globals (except one config). This 1.19-only, but the trunk version of Interwiki was already compatible only with 1.19.
Modified paths:
  • /trunk/extensions/Interwiki/Interwiki.i18n.php (modified) (history)
  • /trunk/extensions/Interwiki/Interwiki.php (modified) (history)
  • /trunk/extensions/Interwiki/Interwiki_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Interwiki/Interwiki_body.php
@@ -27,35 +27,36 @@
2828 * @param $par Mixed: parameter passed to the page or null
2929 */
3030 public function execute( $par ) {
31 - global $wgRequest, $wgOut, $wgUser;
32 -
3331 $this->setHeaders();
3432 $this->outputHeader();
3533
36 - $wgOut->addModuleStyles( 'SpecialInterwiki' );
 34+ $out = $this->getOutput();
 35+ $request = $this->getRequest();
3736
38 - $action = $par ? $par : $wgRequest->getVal( 'action', $par );
 37+ $out->addModuleStyles( 'SpecialInterwiki' );
 38+
 39+ $action = $par ? $par : $request->getVal( 'action', $par );
3940 $return = $this->getTitle();
4041
4142 switch( $action ) {
4243 case 'delete':
4344 case 'edit':
4445 case 'add':
45 - if( $this->canModify( $wgOut ) ) {
46 - $wgOut->addHTML( $this->showForm( $action ) );
 46+ if( $this->canModify( $out ) ) {
 47+ $out->addHTML( $this->showForm( $action ) );
4748 }
48 - $wgOut->returnToMain( false, $return );
 49+ $out->returnToMain( false, $return );
4950 break;
5051 case 'submit':
51 - if( !$this->canModify( $wgOut ) ) {
 52+ if( !$this->canModify( $out ) ) {
5253 # Error msg added by canModify()
53 - } elseif( !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
 54+ } elseif( !$request->wasPosted() || !$this->getUser()->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
5455 // Prevent cross-site request forgeries
55 - $wgOut->addWikiMsg( 'sessionfailure' );
 56+ $out->addWikiMsg( 'sessionfailure' );
5657 } else {
5758 $this->doSubmit();
5859 }
59 - $wgOut->returnToMain( false, $return );
 60+ $out->returnToMain( false, $return );
6061 break;
6162 default:
6263 $this->showList();
@@ -69,8 +70,8 @@
7071 * @return Boolean
7172 */
7273 public function canModify( $out = false ) {
73 - global $wgUser, $wgInterwikiCache;
74 - if( !$wgUser->isAllowed( 'interwiki' ) ) {
 74+ global $wgInterwikiCache;
 75+ if( !$this->getUser()->isAllowed( 'interwiki' ) ) {
7576 # Check permissions
7677 if( $out ) { throw new PermissionsError( 'interwiki' ); }
7778 return false;
@@ -87,9 +88,9 @@
8889 }
8990
9091 function showForm( $action ) {
91 - global $wgRequest, $wgUser;
 92+ $request = $this->getRequest();
9293
93 - $prefix = $wgRequest->getVal( 'prefix' );
 94+ $prefix = $request->getVal( 'prefix' );
9495 $wpPrefix = '';
9596 $label = array( 'class' => 'mw-label' );
9697 $input = array( 'class' => 'mw-input' );
@@ -116,12 +117,12 @@
117118 $intromessage = wfMessage( 'interwiki_editintro' )->text();
118119 $button = 'edit';
119120 } elseif( $action == 'add' ) {
120 - $prefix = $wgRequest->getVal( 'wpInterwikiPrefix', $wgRequest->getVal( 'prefix' ) );
 121+ $prefix = $request->getVal( 'wpInterwikiPrefix', $request->getVal( 'prefix' ) );
121122 $prefix = Xml::input( 'wpInterwikiPrefix', 20, $prefix,
122123 array( 'tabindex' => 1, 'id' => 'mw-interwiki-prefix', 'maxlength' => 20 ) );
123 - $local = $wgRequest->getCheck( 'wpInterwikiLocal' );
124 - $trans = $wgRequest->getCheck( 'wpInterwikiTrans' );
125 - $defaulturl = $wgRequest->getVal( 'wpInterwikiURL', wfMessage( 'interwiki-defaulturl' )->text() );
 124+ $local = $request->getCheck( 'wpInterwikiLocal' );
 125+ $trans = $request->getCheck( 'wpInterwikiTrans' );
 126+ $defaulturl = $request->getVal( 'wpInterwikiURL', wfMessage( 'interwiki-defaulturl' )->text() );
126127 $topmessage = wfMessage( 'interwiki_addtext' )->text();
127128 $intromessage = wfMessage( 'interwiki_addintro' )->text();
128129 $button = 'interwiki_addbutton';
@@ -159,23 +160,23 @@
160161 Html::rawElement( 'td', array( 'class' => 'mw-submit' ),
161162 Xml::submitButton( wfMessage( $button )->text(), array( 'id' => 'mw-interwiki-submit' ) ) )
162163 ) . $wpPrefix .
163 - Html::hidden( 'wpEditToken', $wgUser->editToken() ) .
 164+ Html::hidden( 'wpEditToken', $this->getUser()->editToken() ) .
164165 Html::hidden( 'wpInterwikiAction', $action )
165166 )
166167 ) );
167168 }
168169
169170 function doSubmit() {
170 - global $wgRequest, $wgOut;
171 - $prefix = $wgRequest->getVal( 'wpInterwikiPrefix' );
172 - $do = $wgRequest->getVal( 'wpInterwikiAction' );
 171+ $request = $this->getRequest();
 172+ $prefix = $request->getVal( 'wpInterwikiPrefix' );
 173+ $do = $request->getVal( 'wpInterwikiAction' );
173174 // show an error if the prefix is invalid (only when adding one)
174175 if( preg_match( '/[\s:&=]/', $prefix ) && $do == 'add' ) {
175176 $this->error( 'interwiki-badprefix', htmlspecialchars( $prefix ) );
176177 $this->showForm( $do );
177178 return;
178179 }
179 - $reason = $wgRequest->getText( 'wpInterwikiReason' );
 180+ $reason = $request->getText( 'wpInterwikiReason' );
180181 $selfTitle = $this->getTitle();
181182 $dbw = wfGetDB( DB_MASTER );
182183 switch( $do ){
@@ -186,16 +187,16 @@
187188 $this->error( 'interwiki_delfailed', $prefix );
188189 $this->showForm( $do );
189190 } else {
190 - $wgOut->addWikiMsg( 'interwiki_deleted', $prefix );
 191+ $this->getOutput()->addWikiMsg( 'interwiki_deleted', $prefix );
191192 $log = new LogPage( 'interwiki' );
192193 $log->addEntry( 'iw_delete', $selfTitle, $reason, array( $prefix ) );
193194 }
194195 break;
195196 case 'edit':
196197 case 'add':
197 - $theurl = $wgRequest->getVal( 'wpInterwikiURL' );
198 - $local = $wgRequest->getCheck( 'wpInterwikiLocal' ) ? 1 : 0;
199 - $trans = $wgRequest->getCheck( 'wpInterwikiTrans' ) ? 1 : 0;
 198+ $theurl = $request->getVal( 'wpInterwikiURL' );
 199+ $local = $request->getCheck( 'wpInterwikiLocal' ) ? 1 : 0;
 200+ $trans = $request->getCheck( 'wpInterwikiTrans' ) ? 1 : 0;
200201 $data = array(
201202 'iw_prefix' => $prefix,
202203 'iw_url' => $theurl,
@@ -219,7 +220,7 @@
220221 $this->error( "interwiki_{$do}failed", $prefix );
221222 $this->showForm( $do );
222223 } else {
223 - $wgOut->addWikiMsg( "interwiki_{$do}ed", $prefix );
 224+ $this->getOutput()->addWikiMsg( "interwiki_{$do}ed", $prefix );
224225 $log = new LogPage( 'interwiki' );
225226 $log->addEntry( 'iw_' . $do, $selfTitle, $reason, array( $prefix, $theurl, $trans, $local ) );
226227 }
@@ -228,12 +229,10 @@
229230 }
230231
231232 function showList() {
232 - global $wgOut;
233 -
234233 $canModify = $this->canModify();
235234
236 - $wgOut->addWikiMsg( 'interwiki_intro' );
237 - $wgOut->addHTML(
 235+ $this->getOutput()->addWikiMsg( 'interwiki_intro' );
 236+ $this->getOutput()->addHTML(
238237 Html::rawElement( 'table', array( 'class' => 'mw-interwikitable wikitable intro' ),
239238 self::addInfoRow( 'start', 'interwiki_prefix', 'interwiki_prefix_intro' ) .
240239 self::addInfoRow( 'start', 'interwiki_url', 'interwiki_url_intro' ) .
@@ -245,12 +244,12 @@
246245 self::addInfoRow( 'end', 'interwiki_1', 'interwiki_local_1_intro' )
247246 ) . "\n"
248247 );
249 - $wgOut->addWikiMsg( 'interwiki_intro_footer' );
 248+ $this->getOutput()->addWikiMsg( 'interwiki_intro_footer' );
250249
251250 if ( $canModify ) {
252251 $addtext = wfMessage( 'interwiki_addtext' )->escaped();
253252 $addlink = Linker::linkKnown( $this->getTitle( 'add' ), $addtext );
254 - $wgOut->addHTML( '<p class="mw-interwiki-addlink">' . $addlink . '</p>' );
 253+ $this->getOutput()->addHTML( '<p class="mw-interwiki-addlink">' . $addlink . '</p>' );
255254 }
256255
257256 if( !method_exists( 'Interwiki', 'getAllPrefixes' ) ) {
@@ -302,7 +301,7 @@
303302 }
304303 $out .= Html::closeElement( 'table' );
305304
306 - $wgOut->addHTML( $out );
 305+ $this->getOutput()->addHTML( $out );
307306 }
308307
309308 static function addInfoRow( $align = 'start', $title, $text ) {
@@ -313,9 +312,21 @@
314313 }
315314
316315 function error() {
317 - global $wgOut;
318316 $args = func_get_args();
319 - $wgOut->wrapWikiMsg( "<p class='error'>$1</p>", $args );
 317+ $this->getOutput()->wrapWikiMsg( "<p class='error'>$1</p>", $args );
320318 }
321319
322320 }
 321+
 322+/**
 323+ * Needed to pass the URL as a raw parameter, because it contains $1
 324+*/
 325+class InterwikiLogFormatter extends LogFormatter {
 326+ protected function getMessageParameters() {
 327+ $params = parent::getMessageParameters();
 328+ if( isset( $params[4] ) ) {
 329+ $params[4] = Message::rawParam( $params[4] );
 330+ }
 331+ return $params;
 332+ }
 333+}
Index: trunk/extensions/Interwiki/Interwiki.i18n.php
@@ -85,11 +85,11 @@
8686
8787 # interwiki log
8888 'interwiki_logpagename' => 'Interwiki table log',
89 - 'interwiki_log_added' => 'added prefix "$2" ($3) (trans: $4) (local: $5) to the interwiki table',
90 - 'interwiki_log_edited' => 'modified prefix "$2" : ($3) (trans: $4) (local: $5) in the interwiki table',
91 - 'interwiki_log_deleted' => 'removed prefix "$2" from the interwiki table',
 89+ 'logentry-interwiki-iw_add' => '$1 {{GENDER:$2|added}} prefix "$4" ($5) (trans: $6; local: $7) to the interwiki table',
 90+ 'logentry-interwiki-iw_edit' => '$1 {{GENDER:$2|modified}} prefix "$4" ($5) (trans: $6; local: $7) in the interwiki table',
 91+ 'logentry-interwiki-iw_delete' => '$1 {{GENDER:$2|removed}} prefix "$4" from the interwiki table',
9292 'interwiki_logpagetext' => 'This is a log of changes to the [[Special:Interwiki|interwiki table]].',
93 - 'interwiki_logentry' => '', # do not translate this message
 93+ 'logentry-interwiki-interwiki' => '', # do not translate this message
9494
9595 # rights
9696 'right-interwiki' => 'Edit interwiki data',
@@ -153,9 +153,9 @@
154154 {{Identical|Add}}',
155155 'interwiki_editerror' => 'Error message when modifying a prefix has failed.',
156156 'interwiki_logpagename' => 'Part of the interwiki extension. This message is shown as page title on Special:Log/interwiki.',
157 - 'interwiki_log_added' => 'Shows up in "Special:Log/interwiki" when someone has added a prefix. Leave parameters and text between brackets exactly as it is. (This message is preceded by the username who added it.)',
158 - 'interwiki_log_edited' => 'Shows up in "Special:Log/interwiki" when someone has modified a prefix. Leave parameters and text between brackets exactly as it is. (This message is preceded by the username of the user who modified it.)',
159 - 'interwiki_log_deleted' => 'Shows up in "Special:Log/interwiki" when someone removed a prefix. This message is preceded by the username of the user who deleted it.',
 157+ 'logentry-interwiki-iw_add' => 'Shows up in "Special:Log/interwiki" when someone has added a prefix. Leave parameters and text between brackets exactly as it is. $1 is the username of the user who added it.',
 158+ 'logentry-interwiki-iw_edit' => 'Shows up in "Special:Log/interwiki" when someone has modified a prefix. Leave parameters and text between brackets exactly as it is. $1 the username of the user who modified it.',
 159+ 'logentry-interwiki-iw_delete' => 'Shows up in "Special:Log/interwiki" when someone removed a prefix. $1 is the username of the user who deleted it.',
160160 'interwiki_logpagetext' => 'Part of the interwiki extension. Summary shown on Special:Log/interwiki.',
161161 'right-interwiki' => '{{doc-right}}',
162162 'action-interwiki' => '{{doc-action}}',
Index: trunk/extensions/Interwiki/Interwiki.php
@@ -52,7 +52,6 @@
5353 $wgLogTypes[] = 'interwiki';
5454 $wgLogNames['interwiki'] = 'interwiki_logpagename';
5555 $wgLogHeaders['interwiki'] = 'interwiki_logpagetext';
56 -$wgLogActions['interwiki/interwiki'] = 'interwiki_logentry';
57 -$wgLogActions['interwiki/iw_add'] = 'interwiki_log_added';
58 -$wgLogActions['interwiki/iw_delete'] = 'interwiki_log_deleted';
59 -$wgLogActions['interwiki/iw_edit'] = 'interwiki_log_edited';
 56+$wgAutoloadClasses['InterwikiLogFormatter'] = $dir . 'Interwiki_body.php';
 57+# interwiki, iw_add, iw_delete, iw_edit
 58+$wgLogActionsHandlers['interwiki/*'] = 'InterwikiLogFormatter';

Status & tagging log