Пример #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;
 }
Пример #2
0
 /**
  * @static
  */
 static function actionText($type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks = false)
 {
     global $wgLang, $wgContLang, $wgLogActions;
     $key = "{$type}/{$action}";
     if ($key == 'patrol/patrol') {
         return PatrolLog::makeActionText($title, $params, $skin);
     }
     if (isset($wgLogActions[$key])) {
         if (is_null($title)) {
             $rv = wfMsg($wgLogActions[$key]);
         } else {
             if ($skin) {
                 switch ($type) {
                     case 'move':
                         $titleLink = $skin->makeLinkObj($title, $title->getPrefixedText(), 'redirect=no');
                         $params[0] = $skin->makeLinkObj(Title::newFromText($params[0]), htmlspecialchars($params[0]));
                         break;
                     case 'block':
                         if (substr($title->getText(), 0, 1) == '#') {
                             $titleLink = $title->getText();
                         } else {
                             // TODO: Store the user identifier in the parameters
                             // to make this faster for future log entries
                             $id = User::idFromName($title->getText());
                             $titleLink = $skin->userLink($id, $title->getText()) . $skin->userToolLinks($id, $title->getText(), false, Linker::TOOL_LINKS_NOBLOCK);
                         }
                         break;
                     case 'rights':
                         $text = $wgContLang->ucfirst($title->getText());
                         $titleLink = $skin->makeLinkObj(Title::makeTitle(NS_USER, $text));
                         break;
                     case 'merge':
                         $titleLink = $skin->makeLinkObj($title, $title->getPrefixedText(), 'redirect=no');
                         $params[0] = $skin->makeLinkObj(Title::newFromText($params[0]), htmlspecialchars($params[0]));
                         $params[1] = $wgLang->timeanddate($params[1]);
                         break;
                     default:
                         $titleLink = $skin->makeLinkObj($title);
                 }
             } else {
                 $titleLink = $title->getPrefixedText();
             }
             if ($key == 'rights/rights') {
                 if ($skin) {
                     $rightsnone = wfMsg('rightsnone');
                 } else {
                     $rightsnone = wfMsgForContent('rightsnone');
                 }
                 if (!isset($params[0]) || trim($params[0]) == '') {
                     $params[0] = $rightsnone;
                 }
                 if (!isset($params[1]) || trim($params[1]) == '') {
                     $params[1] = $rightsnone;
                 }
             }
             if (count($params) == 0) {
                 if ($skin) {
                     $rv = wfMsg($wgLogActions[$key], $titleLink);
                 } else {
                     $rv = wfMsgForContent($wgLogActions[$key], $titleLink);
                 }
             } else {
                 array_unshift($params, $titleLink);
                 if ($key == 'block/block') {
                     if ($skin) {
                         $params[1] = '<span 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]) : '';
                 }
                 $rv = wfMsgReal($wgLogActions[$key], $params, true, !$skin);
             }
         }
     } else {
         wfDebug("LogPage::actionText - unknown action {$key}\n");
         $rv = "{$action}";
     }
     if ($filterWikilinks) {
         $rv = str_replace("[[", "", $rv);
         $rv = str_replace("]]", "", $rv);
     }
     return $rv;
 }
Пример #3
0
 /**
  * @static
  * @return HTML string
  */
 static function actionText($type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks = false)
 {
     global $wgLang, $wgContLang, $wgLogActions, $wgMessageCache;
     $wgMessageCache->loadAllMessages();
     $key = "{$type}/{$action}";
     # Defer patrol log to PatrolLog class
     if ($key == 'patrol/patrol') {
         return PatrolLog::makeActionText($title, $params, $skin);
     }
     if (isset($wgLogActions[$key])) {
         if (is_null($title)) {
             $rv = wfMsg($wgLogActions[$key]);
         } else {
             $titleLink = self::getTitleLink($type, $skin, $title, $params);
             if ($key == 'rights/rights') {
                 if ($skin) {
                     $rightsnone = wfMsg('rightsnone');
                     foreach ($params as &$param) {
                         $groupArray = array_map('trim', explode(',', $param));
                         $groupArray = array_map(array('User', 'getGroupName'), $groupArray);
                         $param = $wgLang->listToText($groupArray);
                     }
                 } else {
                     $rightsnone = wfMsgForContent('rightsnone');
                 }
                 if (!isset($params[0]) || trim($params[0]) == '') {
                     $params[0] = $rightsnone;
                 }
                 if (!isset($params[1]) || trim($params[1]) == '') {
                     $params[1] = $rightsnone;
                 }
             }
             if (count($params) == 0) {
                 if ($skin) {
                     $rv = wfMsg($wgLogActions[$key], $titleLink);
                 } else {
                     $rv = wfMsgForContent($wgLogActions[$key], $titleLink);
                 }
             } else {
                 $details = '';
                 array_unshift($params, $titleLink);
                 if ($key == 'block/block' || $key == 'suppress/block' || $key == 'block/reblock') {
                     if ($skin) {
                         $params[1] = '<span 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], is_null($skin)) : '';
                 } else {
                     if ($type == 'protect' && count($params) == 3) {
                         $details .= " {$params[1]}";
                         // restrictions and expiries
                         if ($params[2]) {
                             $details .= ' [' . wfMsg('protect-summary-cascade') . ']';
                         }
                     } else {
                         if ($type == 'move' && count($params) == 3) {
                             if ($params[2]) {
                                 $details .= ' [' . wfMsg('move-redirect-suppressed') . ']';
                             }
                         }
                     }
                 }
                 $rv = wfMsgReal($wgLogActions[$key], $params, true, !$skin) . $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}";
         }
     }
     if ($filterWikilinks) {
         $rv = str_replace("[[", "", $rv);
         $rv = str_replace("]]", "", $rv);
     }
     return $rv;
 }
Пример #4
0
 /**
  * @static
  * @return HTML string
  */
 public static function actionText($type, $action, $title = NULL, $skin = NULL, $params = array(), $filterWikilinks = false)
 {
     global $wgLang, $wgContLang, $wgLogActions, $wgMessageCache;
     $wgMessageCache->loadAllMessages();
     $key = "{$type}/{$action}";
     # Defer patrol log to PatrolLog class
     if ($key == 'patrol/patrol') {
         return PatrolLog::makeActionText($title, $params, $skin);
     }
     if (isset($wgLogActions[$key])) {
         if (is_null($title)) {
             $rv = wfMsg($wgLogActions[$key]);
         } else {
             $titleLink = self::getTitleLink($type, $skin, $title, $params);
             if ($key == 'rights/rights') {
                 if ($skin) {
                     $rightsnone = wfMsg('rightsnone');
                     foreach ($params as &$param) {
                         $groupArray = array_map('trim', explode(',', $param));
                         $groupArray = array_map(array('User', 'getGroupName'), $groupArray);
                         $param = $wgLang->listToText($groupArray);
                     }
                 } else {
                     $rightsnone = wfMsgForContent('rightsnone');
                 }
                 if (!isset($params[0]) || trim($params[0]) == '') {
                     $params[0] = $rightsnone;
                 }
                 if (!isset($params[1]) || trim($params[1]) == '') {
                     $params[1] = $rightsnone;
                 }
             }
             if (count($params) == 0) {
                 if ($skin) {
                     $rv = wfMsg($wgLogActions[$key], $titleLink);
                 } else {
                     $rv = wfMsgForContent($wgLogActions[$key], $titleLink);
                 }
             } else {
                 $details = '';
                 array_unshift($params, $titleLink);
                 if (preg_match('/^(block|suppress)\\/(block|reblock)$/', $key)) {
                     if ($skin) {
                         $params[1] = '<span 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], is_null($skin)) : '';
                 } else {
                     if ($type == 'protect' && count($params) == 3) {
                         $details .= " {$params[1]}";
                         // restrictions and expiries
                         if ($params[2]) {
                             if ($skin) {
                                 $details .= ' [' . wfMsg('protect-summary-cascade') . ']';
                             } else {
                                 $details .= ' [' . wfMsgForContent('protect-summary-cascade') . ']';
                             }
                         }
                     } else {
                         if ($type == 'move' && count($params) == 3) {
                             if ($params[2]) {
                                 if ($skin) {
                                     $details .= ' [' . wfMsg('move-redirect-suppressed') . ']';
                                 } else {
                                     $details .= ' [' . wfMsgForContent('move-redirect-suppressed') . ']';
                                 }
                             }
                         }
                     }
                 }
                 $rv = wfMsgReal($wgLogActions[$key], $params, true, !$skin) . $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;
 }