(bug 41365) Added transclusion count to InfoAction.
authorTyler Anthony Romeo <tylerromeo@gmail.com>
Fri, 2 Nov 2012 20:15:37 +0000 (16:15 -0400)
committerTyler Anthony Romeo <tylerromeo@gmail.com>
Tue, 8 Jan 2013 16:45:45 +0000 (11:45 -0500)
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
includes/DefaultSettings.php
includes/Linker.php
includes/actions/InfoAction.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index e5e5c68..ae51040 100644 (file)
@@ -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
index aae3d5a..c6623de 100644 (file)
@@ -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
index 05a9905..7d84a6a 100644 (file)
@@ -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 . '</li>';
                        }
+
+                       if ( $more instanceof Title ) {
+                               $outText .= '<li>' . self::link( $more, wfMessage( 'moredotdotdot' ) ) . '</li>';
+                       } elseif ( $more ) {
+                               $outText .= "<li>$more</li>";
+                       }
+
                        $outText .= '</ul>';
                }
                wfProfileOut( __METHOD__  );
index 5159a5a..642515b 100644 (file)
@@ -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;
        }
index 49c2949..ef523a5 100644 (file)
@@ -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'           => '&#32;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',
index 8817583..d6c1ada 100644 (file)
@@ -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.',
index 428c190..f2405a7 100644 (file)
@@ -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',