r89898 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89897‎ | r89898 | r89899 >
Date:22:14, 11 June 2011
Author:robin
Status:deferred (Comments)
Tags:
Comment:
Show an error when prefix or URL is empty, instead of adding it.
Various other small fixes, including:
* Show "return to Special:Interwiki" always when on the submit form
* Use nice url Special:Interwiki/add instead of ...&action=add
* Move inline css to css file
Modified paths:
  • /trunk/extensions/Interwiki/Interwiki.css (modified) (history)
  • /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
@@ -38,40 +38,37 @@
3939
4040 $admin = $wgUser->isAllowed( 'interwiki' );
4141 $action = $wgRequest->getVal( 'action', $par );
 42+ $return = SpecialPage::getTitleFor( 'Interwiki' );
4243
4344 switch( $action ) {
4445 case 'delete':
4546 case 'edit':
4647 case 'add':
47 - // Check permissions
4848 if( !$admin ) {
 49+ // Check permissions
4950 $wgOut->permissionRequired( 'interwiki' );
50 - return;
51 - }
52 - // Is the database in read-only mode?
53 - if( wfReadOnly() ) {
 51+ } elseif( wfReadOnly() ) {
 52+ // Is the database in read-only mode?
5453 $wgOut->readOnlyPage();
55 - return;
 54+ } else {
 55+ $this->showForm( $action );
5656 }
57 - $this->showForm( $action );
 57+ $wgOut->returnToMain( false, $return );
5858 break;
5959 case 'submit':
60 - // Check permissions
6160 if( !$admin ) {
 61+ // Check permissions
6262 $wgOut->permissionRequired( 'interwiki' );
63 - return;
64 - }
65 - // Is the database in read-only mode?
66 - if( wfReadOnly() ) {
 63+ } elseif( wfReadOnly() ) {
 64+ // Is the database in read-only mode?
6765 $wgOut->readOnlyPage();
68 - return;
69 - }
70 - // Prevent cross-site request forgeries
71 - if( !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
 66+ } elseif( !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
 67+ // Prevent cross-site request forgeries
7268 $wgOut->addWikiMsg( 'sessionfailure' );
73 - return;
 69+ } else {
 70+ $this->doSubmit();
7471 }
75 - $this->doSubmit();
 72+ $wgOut->returnToMain( false, $return );
7673 break;
7774 default:
7875 $this->showList( $admin );
@@ -99,15 +96,15 @@
10097 Xml::element( 'legend', null, $topmessage ) .
10198 Xml::openElement( 'form', array( 'id' => 'mw-interwiki-deleteform', 'method' => 'post', 'action' => $actionUrl ) ) .
10299 Xml::openElement( 'table' ) .
103 - "<tr><td>$deletingmessage</td></tr>".
 100+ "<tr><td colspan='2'>$deletingmessage</td></tr>".
104101 '<tr><td class="mw-label">' . Xml::label( $reasonmessage, 'mw-interwiki-deletereason' ) . '</td>' .
105102 '<td class="mw-input">' .
106103 Xml::input( 'wpInterwikiReason', 60, '', array( 'tabindex' => '1', 'id' => 'mw-interwiki-deletereason', 'maxlength' => '200' ) ) .
107104 '</td></tr>' .
108105 '<tr><td></td><td class="mw-submit">' . Xml::submitButton( $button, array( 'id' => 'mw-interwiki-submit' ) ) .
109 - Html::Hidden( 'wpInterwikiPrefix', $prefix ) .
110 - Html::Hidden( 'wpInterwikiAction', $action ) .
111 - Html::Hidden( 'wpEditToken', $token ) .
 106+ Html::hidden( 'wpInterwikiPrefix', $prefix ) .
 107+ Html::hidden( 'wpInterwikiAction', $action ) .
 108+ Html::hidden( 'wpEditToken', $token ) .
112109 '</td></tr>' .
113110 Xml::closeElement( 'table' ) .
114111 Xml::closeElement( 'form' ) .
@@ -128,7 +125,7 @@
129126 $defaulturl = $row->iw_url;
130127 $trans = $row->iw_trans;
131128 $local = $row->iw_local;
132 - $old = Html::Hidden( 'wpInterwikiPrefix', $row->iw_prefix );
 129+ $old = Html::hidden( 'wpInterwikiPrefix', $row->iw_prefix );
133130 $topmessage = wfMsgExt( 'interwiki_edittext', array( 'parseinline' ) );
134131 $intromessage = wfMsgExt( 'interwiki_editintro', array( 'parseinline' ) );
135132 $button = wfMsg( 'edit' );
@@ -138,7 +135,7 @@
139136 $local = $wgRequest->getCheck( 'wpInterwikiLocal' );
140137 $trans = $wgRequest->getCheck( 'wpInterwikiTrans' );
141138 $old = '';
142 - $defaulturl = $wgRequest->getVal( 'wpInterwikiURL' ) ? $wgRequest->getVal( 'wpInterwikiURL' ) : wfMsg( 'interwiki_defaulturl' );
 139+ $defaulturl = $wgRequest->getVal( 'wpInterwikiURL' ) ? $wgRequest->getVal( 'wpInterwikiURL' ) : wfMsg( 'interwiki-defaulturl' );
143140 $topmessage = wfMsgExt( 'interwiki_addtext', array( 'parseinline' ) );
144141 $intromessage = wfMsgExt( 'interwiki_addintro', array( 'parseinline' ) );
145142 $button = wfMsg( 'interwiki_addbutton' );
@@ -164,9 +161,9 @@
165162 '<td class="mw-input">' . Xml::input( 'wpInterwikiURL', 60, $defaulturl, array( 'tabindex' => '1', 'maxlength' => '200', 'id' => 'mw-interwiki-url' ) ) . '</td></tr>' .
166163 '<tr><td class="mw-label">' . Xml::label( $reasonmessage, 'mw-interwiki-editreason' ) . '</td>' .
167164 '<td class="mw-input">' . Xml::input( 'wpInterwikiReason', 60, '', array( 'tabindex' => '1', 'id' => 'mw-interwiki-editreason', 'maxlength' => '200' ) ) .
168 - Html::Hidden( 'wpInterwikiAction', $action ) .
 165+ Html::hidden( 'wpInterwikiAction', $action ) .
169166 $old .
170 - Html::Hidden( 'wpEditToken', $token ) .
 167+ Html::hidden( 'wpEditToken', $token ) .
171168 '</td></tr>' .
172169 '<tr><td></td><td class="mw-submit">' . Xml::submitButton( $button, array( 'id' => 'mw-interwiki-submit' ) ) . '</td></tr>' .
173170 Xml::closeElement( 'table' ) .
@@ -199,7 +196,6 @@
200197 $this->showForm( $do );
201198 } else {
202199 $wgOut->addWikiMsg( 'interwiki_deleted', $prefix );
203 - $wgOut->returnToMain( false, $selfTitle );
204200 $log = new LogPage( 'interwiki' );
205201 $log->addEntry( 'iw_delete', $selfTitle, $reason, array( $prefix ) );
206202 }
@@ -215,6 +211,12 @@
216212 'iw_local' => $local,
217213 'iw_trans' => $trans
218214 );
 215+
 216+ if( $prefix == '' || $theurl == '' ) {
 217+ $this->error( 'interwiki-submit-empty' );
 218+ $this->showForm( $do );
 219+ return;
 220+ }
219221
220222 if( $do == 'add' ){
221223 $dbw->insert( 'interwiki', $data, __METHOD__, 'IGNORE' );
@@ -227,7 +229,6 @@
228230 $this->showForm( $do );
229231 } else {
230232 $wgOut->addWikiMsg( "interwiki_{$do}ed", $prefix );
231 - $wgOut->returnToMain( false, $selfTitle );
232233 $log = new LogPage( 'interwiki' );
233234 $log->addEntry( 'iw_' . $do, $selfTitle, $reason, array( $prefix, $theurl, $trans, $local ) );
234235 }
@@ -258,7 +259,7 @@
259260 $message_1 = wfMsgHtml( 'interwiki_1' );
260261
261262 $out = '
262 -<table width="100%" class="mw-interwikitable wikitable intro">
 263+<table class="mw-interwikitable wikitable intro">
263264 <tr><th class="mw-align-left">' . $prefixmessage . '</th><td>' . wfMsgExt( 'interwiki_prefix_intro', 'parseinline' ) . '</td></tr>
264265 <tr><th class="mw-align-left">' . $urlmessage . '</th><td>' . wfMsgExt( 'interwiki_url_intro', 'parseinline' ) . '</td></tr>
265266 <tr><th class="mw-align-left">' . $localmessage . '</th><td>' . wfMsgExt( 'interwiki_local_intro', 'parseinline' ) . '</td></tr>
@@ -272,14 +273,13 @@
273274 $wgOut->addWikiMsg( 'interwiki_intro' );
274275 $wgOut->addHTML( $out );
275276 $wgOut->addWikiMsg( 'interwiki_intro_footer' );
276 - $selfTitle = $this->getTitle();
277277
278278 // Privileged users can add new prefixes
279279 if ( $admin ) {
280280 $skin = $wgUser->getSkin();
281281 $addtext = wfMsgHtml( 'interwiki_addtext' );
282 - $addlink = $skin->link( $selfTitle, $addtext, array(), array( 'action' => 'add' ) );
283 - $wgOut->addHTML( '<p>' . $addlink . '</p>' );
 282+ $addlink = $skin->link( SpecialPage::getTitleFor( 'Interwiki', 'add' ), $addtext );
 283+ $wgOut->addHTML( '<p class="mw-interwiki-addlink">' . $addlink . '</p>' );
284284 }
285285
286286 $dbr = wfGetDB( DB_SLAVE );
@@ -291,8 +291,10 @@
292292 return;
293293 }
294294
 295+ $selfTitle = $this->getTitle();
 296+
295297 $out = "
296 - <table width='100%' class='mw-interwikitable wikitable sortable body'>
 298+ <table class='mw-interwikitable wikitable sortable body'>
297299 <tr id='interwikitable-header'><th>$prefixmessage</th> <th>$urlmessage</th> <th>$localmessage</th> <th>$transmessage</th>";
298300 // Privileged users can modify and delete existing prefixes
299301 if( $admin ) {
Index: trunk/extensions/Interwiki/Interwiki.i18n.php
@@ -46,7 +46,7 @@
4747 'interwiki_trans_intro' => 'If wikitext syntax <code>{<nowiki />{prefix:<i>pagename</i>}}</code> is used, then:',
4848 'interwiki_trans_1_intro' => 'allow transclusion from the foreign wiki, if interwiki transclusions are generally permitted in this wiki,',
4949 'interwiki_trans_0_intro' => 'do not allow it, rather look for a page in the template namespace.',
50 - 'interwiki_intro_footer' => 'See [http://www.mediawiki.org/wiki/Interwiki_table MediaWiki.org] for more information about the interwiki table.
 50+ 'interwiki_intro_footer' => 'See [http://www.mediawiki.org/wiki/Manual:Interwiki_table MediaWiki.org] for more information about the interwiki table.
5151 There is a [[Special:Log/interwiki|log of changes]] to the interwiki table.',
5252 'interwiki_1' => 'yes',
5353 'interwiki_0' => 'no',
@@ -70,16 +70,17 @@
7171 'interwiki_added' => 'Prefix "$1" was successfully added to the interwiki table.',
7272 'interwiki_addfailed' => 'Prefix "$1" could not be added to the interwiki table.
7373 Possibly it already exists in the interwiki table.',
74 - 'interwiki_defaulturl' => 'http://www.example.com/$1', # do not translate or duplicate this message to other languages
 74+ 'interwiki-defaulturl' => 'http://www.example.com/$1', # do not translate or duplicate this message to other languages
7575
7676 # editing a prefix
7777 'interwiki_edittext' => 'Editing an interwiki prefix',
7878 'interwiki_editintro' => 'You are editing an interwiki prefix.
7979 Remember that this can break existing links.',
8080 'interwiki_edited' => 'Prefix "$1" was successfully modified in the interwiki table.',
81 - 'interwiki_editerror' => 'Prefix "$1" can not be modified in the interwiki table.
 81+ 'interwiki_editerror' => 'Prefix "$1" could not be modified in the interwiki table.
8282 Possibly it does not exist.',
8383 'interwiki-badprefix' => 'Specified interwiki prefix "$1" contains invalid characters',
 84+ 'interwiki-submit-empty' => 'The prefix and URL cannot be empty.',
8485
8586 # interwiki log
8687 'interwiki_logpagename' => 'Interwiki table log',
Index: trunk/extensions/Interwiki/Interwiki.php
@@ -9,7 +9,7 @@
1010 * @ingroup Extensions
1111 * @version 1.3
1212 * @author Stephanie Amanda Stevens <phroziac@gmail.com>
13 - * @author SPQRobin <robin_1273@hotmail.com>
 13+ * @author SPQRobin <robinp.1273@gmail.com>
1414 * @copyright Copyright © 2005-2007 Stephanie Amanda Stevens
1515 * @copyright Copyright © 2007 SPQRobin
1616 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
@@ -26,7 +26,7 @@
2727 'path' => __FILE__,
2828 'name' => 'SpecialInterwiki',
2929 'author' => array( 'Stephanie Amanda Stevens', 'SPQRobin', '...' ),
30 - 'version' => '1.3.2',
 30+ 'version' => '1.4.0',
3131 'url' => 'http://www.mediawiki.org/wiki/Extension:SpecialInterwiki',
3232 'descriptionmsg' => 'interwiki-desc',
3333 );
Index: trunk/extensions/Interwiki/Interwiki.css
@@ -1,6 +1,10 @@
22 /**
33 * CSS for Special:Interwiki
44 */
 5+table.mw-interwikitable {
 6+ width: 100%;
 7+}
 8+
59 table.mw-interwikitable.intro th {
610 padding-right: 1.4ex;
711 vertical-align: top;

Sign-offs

UserFlagDate
Nikerabbitinspected13:44, 20 July 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r89924Use $this->getTitle() per comment on r89898.robin11:45, 12 June 2011
r89937Update per r89898robin20:57, 12 June 2011

Comments

#Comment by Nikerabbit (talk | contribs)   07:12, 12 June 2011
- SpecialPage::getTitleFor( 'Interwiki', 'add' )
+ $this->getTitle( 'add' );

Same goes for

+ $return = SpecialPage::getTitleFor( 'Interwiki' );
#Comment by SPQRobin (talk | contribs)   11:46, 12 June 2011

Ah, ok. Done in r89924.

Status & tagging log