From 265404d93cd99bf067064f947f5fc361f54466d7 Mon Sep 17 00:00:00 2001 From: Tyler Anthony Romeo Date: Fri, 2 Nov 2012 16:15:37 -0400 Subject: [PATCH] (bug 41365) Added transclusion count to InfoAction. Currently InfoAction lists the pages that are transcluded onto the specified page. This adds a list of pages on which the current page is transcluded. Also, it adds an option to limit the list size for transclusion links due to memory concerns. Change-Id: I45b077cf3f241b1927f7b1818b04b72115d55c28 --- RELEASE-NOTES-1.21 | 2 + includes/DefaultSettings.php | 7 +++ includes/Linker.php | 19 ++++++-- includes/actions/InfoAction.php | 73 ++++++++++++++++++++++++++---- languages/messages/MessagesEn.php | 2 + languages/messages/MessagesQqq.php | 3 ++ maintenance/language/messages.inc | 2 + 7 files changed, 97 insertions(+), 11 deletions(-) diff --git a/RELEASE-NOTES-1.21 b/RELEASE-NOTES-1.21 index e5e5c6880e..ae51040442 100644 --- a/RELEASE-NOTES-1.21 +++ b/RELEASE-NOTES-1.21 @@ -16,6 +16,8 @@ production. * (bug 39957) Added $wgUnwatchedPageThreshold, specifying minimum count of page watchers required for the number to be accessible to users without the unwatchedpages permission. +* $wgPageInfoTransclusionLimit limits the list size of transcluded articles + on the info action. Default is 50. === New features in 1.21 === * (bug 38110) Schema changes (adding or dropping tables, indicies and diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index aae3d5a381..c6623de588 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -4649,6 +4649,13 @@ $wgAggregateStatsID = false; */ $wgDisableCounters = false; +/** + * InfoAction retrieves a list of transclusion links (both to and from). + * This number puts a limit on that query in the case of highly transcluded + * templates. + */ +$wgPageInfoTransclusionLimit = 50; + /** * Set this to an integer to only do synchronous site_stats updates * one every *this many* updates. The other requests go into pending diff --git a/includes/Linker.php b/includes/Linker.php index 05a9905669..7d84a6a001 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1858,13 +1858,19 @@ class Linker { /** * Returns HTML for the "templates used on this page" list. * + * Make an HTML list of templates, and then add a "More..." link at + * the bottom. If $more is null, do not add a "More..." link. If $more + * is a Title, make a link to that title and use it. If $more is a string, + * directly paste it in as the link. + * * @param $templates Array of templates from Article::getUsedTemplate * or similar - * @param $preview Boolean: whether this is for a preview - * @param $section Boolean: whether this is for a section edit + * @param bool $preview Whether this is for a preview + * @param bool $section Whether this is for a section edit + * @param Title|string|null $more A link for "More..." of the templates * @return String: HTML output */ - public static function formatTemplates( $templates, $preview = false, $section = false ) { + public static function formatTemplates( $templates, $preview = false, $section = false, $more = null ) { wfProfileIn( __METHOD__ ); $outText = ''; @@ -1921,6 +1927,13 @@ class Linker { . wfMessage( 'word-separator' )->escaped() . $protected . ''; } + + if ( $more instanceof Title ) { + $outText .= '
  • ' . self::link( $more, wfMessage( 'moredotdotdot' ) ) . '
  • '; + } elseif ( $more ) { + $outText .= "
  • $more
  • "; + } + $outText .= ''; } wfProfileOut( __METHOD__ ); diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php index 5159a5a42e..642515b1db 100644 --- a/includes/actions/InfoAction.php +++ b/includes/actions/InfoAction.php @@ -165,7 +165,7 @@ class InfoAction extends FormlessAction { * @return array */ protected function pageInfo() { - global $wgContLang, $wgRCMaxAge, $wgMemc, $wgUnwatchedPageThreshold; + global $wgContLang, $wgRCMaxAge, $wgMemc, $wgUnwatchedPageThreshold, $wgPageInfoTransclusionLimit; $user = $this->getUser(); $lang = $this->getLanguage(); @@ -460,11 +460,17 @@ class InfoAction extends FormlessAction { $localizedList = Html::rawElement( 'ul', array(), implode( '', $listItems ) ); $hiddenCategories = $this->page->getHiddenCategories(); - $transcludedTemplates = $title->getTemplateLinksFrom(); - if ( count( $listItems ) > 0 - || count( $hiddenCategories ) > 0 - || count( $transcludedTemplates ) > 0 ) { + if ( + count( $listItems ) > 0 || + count( $hiddenCategories ) > 0 || + $pageCounts['transclusion']['from'] > 0 || + $pageCounts['transclusion']['to'] > 0 + ) { + $options = array( 'LIMIT' => $wgPageInfoTransclusionLimit ); + $transcludedTemplates = $title->getTemplateLinksFrom( $options ); + $transcludedTargets = $title->getTemplateLinksTo( $options ); + // Page properties $pageInfo['header-properties'] = array(); @@ -486,11 +492,44 @@ class InfoAction extends FormlessAction { } // Transcluded templates - if ( count( $transcludedTemplates ) > 0 ) { + if ( $pageCounts['transclusion']['from'] > 0 ) { + if ( $pageCounts['transclusion']['from'] > count( $transcludedTemplates ) ) { + $more = $this->msg( 'morenotlisted' )->escaped(); + } else { + $more = null; + } + $pageInfo['header-properties'][] = array( $this->msg( 'pageinfo-templates' ) - ->numParams( count( $transcludedTemplates ) ), - Linker::formatTemplates( $transcludedTemplates ) + ->numParams( $pageCounts['transclusion']['from'] ), + Linker::formatTemplates( + $transcludedTemplates, + false, + false, + $more ) + ); + } + + if ( $pageCounts['transclusion']['to'] > 0 ) { + if ( $pageCounts['transclusion']['to'] > count( $transcludedTargets ) ) { + $more = Linker::link( + $whatLinksHere, + $this->msg( 'moredotdotdot' )->escaped(), + array(), + array( 'hidelinks' => 1, 'hideredirs' => 1 ) + ); + } else { + $more = null; + } + + $pageInfo['header-properties'][] = array( + $this->msg( 'pageinfo-transclusions' ) + ->numParams( $pageCounts['transclusion']['to'] ), + Linker::formatTemplates( + $transcludedTargets, + false, + false, + $more ) ); } } @@ -608,6 +647,24 @@ class InfoAction extends FormlessAction { + $result['subpages']['nonredirects']; } + // Counts for the number of transclusion links (to/from) + $result['transclusion']['to'] = (int) $dbr->selectField( + 'templatelinks', + 'COUNT(tl_from)', + array( + 'tl_namespace' => $title->getNamespace(), + 'tl_title' => $title->getDBkey() + ), + __METHOD__ + ); + + $result['transclusion']['from'] = (int) $dbr->selectField( + 'templatelinks', + 'COUNT(*)', + array( 'tl_from' => $title->getArticleID() ), + __METHOD__ + ); + wfProfileOut( __METHOD__ ); return $result; } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 49c29499c5..ef523a5154 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -775,6 +775,7 @@ XHTML id names. 'moredotdotdot' => 'More...', 'mypage' => 'Page', 'mytalk' => 'Talk', +'morenotlisted' => 'More not listed...', 'anontalk' => 'Talk for this IP address', 'navigation' => 'Navigation', 'and' => ' and', @@ -3780,6 +3781,7 @@ This is probably caused by a link to a blacklisted external site.', 'pageinfo-hidden-categories' => 'Hidden {{PLURAL:$1|category|categories}} ($1)', 'pageinfo-templates' => 'Transcluded {{PLURAL:$1|template|templates}} ($1)', 'pageinfo-footer' => '-', # do not translate or duplicate this message to other languages +'pageinfo-transclusions' => '{{PLURAL:$1|Page|Pages}} transcluded on ($1)', 'pageinfo-toolboxlink' => 'Page information', 'pageinfo-redirectsto' => 'Redirects to', 'pageinfo-redirectsto-info' => 'info', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index 88175830f6..d6c1adabba 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -363,6 +363,7 @@ See also: * {{msg-mw|Anontalk}} * {{msg-mw|Accesskey-pt-anontalk}} * {{msg-mw|Tooltip-pt-anontalk}}', +'morenotlisted' => 'An indication that more of a certain list is not shown.', 'navigation' => 'This is shown as a section header in the sidebar of most skins. {{Identical|Navigation}}', @@ -6444,6 +6445,8 @@ Used as link text, linked to '{{int:Prefixindex}}' page ([[Special:PrefixIndex]] * $1 is the number of hidden categories on the page.', 'pageinfo-templates' => 'The list of templates transcluded within the page. Parameters: * $1 is the number of templates transcluded within the page.', +'pageinfo-transclusions' => 'The list of pages on which this page is transcluded. Parameters: +* $1 is the number of pages the current page is transcluded on.', 'pageinfo-toolboxlink' => "Information link for the page (like 'What links here', but to action=info for the current page instead)", 'pageinfo-redirectsto' => 'Key for the row shown if this page is a redirect. Verb. See [http://en.wikipedia.org/w/index.php?title=Main_page&action=info example].', 'pageinfo-redirectsto-info' => 'Text to put in parentheses for the link to the action=info of the redirect target.', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 428c1907f9..f2405a70bf 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -167,6 +167,7 @@ $wgMessageStructure = array( 'newwindow', 'cancel', 'moredotdotdot', + 'morenotlisted', 'mypage', 'mytalk', 'anontalk', @@ -2713,6 +2714,7 @@ $wgMessageStructure = array( 'pageinfo-magic-words', 'pageinfo-hidden-categories', 'pageinfo-templates', + 'pageinfo-transclusions', 'pageinfo-footer', 'pageinfo-toolboxlink', 'pageinfo-redirectsto', -- 2.20.1