function WidgetProblemReports($id, $params)
{
    // check whether ProblemReports extension is enabled on this wiki
    global $wgProblemReportsEnable;
    if (!isset($wgProblemReportsEnable) || !$wgProblemReportsEnable) {
        return '<em>Extension ProblemReports not enabled on this wiki</em>';
        // fallback message
    }
    $params['limit'] = intval($params['limit']);
    $apiParams = array('wkshowall' => $params['pr_raports_from_this_wikia'] == 0 && WikiaApiQueryProblemReports::userCanDoActions() ? 1 : NULL, 'wktype' => intval($params['pr_table_problem_type']) >= 0 ? intval($params['pr_table_problem_type']) : NULL, 'wkstaff' => $params['show'] == 2 ? 1 : NULL, 'wkarchived' => $params['show'] == 1 ? 1 : NULL, 'wklimit' => $params['limit'] <= 0 || $params['limit'] > 50 ? 25 : $params['limit']);
    $apiParams['action'] = 'query';
    $apiParams['list'] = 'problemreports';
    //print_pre($apiParams);
    $data = WidgetFramework::callAPI($apiParams);
    $count = intval($data['query']['reports']);
    if ($count == 0) {
        return array('title' => wfMsg('problemreports'), 'body' => wfMsg('pr_no_reports'));
    }
    $reports = $data['query']['problemreports'];
    $problemTypes = array(wfMsg('pr_what_problem_spam_short'), wfMsg('pr_what_problem_vandalised_short'), wfMsg('pr_what_problem_incorrect_content_short'), wfMsg('pr_what_problem_software_bug_short'), wfMsg('pr_what_problem_other_short'));
    // list reports
    $items = array();
    //url used for linking to PR ids
    $baseUrl = Title::newFromText('ProblemReports', NS_SPECIAL)->getLocalURL();
    // build params for 'more' link based on this widget's settings
    $urlParams = array();
    if ($params['show'] == 2) {
        $urlParams[] = 'staff=1';
    } elseif ($params['show'] == 1) {
        $urlParams[] = 'archived=1';
    }
    if ($apiParams['wkshowall'] == 1) {
        $urlParams[] = 'showall=1';
    }
    if ($apiParams['wktype'] != NULL) {
        $urlParams[] = 'problem=' . $apiParams['wktype'];
    }
    // smush
    $urlParams = implode('&', $urlParams);
    // apply and build
    $moreUrl = Title::newFromText('ProblemReports', NS_SPECIAL)->getLocalURL($urlParams);
    foreach ($reports as $problem) {
        $date = date('d m Y', strtotime($problem['date']));
        $items[] = array('href' => $baseUrl . '/' . $problem['id'], 'title' => '#' . $problem['id'] . ' - ' . wfMsg('pr_table_date_submitted') . ': ' . $date, 'name' => wfShortenText($problem['title'], 25) . ' [' . $problemTypes[$problem['type']] . ($apiParams['wkshowall'] == 1 ? ' | ' . str_replace(array('http://', '.wikia.com', '.wikia-inc.com'), '', $problem['server']) : '') . ']');
    }
    return array('title' => wfMsg('problemreports') . ' (' . $count . ')', 'body' => WidgetFramework::wrapLinks($items) . WidgetFramework::moreLink($moreUrl));
}
Example #2
0
 /**
  * Generate text for a log entry.
  * Only LogFormatter should call this function.
  *
  * @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}";
     // macbre: ProblemReports (dirty code hack :[)
     if ($type == 'pr_rep_log' && class_exists('WikiaApiQueryProblemReports')) {
         return WikiaApiQueryProblemReports::makeActionText($key, $title, $params, $skin);
     }
     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)) . ']';
                     }
                 }
                 $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;
 }