diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-06-04 07:31:04 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-06-04 07:58:39 +0200 |
commit | f6d65e533c62f6deb21342d4901ece24497b433e (patch) | |
tree | f28adf0362d14bcd448f7b65a7aaf38650f923aa /includes/skins/Skin.php | |
parent | c27b2e832fe25651ef2410fae85b41072aae7519 (diff) |
Update to MediaWiki 1.25.1
Diffstat (limited to 'includes/skins/Skin.php')
-rw-r--r-- | includes/skins/Skin.php | 176 |
1 files changed, 110 insertions, 66 deletions
diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index 2f6a7101..ac7a85ba 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -168,11 +168,9 @@ abstract class Skin extends ContextSource { * @param OutputPage $out */ function initPage( OutputPage $out ) { - wfProfileIn( __METHOD__ ); $this->preloadExistence(); - wfProfileOut( __METHOD__ ); } /** @@ -239,25 +237,33 @@ abstract class Skin extends ContextSource { * Preload the existence of three commonly-requested pages in a single query */ function preloadExistence() { + $titles = array(); + $user = $this->getUser(); + $title = $this->getRelevantTitle(); // User/talk link - $titles = array( $user->getUserPage(), $user->getTalkPage() ); + if ( $user->isLoggedIn() || $this->showIPinHeader() ) { + $titles[] = $user->getUserPage(); + $titles[] = $user->getTalkPage(); + } // Other tab link - if ( $this->getTitle()->isSpecialPage() ) { + if ( $title->isSpecialPage() ) { // nothing - } elseif ( $this->getTitle()->isTalkPage() ) { - $titles[] = $this->getTitle()->getSubjectPage(); + } elseif ( $title->isTalkPage() ) { + $titles[] = $title->getSubjectPage(); } else { - $titles[] = $this->getTitle()->getTalkPage(); + $titles[] = $title->getTalkPage(); } - wfRunHooks( 'SkinPreloadExistence', array( &$titles, $this ) ); + Hooks::run( 'SkinPreloadExistence', array( &$titles, $this ) ); - $lb = new LinkBatch( $titles ); - $lb->setCaller( __METHOD__ ); - $lb->execute(); + if ( count( $titles ) ) { + $lb = new LinkBatch( $titles ); + $lb->setCaller( __METHOD__ ); + $lb->execute(); + } } /** @@ -333,8 +339,13 @@ abstract class Skin extends ContextSource { $this->mRelevantUser = User::newFromName( $rootUser, false ); } else { $user = User::newFromName( $rootUser, false ); - if ( $user && $user->isLoggedIn() ) { - $this->mRelevantUser = $user; + + if ( $user ) { + $user->load( User::READ_NORMAL ); + + if ( $user->isLoggedIn() ) { + $this->mRelevantUser = $user; + } } } return $this->mRelevantUser; @@ -474,9 +485,10 @@ abstract class Skin extends ContextSource { $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) )->escaped(); $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text(); + $title = Title::newFromText( $linkPage ); + $link = $title ? Linker::link( $title, $msg ) : $msg; $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' . - Linker::link( Title::newFromText( $linkPage ), $msg ) - . $colon . '<ul>' . $t . '</ul>' . '</div>'; + $link . $colon . '<ul>' . $t . '</ul>' . '</div>'; } # Hidden categories @@ -579,7 +591,7 @@ abstract class Skin extends ContextSource { protected function afterContentHook() { $data = ''; - if ( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) { + if ( Hooks::run( 'SkinAfterContent', array( &$data, $this ) ) ) { // adding just some spaces shouldn't toggle the output // of the whole <div/>, so we use trim() here if ( trim( $data ) != '' ) { @@ -616,7 +628,7 @@ abstract class Skin extends ContextSource { // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned // up at some point $bottomScriptText = $this->getOutput()->getBottomScripts(); - wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) ); + Hooks::run( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) ); return $bottomScriptText; } @@ -637,22 +649,23 @@ abstract class Skin extends ContextSource { $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) ); } - return $this->msg( 'retrievedfrom', '<a dir="ltr" href="' . $url - . '">' . $url . '</a>' )->text(); + return $this->msg( 'retrievedfrom' ) + ->rawParams( '<a dir="ltr" href="' . $url. '">' . $url . '</a>' ) + ->parse(); } /** - * @return string + * @return string HTML */ function getUndeleteLink() { $action = $this->getRequest()->getVal( 'action', 'view' ); - if ( $this->getUser()->isAllowed( 'deletedhistory' ) && - ( $this->getTitle()->getArticleID() == 0 || $action == 'history' ) ) { + if ( $this->getTitle()->userCan( 'deletedhistory', $this->getUser() ) && + ( !$this->getTitle()->exists() || $action == 'history' ) ) { $n = $this->getTitle()->isDeleted(); if ( $n ) { - if ( $this->getUser()->isAllowed( 'undelete' ) ) { + if ( $this->getTitle()->quickUserCan( 'undelete', $this->getUser() ) ) { $msg = 'thisisdeleted'; } else { $msg = 'viewdeleted'; @@ -662,7 +675,7 @@ abstract class Skin extends ContextSource { Linker::linkKnown( SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ), $this->msg( 'restorelink' )->numParams( $n )->escaped() ) - )->text(); + )->escaped(); } } @@ -676,7 +689,7 @@ abstract class Skin extends ContextSource { $out = $this->getOutput(); $subpages = ''; - if ( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) { + if ( !Hooks::run( 'SkinSubPageSubtitle', array( &$subpages, $this, $out ) ) ) { return $subpages; } @@ -785,7 +798,7 @@ abstract class Skin extends ContextSource { // @todo Remove deprecated $forContent param from hook handlers and then remove here. $forContent = true; - wfRunHooks( + Hooks::run( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) ); @@ -829,10 +842,19 @@ abstract class Skin extends ContextSource { function getPoweredBy() { global $wgResourceBasePath; - $url = htmlspecialchars( "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png" ); - $text = '<a href="//www.mediawiki.org/"><img src="' . $url - . '" height="31" width="88" alt="Powered by MediaWiki" /></a>'; - wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) ); + $url1 = htmlspecialchars( + "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png" + ); + $url1_5 = htmlspecialchars( + "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png" + ); + $url2 = htmlspecialchars( + "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png" + ); + $text = '<a href="//www.mediawiki.org/"><img src="' . $url1 + . '" srcset="' . $url1_5 . ' 1.5x, ' . $url2 . ' 2x" ' + . 'height="31" width="88" alt="Powered by MediaWiki" /></a>'; + Hooks::run( 'SkinGetPoweredBy', array( &$text, $this ) ); return $text; } @@ -852,13 +874,13 @@ abstract class Skin extends ContextSource { if ( $timestamp ) { $d = $this->getLanguage()->userDate( $timestamp, $this->getUser() ); $t = $this->getLanguage()->userTime( $timestamp, $this->getUser() ); - $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->text(); + $s = ' ' . $this->msg( 'lastmodifiedat', $d, $t )->parse(); } else { $s = ''; } if ( wfGetLB()->getLaggedSlaveMode() ) { - $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->text() . '</strong>'; + $s .= ' <strong>' . $this->msg( 'laggedslavemode' )->parse() . '</strong>'; } return $s; @@ -942,6 +964,10 @@ abstract class Skin extends ContextSource { // but we make the link target be the one site-wide page. $title = Title::newFromText( $this->msg( $page )->inContentLanguage()->text() ); + if ( !$title ) { + return ''; + } + return Linker::linkKnown( $title, $this->msg( $desc )->escaped() @@ -1031,6 +1057,7 @@ abstract class Skin extends ContextSource { * * @param string $name The name or path of a skin resource file * @return string The fully resolved style path url including styleversion + * @throws MWException */ function getSkinStylePath( $name ) { global $wgStylePath, $wgStyleVersion; @@ -1150,7 +1177,7 @@ abstract class Skin extends ContextSource { return array( 'href' => $title->getLocalURL( $urlaction ), - 'exists' => $title->getArticleID() != 0, + 'exists' => $title->isKnown(), ); } @@ -1208,16 +1235,14 @@ abstract class Skin extends ContextSource { */ function buildSidebar() { global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry; - wfProfileIn( __METHOD__ ); $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() ); if ( $wgEnableSidebarCache ) { $cachedsidebar = $wgMemc->get( $key ); if ( $cachedsidebar ) { - wfRunHooks( 'SidebarBeforeOutput', array( $this, &$cachedsidebar ) ); + Hooks::run( 'SidebarBeforeOutput', array( $this, &$cachedsidebar ) ); - wfProfileOut( __METHOD__ ); return $cachedsidebar; } } @@ -1225,14 +1250,13 @@ abstract class Skin extends ContextSource { $bar = array(); $this->addToSidebar( $bar, 'sidebar' ); - wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) ); + Hooks::run( 'SkinBuildSidebar', array( $this, &$bar ) ); if ( $wgEnableSidebarCache ) { $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry ); } - wfRunHooks( 'SidebarBeforeOutput', array( $this, &$bar ) ); + Hooks::run( 'SidebarBeforeOutput', array( $this, &$bar ) ); - wfProfileOut( __METHOD__ ); return $bar; } @@ -1370,7 +1394,7 @@ abstract class Skin extends ContextSource { $out = $this->getOutput(); // Allow extensions to disable or modify the new messages alert - if ( !wfRunHooks( 'GetNewMessagesAlert', array( &$newMessagesAlert, $newtalks, $user, $out ) ) ) { + if ( !Hooks::run( 'GetNewMessagesAlert', array( &$newMessagesAlert, $newtalks, $user, $out ) ) ) { return ''; } if ( $newMessagesAlert ) { @@ -1453,13 +1477,12 @@ abstract class Skin extends ContextSource { * Get a cached notice * * @param string $name Message name, or 'default' for $wgSiteNotice - * @return string HTML fragment + * @return string|bool HTML fragment, or false to indicate that the caller + * should fall back to the next notice in its sequence */ private function getCachedNotice( $name ) { global $wgRenderHashAppend, $parserMemc, $wgContLang; - wfProfileIn( __METHOD__ ); - $needParse = false; if ( $name === 'default' ) { @@ -1467,13 +1490,13 @@ abstract class Skin extends ContextSource { global $wgSiteNotice; $notice = $wgSiteNotice; if ( empty( $notice ) ) { - wfProfileOut( __METHOD__ ); return false; } } else { $msg = $this->msg( $name )->inContentLanguage(); - if ( $msg->isDisabled() ) { - wfProfileOut( __METHOD__ ); + if ( $msg->isBlank() ) { + return ''; + } elseif ( $msg->isDisabled() ) { return false; } $notice = $msg->plain(); @@ -1500,7 +1523,6 @@ abstract class Skin extends ContextSource { $notice = Html::rawElement( 'div', array( 'id' => 'localNotice', 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice ); - wfProfileOut( __METHOD__ ); return $notice; } @@ -1510,7 +1532,6 @@ abstract class Skin extends ContextSource { * @return string HTML fragment */ function getNamespaceNotice() { - wfProfileIn( __METHOD__ ); $key = 'namespacenotice-' . $this->getTitle()->getNsText(); $namespaceNotice = $this->getCachedNotice( $key ); @@ -1520,7 +1541,6 @@ abstract class Skin extends ContextSource { $namespaceNotice = ''; } - wfProfileOut( __METHOD__ ); return $namespaceNotice; } @@ -1530,27 +1550,25 @@ abstract class Skin extends ContextSource { * @return string HTML fragment */ function getSiteNotice() { - wfProfileIn( __METHOD__ ); $siteNotice = ''; - if ( wfRunHooks( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) { + if ( Hooks::run( 'SiteNoticeBefore', array( &$siteNotice, $this ) ) ) { if ( is_object( $this->getUser() ) && $this->getUser()->isLoggedIn() ) { $siteNotice = $this->getCachedNotice( 'sitenotice' ); } else { $anonNotice = $this->getCachedNotice( 'anonnotice' ); - if ( !$anonNotice ) { + if ( $anonNotice === false ) { $siteNotice = $this->getCachedNotice( 'sitenotice' ); } else { $siteNotice = $anonNotice; } } - if ( !$siteNotice ) { + if ( $siteNotice === false ) { $siteNotice = $this->getCachedNotice( 'default' ); } } - wfRunHooks( 'SiteNoticeAfter', array( &$siteNotice, $this ) ); - wfProfileOut( __METHOD__ ); + Hooks::run( 'SiteNoticeAfter', array( &$siteNotice, $this ) ); return $siteNotice; } @@ -1580,20 +1598,46 @@ abstract class Skin extends ContextSource { $attribs['title'] = wfMessage( 'editsectionhint' )->rawParams( $tooltip ) ->inLanguage( $lang )->text(); } - $link = Linker::link( $nt, wfMessage( 'editsection' )->inLanguage( $lang )->text(), - $attribs, - array( 'action' => 'edit', 'section' => $section ), - array( 'noclasses', 'known' ) + + $links = array( + 'editsection' => array( + 'text' => wfMessage( 'editsection' )->inLanguage( $lang )->escaped(), + 'targetTitle' => $nt, + 'attribs' => $attribs, + 'query' => array( 'action' => 'edit', 'section' => $section ), + 'options' => array( 'noclasses', 'known' ) + ) ); - # Add the brackets and the span and run the hook. - $result = '<span class="mw-editsection">' - . '<span class="mw-editsection-bracket">[</span>' - . $link - . '<span class="mw-editsection-bracket">]</span>' - . '</span>'; + Hooks::run( 'SkinEditSectionLinks', array( $this, $nt, $section, $tooltip, &$links, $lang ) ); + + $result = '<span class="mw-editsection"><span class="mw-editsection-bracket">[</span>'; - wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) ); + $linksHtml = array(); + foreach ( $links as $k => $linkDetails ) { + $linksHtml[] = Linker::link( + $linkDetails['targetTitle'], + $linkDetails['text'], + $linkDetails['attribs'], + $linkDetails['query'], + $linkDetails['options'] + ); + } + + $result .= implode( + '<span class="mw-editsection-divider">' + . wfMessage( 'pipe-separator' )->inLanguage( $lang )->text() + . '</span>', + $linksHtml + ); + + $result .= '<span class="mw-editsection-bracket">]</span></span>'; + // Deprecated, use SkinEditSectionLinks hook instead + Hooks::run( + 'DoEditSectionLink', + array( $this, $nt, $section, $tooltip, &$result, $lang ), + '1.25' + ); return $result; } |