Exemplo n.º 1
0
 /**
  * Generate text for a log entry
  *
  * @param $type String: log type
  * @param $action String: log action
  * @param $title Mixed: Title object or null
  * @param $skin Mixed: Skin object or null. If null, we want to use the wiki
  *              content language, since that will go to the IRC feed.
  * @param $params Array: parameters
  * @param $filterWikilinks Boolean: whether to filter wiki links
  * @return HTML string
  */
 public static function actionText($type, $action, $title = null, $skin = null, $params = array(), $filterWikilinks = false)
 {
     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, $langObjOrNull);
     }
     if (isset($wgLogActions[$key])) {
         if (is_null($title)) {
             $rv = wfMsgExt($wgLogActions[$key], array('parsemag', 'escape', 'language' => $langObj));
         } else {
             $titleLink = self::getTitleLink($type, $langObjOrNull, $title, $params);
             if (preg_match('/^rights\\/(rights|autopromote)/', $key)) {
                 $rightsnone = wfMsgExt('rightsnone', array('parsemag', 'language' => $langObj));
                 if ($skin) {
                     foreach ($params as &$param) {
                         $groupArray = array_map('trim', explode(',', $param));
                         $groupArray = array_map(array('User', 'getGroupMember'), $groupArray);
                         $param = $wgLang->listToText($groupArray);
                     }
                 }
                 if (!isset($params[0]) || trim($params[0]) == '') {
                     $params[0] = $rightsnone;
                 }
                 if (!isset($params[1]) || trim($params[1]) == '') {
                     $params[1] = $rightsnone;
                 }
             }
             if (count($params) == 0) {
                 $rv = wfMsgExt($wgLogActions[$key], array('parsemag', 'escape', 'replaceafter', 'language' => $langObj), $titleLink);
             } else {
                 $details = '';
                 array_unshift($params, $titleLink);
                 // User suppression
                 if (preg_match('/^(block|suppress)\\/(block|reblock)$/', $key)) {
                     if ($skin) {
                         $params[1] = '<span class="blockExpiry" dir="ltr" title="' . htmlspecialchars($params[1]) . '">' . $wgLang->translateBlockExpiry($params[1]) . '</span>';
                     } else {
                         $params[1] = $wgContLang->translateBlockExpiry($params[1]);
                     }
                     $params[2] = isset($params[2]) ? self::formatBlockFlags($params[2], $langObj) : '';
                     // Page protections
                 } elseif ($type == 'protect' && count($params) == 3) {
                     // Restrictions and expiries
                     if ($skin) {
                         $details .= $wgLang->getDirMark() . htmlspecialchars(" {$params[1]}");
                     } else {
                         $details .= " {$params[1]}";
                     }
                     // Cascading flag...
                     if ($params[2]) {
                         $details .= ' [' . wfMsgExt('protect-summary-cascade', array('parsemag', 'language' => $langObj)) . ']';
                     }
                     // Page moves
                 } elseif ($type == 'move' && count($params) == 3) {
                     if ($params[2]) {
                         $details .= ' [' . wfMsgExt('move-redirect-suppressed', array('parsemag', 'language' => $langObj)) . ']';
                     }
                     // Revision deletion
                 } elseif (preg_match('/^(delete|suppress)\\/revision$/', $key) && count($params) == 5) {
                     $count = substr_count($params[2], ',') + 1;
                     // revisions
                     $ofield = intval(substr($params[3], 7));
                     // <ofield=x>
                     $nfield = intval(substr($params[4], 7));
                     // <nfield=x>
                     $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));
                     // <ofield=x>
                     $nfield = intval(substr($params[3], 7));
                     // <nfield=x>
                     $details .= ': ' . RevisionDeleter::getLogMessage($count, $nfield, $ofield, $langObj, true);
                 }
                 $rv = wfMsgExt($wgLogActions[$key], array('parsemag', 'escape', 'replaceafter', 'language' => $langObj), $params) . $details;
             }
         }
     } else {
         global $wgLogActionsHandlers;
         if (isset($wgLogActionsHandlers[$key])) {
             $args = func_get_args();
             $rv = call_user_func_array($wgLogActionsHandlers[$key], $args);
         } else {
             wfDebug("LogPage::actionText - unknown action {$key}\n");
             $rv = "{$action}";
         }
     }
     // For the perplexed, this feature was added in r7855 by Erik.
     // The feature was added because we liked adding [[$1]] in our log entries
     // but the log entries are parsed as Wikitext on RecentChanges but as HTML
     // on Special:Log. The hack is essentially that [[$1]] represented a link
     // to the title in question. The first parameter to the HTML version (Special:Log)
     // is that link in HTML form, and so this just gets rid of the ugly [[]].
     // However, this is a horrible hack and it doesn't work like you expect if, say,
     // you want to link to something OTHER than the title of the log entry.
     // The real problem, which Erik was trying to fix (and it sort-of works now) is
     // that the same messages are being treated as both wikitext *and* HTML.
     if ($filterWikilinks) {
         $rv = str_replace('[[', '', $rv);
         $rv = str_replace(']]', '', $rv);
     }
     return $rv;
 }