Example #1
0
 /**
  * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
  *
  * @param OutputPage|string $out By-reference
  * @param string|array $types Log types to show
  * @param string|Title $page The page title to show log entries for
  * @param string $user The user who made the log entries
  * @param array $param Associative Array with the following additional options:
  * - lim Integer Limit of items to show, default is 50
  * - conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
  * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
  *   if set to true (default), "No matching items in log" is displayed if loglist is empty
  * - msgKey Array If you want a nice box with a message, set this to the key of the message.
  *   First element is the message key, additional optional elements are parameters for the key
  *   that are processed with wfMessage
  * - offset Set to overwrite offset parameter in WebRequest
  *   set to '' to unset offset
  * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
  * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
  * - useRequestParams boolean Set true to use Pager-related parameters in the WebRequest
  * - useMaster boolean Use master DB
  * @return int Number of total log items (not limited by $lim)
  */
 public static function showLogExtract(&$out, $types = array(), $page = '', $user = '', $param = array())
 {
     $defaultParameters = array('lim' => 25, 'conds' => array(), 'showIfEmpty' => true, 'msgKey' => array(''), 'wrap' => "\$1", 'flags' => 0, 'useRequestParams' => false, 'useMaster' => false);
     # The + operator appends elements of remaining keys from the right
     # handed array to the left handed, whereas duplicated keys are NOT overwritten.
     $param += $defaultParameters;
     # Convert $param array to individual variables
     $lim = $param['lim'];
     $conds = $param['conds'];
     $showIfEmpty = $param['showIfEmpty'];
     $msgKey = $param['msgKey'];
     $wrap = $param['wrap'];
     $flags = $param['flags'];
     $useRequestParams = $param['useRequestParams'];
     if (!is_array($msgKey)) {
         $msgKey = array($msgKey);
     }
     if ($out instanceof OutputPage) {
         $context = $out->getContext();
     } else {
         $context = RequestContext::getMain();
     }
     # Insert list of top 50 (or top $lim) items
     $loglist = new LogEventsList($context, null, $flags);
     $pager = new LogPager($loglist, $types, $user, $page, '', $conds);
     if (!$useRequestParams) {
         # Reset vars that may have been taken from the request
         $pager->mLimit = 50;
         $pager->mDefaultLimit = 50;
         $pager->mOffset = "";
         $pager->mIsBackwards = false;
     }
     if ($param['useMaster']) {
         $pager->mDb = wfGetDB(DB_MASTER);
     }
     if (isset($param['offset'])) {
         # Tell pager to ignore WebRequest offset
         $pager->setOffset($param['offset']);
     }
     if ($lim > 0) {
         $pager->mLimit = $lim;
     }
     // Fetch the log rows and build the HTML if needed
     $logBody = $pager->getBody();
     $numRows = $pager->getNumRows();
     $s = '';
     if ($logBody) {
         if ($msgKey[0]) {
             $dir = $context->getLanguage()->getDir();
             $lang = $context->getLanguage()->getHtmlCode();
             $s = Xml::openElement('div', array('class' => "mw-warning-with-logexcerpt mw-content-{$dir}", 'dir' => $dir, 'lang' => $lang));
             if (count($msgKey) == 1) {
                 $s .= $context->msg($msgKey[0])->parseAsBlock();
             } else {
                 // Process additional arguments
                 $args = $msgKey;
                 array_shift($args);
                 $s .= $context->msg($msgKey[0], $args)->parseAsBlock();
             }
         }
         $s .= $loglist->beginLogEventsList() . $logBody . $loglist->endLogEventsList();
     } elseif ($showIfEmpty) {
         $s = Html::rawElement('div', array('class' => 'mw-warning-logempty'), $context->msg('logempty')->parse());
     }
     if ($numRows > $pager->mLimit) {
         # Show "Full log" link
         $urlParam = array();
         if ($page instanceof Title) {
             $urlParam['page'] = $page->getPrefixedDBkey();
         } elseif ($page != '') {
             $urlParam['page'] = $page;
         }
         if ($user != '') {
             $urlParam['user'] = $user;
         }
         if (!is_array($types)) {
             # Make it an array, if it isn't
             $types = array($types);
         }
         # If there is exactly one log type, we can link to Special:Log?type=foo
         if (count($types) == 1) {
             $urlParam['type'] = $types[0];
         }
         $s .= Linker::link(SpecialPage::getTitleFor('Log'), $context->msg('log-fulllog')->escaped(), array(), $urlParam);
     }
     if ($logBody && $msgKey[0]) {
         $s .= '</div>';
     }
     if ($wrap != '') {
         // Wrap message in html
         $s = str_replace('$1', $s, $wrap);
     }
     /* hook can return false, if we don't want the message to be emitted (Wikia BugId:7093) */
     if (Hooks::run('LogEventsListShowLogExtract', array(&$s, $types, $page, $user, $param))) {
         // $out can be either an OutputPage object or a String-by-reference
         if ($out instanceof OutputPage) {
             $out->addHTML($s);
         } else {
             $out = $s;
         }
     }
     return $numRows;
 }
Example #2
0
 /**
  * Show log extract. Either with text and a box (set $msgKey) or without (don't set $msgKey)
  *
  * @param $out OutputPage|String-by-reference
  * @param $types String or Array
  * @param $page String The page title to show log entries for
  * @param $user String The user who made the log entries
  * @param $param Associative Array with the following additional options:
  * - lim Integer Limit of items to show, default is 50
  * - conds Array Extra conditions for the query (e.g. "log_action != 'revision'")
  * - showIfEmpty boolean Set to false if you don't want any output in case the loglist is empty
  *   if set to true (default), "No matching items in log" is displayed if loglist is empty
  * - msgKey Array If you want a nice box with a message, set this to the key of the message.
  *   First element is the message key, additional optional elements are parameters for the key
  *   that are processed with wgMsgExt and option 'parse'
  * - offset Set to overwrite offset parameter in $wgRequest
  *   set to '' to unset offset
  * - wrap String Wrap the message in html (usually something like "<div ...>$1</div>").
  * - flags Integer display flags (NO_ACTION_LINK,NO_EXTRA_USER_LINKS)
  * @return Integer Number of total log items (not limited by $lim)
  */
 public static function showLogExtract(&$out, $types = array(), $page = '', $user = '', $param = array())
 {
     global $wgUser, $wgOut;
     $defaultParameters = array('lim' => 25, 'conds' => array(), 'showIfEmpty' => true, 'msgKey' => array(''), 'wrap' => "\$1", 'flags' => 0);
     # The + operator appends elements of remaining keys from the right
     # handed array to the left handed, whereas duplicated keys are NOT overwritten.
     $param += $defaultParameters;
     # Convert $param array to individual variables
     $lim = $param['lim'];
     $conds = $param['conds'];
     $showIfEmpty = $param['showIfEmpty'];
     $msgKey = $param['msgKey'];
     $wrap = $param['wrap'];
     $flags = $param['flags'];
     if (!is_array($msgKey)) {
         $msgKey = array($msgKey);
     }
     # Insert list of top 50 (or top $lim) items
     $loglist = new LogEventsList($wgUser->getSkin(), $wgOut, $flags);
     $pager = new LogPager($loglist, $types, $user, $page, '', $conds);
     if (isset($param['offset'])) {
         # Tell pager to ignore $wgRequest offset
         $pager->setOffset($param['offset']);
     }
     if ($lim > 0) {
         $pager->mLimit = $lim;
     }
     $logBody = $pager->getBody();
     $s = '';
     if ($logBody) {
         if ($msgKey[0]) {
             $s = '<div class="mw-warning-with-logexcerpt">';
             if (count($msgKey) == 1) {
                 $s .= wfMsgExt($msgKey[0], array('parse'));
             } else {
                 // Process additional arguments
                 $args = $msgKey;
                 array_shift($args);
                 $s .= wfMsgExt($msgKey[0], array('parse'), $args);
             }
         }
         $s .= $loglist->beginLogEventsList() . $logBody . $loglist->endLogEventsList();
     } else {
         if ($showIfEmpty) {
             $s = Html::rawElement('div', array('class' => 'mw-warning-logempty'), wfMsgExt('logempty', array('parseinline')));
         }
     }
     if ($pager->getNumRows() > $pager->mLimit) {
         # Show "Full log" link
         $urlParam = array();
         if ($page != '') {
             $urlParam['page'] = $page;
         }
         if ($user != '') {
             $urlParam['user'] = $user;
         }
         if (!is_array($types)) {
             # Make it an array, if it isn't
             $types = array($types);
         }
         # If there is exactly one log type, we can link to Special:Log?type=foo
         if (count($types) == 1) {
             $urlParam['type'] = $types[0];
         }
         $s .= Linker::link(SpecialPage::getTitleFor('Log'), wfMsgHtml('log-fulllog'), array(), $urlParam);
     }
     if ($logBody && $msgKey[0]) {
         $s .= '</div>';
     }
     if ($wrap != '') {
         // Wrap message in html
         $s = str_replace('$1', $s, $wrap);
     }
     // $out can be either an OutputPage object or a String-by-reference
     if ($out instanceof OutputPage) {
         $out->addHTML($s);
     } else {
         $out = $s;
     }
     return $pager->getNumRows();
 }