Adding static functions to User to create links to groups in either HTML or Wikitext...
authorRotem Liss <rotem@users.mediawiki.org>
Sat, 12 Aug 2006 09:24:18 +0000 (09:24 +0000)
committerRotem Liss <rotem@users.mediawiki.org>
Sat, 12 Aug 2006 09:24:18 +0000 (09:24 +0000)
includes/SpecialListusers.php
includes/SpecialStatistics.php
includes/User.php
languages/MessagesEn.php
languages/MessagesHe.php

index 20b26b6..c1cb8f8 100644 (file)
@@ -189,16 +189,12 @@ class ListUsersPage extends QueryPage {
 
                        if( count( $groups ) > 0 ) {
                                foreach( $groups as $group => $desc ) {
-                                       if( $page = User::getGroupPage( $group ) ) {
-                                               $list[] = $skin->makeLinkObj( $page, htmlspecialchars( $desc ) );
-                                       } else {
-                                               $list[] = htmlspecialchars( $desc );
-                                       }
+                                       $list[] = User::makeGroupLinkHTML( $group, $desc );
                                }
                                $groups = implode( ', ', $list );
                        } else {
                                $groups = '';
-                       }                               
+                       }
 
                }
 
index e18399b..4cfe4ca 100644 (file)
@@ -75,13 +75,13 @@ function wfSpecialStatistics() {
                $text .= wfMsg( 'userstatstext',
                        $wgLang->formatNum( $users ),
                        $wgLang->formatNum( $admins ),
-                       '[[' . wfMsgForContent( 'administrators' ) . ']]',
-                       // should logically be after #admins, damn backwards compatability!
-                       $wgLang->formatNum( sprintf( '%.2f', $admins / $users * 100 ) )
+                       '[[' . wfMsgForContent( 'administrators' ) . ']]', # TODO somehow remove, kept for backwards compatibility
+                       $wgLang->formatNum( sprintf( '%.2f', $admins / $users * 100 ) ),
+                       User::makeGroupLinkWiki( 'sysop' )
                );
 
                $wgOut->addWikiText( $text );
-               
+
                global $wgDisableCounters, $wgMiserMode, $wgUser, $wgLang, $wgContLang;
                if( !$wgDisableCounters && !$wgMiserMode ) {
                        $sql = "SELECT page_namespace, page_title, page_counter FROM {$page} WHERE page_is_redirect = 0 AND page_counter > 0 ORDER BY page_counter DESC";
index f4cbbc8..05380d4 100644 (file)
@@ -2001,7 +2001,7 @@ class User {
         * @return array list of permission key names for given groups combined
         * @static
         */
-       function getGroupPermissions( $groups ) {
+       static function getGroupPermissions( $groups ) {
                global $wgGroupPermissions;
                $rights = array();
                foreach( $groups as $group ) {
@@ -2018,7 +2018,7 @@ class User {
         * @return string localized descriptive name for group, if provided
         * @static
         */
-       function getGroupName( $group ) {
+       static function getGroupName( $group ) {
                $key = "group-$group";
                $name = wfMsg( $key );
                if( $name == '' || $name == "&lt;$key&gt;" ) {
@@ -2033,7 +2033,7 @@ class User {
         * @return string localized descriptive name for member of a group, if provided
         * @static
         */
-       function getGroupMember( $group ) {
+       static function getGroupMember( $group ) {
                $key = "group-$group-member";
                $name = wfMsg( $key );
                if( $name == '' || $name == "&lt;$key&gt;" ) {
@@ -2043,7 +2043,6 @@ class User {
                }
        }
 
-
        /**
         * Return the set of defined explicit groups.
         * The *, 'user', 'autoconfirmed' and 'emailconfirmed'
@@ -2052,20 +2051,20 @@ class User {
         * @return array
         * @static
         */
-       function getAllGroups() {
+       static function getAllGroups() {
                global $wgGroupPermissions;
                return array_diff(
                        array_keys( $wgGroupPermissions ),
                        array( '*', 'user', 'autoconfirmed', 'emailconfirmed' ) );
        }
-       
+
        /**
         * Get the title of a page describing a particular group
         *
         * @param $group Name of the group
         * @return mixed
         */
-       function getGroupPage( $group ) {
+       static function getGroupPage( $group ) {
                $page = wfMsgForContent( 'grouppage-' . $group );
                if( !wfEmptyMsg( 'grouppage-' . $group, $page ) ) {
                        $title = Title::newFromText( $page );
@@ -2074,8 +2073,47 @@ class User {
                }
                return false;
        }
-       
-       
+
+       /**
+        * Create a link to the group in HTML, if available
+        *
+        * @param $group Name of the group
+        * @param $text The text of the link
+        * @return mixed
+        */
+       static function makeGroupLinkHTML( $group, $text = '' ) {
+               if( $text == '' ) {
+                       $text = self::getGroupName( $group );
+               }
+               $title = self::getGroupPage( $group );
+               if( $title ) {
+                       global $wgUser;
+                       $sk = $wgUser->getSkin();
+                       return $sk->makeLinkObj( $title, $text );
+               } else {
+                       return $text;
+               }
+       }
+
+       /**
+        * Create a link to the group in Wikitext, if available
+        *
+        * @param $group Name of the group
+        * @param $text The text of the link (by default, the name of the group)
+        * @return mixed
+        */
+       static function makeGroupLinkWiki( $group, $text = '' ) {
+               if( $text == '' ) {
+                       $text = self::getGroupName( $group );
+               }
+               $title = self::getGroupPage( $group );
+               if( $title ) {
+                       $page = $title->getPrefixedText();
+                       return "[[$page|$text]]";
+               } else {
+                       return $text;
+               }
+       }
 }
 
 ?>
index df7714b..8846d21 100644 (file)
@@ -1222,7 +1222,7 @@ That comes to '''$5''' average edits per page, and '''$6''' views per edit.
 
 The [http://meta.wikimedia.org/wiki/Help:Job_queue job queue] length is '''$7'''.",
 'userstatstext' => "There are '''$1''' registered users, of which
-'''$2''' (or '''$4%''') are administrators (see $3).",
+'''$2''' (or '''$4%''') are $5.",
 'statistics-mostpopular' => 'Most viewed pages',
 
 'disambiguations'      => 'Disambiguation pages',
index 6e318be..ba84977 100644 (file)
@@ -997,10 +997,10 @@ $messages = array(
 
 בסך הכול בוצעו בממוצע \'\'\'$5\'\'\' עריכות לדף, והיו \'\'\'$6\'\'\' צפיות לכל עריכה.
 
-אורך [http://meta.wikimedia.org/wiki/Help:Job_queue תור המשימות] הוא \'\'\'$7\'\'\'
+אורך [http://meta.wikimedia.org/wiki/Help:Job_queue תור המשימות] הוא \'\'\'$7\'\'\'.
 
 \'\'\'$8\'\'\' קבצים הועלו לאתר עד כה.',
-"userstatstext"          => "×\99שנ×\9d '''$1''' [[{{ns:special}}:Listusers|×\9eשת×\9eש×\99×\9d ×¨×©×\95×\9e×\99×\9d]] ×\91×\90תר, '''$2''' (×\90×\95 $4%) ×\9eת×\95×\9b×\9d ×\9eפע×\99×\9c×\99 ×\9eער×\9bת (ר×\90×\95 $3).",
+"userstatstext"          => "×\99שנ×\9d '''$1''' [[{{ns:special}}:Listusers|×\9eשת×\9eש×\99×\9d ×¨×©×\95×\9e×\99×\9d]] ×\91×\90תר, '''$2''' (×\90×\95 $4%) ×\9eת×\95×\9b×\9d ×\94×\9d $5.",
 "statistics-mostpopular" => "הדפים הנצפים ביותר",
 
 # Disambiguations Page