From: Timo Tijhof Date: Mon, 18 Jun 2012 23:26:40 +0000 (+0200) Subject: SkinTemplate: Minor clean up X-Git-Tag: 1.31.0-rc.0~23287 X-Git-Url: http://git.cyclocoop.org/data/%24self?a=commitdiff_plain;h=c55cdd64444718db44a4637e8c932aef0c78f93d;p=lhc%2Fweb%2Fwiklou.git SkinTemplate: Minor clean up * Better variable names ($wgContLang is object, $userLang was a string and $lang the object. Made $userLang the object and $userLangCode the string. * Removed trailing whitespace. * Spacing (not all just where it fit better in the context, some isset($) to isset( $ ). and a few `if()` to `if ()` since most in this file are like that. * Some redundant magic quote usage to single quotes. * Weird structure in getPersonalTools(): Instead of accessing the same deep array property over and over again to add something to the newly create array (e.g. $foo[] = array(); and then $foo[0] = $bar;) simply creating it as a literal at once. Change-Id: I861ae1d558f324f61c79089dcd3bff52dd27e0aa --- diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index aee2e837ba..8306304f61 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -272,20 +272,20 @@ class SkinTemplate extends Skin { $tpl->setRef( 'logopath', $wgLogo ); $tpl->setRef( 'sitename', $wgSitename ); - $lang = $this->getLanguage(); - $userlang = $lang->getHtmlCode(); - $userdir = $lang->getDir(); + $userLang = $this->getLanguage(); + $userLangCode = $userLang->getHtmlCode(); + $userLangDir = $userLang->getDir(); - $tpl->set( 'lang', $userlang ); - $tpl->set( 'dir', $userdir ); - $tpl->set( 'rtl', $lang->isRTL() ); + $tpl->set( 'lang', $userLangCode ); + $tpl->set( 'dir', $userLangDir ); + $tpl->set( 'rtl', $userLang->isRTL() ); - $tpl->set( 'capitalizeallnouns', $lang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' ); + $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' ); $tpl->set( 'showjumplinks', $user->getOption( 'showjumplinks' ) ); $tpl->set( 'username', $this->loggedin ? $this->username : null ); $tpl->setRef( 'userpage', $this->userpage ); $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] ); - $tpl->set( 'userlang', $userlang ); + $tpl->set( 'userlang', $userLangCode ); // Users can have their language set differently than the // content of the wiki. For these users, tell the web browser @@ -293,9 +293,9 @@ class SkinTemplate extends Skin { $tpl->set( 'userlangattributes', '' ); $tpl->set( 'specialpageattributes', '' ); # obsolete - if ( $userlang !== $wgContLang->getHtmlCode() || $userdir !== $wgContLang->getDir() ) { - $escUserlang = htmlspecialchars( $userlang ); - $escUserdir = htmlspecialchars( $userdir ); + if ( $userLangCode !== $wgContLang->getHtmlCode() || $userLangDir !== $wgContLang->getDir() ) { + $escUserlang = htmlspecialchars( $userLangCode ); + $escUserdir = htmlspecialchars( $userLangDir ); // Attributes must be in double quotes because htmlspecialchars() doesn't // escape single quotes $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\""; @@ -322,13 +322,13 @@ class SkinTemplate extends Skin { } } - if( $wgPageShowWatchingUsers ) { + if ( $wgPageShowWatchingUsers ) { $dbr = wfGetDB( DB_SLAVE ); $num = $dbr->selectField( 'watchlist', 'COUNT(*)', array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ), __METHOD__ ); - if( $num > 0 ) { + if ( $num > 0 ) { $tpl->set( 'numberofwatchingusers', $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse() ); @@ -404,7 +404,7 @@ class SkinTemplate extends Skin { # when the content is different from the UI language, i.e.: # not for special pages or file pages AND only when viewing AND if the page exists # (or is in MW namespace, because that has default content) - if( !in_array( $title->getNamespace(), array( NS_SPECIAL, NS_FILE ) ) && + if ( !in_array( $title->getNamespace(), array( NS_SPECIAL, NS_FILE ) ) && in_array( $request->getVal( 'action', 'view' ), array( 'view', 'historysubmit' ) ) && ( $title->exists() || $title->getNamespace() == NS_MEDIAWIKI ) ) { $pageLang = $title->getPageLanguage(); @@ -438,7 +438,7 @@ class SkinTemplate extends Skin { } } } - if( count( $language_urls ) ) { + if ( count( $language_urls ) ) { $tpl->setRef( 'language_urls', $language_urls ); } else { $tpl->set( 'language_urls', false ); @@ -617,13 +617,13 @@ class SkinTemplate extends Skin { $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink ? 'nav-login-createaccount' : 'login'; - $is_signup = $request->getText('type') == "signup"; + $is_signup = $request->getText( 'type' ) == 'signup'; # anonlogin & login are the same $login_url = array( 'text' => $this->msg( $loginlink )->text(), 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ), - 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" || !$is_signup ) + 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' || !$is_signup ) ); if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) { $createaccount_url = array( @@ -639,9 +639,9 @@ class SkinTemplate extends Skin { $login_url['href'] = $https_url; # @todo FIXME: Class depends on skin $login_url['class'] = 'link-https'; - if ( isset($createaccount_url) ) { + if ( isset( $createaccount_url ) ) { $https_url = preg_replace( '/^http:/', 'https:', - $title->getFullURL("type=signup") ); + $title->getFullURL( 'type=signup' ) ); $createaccount_url['href'] = $https_url; # @todo FIXME: Class depends on skin $createaccount_url['class'] = 'link-https'; @@ -701,9 +701,9 @@ class SkinTemplate extends Skin { // wfMessageFallback will nicely accept $message as an array of fallbacks // or just a single key $msg = wfMessageFallback( $message )->setContext( $this->getContext() ); - if ( is_array($message) ) { + if ( is_array( $message ) ) { // for hook compatibility just keep the last message name - $message = end($message); + $message = end( $message ); } if ( $msg->exists() ) { $text = $msg->text(); @@ -788,8 +788,9 @@ class SkinTemplate extends Skin { wfProfileIn( __METHOD__ ); - $title = $this->getRelevantTitle(); // Display tabs for the relevant title rather than always the title itself - $onPage = $title->equals($this->getTitle()); + // Display tabs for the relevant title rather than always the title itself + $title = $this->getRelevantTitle(); + $onPage = $title->equals( $this->getTitle() ); $out = $this->getOutput(); $request = $this->getRequest(); @@ -833,7 +834,7 @@ class SkinTemplate extends Skin { // Adds namespace links $subjectMsg = array( "nstab-$subjectId" ); if ( $subjectPage->isMainPage() ) { - array_unshift($subjectMsg, 'mainpage-nstab'); + array_unshift( $subjectMsg, 'mainpage-nstab' ); } $content_navigation['namespaces'][$subjectId] = $this->tabAction( $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead @@ -850,9 +851,10 @@ class SkinTemplate extends Skin { $content_navigation['views']['view'] = $this->tabAction( $isTalk ? $talkPage : $subjectPage, array( "$skname-view-view", 'view' ), - ( $onPage && ($action == 'view' || $action == 'purge' ) ), '', true + ( $onPage && ( $action == 'view' || $action == 'purge' ) ), '', true ); - $content_navigation['views']['view']['redundant'] = true; // signal to hide this from simple content_actions + // signal to hide this from simple content_actions + $content_navigation['views']['view']['redundant'] = true; } wfProfileIn( __METHOD__ . '-edit' ); @@ -870,14 +872,14 @@ class SkinTemplate extends Skin { $section = $request->getVal( 'section' ); $msgKey = $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDefaultMessageText() !== false ) ? - "edit" : "create"; + 'edit' : 'create'; $content_navigation['views']['edit'] = array( 'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection ) ? 'selected' : '' ) . $isTalkClass, 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(), 'href' => $title->getLocalURL( $this->editUrlOptions() ), 'primary' => true, // don't collapse this in vector ); - + // section link if ( $showNewSection ) { // Adds new section link @@ -931,7 +933,7 @@ class SkinTemplate extends Skin { // article doesn't exist or is deleted if ( $user->isAllowed( 'deletedhistory' ) ) { $n = $title->isDeleted(); - if( $n ) { + if ( $n ) { $undelTitle = SpecialPage::getTitleFor( 'Undelete' ); // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead $msgKey = $user->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted'; @@ -971,7 +973,8 @@ class SkinTemplate extends Skin { $token = WatchAction::getWatchToken( $title, $user, $mode ); $content_navigation['actions'][$mode] = array( 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false, - 'text' => $this->msg( $mode )->text(), // uses 'watch' or 'unwatch' message + // uses 'watch' or 'unwatch' message + 'text' => $this->msg( $mode )->text(), 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) ) ); } @@ -985,8 +988,8 @@ class SkinTemplate extends Skin { $variants = $pageLang->getVariants(); // Checks that language conversion is enabled and variants exist // And if it is not in the special namespace - if( count( $variants ) > 1 ) { - // Gets preferred variant (note that user preference is + if ( count( $variants ) > 1 ) { + // Gets preferred variant (note that user preference is // only possible for wiki content language variant) $preferred = $pageLang->getPreferredVariant(); // Loops over each variant @@ -1014,7 +1017,7 @@ class SkinTemplate extends Skin { $content_navigation['namespaces']['special'] = array( 'class' => 'selected', 'text' => $this->msg( 'nstab-special' )->text(), - 'href' => $request->getRequestURL(), // @bug 2457, 2510 + 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510 'context' => 'subject' ); @@ -1033,7 +1036,7 @@ class SkinTemplate extends Skin { $xmlID = 'ca-nstab-' . $xmlID; } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) { $xmlID = 'ca-talk'; - } elseif ( $section == "variants" ) { + } elseif ( $section == 'variants' ) { $xmlID = 'ca-varlang-' . $xmlID; } else { $xmlID = 'ca-' . $xmlID; @@ -1048,14 +1051,14 @@ class SkinTemplate extends Skin { # give the edit tab an accesskey, because that's fairly su- # perfluous and conflicts with an accesskey (Ctrl-E) often # used for editing in Safari. - if( in_array( $action, array( 'edit', 'submit' ) ) ) { - if ( isset($content_navigation['views']['edit']) ) { + if ( in_array( $action, array( 'edit', 'submit' ) ) ) { + if ( isset( $content_navigation['views']['edit'] ) ) { $content_navigation['views']['edit']['tooltiponly'] = true; } - if ( isset($content_navigation['actions']['watch']) ) { + if ( isset( $content_navigation['actions']['watch'] ) ) { $content_navigation['actions']['watch']['tooltiponly'] = true; } - if ( isset($content_navigation['actions']['unwatch']) ) { + if ( isset( $content_navigation['actions']['unwatch'] ) ) { $content_navigation['actions']['unwatch']['tooltiponly'] = true; } } @@ -1084,7 +1087,7 @@ class SkinTemplate extends Skin { foreach ( $links as $key => $value ) { - if ( isset($value["redundant"]) && $value["redundant"] ) { + if ( isset( $value['redundant'] ) && $value['redundant'] ) { // Redundant tabs are dropped from content_actions continue; } @@ -1093,11 +1096,11 @@ class SkinTemplate extends Skin { // so the xmlID based id is much closer to the actual $key that we want // for that reason we'll just strip out the ca- if present and use // the latter potion of the "id" as the $key - if ( isset($value["id"]) && substr($value["id"], 0, 3) == "ca-" ) { - $key = substr($value["id"], 3); + if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) { + $key = substr( $value['id'], 3 ); } - if ( isset($content_actions[$key]) ) { + if ( isset( $content_actions[$key] ) ) { wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening content_navigation into content_actions." ); continue; } @@ -1148,7 +1151,7 @@ class SkinTemplate extends Skin { // A print stylesheet is attached to all pages, but nobody ever // figures that out. :) Add a link... - if( $out->isArticle() ) { + if ( $out->isArticle() ) { if ( !$out->isPrintable() ) { $nav_urls['print'] = array( 'text' => $this->msg( 'printableversion' )->text(), @@ -1417,7 +1420,7 @@ abstract class BaseTemplate extends QuickTemplate { } if ( isset( $this->data['nav_urls']['permalink'] ) && $this->data['nav_urls']['permalink'] ) { $toolbox['permalink'] = $this->data['nav_urls']['permalink']; - if( $toolbox['permalink']['href'] === '' ) { + if ( $toolbox['permalink']['href'] === '' ) { unset( $toolbox['permalink']['href'] ); $toolbox['ispermalink']['tooltiponly'] = true; $toolbox['ispermalink']['id'] = 't-ispermalink'; @@ -1443,20 +1446,24 @@ abstract class BaseTemplate extends QuickTemplate { */ function getPersonalTools() { $personal_tools = array(); - foreach( $this->data['personal_urls'] as $key => $ptool ) { + foreach ( $this->data['personal_urls'] as $key => $plink ) { # The class on a personal_urls item is meant to go on the instead # of the
  • so we have to use a single item "links" array instead - # of using most of the personal_url's keys directly - $personal_tools[$key] = array(); - $personal_tools[$key]["links"][] = array(); - $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key"; - if ( isset($ptool["active"]) ) { - $personal_tools[$key]["active"] = $ptool["active"]; + # of using most of the personal_url's keys directly. + $ptool = array( + 'links' => array( + array( 'single-id' => "pt-$key" ), + ), + 'id' => "pt-$key", + ); + if ( isset( $plink['active'] ) ) { + $ptool['active'] = $plink['active']; } - foreach ( array("href", "class", "text") as $k ) { - if ( isset($ptool[$k]) ) - $personal_tools[$key]["links"][0][$k] = $ptool[$k]; + foreach ( array( 'href', 'class', 'text' ) as $k ) { + if ( isset( $plink[$k] ) ) + $ptool['links'][0][$k] = $plink[$k]; } + $personal_tools[$key] = $ptool; } return $personal_tools; } @@ -1473,7 +1480,7 @@ abstract class BaseTemplate extends QuickTemplate { if ( !isset( $sidebar['LANGUAGES'] ) ) { $sidebar['LANGUAGES'] = true; } - + if ( !isset( $options['search'] ) || $options['search'] !== true ) { unset( $sidebar['SEARCH'] ); } @@ -1483,7 +1490,7 @@ abstract class BaseTemplate extends QuickTemplate { if ( isset( $options['languages'] ) && $options['languages'] === false ) { unset( $sidebar['LANGUAGES'] ); } - + $boxes = array(); foreach ( $sidebar as $boxName => $content ) { if ( $content === false ) { @@ -1493,7 +1500,7 @@ abstract class BaseTemplate extends QuickTemplate { case 'SEARCH': // Search is a special case, skins should custom implement this $boxes[$boxName] = array( - 'id' => "p-search", + 'id' => 'p-search', 'header' => $this->getMsg( 'search' )->text(), 'generated' => false, 'content' => true, @@ -1502,7 +1509,7 @@ abstract class BaseTemplate extends QuickTemplate { case 'TOOLBOX': $msgObj = $this->getMsg( 'toolbox' ); $boxes[$boxName] = array( - 'id' => "p-tb", + 'id' => 'p-tb', 'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox', 'generated' => false, 'content' => $this->getToolbox(), @@ -1512,12 +1519,12 @@ abstract class BaseTemplate extends QuickTemplate { if ( $this->data['language_urls'] ) { $msgObj = $this->getMsg( 'otherlanguages' ); $boxes[$boxName] = array( - 'id' => "p-lang", + 'id' => 'p-lang', 'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages', 'generated' => false, 'content' => $this->data['language_urls'], ); - } + } break; default: $msgObj = $this->getMsg( $boxName ); @@ -1530,7 +1537,7 @@ abstract class BaseTemplate extends QuickTemplate { break; } } - + // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd $hookContents = null; if ( isset( $boxes['TOOLBOX'] ) ) { @@ -1545,17 +1552,17 @@ abstract class BaseTemplate extends QuickTemplate { } } // END hack - + if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) { foreach ( $boxes as $boxName => $box ) { if ( is_array( $box['content'] ) ) { - $content = "
      "; + $content = '
        '; foreach ( $box['content'] as $key => $val ) { $content .= "\n " . $this->makeListItem( $key, $val ); } // HACK, shove the toolbox end onto the toolbox if we're rendering itself if ( $hookContents ) { - $content .= "\n $hookContents"; + $content .= "\n $hookContents"; } // END hack $content .= "\n
      \n"; @@ -1565,7 +1572,7 @@ abstract class BaseTemplate extends QuickTemplate { } else { if ( $hookContents ) { $boxes['TOOLBOXEND'] = array( - 'id' => "p-toolboxend", + 'id' => 'p-toolboxend', 'header' => $boxes['TOOLBOX']['header'], 'generated' => false, 'content' => "
        {$hookContents}
      ", @@ -1585,7 +1592,7 @@ abstract class BaseTemplate extends QuickTemplate { // END hack } } - + return $boxes; } @@ -1863,8 +1870,8 @@ abstract class BaseTemplate extends QuickTemplate { * body and html tags. */ function printTrail() { ?> -html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?> -html('reporttime') ?> +html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?> +html( 'reporttime' ) ?> data['debug'] ): ?>