r99222 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99221‎ | r99222 | r99223 >
Date:17:49, 7 October 2011
Author:ialex
Status:ok
Tags:
Comment:
* 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
Modified paths:
  • /trunk/phase3/includes/Action.php (modified) (history)
  • /trunk/phase3/includes/actions/CreditsAction.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Action.php
@@ -160,6 +160,17 @@
161161 }
162162
163163 /**
 164+ * Get a Message object with context set
 165+ * Parameters are the same as wfMessage()
 166+ *
 167+ * @return Message object
 168+ */
 169+ protected final function msg() {
 170+ $params = func_get_args();
 171+ return call_user_func_array( array( $this->getContext(), 'msg' ), $params );
 172+ }
 173+
 174+ /**
164175 * Protected constructor: use Action::factory( $action, $page ) to actually build
165176 * these things in the real world
166177 * @param Page $page
Index: trunk/phase3/includes/actions/CreditsAction.php
@@ -46,7 +46,7 @@
4747 wfProfileIn( __METHOD__ );
4848
4949 if ( $this->page->getID() == 0 ) {
50 - $s = wfMsg( 'nocredits' );
 50+ $s = $this->msg( 'nocredits' )->parse();
5151 } else {
5252 $s = $this->getCredits( -1 );
5353 }
@@ -68,7 +68,7 @@
6969 $s = '';
7070
7171 if ( $cnt != 0 ) {
72 - $s = self::getAuthor( $this->page );
 72+ $s = $this->getAuthor( $this->page );
7373 if ( $cnt > 1 || $cnt < 0 ) {
7474 $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
7575 }
@@ -83,20 +83,20 @@
8484 * @param $article Article object
8585 * @return String HTML
8686 */
87 - protected static function getAuthor( Page $article ) {
88 - global $wgLang;
 87+ protected function getAuthor( Page $article ) {
 88+ $user = User::newFromName( $article->getUserText(), false );
8989
90 - $user = User::newFromId( $article->getUser() );
91 -
9290 $timestamp = $article->getTimestamp();
9391 if ( $timestamp ) {
94 - $d = $wgLang->date( $article->getTimestamp(), true );
95 - $t = $wgLang->time( $article->getTimestamp(), true );
 92+ $lang = $this->getLang();
 93+ $d = $lang->date( $article->getTimestamp(), true );
 94+ $t = $lang->time( $article->getTimestamp(), true );
9695 } else {
9796 $d = '';
9897 $t = '';
9998 }
100 - return wfMessage( 'lastmodifiedatby', $d, $t )->rawParams( self::userLink( $user ) )->params( $user->getName() )->escaped();
 99+ return $this->msg( 'lastmodifiedatby', $d, $t )->rawParams(
 100+ $this->userLink( $user ) )->params( $user->getName() )->escaped();
101101 }
102102
103103 /**
@@ -106,7 +106,7 @@
107107 * @return String: html
108108 */
109109 protected function getContributors( $cnt, $showIfMax ) {
110 - global $wgLang, $wgHiddenPrefs;
 110+ global $wgHiddenPrefs;
111111
112112 $contributors = $this->page->getContributors();
113113
@@ -116,7 +116,8 @@
117117 if ( $cnt > 0 && $contributors->count() > $cnt ) {
118118 $others_link = $this->othersLink();
119119 if ( !$showIfMax )
120 - return wfMessage( 'othercontribs' )->rawParams( $others_link )->params( $contributors->count() )->escaped();
 120+ return $this->msg( 'othercontribs' )->rawParams(
 121+ $others_link )->params( $contributors->count() )->escaped();
121122 }
122123
123124 $real_names = array();
@@ -127,14 +128,14 @@
128129 foreach ( $contributors as $user ) {
129130 $cnt--;
130131 if ( $user->isLoggedIn() ) {
131 - $link = self::link( $user );
 132+ $link = $this->link( $user );
132133 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
133134 $real_names[] = $link;
134135 } else {
135136 $user_names[] = $link;
136137 }
137138 } else {
138 - $anon_ips[] = self::link( $user );
 139+ $anon_ips[] = $this->link( $user );
139140 }
140141
141142 if ( $cnt == 0 ) {
@@ -142,22 +143,24 @@
143144 }
144145 }
145146
 147+ $lang = $this->getLang();
 148+
146149 if ( count( $real_names ) ) {
147 - $real = $wgLang->listToText( $real_names );
 150+ $real = $lang->listToText( $real_names );
148151 } else {
149152 $real = false;
150153 }
151154
152155 # "ThisSite user(s) A, B and C"
153156 if ( count( $user_names ) ) {
154 - $user = wfMessage( 'siteusers' )->rawParams( $wgLang->listToText( $user_names ) )->params(
 157+ $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
155158 count( $user_names ) )->escaped();
156159 } else {
157160 $user = false;
158161 }
159162
160163 if ( count( $anon_ips ) ) {
161 - $anon = wfMessage( 'anonusers' )->rawParams( $wgLang->listToText( $anon_ips ) )->params(
 164+ $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
162165 count( $anon_ips ) )->escaped();
163166 } else {
164167 $anon = false;
@@ -174,8 +177,8 @@
175178 $count = count( $fulllist );
176179 # "Based on work by ..."
177180 return $count
178 - ? wfMessage( 'othercontribs' )->rawParams(
179 - $wgLang->listToText( $fulllist ) )->params( $count )->escaped()
 181+ ? $this->msg( 'othercontribs' )->rawParams(
 182+ $lang->listToText( $fulllist ) )->params( $count )->escaped()
180183 : '';
181184 }
182185
@@ -184,7 +187,7 @@
185188 * @param $user User object
186189 * @return String: html
187190 */
188 - protected static function link( User $user ) {
 191+ protected function link( User $user ) {
189192 global $wgHiddenPrefs;
190193 if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) {
191194 $real = $user->getRealName();
@@ -204,16 +207,16 @@
205208 * @param $user User object
206209 * @return String: html
207210 */
208 - protected static function userLink( User $user ) {
209 - $link = self::link( $user );
 211+ protected function userLink( User $user ) {
 212+ $link = $this->link( $user );
210213 if ( $user->isAnon() ) {
211 - return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link );
 214+ return $this->msg( 'anonuser' )->rawParams( $link )->parse();
212215 } else {
213216 global $wgHiddenPrefs;
214217 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
215218 return $link;
216219 } else {
217 - return wfMessage( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
 220+ return $this->msg( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
218221 }
219222 }
220223 }
@@ -224,12 +227,11 @@
225228 * @return String: html
226229 */
227230 protected function othersLink() {
228 - return Linker::link(
 231+ return Linker::linkKnown(
229232 $this->getTitle(),
230 - wfMsgHtml( 'others' ),
 233+ $this->msg( 'others' )->escaped(),
231234 array(),
232 - array( 'action' => 'credits' ),
233 - array( 'known' )
 235+ array( 'action' => 'credits' )
234236 );
235237 }
236238 }

Status & tagging log