From c7491fe86bf5955280ea8282cafb29567bcc689a Mon Sep 17 00:00:00 2001 From: Rotem Liss Date: Sat, 12 Aug 2006 09:24:18 +0000 Subject: [PATCH] Adding static functions to User to create links to groups in either HTML or Wikitext; using the HTML function in Special:Listusers; using the Wikitext function in Special:Statistics instead of a raw link to the sysops page (kept for backwards compatibility); several code fixes. --- includes/SpecialListusers.php | 8 ++--- includes/SpecialStatistics.php | 8 ++--- includes/User.php | 56 ++++++++++++++++++++++++++++------ languages/MessagesEn.php | 2 +- languages/MessagesHe.php | 4 +-- 5 files changed, 56 insertions(+), 22 deletions(-) diff --git a/includes/SpecialListusers.php b/includes/SpecialListusers.php index 20b26b6330..c1cb8f8555 100644 --- a/includes/SpecialListusers.php +++ b/includes/SpecialListusers.php @@ -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 = ''; - } + } } diff --git a/includes/SpecialStatistics.php b/includes/SpecialStatistics.php index e18399b37b..4cfe4ca9d8 100644 --- a/includes/SpecialStatistics.php +++ b/includes/SpecialStatistics.php @@ -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"; diff --git a/includes/User.php b/includes/User.php index f4cbbc8e0e..05380d4ccf 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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 == "<$key>" ) { @@ -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 == "<$key>" ) { @@ -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; + } + } } ?> diff --git a/languages/MessagesEn.php b/languages/MessagesEn.php index df7714bad2..8846d21498 100644 --- a/languages/MessagesEn.php +++ b/languages/MessagesEn.php @@ -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', diff --git a/languages/MessagesHe.php b/languages/MessagesHe.php index 6e318bec82..ba84977d62 100644 --- a/languages/MessagesHe.php +++ b/languages/MessagesHe.php @@ -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" => "ישנם '''$1''' [[{{ns:special}}:Listusers|משתמשים רשומים]] באתר, '''$2''' (או $4%) מתוכם מפעילי מערכת (ראו $3).", +"userstatstext" => "ישנם '''$1''' [[{{ns:special}}:Listusers|משתמשים רשומים]] באתר, '''$2''' (או $4%) מתוכם הם $5.", "statistics-mostpopular" => "הדפים הנצפים ביותר", # Disambiguations Page -- 2.20.1