From e7dc5b169170db246c12a3141fc89ce05ca0542d Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 10 Jul 2011 18:12:11 +0000 Subject: [PATCH] * Changed dynamic calls to Linker methods into static ones * Also preferably pass a Language object instead of a Skin one or boolean indicating whether it's for content. No other calls to these methods in core or extensions. --- includes/LogEventsList.php | 34 ++++----- includes/LogPage.php | 79 ++++++++------------- includes/PatrolLog.php | 14 ++-- includes/revisiondelete/RevisionDeleter.php | 29 +++----- 4 files changed, 64 insertions(+), 92 deletions(-) diff --git a/includes/LogEventsList.php b/includes/LogEventsList.php index 0f57966e19..744a60cecf 100644 --- a/includes/LogEventsList.php +++ b/includes/LogEventsList.php @@ -169,7 +169,7 @@ class LogEventsList { $hideVal = 1 - intval($val); $query[$queryKey] = $hideVal; - $link = $this->skin->link( + $link = Linker::link( $this->getDisplayTitle(), $messages[$hideVal], array(), @@ -352,10 +352,10 @@ class LogEventsList { $userLinks = '' . wfMsgHtml( 'rev-deleted-user' ) . ''; } else { - $userLinks = $this->skin->userLink( $row->log_user, $row->user_name ); + $userLinks = Linker::userLink( $row->log_user, $row->user_name ); // Talk|Contribs links... if( !( $this->flags & self::NO_EXTRA_USER_LINKS ) ) { - $userLinks .= $this->skin->userToolLinks( + $userLinks .= Linker::userToolLinks( $row->log_user, $row->user_name, true, 0, $row->user_editcount ); } } @@ -380,7 +380,7 @@ class LogEventsList { } else { global $wgLang; $comment = $wgLang->getDirMark() . - $this->skin->commentBlock( $row->log_comment ); + Linker::commentBlock( $row->log_comment ); } return $comment; } @@ -405,7 +405,7 @@ class LogEventsList { if( self::typeAction( $row, 'move', 'move', 'move' ) && !empty( $paramArray[0] ) ) { $destTitle = Title::newFromText( $paramArray[0] ); if( $destTitle ) { - $revert = '(' . $this->skin->link( + $revert = '(' . Linker::link( SpecialPage::getTitleFor( 'Movepage' ), $this->message['revertmove'], array(), @@ -425,7 +425,7 @@ class LogEventsList { } else { $viewdeleted = $this->message['undeletelink']; } - $revert = '(' . $this->skin->link( + $revert = '(' . Linker::link( SpecialPage::getTitleFor( 'Undelete' ), $viewdeleted, array(), @@ -435,7 +435,7 @@ class LogEventsList { // Show unblock/change block link } elseif( self::typeAction( $row, array( 'block', 'suppress' ), array( 'block', 'reblock' ), 'block' ) ) { $revert = '(' . - $this->skin->link( + Linker::link( SpecialPage::getTitleFor( 'Unblock', $row->log_title ), $this->message['unblocklink'], array(), @@ -443,7 +443,7 @@ class LogEventsList { 'known' ) . $this->message['pipe-separator'] . - $this->skin->link( + Linker::link( SpecialPage::getTitleFor( 'Block', $row->log_title ), $this->message['change-blocklink'], array(), @@ -454,7 +454,7 @@ class LogEventsList { // Show change protection link } elseif( self::typeAction( $row, 'protect', array( 'modify', 'protect', 'unprotect' ) ) ) { $revert .= ' (' . - $this->skin->link( $title, + Linker::link( $title, $this->message['hist'], array(), array( @@ -464,7 +464,7 @@ class LogEventsList { ); if( $wgUser->isAllowed( 'protect' ) ) { $revert .= $this->message['pipe-separator'] . - $this->skin->link( $title, + Linker::link( $title, $this->message['protect_change'], array(), array( 'action' => 'protect' ), @@ -473,7 +473,7 @@ class LogEventsList { $revert .= ')'; // Show unmerge link } elseif( self::typeAction( $row, 'merge', 'merge', 'mergehistory' ) ) { - $revert = '(' . $this->skin->link( + $revert = '(' . Linker::link( SpecialPage::getTitleFor( 'MergeHistory' ), $this->message['revertmerge'], array(), @@ -495,7 +495,7 @@ class LogEventsList { // $paramArray[1] is a CSV of the IDs $query = $paramArray[0]; // Link to each hidden object ID, $paramArray[1] is the url param - $revert = '(' . $this->skin->link( + $revert = '(' . Linker::link( $revdel, $this->message['revdel-restore'], array(), @@ -510,10 +510,10 @@ class LogEventsList { // Self-created users } elseif( self::typeAction( $row, 'newusers', 'create2' ) ) { if( isset( $paramArray[0] ) ) { - $revert = $this->skin->userToolLinks( $paramArray[0], $title->getDBkey(), true ); + $revert = Linker::userToolLinks( $paramArray[0], $title->getDBkey(), true ); } else { # Fall back to a blue contributions link - $revert = $this->skin->userToolLinks( 1, $title->getDBkey() ); + $revert = Linker::userToolLinks( 1, $title->getDBkey() ); } if( wfTimestamp( TS_MW, $row->log_timestamp ) < '20080129000000' ) { # Suppress $comment from old entries (before 2008-01-29), @@ -548,7 +548,7 @@ class LogEventsList { $canHide = $wgUser->isAllowed( 'deleterevision' ); // If event was hidden from sysops if( !self::userCan( $row, LogPage::DELETED_RESTRICTED ) ) { - $del = $this->skin->revDeleteLinkDisabled( $canHide ); + $del = Linker::revDeleteLinkDisabled( $canHide ); } else { $target = SpecialPage::getTitleFor( 'Log', $row->log_type ); $query = array( @@ -556,7 +556,7 @@ class LogEventsList { 'type' => 'logging', 'ids' => $row->log_id, ); - $del = $this->skin->revDeleteLink( $query, + $del = Linker::revDeleteLink( $query, self::isDeleted( $row, LogPage::DELETED_RESTRICTED ), $canHide ); } } @@ -716,7 +716,7 @@ class LogEventsList { # If there is exactly one log type, we can link to Special:Log?type=foo if ( count( $types ) == 1 ) $urlParam['type'] = $types[0]; - $s .= $wgUser->getSkin()->link( + $s .= Linker::link( SpecialPage::getTitleFor( 'Log' ), wfMsgHtml( 'log-fulllog' ), array(), diff --git a/includes/LogPage.php b/includes/LogPage.php index 83dbc9e70c..5155d9a5c0 100644 --- a/includes/LogPage.php +++ b/includes/LogPage.php @@ -207,26 +207,32 @@ class LogPage { { global $wgLang, $wgContLang, $wgLogActions; + if ( is_null( $skin ) ) { + $langObj = $wgContLang; + $langObjOrNull = null; + } else { + $langObj = $wgLang; + $langObjOrNull = $wgLang; + } + $key = "$type/$action"; # Defer patrol log to PatrolLog class if( $key == 'patrol/patrol' ) { - return PatrolLog::makeActionText( $title, $params, $skin ); + return PatrolLog::makeActionText( $title, $params, $langObjOrNull ); } if( isset( $wgLogActions[$key] ) ) { if( is_null( $title ) ) { - $rv = wfMsgHtml( $wgLogActions[$key] ); + $rv = wfMsgExt( $wgLogActions[$key], array( 'parsemag', 'escape', 'language' => $langObj ) ); } else { - $titleLink = self::getTitleLink( $type, $skin, $title, $params ); + $titleLink = self::getTitleLink( $type, $langObjOrNull, $title, $params ); if( preg_match( '/^rights\/(rights|autopromote)/', $key ) ) { + $rightsnone = wfMsgExt( 'rightsnone', array( 'parsemag', 'language' => $langObj ) ); if( $skin ) { - $rightsnone = wfMsg( 'rightsnone' ); foreach ( $params as &$param ) { $groupArray = array_map( 'trim', explode( ',', $param ) ); $groupArray = array_map( array( 'User', 'getGroupMember' ), $groupArray ); $param = $wgLang->listToText( $groupArray ); } - } else { - $rightsnone = wfMsgForContent( 'rightsnone' ); } if( !isset( $params[0] ) || trim( $params[0] ) == '' ) { $params[0] = $rightsnone; @@ -236,11 +242,7 @@ class LogPage { } } if( count( $params ) == 0 ) { - if ( $skin ) { - $rv = wfMsgHtml( $wgLogActions[$key], $titleLink ); - } else { - $rv = wfMsgExt( $wgLogActions[$key], array( 'parsemag', 'escape', 'replaceafter', 'content' ), $titleLink ); - } + $rv = wfMsgExt( $wgLogActions[$key], array( 'parsemag', 'escape', 'replaceafter', 'language' => $langObj ), $titleLink ); } else { $details = ''; array_unshift( $params, $titleLink ); @@ -253,7 +255,7 @@ class LogPage { $params[1] = $wgContLang->translateBlockExpiry( $params[1] ); } $params[2] = isset( $params[2] ) ? - self::formatBlockFlags( $params[2], is_null( $skin ) ) : ''; + self::formatBlockFlags( $params[2], $langObj ) : ''; // Page protections } elseif ( $type == 'protect' && count($params) == 3 ) { @@ -265,21 +267,13 @@ class LogPage { } // Cascading flag... if( $params[2] ) { - if ( $skin ) { - $details .= ' [' . wfMsg( 'protect-summary-cascade' ) . ']'; - } else { - $details .= ' [' . wfMsgForContent( 'protect-summary-cascade' ) . ']'; - } + $details .= ' [' . wfMsgExt( 'protect-summary-cascade', array( 'parsemag', 'language' => $langObj ) ) . ']'; } // Page moves } elseif ( $type == 'move' && count( $params ) == 3 ) { if( $params[2] ) { - if ( $skin ) { - $details .= ' [' . wfMsg( 'move-redirect-suppressed' ) . ']'; - } else { - $details .= ' [' . wfMsgForContent( 'move-redirect-suppressed' ) . ']'; - } + $details .= ' [' . wfMsgExt( 'move-redirect-suppressed', array( 'parsemag', 'language' => $langObj ) ) . ']'; } // Revision deletion @@ -287,21 +281,17 @@ class LogPage { $count = substr_count( $params[2], ',' ) + 1; // revisions $ofield = intval( substr( $params[3], 7 ) ); // $nfield = intval( substr( $params[4], 7 ) ); // - $details .= ': ' . RevisionDeleter::getLogMessage( $count, $nfield, $ofield, false, is_null( $skin ) ); + $details .= ': ' . RevisionDeleter::getLogMessage( $count, $nfield, $ofield, $langObj, false ); // Log deletion } elseif ( preg_match( '/^(delete|suppress)\/event$/', $key ) && count( $params ) == 4 ) { $count = substr_count( $params[1], ',' ) + 1; // log items $ofield = intval( substr( $params[2], 7 ) ); // $nfield = intval( substr( $params[3], 7 ) ); // - $details .= ': ' . RevisionDeleter::getLogMessage( $count, $nfield, $ofield, true, is_null( $skin ) ); + $details .= ': ' . RevisionDeleter::getLogMessage( $count, $nfield, $ofield, $langObj, true ); } - if ( $skin ) { - $rv = wfMsgHtml( $wgLogActions[$key], $params ) . $details; - } else { - $rv = wfMsgExt( $wgLogActions[$key], array( 'parsemag', 'escape', 'replaceafter', 'content' ), $params ) . $details; - } + $rv = wfMsgExt( $wgLogActions[$key], array( 'parsemag', 'escape', 'replaceafter', 'language' => $langObj ), $params ) . $details; } } } else { @@ -335,14 +325,14 @@ class LogPage { /** * TODO document * @param $type String - * @param $skin Skin + * @param $lang Language or null * @param $title Title * @param $params Array * @return String */ - protected static function getTitleLink( $type, $skin, $title, &$params ) { - global $wgLang, $wgContLang, $wgUserrightsInterwikiDelimiter; - if( !$skin ) { + protected static function getTitleLink( $type, $lang, $title, &$params ) { + global $wgContLang, $wgUserrightsInterwikiDelimiter; + if( !$lang ) { return $title->getPrefixedText(); } switch( $type ) { @@ -398,7 +388,7 @@ class LogPage { Title::newFromText( $params[0] ), htmlspecialchars( $params[0] ) ); - $params[1] = $wgLang->timeanddate( $params[1] ); + $params[1] = $lang->timeanddate( $params[1] ); break; default: if( $title->getNamespace() == NS_SPECIAL ) { @@ -507,19 +497,16 @@ class LogPage { * into a more readable (and translated) form * * @param $flags Flags to format - * @param $forContent Whether to localize the message depending of the user - * language + * @param $lang Language object to use * @return String */ - public static function formatBlockFlags( $flags, $forContent = false ) { - global $wgLang; - + public static function formatBlockFlags( $flags, $lang ) { $flags = explode( ',', trim( $flags ) ); if( count( $flags ) > 0 ) { for( $i = 0; $i < count( $flags ); $i++ ) { - $flags[$i] = self::formatBlockFlag( $flags[$i], $forContent ); + $flags[$i] = self::formatBlockFlag( $flags[$i], $lang ); } - return '(' . $wgLang->commaList( $flags ) . ')'; + return '(' . $lang->commaList( $flags ) . ')'; } else { return ''; } @@ -529,19 +516,15 @@ class LogPage { * Translate a block log flag if possible * * @param $flag int Flag to translate - * @param $forContent Whether to localize the message depending of the user - * language + * @param $lang Language object to use * @return String */ - public static function formatBlockFlag( $flag, $forContent = false ) { + public static function formatBlockFlag( $flag, $lang ) { static $messages = array(); if( !isset( $messages[$flag] ) ) { $messages[$flag] = htmlspecialchars( $flag ); // Fallback - $msg = wfMessage( 'block-log-flags-' . $flag ); - if ( $forContent ) { - $msg->inContentLanguage(); - } + $msg = wfMessage( 'block-log-flags-' . $flag )->inLanguage( $lang ); if ( $msg->exists() ) { $messages[$flag] = $msg->escaped(); } diff --git a/includes/PatrolLog.php b/includes/PatrolLog.php index 26fe5ebb62..0df48a8576 100644 --- a/includes/PatrolLog.php +++ b/includes/PatrolLog.php @@ -35,16 +35,14 @@ class PatrolLog { * * @param $title Title of the page that was patrolled * @param $params Array: log parameters (from logging.log_params) - * @param $skin Skin to use for building links, etc. + * @param $lang Language object to use, or false * @return String */ - public static function makeActionText( $title, $params, $skin ) { - global $wgLang; - + public static function makeActionText( $title, $params, $lang ) { list( $cur, /* $prev */, $auto ) = $params; - if( is_object( $skin ) ) { + if( is_object( $lang ) ) { # Standard link to the page in question - $link = $skin->link( $title ); + $link = Linker::link( $title ); if( $title->exists() ) { # Generate a diff link $query = array( @@ -52,9 +50,9 @@ class PatrolLog { 'diff' => 'prev' ); - $diff = $skin->link( + $diff = Linker::link( $title, - htmlspecialchars( wfMsg( 'patrol-log-diff', $wgLang->formatNum( $cur, true ) ) ), + htmlspecialchars( wfMsg( 'patrol-log-diff', $lang->formatNum( $cur, true ) ) ), array(), $query, array( 'known', 'noclasses' ) diff --git a/includes/revisiondelete/RevisionDeleter.php b/includes/revisiondelete/RevisionDeleter.php index 6e38c6e4e1..bde586c595 100644 --- a/includes/revisiondelete/RevisionDeleter.php +++ b/includes/revisiondelete/RevisionDeleter.php @@ -67,45 +67,36 @@ class RevisionDeleter { * @param $count Integer: The number of effected revisions. * @param $nbitfield Integer: The new bitfield for the revision. * @param $obitfield Integer: The old bitfield for the revision. + * @param $language Language object to use * @param $isForLog Boolean - * @param $forContent Boolean */ - public static function getLogMessage( $count, $nbitfield, $obitfield, $isForLog = false, $forContent = false ) { - global $wgLang, $wgContLang; - - $lang = $forContent ? $wgContLang : $wgLang; - $msgFunc = $forContent ? "wfMsgForContent" : "wfMsg"; - + public static function getLogMessage( $count, $nbitfield, $obitfield, $language, $isForLog = false ) { $changes = self::getChanges( $nbitfield, $obitfield ); - array_walk( $changes, array( __CLASS__, 'expandMessageArray' ), $forContent ); + array_walk( $changes, array( __CLASS__, 'expandMessageArray' ), $language ); $changesText = array(); if( count( $changes[0] ) ) { - $changesText[] = $msgFunc( 'revdelete-hid', $lang->commaList( $changes[0] ) ); + $changesText[] = wfMsgExt( 'revdelete-hid', array( 'parsemag', 'language' => $language ), $language->commaList( $changes[0] ) ); } if( count( $changes[1] ) ) { - $changesText[] = $msgFunc( 'revdelete-unhid', $lang->commaList( $changes[1] ) ); + $changesText[] = wfMsgExt( 'revdelete-unhid', array( 'parsemag', 'language' => $language ), $language->commaList( $changes[1] ) ); } - $s = $lang->semicolonList( $changesText ); + $s = $language->semicolonList( $changesText ); if( count( $changes[2] ) ) { $s .= $s ? ' (' . $changes[2][0] . ')' : ' ' . $changes[2][0]; } $msg = $isForLog ? 'logdelete-log-message' : 'revdelete-log-message'; - return wfMsgExt( $msg, $forContent ? array( 'parsemag', 'content' ) : array( 'parsemag' ), $s, $lang->formatNum($count) ); + return wfMsgExt( $msg, array( 'parsemag', 'language' => $language ), $s, $language->formatNum($count) ); } - private static function expandMessageArray(& $msg, $key, $forContent) { + private static function expandMessageArray( &$msg, $key, $language ) { if ( is_array ( $msg ) ) { - array_walk( $msg, array( __CLASS__, 'expandMessageArray' ), $forContent ); + array_walk( $msg, array( __CLASS__, 'expandMessageArray' ), $language ); } else { - if ( $forContent ) { - $msg = wfMsgForContent($msg); - } else { - $msg = wfMsg($msg); - } + $msg = wfMsgExt( $msg, array( 'parsemag', 'language' => $language ) ); } } -- 2.20.1