r98876 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98875‎ | r98876 | r98877 >
Date:17:46, 4 October 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
[RL2] Address r98729 CR (Title::makeSafeTitle possibly returning null)
* Wasn't sure whether to use instanceof, !is_null, is_object or just casting to boolean. Roan to just cast to boolean
* Adding checks were missing and change one lost is_object check to cast to boolean too.
* While at it, making gadgetlinks-section re-use the Title object for the gadget definition page instead of re-creating it.
Modified paths:
  • /branches/RL2/extensions/Gadgets/SpecialGadgets.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/SpecialGadgets.php
@@ -122,50 +122,59 @@
123123 )
124124
125125 );
126 - if ( $user->isAllowed( 'gadgets-definition-edit' ) ) {
127 - $extra[] = Linker::link(
128 - GadgetsHooks::getDefinitionTitleFromID( $gadget->getId() ),
129 - wfMessage( 'gadgets-gadget-modify' )->escaped(),
130 - array(
131 - 'title' => wfMessage( 'gadgets-gadget-modify-tooltip' )->plain(),
132 - 'class' => 'mw-gadgets-modify',
133 - ),
134 - array( 'action' => 'edit' )
135 - );
136 - }
 126+ $gadgetDefinitionTitle = GadgetsHooks::getDefinitionTitleFromID( $gadget->getId() );
137127
138 - if ( $user->isAllowed( 'gadgets-definition-delete' ) ) {
139 - $extra[] = Linker::link(
140 - GadgetsHooks::getDefinitionTitleFromID( $gadget->getId() ),
141 - wfMessage( 'gadgets-gadget-delete' )->escaped(),
142 - array(
143 - 'title' => wfMessage( 'gadgets-gadget-delete-tooltip' )->plain(),
144 - 'class' => 'mw-gadgets-delete',
145 - ),
146 - array( 'action' => 'delete' )
147 - );
 128+ if ( $gadgetDefinitionTitle instanceof Title ) {
 129+
 130+ if ( $user->isAllowed( 'gadgets-definition-edit' ) ) {
 131+ $extra[] = Linker::link(
 132+ $gadgetDefinitionTitle,
 133+ wfMessage( 'gadgets-gadget-modify' )->escaped(),
 134+ array(
 135+ 'title' => wfMessage( 'gadgets-gadget-modify-tooltip' )->plain(),
 136+ 'class' => 'mw-gadgets-modify',
 137+ ),
 138+ array( 'action' => 'edit' )
 139+ );
 140+ }
 141+
 142+ if ( $user->isAllowed( 'gadgets-definition-delete' ) ) {
 143+ $extra[] = Linker::link(
 144+ $gadgetDefinitionTitle,
 145+ wfMessage( 'gadgets-gadget-delete' )->escaped(),
 146+ array(
 147+ 'title' => wfMessage( 'gadgets-gadget-delete-tooltip' )->plain(),
 148+ 'class' => 'mw-gadgets-delete',
 149+ ),
 150+ array( 'action' => 'delete' )
 151+ );
 152+ }
148153 }
149154
150155 // Edit interface (gadget title and description)
151156 $editTitle = $editDescription = '';
152157 if ( $user->isAllowed( 'editinterface' ) ) {
153158 $t = Title::makeTitleSafe( NS_MEDIAWIKI, $gadget->getTitleMessageKey() . $suffix );
154 - $editLink = Linker::link(
155 - $t,
156 - wfMessage( 'gadgets-message-edit' )->escaped(),
157 - array( 'title' => wfMessage( 'gadgets-message-edit-tooltip', $t->getPrefixedText() ) ),
158 - array( 'action' => 'edit' )
159 - );
160 - $editTitle = '<span class="mw-gadgets-messagelink">' . $editLink . '</span>';
 159+ if ( $t ) {
 160+ $editLink = Linker::link(
 161+ $t,
 162+ wfMessage( 'gadgets-message-edit' )->escaped(),
 163+ array( 'title' => wfMessage( 'gadgets-message-edit-tooltip', $t->getPrefixedText() ) ),
 164+ array( 'action' => 'edit' )
 165+ );
 166+ $editTitle = '<span class="mw-gadgets-messagelink">' . $editLink . '</span>';
 167+ }
161168
162169 $t = Title::makeTitleSafe( NS_MEDIAWIKI, $gadget->getDescriptionMessageKey() . $suffix );
163 - $editLink = Linker::link(
164 - $t,
165 - wfMessage( $t->isKnown() ? 'gadgets-desc-edit' : 'gadgets-desc-add' )->escaped(),
166 - array( 'title' => wfMessage( $t->isKnown() ? 'gadgets-desc-edit-tooltip' : 'gadgets-desc-add-tooltip', $t->getPrefixedText() ) ),
167 - array( 'action' => 'edit' )
168 - );
169 - $editDescription = '<span class="mw-gadgets-messagelink">' . $editLink . '</span>';
 170+ if ( $t ) {
 171+ $editLink = Linker::link(
 172+ $t,
 173+ wfMessage( $t->isKnown() ? 'gadgets-desc-edit' : 'gadgets-desc-add' )->escaped(),
 174+ array( 'title' => wfMessage( $t->isKnown() ? 'gadgets-desc-edit-tooltip' : 'gadgets-desc-add-tooltip', $t->getPrefixedText() ) ),
 175+ array( 'action' => 'edit' )
 176+ );
 177+ $editDescription = '<span class="mw-gadgets-messagelink">' . $editLink . '</span>';
 178+ }
170179 }
171180
172181 // Gadget heading
@@ -262,13 +271,15 @@
263272 $editLink = '';
264273 if ( $user->isAllowed( 'editinterface' ) && $category !== '' ) {
265274 $t = Title::makeTitleSafe( NS_MEDIAWIKI, "gadgetcategory-{$category}{$suffix}" );
266 - $editLink = Linker::link(
267 - $t,
268 - wfMessage( 'gadgets-message-edit' )->escaped(),
269 - array( 'title' => wfMessage( 'gadgets-message-edit-tooltip', $t->getPrefixedText() ) ),
270 - array( 'action' => 'edit' )
271 - );
272 - $editLink = '<span class="mw-gadgets-messagelink">' . $editLink . '</span>';
 275+ if ( $t ) {
 276+ $editLink = Linker::link(
 277+ $t,
 278+ wfMessage( 'gadgets-message-edit' )->escaped(),
 279+ array( 'title' => wfMessage( 'gadgets-message-edit-tooltip', $t->getPrefixedText() ) ),
 280+ array( 'action' => 'edit' )
 281+ );
 282+ $editLink = '<span class="mw-gadgets-messagelink">' . $editLink . '</span>';
 283+ }
273284 }
274285
275286 // Category heading
@@ -369,7 +380,7 @@
370381 // from NS_MEDIAWIKI that don't exist but are 'isAlwaysKnown'
371382 // due to their default value from PHP messages files
372383 // (which we don't want to export)
373 - if ( is_object( $exportTitle ) && $exportTitle->exists() ) {
 384+ if ( $exportTitle && $exportTitle->exists() ) {
374385 $exportList .= $exportTitle->getPrefixedDBkey() . "\n";
375386 $exportDisplayList .= '<li>'. Linker::link( $exportTitle ) . '</li>';
376387 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98729[RL2] Merge gadget manager into SpecialGadgets...krinkle01:26, 3 October 2011

Comments

#Comment by Krinkle (talk | contribs)   22:41, 4 October 2011

ViewVC gives a nicer diff :)

Status & tagging log