From 2b3f7ae7b48781c15f6eab51e3faf8c6da2f8bff Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Fri, 7 Oct 2011 17:49:45 +0000 Subject: [PATCH] * Use local context instead of global variables, made static function in CreditsAction non-static so that they can use the context * Added missing Action::msg() method --- includes/Action.php | 11 ++++++ includes/actions/CreditsAction.php | 56 ++++++++++++++++-------------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/includes/Action.php b/includes/Action.php index b165721e69..d21cd6b8fb 100644 --- a/includes/Action.php +++ b/includes/Action.php @@ -159,6 +159,17 @@ abstract class Action { return $this->page->getTitle(); } + /** + * Get a Message object with context set + * Parameters are the same as wfMessage() + * + * @return Message object + */ + protected final function msg() { + $params = func_get_args(); + return call_user_func_array( array( $this->getContext(), 'msg' ), $params ); + } + /** * Protected constructor: use Action::factory( $action, $page ) to actually build * these things in the real world diff --git a/includes/actions/CreditsAction.php b/includes/actions/CreditsAction.php index d03ff5709b..17361ccb6b 100644 --- a/includes/actions/CreditsAction.php +++ b/includes/actions/CreditsAction.php @@ -46,7 +46,7 @@ class CreditsAction extends FormlessAction { wfProfileIn( __METHOD__ ); if ( $this->page->getID() == 0 ) { - $s = wfMsg( 'nocredits' ); + $s = $this->msg( 'nocredits' )->parse(); } else { $s = $this->getCredits( -1 ); } @@ -68,7 +68,7 @@ class CreditsAction extends FormlessAction { $s = ''; if ( $cnt != 0 ) { - $s = self::getAuthor( $this->page ); + $s = $this->getAuthor( $this->page ); if ( $cnt > 1 || $cnt < 0 ) { $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax ); } @@ -83,20 +83,20 @@ class CreditsAction extends FormlessAction { * @param $article Article object * @return String HTML */ - protected static function getAuthor( Page $article ) { - global $wgLang; - - $user = User::newFromId( $article->getUser() ); + protected function getAuthor( Page $article ) { + $user = User::newFromName( $article->getUserText(), false ); $timestamp = $article->getTimestamp(); if ( $timestamp ) { - $d = $wgLang->date( $article->getTimestamp(), true ); - $t = $wgLang->time( $article->getTimestamp(), true ); + $lang = $this->getLang(); + $d = $lang->date( $article->getTimestamp(), true ); + $t = $lang->time( $article->getTimestamp(), true ); } else { $d = ''; $t = ''; } - return wfMessage( 'lastmodifiedatby', $d, $t )->rawParams( self::userLink( $user ) )->params( $user->getName() )->escaped(); + return $this->msg( 'lastmodifiedatby', $d, $t )->rawParams( + $this->userLink( $user ) )->params( $user->getName() )->escaped(); } /** @@ -106,7 +106,7 @@ class CreditsAction extends FormlessAction { * @return String: html */ protected function getContributors( $cnt, $showIfMax ) { - global $wgLang, $wgHiddenPrefs; + global $wgHiddenPrefs; $contributors = $this->page->getContributors(); @@ -116,7 +116,8 @@ class CreditsAction extends FormlessAction { if ( $cnt > 0 && $contributors->count() > $cnt ) { $others_link = $this->othersLink(); if ( !$showIfMax ) - return wfMessage( 'othercontribs' )->rawParams( $others_link )->params( $contributors->count() )->escaped(); + return $this->msg( 'othercontribs' )->rawParams( + $others_link )->params( $contributors->count() )->escaped(); } $real_names = array(); @@ -127,14 +128,14 @@ class CreditsAction extends FormlessAction { foreach ( $contributors as $user ) { $cnt--; if ( $user->isLoggedIn() ) { - $link = self::link( $user ); + $link = $this->link( $user ); if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) { $real_names[] = $link; } else { $user_names[] = $link; } } else { - $anon_ips[] = self::link( $user ); + $anon_ips[] = $this->link( $user ); } if ( $cnt == 0 ) { @@ -142,22 +143,24 @@ class CreditsAction extends FormlessAction { } } + $lang = $this->getLang(); + if ( count( $real_names ) ) { - $real = $wgLang->listToText( $real_names ); + $real = $lang->listToText( $real_names ); } else { $real = false; } # "ThisSite user(s) A, B and C" if ( count( $user_names ) ) { - $user = wfMessage( 'siteusers' )->rawParams( $wgLang->listToText( $user_names ) )->params( + $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params( count( $user_names ) )->escaped(); } else { $user = false; } if ( count( $anon_ips ) ) { - $anon = wfMessage( 'anonusers' )->rawParams( $wgLang->listToText( $anon_ips ) )->params( + $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params( count( $anon_ips ) )->escaped(); } else { $anon = false; @@ -174,8 +177,8 @@ class CreditsAction extends FormlessAction { $count = count( $fulllist ); # "Based on work by ..." return $count - ? wfMessage( 'othercontribs' )->rawParams( - $wgLang->listToText( $fulllist ) )->params( $count )->escaped() + ? $this->msg( 'othercontribs' )->rawParams( + $lang->listToText( $fulllist ) )->params( $count )->escaped() : ''; } @@ -184,7 +187,7 @@ class CreditsAction extends FormlessAction { * @param $user User object * @return String: html */ - protected static function link( User $user ) { + protected function link( User $user ) { global $wgHiddenPrefs; if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) { $real = $user->getRealName(); @@ -204,16 +207,16 @@ class CreditsAction extends FormlessAction { * @param $user User object * @return String: html */ - protected static function userLink( User $user ) { - $link = self::link( $user ); + protected function userLink( User $user ) { + $link = $this->link( $user ); if ( $user->isAnon() ) { - return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link ); + return $this->msg( 'anonuser' )->rawParams( $link )->parse(); } else { global $wgHiddenPrefs; if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) { return $link; } else { - return wfMessage( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped(); + return $this->msg( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped(); } } } @@ -224,12 +227,11 @@ class CreditsAction extends FormlessAction { * @return String: html */ protected function othersLink() { - return Linker::link( + return Linker::linkKnown( $this->getTitle(), - wfMsgHtml( 'others' ), + $this->msg( 'others' )->escaped(), array(), - array( 'action' => 'credits' ), - array( 'known' ) + array( 'action' => 'credits' ) ); } } -- 2.20.1