r47044 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47043‎ | r47044 | r47045 >
Date:16:24, 9 February 2009
Author:siebrand
Status:deferred
Tags:
Comment:
Remove hard coding of pipe separators in skins. Use Language::pipeList as much as possible. Should also make code a bit more readable here and there.
Modified paths:
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/skins/CologneBlue.php (modified) (history)
  • /trunk/phase3/skins/Standard.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/CologneBlue.php
@@ -66,7 +66,7 @@
6767
6868 function doAfterContent()
6969 {
70 - global $wgOut;
 70+ global $wgOut, $wgLang;
7171
7272 $s = "\n</div><br clear='all' />\n";
7373
@@ -80,9 +80,11 @@
8181 $s .= "<td class='bottom' align='center' valign='top'>";
8282
8383 $s .= $this->bottomLinks();
84 - $s .= "\n<br />" . $this->makeKnownLinkObj( Title::newMainPage() ) . " | "
85 - . $this->aboutLink() . " | "
86 - . $this->searchForm( wfMsg( "qbfind" ) );
 84+ $s .= $wgLang->pipeList( array(
 85+ "\n<br />" . $this->makeKnownLinkObj( Title::newMainPage() ),
 86+ $this->aboutLink(),
 87+ $this->searchForm( wfMsg( "qbfind" ) )
 88+ ) );
8789
8890 $s .= "\n<br />" . $this->pageStats();
8991
@@ -121,7 +123,7 @@
122124 }
123125
124126 function sysLinks() {
125 - global $wgUser, $wgContLang, $wgTitle;
 127+ global $wgUser, $wgLang, $wgContLang, $wgTitle;
126128 $li = $wgContLang->specialPage("Userlogin");
127129 $lo = $wgContLang->specialPage("Userlogout");
128130
@@ -132,29 +134,28 @@
133135 $q = "returnto={$rt}";
134136 }
135137
136 - $s = "" .
137 - $this->mainPageLink()
138 - . " | " .
139 - $this->makeKnownLink( wfMsgForContent( "aboutpage" ), wfMsg( "about" ) )
140 - . " | " .
141 - $this->makeKnownLink( wfMsgForContent( "helppage" ), wfMsg( "help" ) )
142 - . " | " .
143 - $this->makeKnownLink( wfMsgForContent( "faqpage" ), wfMsg("faq") )
144 - . " | " .
145 - $this->specialLink( "specialpages" );
 138+ $s = array(
 139+ $this->mainPageLink(),
 140+ $this->makeKnownLink( wfMsgForContent( "aboutpage" ), wfMsg( "about" ) ),
 141+ $this->makeKnownLink( wfMsgForContent( "helppage" ), wfMsg( "help" ) ),
 142+ $this->makeKnownLink( wfMsgForContent( "faqpage" ), wfMsg("faq") ),
 143+ $this->specialLink( "specialpages" )
 144+ );
146145
147146 /* show links to different language variants */
148 - $s .= $this->variantLinks();
149 - $s .= $this->extensionTabLinks();
150 -
151 - $s .= " | ";
 147+ if( $this->variantLinks() ) {
 148+ $s[] = $this->variantLinks();
 149+ }
 150+ if( $this->extensionTabLinks() ) {
 151+ $s[] = $this->extensionTabLinks();
 152+ }
152153 if ( $wgUser->isLoggedIn() ) {
153 - $s .= $this->makeKnownLink( $lo, wfMsg( "logout" ), $q );
 154+ $s[] = $this->makeKnownLink( $lo, wfMsg( "logout" ), $q );
154155 } else {
155 - $s .= $this->makeKnownLink( $li, wfMsg( "login" ), $q );
 156+ $s[] = $this->makeKnownLink( $li, wfMsg( "login" ), $q );
156157 }
157158
158 - return $s;
 159+ return $wgLang->pipeList( $s );
159160 }
160161
161162 /**
Index: trunk/phase3/skins/Standard.php
@@ -82,7 +82,7 @@
8383 }
8484
8585 function doAfterContent() {
86 - global $wgContLang;
 86+ global $wgContLang, $wgLang;
8787 $fname = 'SkinStandard::doAfterContent';
8888 wfProfileIn( $fname );
8989 wfProfileIn( $fname.'-1' );
@@ -108,10 +108,11 @@
109109 $s .= "<td class='bottom' align='$l' valign='top'>";
110110
111111 $s .= $this->bottomLinks();
112 - $s .= "\n<br />" . $this->mainPageLink()
113 - . ' | ' . $this->aboutLink()
114 - . ' | ' . $this->specialLink( 'recentchanges' )
115 - . ' | ' . $this->searchForm()
 112+ $s .= "\n<br />" . $wgLang->pipeList( array(
 113+ $this->mainPageLink(),
 114+ $this->aboutLink(),
 115+ $this->specialLink( 'recentchanges' ),
 116+ $this->searchForm() ) )
116117 . '<br /><span id="pagestats">' . $this->pageStats() . '</span>';
117118
118119 $s .= "</td>";
Index: trunk/phase3/includes/Skin.php
@@ -940,20 +940,20 @@
941941 function doAfterContent() { return "</div></div>"; }
942942
943943 function pageTitleLinks() {
944 - global $wgOut, $wgTitle, $wgUser, $wgRequest;
 944+ global $wgOut, $wgTitle, $wgUser, $wgRequest, $wgLang;
945945
946946 $oldid = $wgRequest->getVal( 'oldid' );
947947 $diff = $wgRequest->getVal( 'diff' );
948948 $action = $wgRequest->getText( 'action' );
949949
950 - $s = $this->printableLink();
 950+ $s[] = $this->printableLink();
951951 $disclaimer = $this->disclaimerLink(); # may be empty
952952 if( $disclaimer ) {
953 - $s .= ' | ' . $disclaimer;
 953+ $s[] = $disclaimer;
954954 }
955955 $privacy = $this->privacyLink(); # may be empty too
956956 if( $privacy ) {
957 - $s .= ' | ' . $privacy;
 957+ $s[] = $privacy;
958958 }
959959
960960 if ( $wgOut->isArticleRelated() ) {
@@ -963,12 +963,12 @@
964964 if( $image ) {
965965 $link = htmlspecialchars( $image->getURL() );
966966 $style = $this->getInternalLinkAttributes( $link, $name );
967 - $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
 967+ $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
968968 }
969969 }
970970 }
971971 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
972 - $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
 972+ $s[] .= $this->makeKnownLinkObj( $wgTitle,
973973 wfMsg( 'currentrev' ) );
974974 }
975975
@@ -978,7 +978,7 @@
979979 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
980980 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
981981 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
982 - $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
 982+ $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
983983 # disable caching
984984 $wgOut->setSquidMaxage(0);
985985 $wgOut->enableClientCache(false);
@@ -987,9 +987,9 @@
988988
989989 $undelete = $this->getUndeleteLink();
990990 if( !empty( $undelete ) ) {
991 - $s .= ' | '.$undelete;
 991+ $s[] = $undelete;
992992 }
993 - return $s;
 993+ return $wgLang->pipeList( $s );
994994 }
995995
996996 function getUndeleteLink() {
@@ -1012,18 +1012,18 @@
10131013 }
10141014
10151015 function printableLink() {
1016 - global $wgOut, $wgFeedClasses, $wgRequest;
 1016+ global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
10171017
10181018 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
10191019
1020 - $s = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
 1020+ $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
10211021 if( $wgOut->isSyndicated() ) {
10221022 foreach( $wgFeedClasses as $format => $class ) {
10231023 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1024 - $s .= " | <a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\" class=\"feedlink\">{$format}</a>";
 1024+ $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\" class=\"feedlink\">{$format}</a>";
10251025 }
10261026 }
1027 - return $s;
 1027+ return $wgLang->pipeList( $s );
10281028 }
10291029
10301030 function pageTitle() {
@@ -1068,7 +1068,7 @@
10691069 $getlink = $this->makeKnownLinkObj( $linkObj, htmlspecialchars( $display ) );
10701070 $c++;
10711071 if ($c>1) {
1072 - $subpages .= ' | ';
 1072+ $subpages .= wfMsgExt( 'pipe-separator' , 'escapenoentities' );
10731073 } else {
10741074 $subpages .= '&lt; ';
10751075 }
@@ -1131,16 +1131,21 @@
11321132 $ret .= $this->link( $wgUser->getUserPage(),
11331133 htmlspecialchars( $wgUser->getName() ) );
11341134 $ret .= " ($talkLink)<br />";
1135 - $ret .= $this->link(
1136 - SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1137 - array(), array( 'returnto' => $returnTo )
1138 - );
1139 - $ret .= ' | ' . $this->specialLink( 'preferences' );
 1135+ $ret .= $wgLang->pipeList( array(
 1136+ $this->link(
 1137+ SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
 1138+ array(), array( 'returnto' => $returnTo )
 1139+ ),
 1140+ $this->specialLink( 'preferences' ),
 1141+ ) );
11401142 }
1141 - $ret .= ' | ' . $this->link(
1142 - Title::newFromText( wfMsgForContent( 'helppage' ) ),
1143 - wfMsg( 'help' )
1144 - );
 1143+ $ret = $wgLang->pipeList( array(
 1144+ $ret,
 1145+ $this->link(
 1146+ Title::newFromText( wfMsgForContent( 'helppage' ) ),
 1147+ wfMsg( 'help' )
 1148+ ),
 1149+ ) );
11451150
11461151 return $ret;
11471152 }
@@ -1179,23 +1184,29 @@
11801185
11811186 function topLinks() {
11821187 global $wgOut;
1183 - $sep = " |\n";
11841188
1185 - $s = $this->mainPageLink() . $sep
1186 - . $this->specialLink( 'recentchanges' );
 1189+ $s = array(
 1190+ $this->mainPageLink(),
 1191+ $this->specialLink( 'recentchanges' )
 1192+ );
11871193
11881194 if ( $wgOut->isArticleRelated() ) {
1189 - $s .= $sep . $this->editThisPage()
1190 - . $sep . $this->historyLink();
 1195+ $s[] = $this->editThisPage();
 1196+ $s[] = $this->historyLink();
11911197 }
11921198 # Many people don't like this dropdown box
1193 - #$s .= $sep . $this->specialPagesList();
 1199+ #$s[] = $this->specialPagesList();
11941200
1195 - $s .= $this->variantLinks();
 1201+ if( $this->variantLinks() ) {
 1202+ $s = $this->variantLinks();
 1203+ }
11961204
1197 - $s .= $this->extensionTabLinks();
 1205+ if( $this->extensionTabLinks() ) {
 1206+ $s[] = $this->extensionTabLinks();
 1207+ }
11981208
1199 - return $s;
 1209+ // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
 1210+ return implode( $s, wfMsgExt( 'pipe-separator' , 'escapenoentities' ) . "\n" );
12001211 }
12011212
12021213 /**
@@ -1206,14 +1217,23 @@
12071218 */
12081219 function extensionTabLinks() {
12091220 $tabs = array();
1210 - $s = '';
 1221+ $out = '';
 1222+ $s = array();
12111223 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
12121224 foreach( $tabs as $tab ) {
1213 - $s .= ' | ' . Xml::element( 'a',
 1225+ $s[] = Xml::element( 'a',
12141226 array( 'href' => $tab['href'] ),
12151227 $tab['text'] );
12161228 }
1217 - return $s;
 1229+
 1230+ if( count( $s ) ) {
 1231+ global $wgLang;
 1232+
 1233+ $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
 1234+ $out .= $wgLang->pipeList( $s );
 1235+ }
 1236+
 1237+ return $out;
12181238 }
12191239
12201240 /**
@@ -1223,14 +1243,14 @@
12241244 function variantLinks() {
12251245 $s = '';
12261246 /* show links to different language variants */
1227 - global $wgDisableLangConversion, $wgContLang, $wgTitle;
 1247+ global $wgDisableLangConversion, $wgLang, $wgContLang, $wgTitle;
12281248 $variants = $wgContLang->getVariants();
12291249 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
12301250 foreach( $variants as $code ) {
12311251 $varname = $wgContLang->getVariantname( $code );
12321252 if( $varname == 'disable' )
12331253 continue;
1234 - $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
 1254+ $s = $wgLang->pipeList( array( $s, '<a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>' ) );
12351255 }
12361256 }
12371257 return $s;
@@ -1238,21 +1258,21 @@
12391259
12401260 function bottomLinks() {
12411261 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
1242 - $sep = " |\n";
 1262+ $sep = wfMsgExt( 'pipe-separator' , 'escapenoentities' ) . "\n";
12431263
12441264 $s = '';
12451265 if ( $wgOut->isArticleRelated() ) {
1246 - $s .= '<strong>' . $this->editThisPage() . '</strong>';
 1266+ $element[] = '<strong>' . $this->editThisPage() . '</strong>';
12471267 if ( $wgUser->isLoggedIn() ) {
1248 - $s .= $sep . $this->watchThisPage();
 1268+ $element[] = $this->watchThisPage();
12491269 }
1250 - $s .= $sep . $this->talkLink()
1251 - . $sep . $this->historyLink()
1252 - . $sep . $this->whatLinksHere()
1253 - . $sep . $this->watchPageLinksLink();
 1270+ $element[] = $this->talkLink();
 1271+ $element[] = $this->historyLink();
 1272+ $element[] = $this->whatLinksHere();
 1273+ $element[] = $this->watchPageLinksLink();
12541274
12551275 if ($wgUseTrackbacks)
1256 - $s .= $sep . $this->trackbackLink();
 1276+ $element[] = $this->trackbackLink();
12571277
12581278 if ( $wgTitle->getNamespace() == NS_USER
12591279 || $wgTitle->getNamespace() == NS_USER_TALK )
@@ -1262,12 +1282,15 @@
12631283 $ip=User::isIP($wgTitle->getText());
12641284
12651285 if($id || $ip) { # both anons and non-anons have contri list
1266 - $s .= $sep . $this->userContribsLink();
 1286+ $element[] = $this->userContribsLink();
12671287 }
12681288 if( $this->showEmailUser( $id ) ) {
1269 - $s .= $sep . $this->emailUserLink();
 1289+ $element[] = $this->emailUserLink();
12701290 }
12711291 }
 1292+
 1293+ $s = implode( $element, $sep );
 1294+
12721295 if ( $wgTitle->getArticleId() ) {
12731296 $s .= "\n<br />";
12741297 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
@@ -1276,6 +1299,7 @@
12771300 }
12781301 $s .= "<br />\n" . $this->otherLanguages();
12791302 }
 1303+
12801304 return $s;
12811305 }
12821306
@@ -1657,7 +1681,7 @@
16581682 $first = true;
16591683 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
16601684 foreach( $a as $l ) {
1661 - if ( ! $first ) { $s .= ' | '; }
 1685+ if ( ! $first ) { $s .= wfMsgExt( 'pipe-separator' , 'escapenoentities' ); }
16621686 $first = false;
16631687
16641688 $nt = Title::newFromText( $l );

Follow-up revisions

RevisionCommit summaryAuthorDate
r47046(bug 7509) Separation strings should be configurable...siebrand17:48, 9 February 2009

Status & tagging log