diff options
Diffstat (limited to 'includes/SkinTemplate.php')
-rw-r--r-- | includes/SkinTemplate.php | 332 |
1 files changed, 173 insertions, 159 deletions
diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 2dd00980..bda43957 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -1,6 +1,6 @@ <?php /** - * Base class for template-based skins + * Base class for template-based skins. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,10 +20,6 @@ * @file */ -if ( !defined( 'MEDIAWIKI' ) ) { - die( 1 ); -} - /** * Wrapper object for MediaWiki's localization functions, * to be passed to the template engine. @@ -44,7 +40,7 @@ class MediaWiki_I18N { // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23 $value = preg_replace( '/^string:/', '', $value ); - $value = wfMsg( $value ); + $value = wfMessage( $value )->text(); // interpolate variables $m = array(); while( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) { @@ -95,7 +91,7 @@ class SkinTemplate extends Skin { var $template = 'QuickTemplate'; /** - * Whether this skin use OutputPage::headElement() to generate the <head> + * Whether this skin use OutputPage::headElement() to generate the "<head>" * tag */ var $useHeadElement = false; @@ -139,7 +135,6 @@ class SkinTemplate extends Skin { global $wgDisableCounters, $wgSitename, $wgLogo, $wgHideInterlanguageLinks; global $wgMaxCredits, $wgShowCreditsIfMax; global $wgPageShowWatchingUsers; - global $wgDebugComments; global $wgArticlePath, $wgScriptPath, $wgServer; wfProfileIn( __METHOD__ ); @@ -216,7 +211,7 @@ class SkinTemplate extends Skin { $tpl->setRef( 'thispage', $this->thispage ); $tpl->setRef( 'titleprefixeddbkey', $this->thispage ); $tpl->set( 'titletext', $title->getText() ); - $tpl->set( 'articleid', $title->getArticleId() ); + $tpl->set( 'articleid', $title->getArticleID() ); $tpl->set( 'isarticle', $out->isArticle() ); @@ -262,7 +257,7 @@ class SkinTemplate extends Skin { /* XXX currently unused, might get useful later $tpl->set( 'editable', ( !$title->isSpecialPage() ) ); $tpl->set( 'exists', $title->getArticleID() != 0 ); - $tpl->set( 'watch', $title->userIsWatching() ? 'unwatch' : 'watch' ); + $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' ); $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' ); $tpl->set( 'helppage', $this->msg( 'helppage' )->text() ); */ @@ -276,20 +271,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 @@ -297,9 +292,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\""; @@ -326,13 +321,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() ); @@ -391,12 +386,6 @@ class SkinTemplate extends Skin { } } - if ( $wgDebugComments ) { - $tpl->setRef( 'debug', $out->mDebugtext ); - } else { - $tpl->set( 'debug', '' ); - } - $tpl->set( 'sitenotice', $this->getSiteNotice() ); $tpl->set( 'bottomscripts', $this->bottomScripts() ); $tpl->set( 'printfooter', $this->printSource() ); @@ -408,10 +397,10 @@ 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(); + $pageLang = $title->getPageViewLanguage(); $realBodyAttribs['lang'] = $pageLang->getHtmlCode(); $realBodyAttribs['dir'] = $pageLang->getDir(); $realBodyAttribs['class'] = 'mw-content-'.$pageLang->getDir(); @@ -430,10 +419,15 @@ class SkinTemplate extends Skin { unset( $tmp ); $nt = Title::newFromText( $l ); if ( $nt ) { + $ilLangName = Language::fetchLanguageName( $nt->getInterwiki() ); + if ( strval( $ilLangName ) === '' ) { + $ilLangName = $l; + } else { + $ilLangName = $this->getLanguage()->ucfirst( $ilLangName ); + } $language_urls[] = array( 'href' => $nt->getFullURL(), - 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ? - $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ), + 'text' => $ilLangName, 'title' => $nt->getText(), 'class' => $class, 'lang' => $nt->getInterwiki(), @@ -442,7 +436,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 ); @@ -467,6 +461,7 @@ class SkinTemplate extends Skin { $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() ); } + $tpl->set( 'debug', '' ); $tpl->set( 'debughtml', $this->generateDebugHTML() ); $tpl->set( 'reporttime', wfReportTime() ); @@ -522,6 +517,7 @@ class SkinTemplate extends Skin { * This is setup as a method so that like with $wgLogo and getLogo() a skin * can override this setting and always output one or the other if it has * a reason it can't output one of the two modes. + * @return bool */ function useCombinedLoginLink() { global $wgUseCombinedLoginLink; @@ -561,7 +557,8 @@ class SkinTemplate extends Skin { 'text' => $this->username, 'href' => &$this->userpageUrlDetails['href'], 'class' => $this->userpageUrlDetails['exists'] ? false : 'new', - 'active' => ( $this->userpageUrlDetails['href'] == $pageurl ) + 'active' => ( $this->userpageUrlDetails['href'] == $pageurl ), + 'dir' => 'auto' ); $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage ); $personal_urls['mytalk'] = array( @@ -584,10 +581,12 @@ class SkinTemplate extends Skin { ); # We need to do an explicit check for Special:Contributions, as we - # have to match both the title, and the target (which could come - # from request values or be specified in "sub page" form. The plot + # have to match both the title, and the target, which could come + # from request values (Special:Contributions?target=Jimbo_Wales) + # or be specified in "sub page" form + # (Special:Contributions/Jimbo_Wales). The plot # thickens, because the Title object is altered for special pages, - # so doesn't contain the original alias-with-subpage. + # so it doesn't contain the original alias-with-subpage. $origTitle = Title::newFromText( $request->getText( 'title' ) ); if( $origTitle instanceof Title && $origTitle->isSpecialPage() ) { list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() ); @@ -618,37 +617,25 @@ 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 + global $wgSecureLogin; + $proto = $wgSecureLogin ? PROTO_HTTPS : null; + + $login_id = $this->showIPinHeader() ? 'anonlogin' : 'login'; $login_url = array( 'text' => $this->msg( $loginlink )->text(), - 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ), - 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" || !$is_signup ) + 'href' => self::makeSpecialUrl( 'Userlogin', $returnto, $proto ), + 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' || !$is_signup ), + 'class' => $wgSecureLogin ? 'link-https' : '' + ); + $createaccount_url = array( + 'text' => $this->msg( 'createaccount' )->text(), + 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup", $proto ), + 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup, + 'class' => $wgSecureLogin ? 'link-https' : '' ); - if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) { - $createaccount_url = array( - 'text' => $this->msg( 'createaccount' )->text(), - 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ), - 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup - ); - } - global $wgServer, $wgSecureLogin; - if( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) { - $title = SpecialPage::getTitleFor( 'Userlogin' ); - $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() ); - $login_url['href'] = $https_url; - # @todo FIXME: Class depends on skin - $login_url['class'] = 'link-https'; - if ( isset($createaccount_url) ) { - $https_url = preg_replace( '/^http:/', 'https:', - $title->getFullURL("type=signup") ); - $createaccount_url['href'] = $https_url; - # @todo FIXME: Class depends on skin - $createaccount_url['class'] = 'link-https'; - } - } - if( $this->showIPinHeader() ) { $href = &$this->userpageUrlDetails['href']; @@ -666,13 +653,13 @@ class SkinTemplate extends Skin { 'class' => $usertalkUrlDetails['exists'] ? false : 'new', 'active' => ( $pageurl == $href ) ); - $personal_urls['anonlogin'] = $login_url; - } else { - $personal_urls['login'] = $login_url; } - if ( isset($createaccount_url) ) { + + if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) { $personal_urls['createaccount'] = $createaccount_url; } + + $personal_urls[$login_id] = $login_url; } wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) ); @@ -702,9 +689,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(); @@ -789,8 +776,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(); @@ -834,7 +822,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 @@ -851,9 +839,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' ); @@ -871,14 +860,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 @@ -932,7 +921,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'; @@ -968,11 +957,12 @@ class SkinTemplate extends Skin { * a change to that procedure these messages will have to remain as * the global versions. */ - $mode = $title->userIsWatching() ? 'unwatch' : 'watch'; + $mode = $user->isWatched( $title ) ? 'unwatch' : 'watch'; $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 ) ) ); } @@ -986,8 +976,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 @@ -1003,7 +993,9 @@ class SkinTemplate extends Skin { $content_navigation['variants'][] = array( 'class' => ( $code == $preferred ) ? 'selected' : false, 'text' => $varname, - 'href' => $title->getLocalURL( array( 'variant' => $code ) ) + 'href' => $title->getLocalURL( array( 'variant' => $code ) ), + 'lang' => $code, + 'hreflang' => $code ); } } @@ -1013,7 +1005,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' ); @@ -1032,7 +1024,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; @@ -1047,14 +1039,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; } } @@ -1083,7 +1075,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; } @@ -1092,11 +1084,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; } @@ -1147,7 +1139,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(), @@ -1161,7 +1153,7 @@ class SkinTemplate extends Skin { if ( $revid ) { $nav_urls['permalink'] = array( 'text' => $this->msg( 'permalink' )->text(), - 'href' => $out->getTitle()->getLocalURL( "oldid=$revid" ) + 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" ) ); } @@ -1174,7 +1166,7 @@ class SkinTemplate extends Skin { $nav_urls['whatlinkshere'] = array( 'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalUrl() ); - if ( $this->getTitle()->getArticleId() ) { + if ( $this->getTitle()->getArticleID() ) { $nav_urls['recentchangeslinked'] = array( 'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalUrl() ); @@ -1189,12 +1181,9 @@ class SkinTemplate extends Skin { 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser ) ); - if ( $user->isLoggedIn() ) { - $logPage = SpecialPage::getTitleFor( 'Log' ); - $nav_urls['log'] = array( - 'href' => $logPage->getLocalUrl( array( 'user' => $rootUser ) ) - ); - } + $nav_urls['log'] = array( + 'href' => self::makeSpecialUrlSubpage( 'Log', $rootUser ) + ); if ( $this->getUser()->isAllowed( 'block' ) ) { $nav_urls['blockip'] = array( @@ -1319,6 +1308,7 @@ abstract class QuickTemplate { /** * @private + * @return bool */ function haveData( $str ) { return isset( $this->data[$str] ); @@ -1354,7 +1344,7 @@ abstract class BaseTemplate extends QuickTemplate { /** * Get a Message object with its context set * - * @param $name Str message name + * @param $name string message name * @return Message */ public function getMsg( $name ) { @@ -1378,6 +1368,7 @@ abstract class BaseTemplate extends QuickTemplate { * stored by SkinTemplate. * The resulting array is built acording to a format intended to be passed * through makeListItem to generate the html. + * @return array */ function getToolbox() { wfProfileIn( __METHOD__ ); @@ -1411,12 +1402,13 @@ abstract class BaseTemplate extends QuickTemplate { } if ( isset( $this->data['nav_urls']['print'] ) && $this->data['nav_urls']['print'] ) { $toolbox['print'] = $this->data['nav_urls']['print']; + $toolbox['print']['id'] = 't-print'; $toolbox['print']['rel'] = 'alternate'; $toolbox['print']['msg'] = 'printableversion'; } 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'; @@ -1438,23 +1430,28 @@ abstract class BaseTemplate extends QuickTemplate { * This is in reality the same list as already stored in personal_urls * however it is reformatted so that you can just pass the individual items * to makeListItem instead of hardcoding the element creation boilerplate. + * @return array */ 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 <a> instead # of the <li> 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; } @@ -1471,7 +1468,7 @@ abstract class BaseTemplate extends QuickTemplate { if ( !isset( $sidebar['LANGUAGES'] ) ) { $sidebar['LANGUAGES'] = true; } - + if ( !isset( $options['search'] ) || $options['search'] !== true ) { unset( $sidebar['SEARCH'] ); } @@ -1481,7 +1478,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 ) { @@ -1491,7 +1488,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, @@ -1500,7 +1497,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(), @@ -1510,12 +1507,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 ); @@ -1528,7 +1525,7 @@ abstract class BaseTemplate extends QuickTemplate { break; } } - + // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd $hookContents = null; if ( isset( $boxes['TOOLBOX'] ) ) { @@ -1543,17 +1540,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 = "<ul>"; + $content = '<ul>'; 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</ul>\n"; @@ -1563,7 +1560,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' => "<ul>{$hookContents}</ul>", @@ -1583,7 +1580,7 @@ abstract class BaseTemplate extends QuickTemplate { // END hack } } - + return $boxes; } @@ -1591,26 +1588,40 @@ abstract class BaseTemplate extends QuickTemplate { * Makes a link, usually used by makeListItem to generate a link for an item * in a list used in navigation lists, portlets, portals, sidebars, etc... * - * $key is a string, usually a key from the list you are generating this link from - * $item is an array containing some of a specific set of keys. - * The text of the link will be generated either from the contents of the "text" - * key in the $item array, if a "msg" key is present a message by that name will - * be used, and if neither of those are set the $key will be used as a message name. + * @param $key string usually a key from the list you are generating this + * link from. + * @param $item array contains some of a specific set of keys. + * + * The text of the link will be generated either from the contents of the + * "text" key in the $item array, if a "msg" key is present a message by + * that name will be used, and if neither of those are set the $key will be + * used as a message name. + * * If a "href" key is not present makeLink will just output htmlescaped text. - * The href, id, class, rel, and type keys are used as attributes for the link if present. - * If an "id" or "single-id" (if you don't want the actual id to be output on the link) - * is present it will be used to generate a tooltip and accesskey for the link. + * The "href", "id", "class", "rel", and "type" keys are used as attributes + * for the link if present. + * + * If an "id" or "single-id" (if you don't want the actual id to be output + * on the link) is present it will be used to generate a tooltip and + * accesskey for the link. + * * If you don't want an accesskey, set $item['tooltiponly'] = true; - * $options can be used to affect the output of a link: - * You can use a text-wrapper key to specify a list of elements to wrap the - * text of a link in. This should be an array of arrays containing a 'tag' and - * optionally an 'attributes' key. If you only have one element you don't need - * to wrap it in another array. eg: To use <a><span>...</span></a> in all links - * use array( 'text-wrapper' => array( 'tag' => 'span' ) ) for your options. - * A link-class key can be used to specify additional classes to apply to all links. - * A link-fallback can be used to specify a tag to use instead of <a> if there is - * no link. eg: If you specify 'link-fallback' => 'span' than any non-link will - * output a <span> instead of just text. + * + * @param $options array can be used to affect the output of a link. + * Possible options are: + * - 'text-wrapper' key to specify a list of elements to wrap the text of + * a link in. This should be an array of arrays containing a 'tag' and + * optionally an 'attributes' key. If you only have one element you don't + * need to wrap it in another array. eg: To use <a><span>...</span></a> + * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) ) + * for your options. + * - 'link-class' key can be used to specify additional classes to apply + * to all links. + * - 'link-fallback' can be used to specify a tag to use instead of "<a>" + * if there is no link. eg: If you specify 'link-fallback' => 'span' than + * any non-link will output a "<span>" instead of just text. + * + * @return string */ function makeLink( $key, $item, $options = array() ) { if ( isset( $item['text'] ) ) { @@ -1671,17 +1682,22 @@ abstract class BaseTemplate extends QuickTemplate { } /** - * Generates a list item for a navigation, portlet, portal, sidebar... etc list - * $key is a string, usually a key from the list you are generating this link from - * $item is an array of list item data containing some of a specific set of keys. + * Generates a list item for a navigation, portlet, portal, sidebar... list + * + * @param $key string, usually a key from the list you are generating this link from. + * @param $item array, of list item data containing some of a specific set of keys. * The "id" and "class" keys will be used as attributes for the list item, * if "active" contains a value of true a "active" class will also be appended to class. - * If you want something other than a <li> you can pass a tag name such as + * + * @param $options array + * + * If you want something other than a "<li>" you can pass a tag name such as * "tag" => "span" in the $options array to change the tag used. * link/content data for the list item may come in one of two forms * A "links" key may be used, in which case it should contain an array with - * a list of links to include inside the list item, see makeLink for the format - * of individual links array items. + * a list of links to include inside the list item, see makeLink for the + * format of individual links array items. + * * Otherwise the relevant keys from the list item $item array will be passed * to makeLink instead. Note however that "id" and "class" are used by the * list item directly so they will not be passed to makeLink @@ -1689,6 +1705,8 @@ abstract class BaseTemplate extends QuickTemplate { * If you need an id or class on a single link you should include a "links" * array with just one link item inside of it. * $options is also passed on to makeLink calls + * + * @return string */ function makeListItem( $key, $item, $options = array() ) { if ( isset( $item['links'] ) ) { @@ -1783,6 +1801,7 @@ abstract class BaseTemplate extends QuickTemplate { * If you pass "flat" as an option then the returned array will be a flat array * of footer icons instead of a key/value array of footerlinks arrays broken * up into categories. + * @return array|mixed */ function getFooterLinks( $option = null ) { $footerlinks = $this->data['footerlinks']; @@ -1821,6 +1840,7 @@ abstract class BaseTemplate extends QuickTemplate { * in the list of footer icons. This is mostly useful for skins which only * display the text from footericons instead of the images and don't want a * duplicate copyright statement because footerlinks already rendered one. + * @return */ function getFooterIcons( $option = null ) { // Generate additional footer icons @@ -1857,15 +1877,9 @@ abstract class BaseTemplate extends QuickTemplate { * body and html tags. */ function printTrail() { ?> -<?php $this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?> -<?php $this->html('reporttime') ?> -<?php if ( $this->data['debug'] ): ?> -<!-- Debug output: -<?php $this->text( 'debug' ); ?> - ---> -<?php endif; +<?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?> +<?php $this->html( 'reporttime' ) ?> +<?php echo MWDebug::getDebugHTML( $this->getSkin()->getContext() ); } } - |