A few action=info bugfixes and enhancements.
authorAlex Monk <krenair@gmail.com>
Tue, 4 Sep 2012 13:02:32 +0000 (14:02 +0100)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 4 Oct 2012 15:29:51 +0000 (15:29 +0000)
(bug 39533) Merge action=credits into action=info.
(bug 39951) Remove redundant 'Page protection' text.
(bug 39953) Don't show irrelevant protection statuses.
(bug 39954) Use proper section headers.
(bug 39955) Link page creator and latest editor values.

Change-Id: I68308aac96b89c2aec296e2a4fa385fd1d42ab5a

includes/actions/CreditsAction.php
includes/actions/InfoAction.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index f715229..defd93e 100644 (file)
@@ -29,204 +29,12 @@ class CreditsAction extends FormlessAction {
                return 'credits';
        }
 
-       protected function getDescription() {
-               return $this->msg( 'creditspage' )->escaped();
-       }
-
        /**
         * This is largely cadged from PageHistory::history
         *
         * @return String HTML
         */
        public function onView() {
-               wfProfileIn( __METHOD__ );
-
-               if ( $this->page->getID() == 0 ) {
-                       $s = $this->msg( 'nocredits' )->parse();
-               } else {
-                       $s = $this->getCredits( -1 );
-               }
-
-               wfProfileOut( __METHOD__ );
-
-               return Html::rawElement( 'div', array( 'id' => 'mw-credits' ), $s );
-       }
-
-       /**
-        * Get a list of contributors
-        *
-        * @param $cnt Int: maximum list of contributors to show
-        * @param $showIfMax Bool: whether to contributors if there more than $cnt
-        * @return String: html
-        */
-       public function getCredits( $cnt, $showIfMax = true ) {
-               wfProfileIn( __METHOD__ );
-               $s = '';
-
-               if ( $cnt != 0 ) {
-                       $s = $this->getAuthor( $this->page );
-                       if ( $cnt > 1 || $cnt < 0 ) {
-                               $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
-                       }
-               }
-
-               wfProfileOut( __METHOD__ );
-               return $s;
-       }
-
-       /**
-        * Get the last author with the last modification time
-        * @param $article Article object
-        * @return String HTML
-        */
-       protected function getAuthor( Page $article ) {
-               $user = User::newFromName( $article->getUserText(), false );
-
-               $timestamp = $article->getTimestamp();
-               if ( $timestamp ) {
-                       $lang = $this->getLanguage();
-                       $d = $lang->date( $article->getTimestamp(), true );
-                       $t = $lang->time( $article->getTimestamp(), true );
-               } else {
-                       $d = '';
-                       $t = '';
-               }
-               return $this->msg( 'lastmodifiedatby', $d, $t )->rawParams(
-                       $this->userLink( $user ) )->params( $user->getName() )->escaped();
-       }
-
-       /**
-        * Get a list of contributors of $article
-        * @param $cnt Int: maximum list of contributors to show
-        * @param $showIfMax Bool: whether to contributors if there more than $cnt
-        * @return String: html
-        */
-       protected function getContributors( $cnt, $showIfMax ) {
-               global $wgHiddenPrefs;
-
-               $contributors = $this->page->getContributors();
-
-               $others_link = false;
-
-               # Hmm... too many to fit!
-               if ( $cnt > 0 && $contributors->count() > $cnt ) {
-                       $others_link = $this->othersLink();
-                       if ( !$showIfMax )
-                               return $this->msg( 'othercontribs' )->rawParams(
-                                       $others_link )->params( $contributors->count() )->escaped();
-               }
-
-               $real_names = array();
-               $user_names = array();
-               $anon_ips = array();
-
-               # Sift for real versus user names
-               foreach ( $contributors as $user ) {
-                       $cnt--; 
-                       if ( $user->isLoggedIn() ) {
-                               $link = $this->link( $user );
-                               if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
-                                       $real_names[] = $link;
-                               } else {
-                                       $user_names[] = $link;
-                               }
-                       } else {
-                               $anon_ips[] = $this->link( $user );
-                       }
-
-                       if ( $cnt == 0 ) {
-                               break;
-                       }
-               }
-
-               $lang = $this->getLanguage();
-
-               if ( count( $real_names ) ) {
-                       $real = $lang->listToText( $real_names );
-               } else {
-                       $real = false;
-               }
-
-               # "ThisSite user(s) A, B and C"
-               if ( count( $user_names ) ) {
-                       $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
-                               count( $user_names ) )->escaped();
-               } else {
-                       $user = false;
-               }
-
-               if ( count( $anon_ips ) ) {
-                       $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
-                               count( $anon_ips ) )->escaped();
-               } else {
-                       $anon = false;
-               }
-
-               # This is the big list, all mooshed together. We sift for blank strings
-               $fulllist = array();
-               foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
-                       if ( $s !== false ) {
-                               array_push( $fulllist, $s );
-                       }
-               }
-
-               $count = count( $fulllist );
-               # "Based on work by ..."
-               return $count
-                       ? $this->msg( 'othercontribs' )->rawParams(
-                               $lang->listToText( $fulllist ) )->params( $count )->escaped()
-                       : '';
-       }
-
-       /**
-        * Get a link to $user's user page
-        * @param $user User object
-        * @return String: html
-        */
-       protected function link( User $user ) {
-               global $wgHiddenPrefs;
-               if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) {
-                       $real = $user->getRealName();
-               } else {
-                       $real = false;
-               }
-
-               $page = $user->isAnon()
-                       ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
-                       : $user->getUserPage();
-
-               return Linker::link( $page, htmlspecialchars( $real ? $real : $user->getName() ) );
-       }
-
-       /**
-        * Get a link to $user's user page
-        * @param $user User object
-        * @return String: html
-        */
-       protected function userLink( User $user ) {
-               $link = $this->link( $user );
-               if ( $user->isAnon() ) {
-                       return $this->msg( 'anonuser' )->rawParams( $link )->parse();
-               } else {
-                       global $wgHiddenPrefs;
-                       if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
-                               return $link;
-                       } else {
-                               return $this->msg( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
-                       }
-               }
-       }
-
-       /**
-        * Get a link to action=credits of $article page
-        * @return String: HTML link
-        */
-       protected function othersLink() {
-               return Linker::linkKnown(
-                       $this->getTitle(),
-                       $this->msg( 'others' )->escaped(),
-                       array(),
-                       array( 'action' => 'credits' )
-               );
+               $this->getOutput()->redirect( $this->getTitle()->getLocalURL( "action=info" ) );
        }
 }
index b523111..cb04ec5 100644 (file)
@@ -56,7 +56,7 @@ class InfoAction extends FormlessAction {
         * @return string Page information that will be added to the output
         */
        public function onView() {
-               global $wgContLang, $wgDisableCounters, $wgRCMaxAge, $wgRestrictionTypes;
+               global $wgContLang, $wgDisableCounters, $wgRCMaxAge;
 
                $user = $this->getUser();
                $lang = $this->getLanguage();
@@ -86,11 +86,16 @@ class InfoAction extends FormlessAction {
 
                // Header
                if ( !$this->msg( 'pageinfo-header' )->isDisabled() ) {
-                       $content .= $this->msg( 'pageinfo-header ' )->parse();
+                       $content .= $this->msg( 'pageinfo-header' )->parse();
+               }
+
+               // Credits
+               if ( $title->exists() ) {
+                       $content .= Html::rawElement( 'div', array( 'id' => 'mw-credits' ), $this->getContributors() );
                }
 
                // Basic information
-               $content = $this->addHeader( $content, $this->msg( 'pageinfo-header-basic' )->text() );
+               $content .= $this->makeHeader( $this->msg( 'pageinfo-header-basic' )->plain() );
 
                // Display title
                $displayTitle = $title->getPrefixedText();
@@ -172,12 +177,13 @@ class InfoAction extends FormlessAction {
 
                // Page protection
                $content = $this->addTable( $content, $table );
-               $content = $this->addHeader( $content, $this->msg( 'pageinfo-header-restrictions' )->text() );
+               $content .= $this->makeHeader( $this->msg( 'pageinfo-header-restrictions' )->plain() );
                $table = '';
 
                // Page protection
-               foreach ( $wgRestrictionTypes as $restrictionType ) {
+               foreach ( $title->getRestrictionTypes() as $restrictionType ) {
                        $protectionLevel = implode( ', ', $title->getRestrictions( $restrictionType ) );
+
                        if ( $protectionLevel == '' ) {
                                // Allow all users
                                $message = $this->msg( 'protect-default' )->escaped();
@@ -193,23 +199,22 @@ class InfoAction extends FormlessAction {
                        }
 
                        $table = $this->addRow( $table,
-                               $this->msg( 'pageinfo-restriction',
-                                       $this->msg( "restriction-$restrictionType" )->plain()
-                               )->parse(), $message
+                               $this->msg( "restriction-$restrictionType" )->plain(),
+                               $message
                        );
                }
 
                // Edit history
                $content = $this->addTable( $content, $table );
-               $content = $this->addHeader( $content, $this->msg( 'pageinfo-header-edits' )->text() );
+               $content .= $this->makeHeader( $this->msg( 'pageinfo-header-edits' )->plain() );
                $table = '';
 
                $firstRev = $this->page->getOldestRevision();
 
                // Page creator
                $table = $this->addRow( $table,
-                       $this->msg( 'pageinfo-firstuser' )->escaped(),
-                       $firstRev->getUserText( Revision::FOR_THIS_USER, $user )
+               $this->msg( 'pageinfo-firstuser' )->escaped(),
+                       Linker::userLink( $firstRev->getUser( Revision::FOR_THIS_USER, $user ), $firstRev->getUserText( Revision::FOR_THIS_USER, $user ) )
                );
 
                // Date of page creation
@@ -225,8 +230,8 @@ class InfoAction extends FormlessAction {
 
                // Latest editor
                $table = $this->addRow( $table,
-                       $this->msg( 'pageinfo-lastuser' )->escaped(),
-                       $this->page->getUserText( Revision::FOR_THIS_USER, $user )
+               $this->msg( 'pageinfo-lastuser' )->escaped(),
+                       Linker::userLink( $this->page->getUser( Revision::FOR_THIS_USER, $user ), $this->page->getUserText( Revision::FOR_THIS_USER, $user ) )
                );
 
                // Date of latest edit
@@ -287,7 +292,7 @@ class InfoAction extends FormlessAction {
                        || count( $hiddenCategories ) > 0
                        || count( $transcludedTemplates ) > 0 ) {
                        // Page properties
-                       $content = $this->addHeader( $content, $this->msg( 'pageinfo-header-properties' )->text() );
+                       $content .= $this->makeHeader( $this->msg( 'pageinfo-header-properties' )->plain() );
                        $table = '';
 
                        // Magic words
@@ -335,6 +340,18 @@ class InfoAction extends FormlessAction {
                return $content;
        }
 
+       /**
+        * Creates a header that can be added to the output.
+        *
+        * @param $header The header text.
+        * @return string The HTML.
+        */
+       public static function makeHeader( $header ) {
+               global $wgParser;
+               $spanAttribs = array( 'class' => 'mw-headline', 'id' => $wgParser->guessSectionNameFromWikiText( $header ) );
+               return Html::rawElement( 'h2', array(), Html::element( 'span', $spanAttribs, $header ) );
+       }
+
        /**
         * Returns page information that would be too "expensive" to retrieve by normal means.
         *
@@ -453,17 +470,6 @@ class InfoAction extends FormlessAction {
                return $result;
        }
 
-       /**
-        * Adds a header to the content that will be added to the output.
-        *
-        * @param $content string The content that will be added to the output
-        * @param $header string The value of the header
-        * @return string The content with the header added
-        */
-       protected function addHeader( $content, $header ) {
-               return $content . Html::element( 'h2', array(), $header );
-       }
-
        /**
         * Adds a row to a table that will be added to the content.
         *
@@ -508,4 +514,66 @@ class InfoAction extends FormlessAction {
        protected function getPageTitle() {
                return $this->msg( 'pageinfo-title', $this->getTitle()->getPrefixedText() )->text();
        }
+
+       /**
+        * Get a list of contributors of $article
+        * @return string: html
+        */
+       protected function getContributors() {
+               global $wgHiddenPrefs;
+
+               $contributors = $this->page->getContributors();
+               $real_names = array();
+               $user_names = array();
+               $anon_ips = array();
+
+               # Sift for real versus user names
+               foreach ( $contributors as $user ) {
+                       $page = $user->isAnon()
+                               ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
+                               : $user->getUserPage();
+
+                       if ( $user->getID() == 0 ) {
+                               $anon_ips[] = Linker::link( $page, htmlspecialchars( $user->getName() ) );
+                       } elseif ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
+                               $real_names[] = Linker::link( $page, htmlspecialchars( $user->getRealName() ) );
+                       } else {
+                               $user_names[] = Linker::link( $page, htmlspecialchars( $user->getName() ) );
+                       }
+               }
+
+               $lang = $this->getLanguage();
+
+               $real = $lang->listToText( $real_names );
+
+               # "ThisSite user(s) A, B and C"
+               if ( count( $user_names ) ) {
+                       $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
+                               count( $user_names ) )->escaped();
+               } else {
+                       $user = false;
+               }
+
+               if ( count( $anon_ips ) ) {
+                       $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
+                               count( $anon_ips ) )->escaped();
+               } else {
+                       $anon = false;
+               }
+
+               # This is the big list, all mooshed together. We sift for blank strings
+               $fulllist = array();
+               foreach ( array( $real, $user, $anon ) as $s ) {
+                       if ( $s !== '' ) {
+                               array_push( $fulllist, $s );
+                       }
+               }
+
+               $count = count( $fulllist );
+               # "Based on work by ..."
+               return $count
+                       ? $this->msg( 'othercontribs' )->rawParams(
+                               $lang->listToText( $fulllist ) )->params( $count )->escaped()
+                       : '';
+       }
 }
index f0444cb..8971421 100644 (file)
@@ -3758,7 +3758,6 @@ This is probably caused by a link to a blacklisted external site.',
 'pageinfo-authors'             => 'Total number of distinct authors',
 'pageinfo-recent-edits'        => 'Recent number of edits (within past $1)',
 'pageinfo-recent-authors'      => 'Recent number of distinct authors',
-'pageinfo-restriction'         => 'Page protection ({{lcfirst:$1}})',
 'pageinfo-magic-words'         => 'Magic {{PLURAL:$1|word|words}} ($1)',
 'pageinfo-hidden-categories'   => 'Hidden {{PLURAL:$1|category|categories}} ($1)',
 'pageinfo-templates'           => 'Transcluded {{PLURAL:$1|template|templates}} ($1)',
index c8c958b..a895f0b 100644 (file)
@@ -3498,8 +3498,6 @@ See also {{msg-mw|Anonuser}} and {{msg-mw|Siteusers}}.',
 'pageinfo-authors' => 'The total number of users who have edited the page.',
 'pageinfo-recent-edits' => 'The number of times the page has been edited recently. $1 is a localised duration (e.g. 9 days).',
 'pageinfo-recent-authors' => 'The number of users who have edited the page recently.',
-'pageinfo-restriction' => 'Parameters:
-* $1 is the type of page protection (message restriction-$type, preferably in lowercase). If your language doesn\'t have small and capital letters, you can simply write <nowiki>$1</nowiki>.',
 'pageinfo-magic-words' => 'The list of magic words on the page. Parameters:
 * $1 is the number of magic words on the page.',
 'pageinfo-hidden-categories' => 'The list of hidden categories on the page. Parameters:
index 8fa26f6..4d2542f 100644 (file)
@@ -2688,7 +2688,6 @@ $wgMessageStructure = array(
                'pageinfo-authors',
                'pageinfo-recent-edits',
                'pageinfo-recent-authors',
-               'pageinfo-restriction',
                'pageinfo-magic-words',
                'pageinfo-hidden-categories',
                'pageinfo-templates',