r40717 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40716‎ | r40717 | r40718 >
Date:22:29, 10 September 2008
Author:aaron
Status:old
Tags:
Comment:
Refactor this code some
Modified paths:
  • /trunk/phase3/includes/LogPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LogPage.php
@@ -155,70 +155,20 @@
156156 * @static
157157 * @return HTML string
158158 */
159 - static function actionText( $type, $action, $title = NULL, $skin = NULL,
160 - $params = array(), $filterWikilinks=false )
161 - {
 159+ static function actionText( $type, $action, $title=NULL, $skin=NULL, $params=array(), $filterWikilinks=false ) {
162160 global $wgLang, $wgContLang, $wgLogActions, $wgMessageCache;
163161
164162 $wgMessageCache->loadAllMessages();
165163 $key = "$type/$action";
166 -
167 - if( $key == 'patrol/patrol' )
 164+ # Defer patrol log to PatrolLog class
 165+ if( $key == 'patrol/patrol' ) {
168166 return PatrolLog::makeActionText( $title, $params, $skin );
169 -
 167+ }
170168 if( isset( $wgLogActions[$key] ) ) {
171169 if( is_null( $title ) ) {
172170 $rv = wfMsg( $wgLogActions[$key] );
173171 } else {
174 - if( $skin ) {
175 - switch( $type ) {
176 - case 'move':
177 - $titleLink = $skin->makeLinkObj( $title,
178 - htmlspecialchars( $title->getPrefixedText() ), 'redirect=no' );
179 - $targetTitle = Title::newFromText( $params[0] );
180 - if ( !$targetTitle ) {
181 - # Workaround for broken database
182 - $params[0] = htmlspecialchars( $params[0] );
183 - } else {
184 - $params[0] = $skin->makeLinkObj( $targetTitle, htmlspecialchars( $params[0] ) );
185 - }
186 - break;
187 - case 'block':
188 - if( substr( $title->getText(), 0, 1 ) == '#' ) {
189 - $titleLink = $title->getText();
190 - } else {
191 - // TODO: Store the user identifier in the parameters
192 - // to make this faster for future log entries
193 - $id = User::idFromName( $title->getText() );
194 - $titleLink = $skin->userLink( $id, $title->getText() )
195 - . $skin->userToolLinks( $id, $title->getText(), false, Linker::TOOL_LINKS_NOBLOCK );
196 - }
197 - break;
198 - case 'rights':
199 - $text = $wgContLang->ucfirst( $title->getText() );
200 - $titleLink = $skin->makeLinkObj( Title::makeTitle( NS_USER, $text ) );
201 - break;
202 - case 'merge':
203 - $titleLink = $skin->makeLinkObj( $title, $title->getPrefixedText(), 'redirect=no' );
204 - $params[0] = $skin->makeLinkObj( Title::newFromText( $params[0] ), htmlspecialchars( $params[0] ) );
205 - $params[1] = $wgLang->timeanddate( $params[1] );
206 - break;
207 - default:
208 - if( $title->getNamespace() == NS_SPECIAL ) {
209 - list( $name, $par ) = SpecialPage::resolveAliasWithSubpage( $title->getDBKey() );
210 - # Use the language name for log titles, rather than Log/X
211 - if( $name == 'Log' ) {
212 - $titleLink = '('.$skin->makeLinkObj( $title, LogPage::logName( $par ) ).')';
213 - } else {
214 - $titleLink = $skin->makeLinkObj( $title );
215 - }
216 - } else {
217 - $titleLink = $skin->makeLinkObj( $title );
218 - }
219 - }
220 - } else {
221 - $titleLink = $title->getPrefixedText();
222 - }
 172+ $titleLink = self::getTitleLink( $type, $skin, $title, $params );
223173 if( $key == 'rights/rights' ) {
224174 if( $skin ) {
225175 $rightsnone = wfMsg( 'rightsnone' );
@@ -282,6 +232,59 @@
283233 }
284234 return $rv;
285235 }
 236+
 237+ protected static function getTitleLink( $type, $skin, $title, &$params ) {
 238+ global $wgLang, $wgContLang;
 239+ if( !$skin ) {
 240+ return $title->getPrefixedText();
 241+ }
 242+ switch( $type ) {
 243+ case 'move':
 244+ $titleLink = $skin->makeLinkObj( $title,
 245+ htmlspecialchars( $title->getPrefixedText() ), 'redirect=no' );
 246+ $targetTitle = Title::newFromText( $params[0] );
 247+ if ( !$targetTitle ) {
 248+ # Workaround for broken database
 249+ $params[0] = htmlspecialchars( $params[0] );
 250+ } else {
 251+ $params[0] = $skin->makeLinkObj( $targetTitle, htmlspecialchars( $params[0] ) );
 252+ }
 253+ break;
 254+ case 'block':
 255+ if( substr( $title->getText(), 0, 1 ) == '#' ) {
 256+ $titleLink = $title->getText();
 257+ } else {
 258+ // TODO: Store the user identifier in the parameters
 259+ // to make this faster for future log entries
 260+ $id = User::idFromName( $title->getText() );
 261+ $titleLink = $skin->userLink( $id, $title->getText() )
 262+ . $skin->userToolLinks( $id, $title->getText(), false, Linker::TOOL_LINKS_NOBLOCK );
 263+ }
 264+ break;
 265+ case 'rights':
 266+ $text = $wgContLang->ucfirst( $title->getText() );
 267+ $titleLink = $skin->makeLinkObj( Title::makeTitle( NS_USER, $text ) );
 268+ break;
 269+ case 'merge':
 270+ $titleLink = $skin->makeLinkObj( $title, $title->getPrefixedText(), 'redirect=no' );
 271+ $params[0] = $skin->makeLinkObj( Title::newFromText( $params[0] ), htmlspecialchars( $params[0] ) );
 272+ $params[1] = $wgLang->timeanddate( $params[1] );
 273+ break;
 274+ default:
 275+ if( $title->getNamespace() == NS_SPECIAL ) {
 276+ list( $name, $par ) = SpecialPage::resolveAliasWithSubpage( $title->getDBKey() );
 277+ # Use the language name for log titles, rather than Log/X
 278+ if( $name == 'Log' ) {
 279+ $titleLink = '('.$skin->makeLinkObj( $title, LogPage::logName( $par ) ).')';
 280+ } else {
 281+ $titleLink = $skin->makeLinkObj( $title );
 282+ }
 283+ } else {
 284+ $titleLink = $skin->makeLinkObj( $title );
 285+ }
 286+ }
 287+ return $titleLink;
 288+ }
286289
287290 /**
288291 * Add a log entry

Follow-up revisions

RevisionCommit summaryAuthorDate
r40900Revert revert r40717 of my formatting change r40416.tstarling05:21, 16 September 2008