r85195 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85194‎ | r85195 | r85196 >
Date:14:50, 2 April 2011
Author:ashley
Status:ok
Tags:
Comment:
ImagePage.php: add missing braces + other code style tweaks
Modified paths:
  • /trunk/phase3/includes/ImagePage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ImagePage.php
@@ -28,7 +28,7 @@
2929 }
3030
3131 /**
32 - * @param $file File:
 32+ * @param $file File:
3333 * @return void
3434 */
3535 public function setFile( $file ) {
@@ -106,11 +106,13 @@
107107 $showmeta = false;
108108 }
109109
110 - if ( !$diff && $this->displayImg->exists() )
 110+ if ( !$diff && $this->displayImg->exists() ) {
111111 $wgOut->addHTML( $this->showTOC( $showmeta ) );
 112+ }
112113
113 - if ( !$diff )
 114+ if ( !$diff ) {
114115 $this->openShowImage();
 116+ }
115117
116118 # No need to display noarticletext, we use our own message, output in openShowImage()
117119 if ( $this->getID() ) {
@@ -147,8 +149,9 @@
148150 # Allow extensions to add something after the image links
149151 $html = '';
150152 wfRunHooks( 'ImagePageAfterImageLinks', array( $this, &$html ) );
151 - if ( $html )
 153+ if ( $html ) {
152154 $wgOut->addHTML( $html );
 155+ }
153156
154157 if ( $showmeta ) {
155158 $wgOut->addHTML( Xml::element( 'h2', array( 'id' => 'metadata' ), wfMsg( 'metadata' ) ) . "\n" );
@@ -191,8 +194,9 @@
192195
193196 public function isRedirect( $text = false ) {
194197 $this->loadFile();
195 - if ( $this->img->isLocal() )
 198+ if ( $this->img->isLocal() ) {
196199 return parent::isRedirect( $text );
 200+ }
197201
198202 return (bool)$this->img->getRedirected();
199203 }
@@ -217,7 +221,8 @@
218222 if ( !is_null( $this->dupes ) ) {
219223 return $this->dupes;
220224 }
221 - if ( !( $hash = $this->img->getSha1() ) ) {
 225+ $hash = $this->img->getSha1();
 226+ if ( !( $hash ) ) {
222227 return $this->dupes = array();
223228 }
224229 $dupes = RepoGroup::singleton()->findBySha1( $hash );
@@ -226,13 +231,14 @@
227232 $size = $this->img->getSize();
228233 foreach ( $dupes as $index => $file ) {
229234 $key = $file->getRepoName() . ':' . $file->getName();
230 - if ( $key == $self )
 235+ if ( $key == $self ) {
231236 unset( $dupes[$index] );
232 - if ( $file->getSize() != $size )
 237+ }
 238+ if ( $file->getSize() != $size ) {
233239 unset( $dupes[$index] );
 240+ }
234241 }
235242 return $this->dupes = $dupes;
236 -
237243 }
238244
239245 /**
@@ -243,9 +249,9 @@
244250 */
245251 protected function showTOC( $metadata ) {
246252 $r = array(
247 - '<li><a href="#file">' . wfMsgHtml( 'file-anchor-link' ) . '</a></li>',
248 - '<li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>',
249 - '<li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>',
 253+ '<li><a href="#file">' . wfMsgHtml( 'file-anchor-link' ) . '</a></li>',
 254+ '<li><a href="#filehistory">' . wfMsgHtml( 'filehist' ) . '</a></li>',
 255+ '<li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>',
250256 );
251257 if ( $metadata ) {
252258 $r[] = '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>';
@@ -343,7 +349,7 @@
344350 # image
345351
346352 # "Download high res version" link below the image
347 - # $msgsize = wfMsgHtml('file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
 353+ # $msgsize = wfMsgHtml( 'file-info-size', $width_orig, $height_orig, $sk->formatSize( $this->displayImg->getSize() ), $mime );
348354 # We'll show a thumbnail of this image
349355 if ( $width > $maxWidth || $height > $maxHeight ) {
350356 # Calculate the thumbnail size.
@@ -382,7 +388,7 @@
383389 $thumbnail = $this->displayImg->transform( $params );
384390
385391 $showLink = true;
386 - $anchorclose = "<br />" . $msgsmall;
 392+ $anchorclose = '<br />' . $msgsmall;
387393
388394 $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
389395 if ( $isMulti ) {
@@ -450,7 +456,7 @@
451457 $wgOut->addHTML(
452458 '</td><td><div class="multipageimagenavbox">' .
453459 Xml::openElement( 'form', $formParams ) .
454 - Html::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
 460+ Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
455461 wfMsgExt( 'imgmultigoto', array( 'parseinline', 'replaceafter' ), $select ) .
456462 Xml::submitButton( wfMsg( 'imgmultigo' ) ) .
457463 Xml::closeElement( 'form' ) .
@@ -463,14 +469,13 @@
464470 $icon = $this->displayImg->iconThumb();
465471
466472 $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
467 - $icon->toHtml( array( 'file-link' => true ) ) .
468 - "</div>\n" );
 473+ $icon->toHtml( array( 'file-link' => true ) ) .
 474+ "</div>\n" );
469475 }
470476
471477 $showLink = true;
472478 }
473479
474 -
475480 if ( $showLink ) {
476481 $filename = wfEscapeWikiText( $this->displayImg->getName() );
477482 $linktext = $filename;
@@ -505,11 +510,9 @@
506511 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
507512 $nofile = array(
508513 'filepage-nofile-link',
509 - $uploadTitle->getFullUrl( array( 'wpDestFile' => $this->img->getName() ) )
 514+ $uploadTitle->getFullURL( array( 'wpDestFile' => $this->img->getName() ) )
510515 );
511 - }
512 - else
513 - {
 516+ } else {
514517 $nofile = 'filepage-nofile';
515518 }
516519 // Note, if there is an image description page, but
@@ -520,7 +523,7 @@
521524 if ( !$this->getID() ) {
522525 // If there is no image, no shared image, and no description page,
523526 // output a 404, to be consistent with articles.
524 - $wgRequest->response()->header( "HTTP/1.1 404 Not Found" );
 527+ $wgRequest->response()->header( 'HTTP/1.1 404 Not Found' );
525528 }
526529 }
527530 }
@@ -584,7 +587,7 @@
585588 public function getUploadUrl() {
586589 $this->loadFile();
587590 $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
588 - return $uploadTitle->getFullUrl( array(
 591+ return $uploadTitle->getFullURL( array(
589592 'wpDestFile' => $this->img->getName(),
590593 'wpForReUpload' => 1
591594 ) );
@@ -602,8 +605,9 @@
603606 }
604607
605608 $this->loadFile();
606 - if ( !$this->img->isLocal() )
 609+ if ( !$this->img->isLocal() ) {
607610 return;
 611+ }
608612
609613 $sk = $wgUser->getSkin();
610614
@@ -628,7 +632,11 @@
629633 ),
630634 array( 'known', 'noclasses' )
631635 );
632 - $wgOut->addHTML( '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' . wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) . "</small></li>\n" );
 636+ $wgOut->addHTML(
 637+ '<li id="mw-imagepage-edit-external">' . $elink . ' <small>' .
 638+ wfMsgExt( 'edit-externally-help', array( 'parseinline' ) ) .
 639+ "</small></li>\n"
 640+ );
633641 }
634642
635643 $wgOut->addHTML( "</ul>\n" );
@@ -673,7 +681,11 @@
674682 );
675683 $count = $dbr->numRows( $res );
676684 if ( $count == 0 ) {
677 - $wgOut->wrapWikiMsg( Html::rawElement( 'div', array ( 'id' => 'mw-imagepage-nolinkstoimage' ), "\n$1\n" ), 'nolinkstoimage' );
 685+ $wgOut->wrapWikiMsg(
 686+ Html::rawElement( 'div',
 687+ array( 'id' => 'mw-imagepage-nolinkstoimage' ), "\n$1\n" ),
 688+ 'nolinkstoimage'
 689+ );
678690 return;
679691 }
680692
@@ -688,7 +700,10 @@
689701 );
690702 }
691703
692 - $wgOut->addHTML( Html::openElement( 'ul', array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n" );
 704+ $wgOut->addHTML(
 705+ Html::openElement( 'ul',
 706+ array( 'class' => 'mw-imagepage-linkstoimage' ) ) . "\n"
 707+ );
693708 $sk = $wgUser->getSkin();
694709 $count = 0;
695710 $elements = array();
@@ -701,16 +716,16 @@
702717 }
703718
704719 // Sort the list by namespace:title
705 - usort ( $elements, array( $this, 'compare' ) );
 720+ usort( $elements, array( $this, 'compare' ) );
706721
707722 // Create links for every element
708723 foreach( $elements as $element ) {
709724 $link = $sk->linkKnown( Title::makeTitle( $element->page_namespace, $element->page_title ) );
710725 $wgOut->addHTML( Html::rawElement(
711 - 'li',
712 - array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
713 - $link
714 - ) . "\n"
 726+ 'li',
 727+ array( 'id' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ),
 728+ $link
 729+ ) . "\n"
715730 );
716731
717732 };
@@ -728,7 +743,9 @@
729744 global $wgUser, $wgOut, $wgLang;
730745
731746 $redirects = $this->getTitle()->getRedirectsHere( NS_FILE );
732 - if ( count( $redirects ) == 0 ) return;
 747+ if ( count( $redirects ) == 0 ) {
 748+ return;
 749+ }
733750
734751 $wgOut->addHTML( "<div id='mw-imagepage-section-redirectstofile'>\n" );
735752 $wgOut->addWikiMsg( 'redirectstofile',
@@ -748,7 +765,6 @@
749766 $wgOut->addHTML( "<li>{$link}</li>\n" );
750767 }
751768 $wgOut->addHTML( "</ul></div>\n" );
752 -
753769 }
754770
755771 protected function imageDupes() {
@@ -824,13 +840,13 @@
825841 public function doPurge() {
826842 $this->loadFile();
827843 if ( $this->img->exists() ) {
828 - wfDebug( "ImagePage::doPurge purging " . $this->img->getName() . "\n" );
 844+ wfDebug( 'ImagePage::doPurge purging ' . $this->img->getName() . "\n" );
829845 $update = new HTMLCacheUpdate( $this->mTitle, 'imagelinks' );
830846 $update->doUpdate();
831847 $this->img->upgradeRow();
832848 $this->img->purgeCache();
833849 } else {
834 - wfDebug( "ImagePage::doPurge no image for " . $this->img->getName() . "; limiting purge to cache only\n" );
 850+ wfDebug( 'ImagePage::doPurge no image for ' . $this->img->getName() . "; limiting purge to cache only\n" );
835851 // even if the file supposedly doesn't exist, force any cached information
836852 // to be updated (in case the cached information is wrong)
837853 $this->img->purgeCache();
@@ -843,8 +859,8 @@
844860 */
845861 function showError( $description ) {
846862 global $wgOut;
847 - $wgOut->setPageTitle( wfMsg( "internalerror" ) );
848 - $wgOut->setRobotPolicy( "noindex,nofollow" );
 863+ $wgOut->setPageTitle( wfMsg( 'internalerror' ) );
 864+ $wgOut->setRobotPolicy( 'noindex,nofollow' );
849865 $wgOut->setArticleRelated( false );
850866 $wgOut->enableClientCache( false );
851867 $wgOut->addWikiText( $description );
@@ -944,8 +960,8 @@
945961 }
946962
947963 /**
948 - * @param $iscur
949 - * @param File $file
 964+ * @param $iscur
 965+ * @param $file File
950966 * @return string
951967 */
952968 public function imageHistoryLine( $iscur, $file ) {
@@ -966,8 +982,9 @@
967983 # Link to remove from history
968984 if ( $wgUser->isAllowed( 'delete' ) ) {
969985 $q = array( 'action' => 'delete' );
970 - if ( !$iscur )
 986+ if ( !$iscur ) {
971987 $q['oldimage'] = $img;
 988+ }
972989 $row .= $this->skin->link(
973990 $this->title,
974991 wfMsgHtml( $iscur ? 'filehist-deleteall' : 'filehist-deleteone' ),
@@ -1059,7 +1076,7 @@
10601077 // Image dimensions + size
10611078 $row .= '<td>';
10621079 $row .= htmlspecialchars( $file->getDimensionsString() );
1063 - $row .= " <span style='white-space: nowrap;'>(" . $this->skin->formatSize( $file->getSize() ) . ')</span>';
 1080+ $row .= ' <span style="white-space: nowrap;">(' . $this->skin->formatSize( $file->getSize() ) . ')</span>';
10641081 $row .= '</td>';
10651082
10661083 // Uploading user
@@ -1069,8 +1086,8 @@
10701087 if ( $file->isDeleted( File::DELETED_USER ) ) {
10711088 $row .= '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
10721089 } else {
1073 - $row .= $this->skin->userLink( $user, $usertext ) . " <span style='white-space: nowrap;'>" .
1074 - $this->skin->userToolLinks( $user, $usertext ) . "</span>";
 1090+ $row .= $this->skin->userLink( $user, $usertext ) . ' <span style="white-space: nowrap;">' .
 1091+ $this->skin->userToolLinks( $user, $usertext ) . '</span>';
10751092 }
10761093 } else {
10771094 $row .= htmlspecialchars( $usertext );
@@ -1087,13 +1104,13 @@
10881105
10891106 $rowClass = null;
10901107 wfRunHooks( 'ImagePageFileHistoryLine', array( $this, $file, &$row, &$rowClass ) );
1091 - $classAttr = $rowClass ? " class='$rowClass'" : "";
 1108+ $classAttr = $rowClass ? " class='$rowClass'" : '';
10921109
10931110 return "<tr{$classAttr}>{$row}</tr>\n";
10941111 }
10951112
10961113 /**
1097 - * @param File $file
 1114+ * @param $file File
10981115 * @return string
10991116 */
11001117 protected function getThumbForLine( $file ) {
@@ -1115,7 +1132,9 @@
11161133 'file-link' => true,
11171134 );
11181135
1119 - if ( !$thumbnail ) return wfMsgHtml( 'filehist-nothumb' );
 1136+ if ( !$thumbnail ) {
 1137+ return wfMsgHtml( 'filehist-nothumb' );
 1138+ }
11201139
11211140 return $thumbnail->toHtml( $options );
11221141 } else {
@@ -1197,7 +1216,9 @@
11981217 }
11991218
12001219 function doQuery() {
1201 - if ( $this->mQueryDone ) return;
 1220+ if ( $this->mQueryDone ) {
 1221+ return;
 1222+ }
12021223 $this->mImg = $this->mImagePage->getFile(); // ensure loading
12031224 if ( !$this->mImg->exists() ) {
12041225 return;

Status & tagging log