r92636 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92635‎ | r92636 | r92637 >
Date:15:29, 20 July 2011
Author:robin
Status:resolved (Comments)
Tags:
Comment:
Use wfMessage() functions, and rewrite/clean-up showForm() using Html and Xml functions.
Modified paths:
  • /trunk/extensions/Interwiki/Interwiki_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Interwiki/Interwiki_body.php
@@ -17,7 +17,7 @@
1818 * whether the user can modify the data.
1919 */
2020 function getDescription() {
21 - return wfMsg( $this->canModify() ?
 21+ return wfMessage( $this->canModify() ?
2222 'interwiki' : 'interwiki-title-norights' );
2323 }
2424
@@ -42,7 +42,7 @@
4343 case 'edit':
4444 case 'add':
4545 if( $this->canModify( $wgOut ) ) {
46 - $this->showForm( $action );
 46+ $wgOut->addHTML( $this->showForm( $action ) );
4747 }
4848 $wgOut->returnToMain( false, $return );
4949 break;
@@ -72,7 +72,7 @@
7373 global $wgUser, $wgInterwikiCache;
7474 if( !$wgUser->isAllowed( 'interwiki' ) ) {
7575 # Check permissions
76 - if( $out ) { $out->permissionRequired( 'interwiki' ); }
 76+ if( $out ) { throw new PermissionsError( 'interwiki' ); }
7777 return false;
7878 } elseif( $wgInterwikiCache ) {
7979 # Editing the interwiki cache is not supported
@@ -87,101 +87,84 @@
8888 }
8989
9090 function showForm( $action ) {
91 - global $wgRequest, $wgUser, $wgOut;
 91+ global $wgRequest, $wgUser;
9292
93 - $actionUrl = $this->getTitle()->getLocalURL( 'action=submit' );
94 - $token = $wgUser->editToken();
 93+ $prefix = $wgRequest->getVal( 'prefix' );
 94+ $wpPrefix = '';
 95+ $label = array( 'class' => 'mw-label' );
 96+ $input = array( 'class' => 'mw-input' );
9597
96 - switch( $action ) {
97 - case 'delete':
98 -
99 - $prefix = $wgRequest->getVal( 'prefix' );
100 - $button = wfMsg( 'delete' );
101 - $topmessage = wfMsg( 'interwiki_delquestion', $prefix );
102 - $deletingmessage = wfMsgExt( 'interwiki_deleting', array( 'parseinline' ), $prefix );
103 - $reasonmessage = wfMsg( 'deletecomment' );
104 -
105 - $wgOut->addHTML(
106 - Xml::openElement( 'fieldset' ) .
107 - Xml::element( 'legend', null, $topmessage ) .
108 - Xml::openElement( 'form', array( 'id' => 'mw-interwiki-deleteform', 'method' => 'post', 'action' => $actionUrl ) ) .
109 - Xml::openElement( 'table' ) .
110 - "<tr><td colspan='2'>$deletingmessage</td></tr>".
111 - '<tr><td class="mw-label">' . Xml::label( $reasonmessage, 'mw-interwiki-deletereason' ) . '</td>' .
112 - '<td class="mw-input">' .
113 - Xml::input( 'wpInterwikiReason', 60, '', array( 'tabindex' => '1', 'id' => 'mw-interwiki-deletereason', 'maxlength' => '200' ) ) .
114 - '</td></tr>' .
115 - '<tr><td></td><td class="mw-submit">' . Xml::submitButton( $button, array( 'id' => 'mw-interwiki-submit' ) ) .
116 - Html::hidden( 'wpInterwikiPrefix', $prefix ) .
117 - Html::hidden( 'wpInterwikiAction', $action ) .
118 - Html::hidden( 'wpEditToken', $token ) .
119 - '</td></tr>' .
120 - Xml::closeElement( 'table' ) .
121 - Xml::closeElement( 'form' ) .
122 - Xml::closeElement( 'fieldset' )
123 - );
124 - break;
125 - case 'edit':
126 - case 'add':
127 - if( $action == 'edit' ){
128 - $prefix = $wgRequest->getVal( 'prefix' );
129 - $dbr = wfGetDB( DB_SLAVE );
130 - $row = $dbr->selectRow( 'interwiki', '*', array( 'iw_prefix' => $prefix ), __METHOD__ );
131 - if( !$row ) {
132 - $this->error( 'interwiki_editerror', $prefix );
133 - return;
134 - }
135 - $prefix = '<tt>' . htmlspecialchars( $row->iw_prefix ) . '</tt>';
136 - $defaulturl = $row->iw_url;
137 - $trans = $row->iw_trans;
138 - $local = $row->iw_local;
139 - $old = Html::hidden( 'wpInterwikiPrefix', $row->iw_prefix );
140 - $topmessage = wfMsgExt( 'interwiki_edittext', array( 'parseinline' ) );
141 - $intromessage = wfMsgExt( 'interwiki_editintro', array( 'parseinline' ) );
142 - $button = wfMsg( 'edit' );
143 - } else {
144 - $prefix = $wgRequest->getVal( 'wpInterwikiPrefix' ) ? $wgRequest->getVal( 'wpInterwikiPrefix' ) : $wgRequest->getVal( 'prefix' );
145 - $prefix = Xml::input( 'wpInterwikiPrefix', 20, $prefix, array( 'tabindex' => '1', 'id' => 'mw-interwiki-prefix', 'maxlength' => '20' ) );
146 - $local = $wgRequest->getCheck( 'wpInterwikiLocal' );
147 - $trans = $wgRequest->getCheck( 'wpInterwikiTrans' );
148 - $old = '';
149 - $defaulturl = $wgRequest->getVal( 'wpInterwikiURL' ) ? $wgRequest->getVal( 'wpInterwikiURL' ) : wfMsg( 'interwiki-defaulturl' );
150 - $topmessage = wfMsgExt( 'interwiki_addtext', array( 'parseinline' ) );
151 - $intromessage = wfMsgExt( 'interwiki_addintro', array( 'parseinline' ) );
152 - $button = wfMsg( 'interwiki_addbutton' );
 98+ if( $action == 'delete' ) {
 99+ $topmessage = wfMessage( 'interwiki_delquestion', $prefix )->parse();
 100+ $intromessage = wfMessage( 'interwiki_deleting', $prefix )->parse();
 101+ $wpPrefix = Html::hidden( 'wpInterwikiPrefix', $prefix );
 102+ $button = 'delete';
 103+ $formContent = '';
 104+ } elseif( $action == 'edit' ) {
 105+ $dbr = wfGetDB( DB_SLAVE );
 106+ $row = $dbr->selectRow( 'interwiki', '*', array( 'iw_prefix' => $prefix ), __METHOD__ );
 107+ if( !$row ) {
 108+ $this->error( 'interwiki_editerror', $prefix );
 109+ return;
153110 }
 111+ $prefix = $row->iw_prefix;
 112+ $defaulturl = $row->iw_url;
 113+ $trans = $row->iw_trans;
 114+ $local = $row->iw_local;
 115+ $wpPrefix = Html::hidden( 'wpInterwikiPrefix', $row->iw_prefix );
 116+ $topmessage = wfMessage( 'interwiki_edittext' )->parse();
 117+ $intromessage = wfMessage( 'interwiki_editintro' )->parse();
 118+ $button = 'edit';
 119+ } elseif( $action == 'add' ) {
 120+ $prefix = $wgRequest->getVal( 'wpInterwikiPrefix' ) ?
 121+ $wgRequest->getVal( 'wpInterwikiPrefix' ) : $wgRequest->getVal( 'prefix' );
 122+ $prefix = Xml::input( 'wpInterwikiPrefix', 20, $prefix,
 123+ array( 'tabindex' => 1, 'id' => 'mw-interwiki-prefix', 'maxlength' => 20 ) );
 124+ $local = $wgRequest->getCheck( 'wpInterwikiLocal' );
 125+ $trans = $wgRequest->getCheck( 'wpInterwikiTrans' );
 126+ $defaulturl = $wgRequest->getVal( 'wpInterwikiURL' ) ?
 127+ $wgRequest->getVal( 'wpInterwikiURL' ) : wfMessage( 'interwiki-defaulturl' );
 128+ $topmessage = wfMessage( 'interwiki_addtext' )->parse();
 129+ $intromessage = wfMessage( 'interwiki_addintro' )->parse();
 130+ $button = 'interwiki_addbutton';
 131+ }
154132
155 - $prefixmessage = wfMsgHtml( 'interwiki-prefix-label' );
156 - $localmessage = wfMsg( 'interwiki-local-label' );
157 - $transmessage = wfMsg( 'interwiki-trans-label' );
158 - $reasonmessage = wfMsg( 'interwiki_reasonfield' );
159 - $urlmessage = wfMsg( 'interwiki-url-label' );
160 -
161 - $wgOut->addHTML(
162 - Xml::fieldset( $topmessage ) .
163 - $intromessage .
164 - Xml::openElement( 'form', array( 'id' => 'mw-interwiki-editform', 'method' => 'post', 'action' => $actionUrl ) ) .
165 - Xml::openElement( 'table', array( 'id' => "mw-interwiki-$action" ) ) .
166 - "<tr><td class='mw-label'>$prefixmessage</td><td><tt>$prefix</tt></td></tr>" .
167 - '<tr><td class="mw-label">' . Xml::label( $localmessage, 'mw-interwiki-local' ) . '</td>' .
168 - '<td class="mw-input">' . Xml::check( 'wpInterwikiLocal', $local, array( 'id' => 'mw-interwiki-local' ) ) . '</td></tr>' .
169 - '<tr><td class="mw-label">' . Xml::label( $transmessage, 'mw-interwiki-trans' ) . '</td>' .
170 - '<td class="mw-input">' . Xml::check( 'wpInterwikiTrans', $trans, array( 'id' => 'mw-interwiki-trans' ) ) . '</td></tr>' .
171 - '<tr><td class="mw-label">' . Xml::label( $urlmessage, 'mw-interwiki-url' ) . '</td>' .
172 - '<td class="mw-input">' . Xml::input( 'wpInterwikiURL', 60, $defaulturl, array( 'tabindex' => '1', 'maxlength' => '200', 'id' => 'mw-interwiki-url' ) ) . '</td></tr>' .
173 - '<tr><td class="mw-label">' . Xml::label( $reasonmessage, 'mw-interwiki-editreason' ) . '</td>' .
174 - '<td class="mw-input">' . Xml::input( 'wpInterwikiReason', 60, '', array( 'tabindex' => '1', 'id' => 'mw-interwiki-editreason', 'maxlength' => '200' ) ) .
175 - Html::hidden( 'wpInterwikiAction', $action ) .
176 - $old .
177 - Html::hidden( 'wpEditToken', $token ) .
178 - '</td></tr>' .
179 - '<tr><td></td><td class="mw-submit">' . Xml::submitButton( $button, array( 'id' => 'mw-interwiki-submit' ) ) . '</td></tr>' .
180 - Xml::closeElement( 'table' ) .
181 - Xml::closeElement( 'form' ) .
182 - Xml::closeElement( 'fieldset' )
 133+ if( $action == 'add' || $action == 'edit' ) {
 134+ $formContent = Html::rawElement( 'tr', null,
 135+ Html::element( 'td', $label, wfMessage( 'interwiki-prefix-label' ) ) .
 136+ Html::rawElement( 'td', null, '<tt>' . $prefix . '</tt>' )
 137+ ) . Html::rawElement( 'tr', null,
 138+ Html::rawElement( 'td', $label, Xml::label( wfMessage( 'interwiki-local-label' ), 'mw-interwiki-local' ) ) .
 139+ Html::rawElement( 'td', $input, Xml::check( 'wpInterwikiLocal', $local, array( 'id' => 'mw-interwiki-local' ) ) )
 140+ ) . Html::rawElement( 'tr', null,
 141+ Html::rawElement( 'td', $label, Xml::label( wfMessage( 'interwiki-trans-label' ), 'mw-interwiki-trans' ) ) .
 142+ Html::rawElement( 'td', $input, Xml::check( 'wpInterwikiTrans', $trans, array( 'id' => 'mw-interwiki-trans' ) ) )
 143+ ) . Html::rawElement( 'tr', null,
 144+ Html::rawElement( 'td', $label, Xml::label( wfMessage( 'interwiki-url-label' ), 'mw-interwiki-url' ) ) .
 145+ Html::rawElement( 'td', $input, Xml::input( 'wpInterwikiURL', 60, $defaulturl,
 146+ array( 'tabindex' => 1, 'maxlength' => 200, 'id' => 'mw-interwiki-url' ) ) )
183147 );
184 - break;
185148 }
 149+
 150+ return Xml::fieldset( $topmessage, Html::rawElement( 'form',
 151+ array( 'id' => "mw-interwiki-{$action}form", 'method' => 'post',
 152+ 'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ),
 153+ Html::element( 'p', null, $intromessage ) .
 154+ Html::rawElement( 'table', array( 'id' => "mw-interwiki-{$action}" ),
 155+ $formContent . Html::rawElement( 'tr', null,
 156+ Html::rawElement( 'td', $label, Xml::label( wfMessage( 'interwiki_reasonfield' ),
 157+ "mw-interwiki-{$action}reason" ) ) .
 158+ Html::rawElement( 'td', $input, Xml::input( 'wpInterwikiReason', 60, '',
 159+ array( 'tabindex' => 1, 'id' => "mw-interwiki-{$action}reason", 'maxlength' => 200 ) ) )
 160+ ) . Html::rawElement( 'tr', null,
 161+ Html::rawElement( 'td', null, '' ) .
 162+ Html::rawElement( 'td', array( 'class' => 'mw-submit' ),
 163+ Xml::submitButton( wfMessage( $button )->text(), array( 'id' => 'mw-interwiki-submit' ) ) )
 164+ ) . $wpPrefix .
 165+ Html::hidden( 'wpEditToken', $wgUser->editToken() ) .
 166+ Html::hidden( 'wpInterwikiAction', $action )
 167+ )
 168+ ) );
186169 }
187170
188171 function doSubmit() {
@@ -267,7 +250,7 @@
268251 $wgOut->addWikiMsg( 'interwiki_intro_footer' );
269252
270253 if ( $canModify ) {
271 - $addtext = wfMsgHtml( 'interwiki_addtext' );
 254+ $addtext = wfMessage( 'interwiki_addtext' )->escaped();
272255 $addlink = Linker::linkKnown( $this->getTitle( 'add' ), $addtext );
273256 $wgOut->addHTML( '<p class="mw-interwiki-addlink">' . $addlink . '</p>' );
274257 }
@@ -290,11 +273,11 @@
291274 # Output the table header
292275 $out .= Html::openElement( 'table', array( 'class' => 'mw-interwikitable wikitable sortable body' ) ) . "\n";
293276 $out .= Html::openElement( 'tr', array( 'id' => 'interwikitable-header' ) ) .
294 - Html::element( 'th', null, wfMsgHtml( 'interwiki_prefix' ) ) .
295 - Html::element( 'th', null, wfMsgHtml( 'interwiki_url' ) ) .
296 - Html::element( 'th', null, wfMsgHtml( 'interwiki_local' ) ) .
297 - Html::element( 'th', null, wfMsgHtml( 'interwiki_trans' ) ) .
298 - ( $canModify ? Html::element( 'th', array( 'class' => 'unsortable' ), wfMsgHtml( 'interwiki_edit' ) ) : '' );
 277+ Html::element( 'th', null, wfMessage( 'interwiki_prefix' ) ) .
 278+ Html::element( 'th', null, wfMessage( 'interwiki_url' ) ) .
 279+ Html::element( 'th', null, wfMessage( 'interwiki_local' ) ) .
 280+ Html::element( 'th', null, wfMessage( 'interwiki_trans' ) ) .
 281+ ( $canModify ? Html::element( 'th', array( 'class' => 'unsortable' ), wfMessage( 'interwiki_edit' ) ) : '' );
299282 $out .= Html::closeElement( 'tr' ) . "\n";
300283
301284 $selfTitle = $this->getTitle();
@@ -305,15 +288,15 @@
306289 htmlspecialchars( $iwPrefix['iw_prefix'] ) );
307290 $out .= Html::element( 'td', array( 'class' => 'mw-interwikitable-url' ), $iwPrefix['iw_url'] );
308291 $out .= Html::element( 'td', array( 'class' => 'mw-interwikitable-local' ),
309 - ( isset( $iwPrefix['iw_local'] ) ? wfMsgHtml( 'interwiki_' . $iwPrefix['iw_local'] ) : '-' ) );
 292+ ( isset( $iwPrefix['iw_local'] ) ? wfMessage( 'interwiki_' . $iwPrefix['iw_local'] ) : '-' ) );
310293 $out .= Html::element( 'td', array( 'class' => 'mw-interwikitable-trans' ),
311 - ( isset( $iwPrefix['iw_trans'] ) ? wfMsgHtml( 'interwiki_' . $iwPrefix['iw_trans'] ) : '-' ) );
 294+ ( isset( $iwPrefix['iw_trans'] ) ? wfMessage( 'interwiki_' . $iwPrefix['iw_trans'] ) : '-' ) );
312295 if( $canModify ) {
313296 $out .= Html::rawElement( 'td', array( 'class' => 'mw-interwikitable-modify' ),
314 - Linker::linkKnown( $selfTitle, wfMsgHtml( 'edit' ), array(),
 297+ Linker::linkKnown( $selfTitle, wfMessage( 'edit' )->escaped(), array(),
315298 array( 'action' => 'edit', 'prefix' => $iwPrefix['iw_prefix'] ) ) .
316 - wfMsg( 'comma-separator' ) .
317 - Linker::linkKnown( $selfTitle, wfMsgHtml( 'delete' ), array(),
 299+ wfMessage( 'comma-separator' ) .
 300+ Linker::linkKnown( $selfTitle, wfMessage( 'delete' )->escaped(), array(),
318301 array( 'action' => 'delete', 'prefix' => $iwPrefix['iw_prefix'] ) )
319302 );
320303 }
@@ -326,8 +309,8 @@
327310
328311 static function addInfoRow( $align = 'start', $title, $text ) {
329312 return Html::rawElement( 'tr', null,
330 - Html::rawElement( 'th', array( 'class' => 'mw-align-' . $align ), wfMsg( $title ) ) .
331 - Html::rawElement( 'td', null, wfMsgExt( $text, 'parseinline' ) )
 313+ Html::rawElement( 'th', array( 'class' => 'mw-align-' . $align ), wfMessage( $title )->escaped() ) .
 314+ Html::rawElement( 'td', null, wfMessage( $text )->parse() )
332315 );
333316 }
334317

Follow-up revisions

RevisionCommit summaryAuthorDate
r92641fix escaping of r92636.robin16:25, 20 July 2011
r92672fixes for r92636robin19:58, 20 July 2011
r92733getDescription must return a string, fu r92636nikerabbit05:43, 21 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92529* Use interwiki cache (per r92528)...robin12:45, 19 July 2011

Comments

#Comment by Nikerabbit (talk | contribs)   05:40, 21 July 2011

getDescription() must return a string. This breaks Special:SpecialPages.

Status & tagging log