r24969 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24968‎ | r24969 | r24970 >
Date:03:57, 21 August 2007
Author:nickj
Status:old
Tags:
Comment:
Static code analysis housekeeping time... things that could be double-checked are marked with "[Note: some-comment]" :
if-if-else without curly braces [api/ApiQuerySiteinfo.php] --> adding
Unused global declaration: $wgGroupPermissions --> removing
Unused global declaration: $wgEmailConfirmToEdit (line 301) --> removing
Variable $id appears only once (line 1021) --> removing
Variable $m was used before it was defined (line 805) --> defining.
Variable $retval was used before it was defined (line 2346) --> renaming to $result
Variable $rcid appears only once (line 244 of RecentChange.php) --> using this instead of $change [Note: was left over from r24607 refactoring, revert if wrong please]
Unused global declaration: $wgCommandLineMode (line 11) --> removing
Variable $k appears only once (line 132 of ImagePage.php) --> removing.
Variable $info appears only once (line 311 of ImagePage.php) --> removing.
Unused global declaration: $wgTitle (line 569 of ImagePage.php) -> removing.
Variable $handlerParams was used before it was defined (line 616 of Linker.php) --> resolved by Raymond in r24966
Variable $match was used before it was defined (line 1031 of Linker.php) --> defining.
Unused global declaration: $wgEnotifWatchlist (line 253 of UserMailer.php) --> removing
Unused global declaration: $wgShowUpdatedMarker (line 253 of UserMailer.php) --> removing
Variable $img appears only once (line 446 of SpecialUpload.php) --> added definition, defined as null, flagged with @todo [Note: should $img be defined in this context, or is it intended to be null? And should the return value after the hook be checked in some way?]
Unused global declaration: $wgEnableAPI (line 739 of SpecialUpload.php) --> removing.
Unused global declaration: $wgNamespaceProtection (line 1030 of OutputPage.php) --> removing.
Unused global declaration: $wgContLang (line 18 of SpecialWatchlist.php) --> removing.
Unused global declaration: $wgRawHtml (line 269 of SpecialMovepage.php) --> removing.
The value of variable $page was never used (line 331 of SpecialUndelete.php) --> removing line, as $page gets redefined a few lines down.
Variable $synIndex appears only once (line 521 of MagicWord.php) --> commenting out.
Variable $case appears only once (line 539 of MagicWord.php) --> removing from foreach index key usage.
Variable $wgUser appears only once (line 1039 of Title.php) --> adding line to declare as a global, would be null otherwise.
Variable $m was used before it was defined (line 285 of Title.php) --> defining.
Variable $id appears only once (line 1150 of Title.php) --> removing from foreach index key usage.
Variable $subpage appears only once (line 1297 of Title.php) --> commenting out.
Variable $restrictions appears only once (line 1399 of Title.php) --> commenting out.
Variable $mime appears only once (line 210 of filerepo/OldLocalFile.php) --> removing.
Variable $deprefixedName appears only once (line 213 of filerepo/LocalFile.php) --> removing.
Variable $m appears only once (line 541 of filerepo/LocalFile.php) --> removing.
Variable $where appears only once (line 1245 of filerepo/LocalFile.php) --> removing.
Variable $info appears only once (line 1427 of filerepo/LocalFile.php) --> removing.
Variable $rel appears only once (line 138 of filerepo/RepoGroup.php) --> commenting out.
Variable $zone appears only once (line 138 of filerepo/RepoGroup.php) --> commenting out.
Variable $nbytes appears only once (line 208 of media/Generic.php) --> added a return line that uses $nbytes. [Note: I'm assuming that this was the intent]
Variable $offset appears only once (line 201 of SpecialListusers.php) --> removing.
Variable $limit appears only once (line 201 of SpecialListusers.php) --> removing.
Variable $groupTarget appears only once (line 203 of SpecialListusers.php) --> removing.
Unused global declaration: $wgLang (line 74 of SpecialWantedpages.php) --> removing.
Variable $block appears only once (line 244 of SpecialProtectedpages.php) --> removing.
Variable $offset appears only once (line 281 of SpecialProtectedpages.php) --> removing.
Variable $limit appears only once (line 281 of SpecialProtectedpages.php) --> removing.
Unused global declaration: $wgLang (line 30 of FileDeleteForm.php) --> removing.
Unused global declaration: $wgServer (line 30 of FileDeleteForm.php) --> removing.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Database.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/FileDeleteForm.php (modified) (history)
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/MagicWord.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/RecentChange.php (modified) (history)
  • /trunk/phase3/includes/SpecialListusers.php (modified) (history)
  • /trunk/phase3/includes/SpecialMovepage.php (modified) (history)
  • /trunk/phase3/includes/SpecialProtectedpages.php (modified) (history)
  • /trunk/phase3/includes/SpecialUndelete.php (modified) (history)
  • /trunk/phase3/includes/SpecialUpload.php (modified) (history)
  • /trunk/phase3/includes/SpecialUserlogin.php (modified) (history)
  • /trunk/phase3/includes/SpecialUserrights.php (modified) (history)
  • /trunk/phase3/includes/SpecialWantedpages.php (modified) (history)
  • /trunk/phase3/includes/SpecialWatchlist.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/UserMailer.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySiteinfo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalFile.php (modified) (history)
  • /trunk/phase3/includes/filerepo/OldLocalFile.php (modified) (history)
  • /trunk/phase3/includes/filerepo/RepoGroup.php (modified) (history)
  • /trunk/phase3/includes/media/Generic.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialListusers.php
@@ -198,10 +198,6 @@
199199 function wfSpecialListusers( $par = null ) {
200200 global $wgRequest, $wgOut;
201201
202 - list( $limit, $offset ) = wfCheckLimits();
203 -
204 - $groupTarget = isset($par) ? $par : $wgRequest->getVal( 'group' );
205 -
206202 $up = new UsersPager($par);
207203
208204 # getBody() first to check, if empty
Index: trunk/phase3/includes/Database.php
@@ -214,7 +214,7 @@
215215
216216 $cache = new HTMLFileCache( $t );
217217 if( $cache->isFileCached() ) {
218 - // FIXME: $msg is not defined on the next line.
 218+ // @todo, FIXME: $msg is not defined on the next line.
219219 $msg = '<p style="color: red"><b>'.$msg."<br />\n" .
220220 $cachederror . "</b></p>\n";
221221
Index: trunk/phase3/includes/SpecialUndelete.php
@@ -328,7 +328,6 @@
329329 $restoreAll = empty( $timestamps );
330330
331331 $dbw = wfGetDB( DB_MASTER );
332 - $page = $dbw->tableName( 'archive' );
333332
334333 # Does this page already exist? We'll have to update it...
335334 $article = new Article( $this->title );
Index: trunk/phase3/includes/Linker.php
@@ -1028,6 +1028,7 @@
10291029 $medians = '(?:' . preg_quote( Namespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
10301030 $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
10311031
 1032+ $match = array();
10321033 while(preg_match('/\[\[:?(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
10331034 # Handle link renaming [[foo|text]] will show link as "text"
10341035 if( "" != $match[3] ) {
Index: trunk/phase3/includes/media/Generic.php
@@ -207,6 +207,7 @@
208208 global $wgLang;
209209 $nbytes = '(' . wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
210210 $wgLang->formatNum( $file->getSize() ) ) . ')';
 211+ return "($nbytes)";
211212 }
212213
213214 function getLongDesc( $file ) {
Index: trunk/phase3/includes/SpecialWantedpages.php
@@ -71,7 +71,6 @@
7272 * @return string
7373 */
7474 public function formatResult( $skin, $result ) {
75 - global $wgLang;
7675 $title = Title::makeTitleSafe( $result->namespace, $result->title );
7776 if( $title instanceof Title ) {
7877 if( $this->isCached() ) {
Index: trunk/phase3/includes/SpecialUserlogin.php
@@ -8,7 +8,6 @@
99 * constructor
1010 */
1111 function wfSpecialUserlogin() {
12 - global $wgCommandLineMode;
1312 global $wgRequest;
1413 if( session_id() == '' ) {
1514 wfSetupSession();
Index: trunk/phase3/includes/MagicWord.php
@@ -518,7 +518,7 @@
519519 // continue;
520520 throw new MWException( __METHOD__ . ': bad parameter name' );
521521 }
522 - list( $synIndex, $magicName ) = $parts;
 522+ list( /* $synIndex */, $magicName ) = $parts;
523523 $paramValue = next( $m );
524524 return array( $magicName, $paramValue );
525525 }
@@ -536,7 +536,7 @@
537537 public function matchVariableStartToEnd( $text ) {
538538 global $wgContLang;
539539 $regexes = $this->getVariableStartToEndRegex();
540 - foreach ( $regexes as $case => $regex ) {
 540+ foreach ( $regexes as $regex ) {
541541 if ( $regex !== '' ) {
542542 $m = false;
543543 if ( preg_match( $regex, $text, $m ) ) {
Index: trunk/phase3/includes/EditPage.php
@@ -298,7 +298,6 @@
299299 */
300300 function edit() {
301301 global $wgOut, $wgUser, $wgRequest, $wgTitle;
302 - global $wgEmailConfirmToEdit;
303302
304303 if ( ! wfRunHooks( 'AlternateEdit', array( &$this ) ) )
305304 return;
@@ -333,10 +332,11 @@
334333
335334 if ($error[0] == 'readonlytext')
336335 {
337 - if ($this->edit)
 336+ if ($this->edit) {
338337 $this->formtype = 'preview';
339 - else if ($this->save || $this->preview || $this->diff)
 338+ } elseif ($this->save || $this->preview || $this->diff) {
340339 $remove[] = $error;
 340+ }
341341 }
342342 }
343343 # array_diff returns elements in $permErrors that are not in $remove.
@@ -1018,9 +1018,10 @@
10191019 if ( count($cascadeSources) > 0 ) {
10201020 # Explain, and list the titles responsible
10211021 $notice = wfMsgExt( 'cascadeprotectedwarning', array('parsemag'), count($cascadeSources) ) . "\n";
1022 - foreach( $cascadeSources as $id => $page )
 1022+ foreach( $cascadeSources as $page ) {
10231023 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
10241024 }
 1025+ }
10251026 $wgOut->addWikiText( $notice );
10261027 }
10271028
Index: trunk/phase3/includes/FileDeleteForm.php
@@ -29,7 +29,7 @@
3030 * pending authentication, confirmation, etc.
3131 */
3232 public function execute() {
33 - global $wgOut, $wgRequest, $wgUser, $wgLang, $wgServer;
 33+ global $wgOut, $wgRequest, $wgUser;
3434 $this->setHeaders();
3535
3636 if( wfReadOnly() ) {
Index: trunk/phase3/includes/SpecialWatchlist.php
@@ -15,7 +15,7 @@
1616 * @param $par Parameter passed to the page
1717 */
1818 function wfSpecialWatchlist( $par ) {
19 - global $wgUser, $wgOut, $wgLang, $wgRequest, $wgContLang;
 19+ global $wgUser, $wgOut, $wgLang, $wgRequest;
2020 global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
2121 global $wgEnotifWatchlist;
2222 $fname = 'wfSpecialWatchlist';
Index: trunk/phase3/includes/Article.php
@@ -802,6 +802,7 @@
803803 // Give hooks a chance to customise the output
804804 if( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->mTitle, $wgOut ) ) ) {
805805 // Wrap the whole lot in a <pre> and don't parse
 806+ $m = array();
806807 preg_match( '!\.(css|js)$!u', $this->mTitle->getText(), $m );
807808 $wgOut->addHtml( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
808809 $wgOut->addHtml( htmlspecialchars( $this->mContent ) );
@@ -2344,7 +2345,7 @@
23452346 $wgOut->returnToMain( false, $this->mTitle );
23462347 break;
23472348 default:
2348 - throw new MWException( __METHOD__ . ": Unknown return value `{$retval}`" );
 2349+ throw new MWException( __METHOD__ . ": Unknown return value `{$result}`" );
23492350 }
23502351
23512352 }
Index: trunk/phase3/includes/SpecialUpload.php
@@ -443,6 +443,7 @@
444444 }
445445 // Success, redirect to description page
446446 $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
 447+ $img = null; // @todo: added to avoid passing a ref to null - should this be defined somewhere?
447448 wfRunHooks( 'UploadComplete', array( &$img ) );
448449 }
449450 }
@@ -736,7 +737,7 @@
737738 function mainUploadForm( $msg='' ) {
738739 global $wgOut, $wgUser, $wgContLang;
739740 global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
740 - global $wgRequest, $wgAllowCopyUploads, $wgEnableAPI;
 741+ global $wgRequest, $wgAllowCopyUploads;
741742 global $wgStylePath, $wgStyleVersion;
742743
743744 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
Index: trunk/phase3/includes/UserMailer.php
@@ -250,7 +250,6 @@
251251
252252 function notifyOnPageChange($editor, &$title, $timestamp, $summary, $minorEdit, $oldid = false) {
253253 global $wgEnotifUseJobQ;
254 - global $wgEnotifWatchlist, $wgShowUpdatedMarker;
255254
256255 if( $title->getNamespace() < 0 )
257256 return;
Index: trunk/phase3/includes/SpecialProtectedpages.php
@@ -241,7 +241,6 @@
242242 }
243243
244244 function formatRow( $row ) {
245 - $block = new Block;
246245 return $this->mForm->formatRow( $row );
247246 }
248247
@@ -278,8 +277,6 @@
279278 */
280279 function wfSpecialProtectedpages() {
281280
282 - list( $limit, $offset ) = wfCheckLimits();
283 -
284281 $ppForm = new ProtectedPagesForm();
285282
286283 $ppForm->showList();
Index: trunk/phase3/includes/RecentChange.php
@@ -251,7 +251,7 @@
252252 'rc_patrolled' => 1
253253 ),
254254 array(
255 - 'rc_id' => $change
 255+ 'rc_id' => $rcid
256256 ),
257257 __METHOD__
258258 );
Index: trunk/phase3/includes/OutputPage.php
@@ -1027,7 +1027,6 @@
10281028 $this->addWikiText( wfMsgExt( 'cascadeprotected', 'parsemag', $count ) . "\n{$titles}" );
10291029 } elseif( !$wgTitle->isProtected( 'edit' ) && $wgTitle->isNamespaceProtected() ) {
10301030 // Namespace protection
1031 - global $wgNamespaceProtection;
10321031 $ns = $wgTitle->getNamespace() == NS_MAIN
10331032 ? wfMsg( 'nstab-main' )
10341033 : $wgTitle->getNsText();
Index: trunk/phase3/includes/SpecialUserrights.php
@@ -319,7 +319,7 @@
320320 * @return Array array( 'add' => array( addablegroups ), 'remove' => array( removablegroups ) )
321321 */
322322 private function changeableGroups() {
323 - global $wgUser, $wgGroupPermissions;
 323+ global $wgUser;
324324
325325 $groups = array( 'add' => array(), 'remove' => array() );
326326 $addergroups = $wgUser->getEffectiveGroups();
Index: trunk/phase3/includes/Title.php
@@ -279,6 +279,7 @@
280280 $redir = MagicWord::get( 'redirect' );
281281 if( $redir->matchStart( $text ) ) {
282282 // Extract the first link and see if it's usable
 283+ $m = array();
283284 if( preg_match( '!\[{2}(.*?)(?:\||\]{2})!', $text, $m ) ) {
284285 // Strip preceding colon used to "escape" categories, etc.
285286 // and URL-decode links
@@ -1034,7 +1035,7 @@
10351036 $errors[] = array( 'readonlytext' );
10361037 }
10371038
1038 - global $wgEmailConfirmToEdit;
 1039+ global $wgEmailConfirmToEdit, $wgUser;
10391040
10401041 if ( $wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed() )
10411042 {
@@ -1147,7 +1148,7 @@
11481149 $right = ( $right == 'sysop' ) ? 'protect' : $right;
11491150 if( '' != $right && !$user->isAllowed( $right ) ) {
11501151 $pages = '';
1151 - foreach( $cascadingSources as $id => $page )
 1152+ foreach( $cascadingSources as $page )
11521153 $pages .= '* [[:' . $page->getPrefixedText() . "]]\n";
11531154 $errors[] = array( 'cascadeprotected', count( $cascadingSources ), $pages );
11541155 }
@@ -1294,7 +1295,7 @@
12951296 */
12961297 if( $this->getNamespace() == NS_SPECIAL ) {
12971298 $name = $this->getText();
1298 - list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $name );
 1299+ list( $name, /* $subpage */) = SpecialPage::resolveAliasWithSubpage( $name );
12991300 $pure = SpecialPage::getTitleFor( $name )->getPrefixedText();
13001301 if( in_array( $pure, $wgWhitelistRead, true ) )
13011302 return true;
@@ -1396,7 +1397,7 @@
13971398 * @return bool If the page is subject to cascading restrictions.
13981399 */
13991400 public function isCascadeProtected() {
1400 - list( $sources, $restrictions ) = $this->getCascadeProtectionSources( false );
 1401+ list( $sources, /* $restrictions */ ) = $this->getCascadeProtectionSources( false );
14011402 return ( $sources > 0 );
14021403 }
14031404
Index: trunk/phase3/includes/SpecialMovepage.php
@@ -266,7 +266,7 @@
267267 }
268268
269269 function showSuccess() {
270 - global $wgOut, $wgRequest, $wgUser, $wgRawHtml;
 270+ global $wgOut, $wgRequest, $wgUser;
271271
272272 $old = Title::newFromText( $wgRequest->getVal( 'oldtitle' ) );
273273 $new = Title::newFromText( $wgRequest->getVal( 'newtitle' ) );
Index: trunk/phase3/includes/filerepo/OldLocalFile.php
@@ -207,7 +207,6 @@
208208
209209 $dbw = $this->repo->getMasterDB();
210210 list( $major, $minor ) = self::splitMime( $this->mime );
211 - $mime = $this->mime;
212211
213212 wfDebug(__METHOD__.': upgrading '.$this->archive_name." to the current schema\n");
214213 $dbw->update( 'oldimage',
Index: trunk/phase3/includes/filerepo/LocalFile.php
@@ -210,7 +210,6 @@
211211 }
212212 $decoded = array();
213213 foreach ( $array as $name => $value ) {
214 - $deprefixedName = substr( $name, $prefixLength );
215214 $decoded[substr( $name, $prefixLength )] = $value;
216215 }
217216 $decoded['timestamp'] = wfTimestamp( TS_MW, $decoded['timestamp'] );
@@ -539,7 +538,6 @@
540539 $dir = $this->getThumbPath();
541540 $urls = array();
542541 foreach ( $files as $file ) {
543 - $m = array();
544542 # Check that the base file name is part of the thumb name
545543 # This is a basic sanity check to avoid erasing unrelated directories
546544 if ( strpos( $file, $this->getName() ) !== false ) {
@@ -1243,7 +1241,6 @@
12441242 $dbw = $this->file->repo->getMasterDB();
12451243 list( $oldRels, $deleteCurrent ) = $this->getOldRels();
12461244 if ( $deleteCurrent ) {
1247 - $where = array( 'img_name' => $this->file->getName() );
12481245 $dbw->delete( 'image', array( 'img_name' => $this->file->getName() ), __METHOD__ );
12491246 }
12501247 if ( count( $oldRels ) ) {
@@ -1425,7 +1422,6 @@
14261423 if ( $first && !$exists ) {
14271424 // This revision will be published as the new current version
14281425 $destRel = $this->file->getRel();
1429 - $info = $this->file->repo->getFileProps( $deletedUrl );
14301426 $insertCurrent = array(
14311427 'img_name' => $row->fa_name,
14321428 'img_size' => $row->fa_size,
Index: trunk/phase3/includes/filerepo/RepoGroup.php
@@ -135,7 +135,7 @@
136136
137137 function getFileProps( $fileName ) {
138138 if ( FileRepo::isVirtualUrl( $fileName ) ) {
139 - list( $repoName, $zone, $rel ) = $this->splitVirtualUrl( $fileName );
 139+ list( $repoName, /* $zone */, /* $rel */ ) = $this->splitVirtualUrl( $fileName );
140140 if ( $repoName === '' ) {
141141 $repoName = 'local';
142142 }
Index: trunk/phase3/includes/ImagePage.php
@@ -129,7 +129,7 @@
130130 $r = wfMsg( 'metadata-help' ) . "\n\n";
131131 $r .= "{| id=mw_metadata class=mw_metadata\n";
132132 foreach ( $metadata as $type => $stuff ) {
133 - foreach ( $stuff as $k => $v ) {
 133+ foreach ( $stuff as $v ) {
134134 $class = Sanitizer::escapeId( $v['id'] );
135135 if( $type == 'collapsed' ) {
136136 $class .= ' collapsable';
@@ -308,7 +308,6 @@
309309
310310 if ($showLink) {
311311 $filename = wfEscapeWikiText( $this->img->getName() );
312 - $info = wfMsg( 'file-info', $sk->formatSize( $this->img->getSize() ), $mime );
313312
314313 global $wgContLang;
315314 $dirmark = $wgContLang->getDirMark();
@@ -566,7 +565,7 @@
567566 }
568567
569568 public function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description, $dims ) {
570 - global $wgUser, $wgLang, $wgTitle, $wgContLang;
 569+ global $wgUser, $wgLang, $wgContLang;
571570 $local = $this->img->isLocal();
572571 $row = '';
573572
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php
@@ -106,12 +106,13 @@
107107 $this->addTables('interwiki');
108108 $this->addFields(array('iw_prefix', 'iw_local', 'iw_url'));
109109
110 - if($filter === 'local')
 110+ if($filter === 'local') {
111111 $this->addWhere('iw_local = 1');
112 - else if($filter === '!local')
 112+ } elseif($filter === '!local') {
113113 $this->addWhere('iw_local = 0');
114 - else if($filter !== false)
 114+ } elseif($filter !== false) {
115115 ApiBase :: dieDebug(__METHOD__, "Unknown filter=$filter");
 116+ }
116117
117118 $this->addOption('ORDER BY', 'iw_prefix');
118119

Follow-up revisions

RevisionCommit summaryAuthorDate
r25016Merged revisions 24866-25015 via svnmerge from...david23:06, 21 August 2007
r47660* Fix broken since added in r24969 preload check which forced forced preview ...nikerabbit13:58, 22 February 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r24607* (bug 10793) Show patrol links on all eligible diff pages...robchurch03:29, 6 August 2007
r24966Fix a regression from r24808:...raymond21:37, 20 August 2007

Status & tagging log