Пример #1
0
 /**
  * @covers MWDebug::deprecated
  */
 public function testAvoidNonConsecutivesDuplicateDeprecations()
 {
     MWDebug::deprecated('wfOldFunction', '1.0', 'component');
     MWDebug::warning('some warning');
     MWDebug::log('we could have logged something too');
     // Another deprecation
     MWDebug::deprecated('wfOldFunction', '1.0', 'component');
     // assertCount() not available on WMF integration server
     $this->assertEquals(3, count(MWDebug::getLog()), "Only one deprecated warning per function should be kept");
 }
 /**
  * Main Hook
  */
 public static function hOutputPageParserOutput(&$op, $parserOutput)
 {
     $action = $op->parserOptions()->getUser()->getRequest()->getVal("action");
     if ($action == 'edit' || $action == 'submit' || $action == 'history') {
         return true;
     }
     global $wgTitle, $wgOut;
     $ns = $wgTitle->getNsText();
     $name = $wgTitle->getPrefixedDBKey();
     $text = $parserOutput->getText();
     $categories = $wgTitle->getParentCategories();
     $categories = array_keys($categories);
     var_dump($categories);
     $categories = array_map(function ($cat) {
         return Title::newFromText($cat, NS_CATEGORY)->getText();
     }, $categories);
     var_dump($categories);
     //MWDebug::warning( "ns=" . $ns ) ;
     //MWDebug::warning( "name=" . $name ) ;
     $nsheader = "hf-nsheader-{$ns}";
     $nsfooter = "hf-nsfooter-{$ns}";
     $header = "hf-header-{$name}";
     $footer = "hf-footer-{$name}";
     /**
      * headers/footers are wrapped around page content.
      * header:	page + namespace + categories in reverse alphabetical order
      * footer:	categories in alphabetical order + namespace + page
      */
     $text = '<div class="hf-header">' . self::conditionalInclude($text, '__NOHEADER__', $header) . '</div>' . $text;
     $text = '<div class="hf-nsheader">' . self::conditionalInclude($text, '__NONSHEADER__', $nsheader) . '</div>' . $text;
     foreach ($categories as &$category) {
         MWDebug::warning("cat=" . $category);
         $catheader = "hf-catheader-{$category}";
         $text = '<div class="hf-catheader">' . self::conditionalInclude($text, '__NOCATHEADER__', $catheader) . '</div>' . $text;
         $catfooter = "hf-catfooter-{$category}";
         $text .= '<div class="hf-catfooter">' . self::conditionalInclude($text, '__NOCATFOOTER__', $catfooter) . '</div>';
     }
     ////
     $text .= '<div class="hf-footer">' . self::conditionalInclude($text, '__NOFOOTER__', $footer) . '</div>';
     $text .= '<div class="hf-nsfooter">' . self::conditionalInclude($text, '__NONSFOOTER__', $nsfooter) . '</div>';
     $parserOutput->setText($text);
     return true;
 }
Пример #3
0
/**
 * Send a warning as a PHP error and the debug log. This is intended for logging
 * warnings in production. For logging development warnings, use WfWarn instead.
 *
 * @param string $msg Message to send
 * @param int $callerOffset Number of items to go back in the backtrace to
 *        find the correct caller (1 = function calling wfLogWarning, ...)
 * @param int $level PHP error level; defaults to E_USER_WARNING
 */
function wfLogWarning($msg, $callerOffset = 1, $level = E_USER_WARNING)
{
    MWDebug::warning($msg, $callerOffset + 1, $level, 'production');
}
Пример #4
0
 static function onImageBeforeProduceHTML(&$dummy, &$title, &$file, &$frameParams, &$handlerParams, &$time, &$res)
 {
     if (!$file) {
         MWDebug::warning("could not load file from title: {$title}");
         return false;
     }
     return true;
 }
Пример #5
0
/**
 * Send a warning either to the debug log or in a PHP error depending on
 * $wgDevelopmentWarnings
 *
 * @param $msg String: message to send
 * @param $callerOffset Integer: number of items to go back in the backtrace to
 *        find the correct caller (1 = function calling wfWarn, ...)
 * @param $level Integer: PHP error level; only used when $wgDevelopmentWarnings
 *        is true
 */
function wfWarn($msg, $callerOffset = 1, $level = E_USER_NOTICE)
{
    MWDebug::warning($msg, $callerOffset + 1, $level);
}
Пример #6
0
/**
 * Send a warning either to the debug log or in a PHP error depending on
 * $wgDevelopmentWarnings
 *
 * @param $msg String: message to send
 * @param $callerOffset Integer: number of items to go back in the backtrace to
 *        find the correct caller (1 = function calling wfWarn, ...)
 * @param $level Integer: PHP error level; only used when $wgDevelopmentWarnings
 *        is true
 */
function wfWarn($msg, $callerOffset = 1, $level = E_USER_NOTICE)
{
    global $wgDevelopmentWarnings;
    MWDebug::warning($msg, $callerOffset + 2);
    $callers = wfDebugBacktrace();
    if (isset($callers[$callerOffset + 1])) {
        $callerfunc = $callers[$callerOffset + 1];
        $callerfile = $callers[$callerOffset];
        if (isset($callerfile['file']) && isset($callerfile['line'])) {
            $file = $callerfile['file'] . ' at line ' . $callerfile['line'];
        } else {
            $file = '(internal function)';
        }
        $func = '';
        if (isset($callerfunc['class'])) {
            $func .= $callerfunc['class'] . '::';
        }
        if (isset($callerfunc['function'])) {
            $func .= $callerfunc['function'];
        }
        $msg .= " [Called from {$func} in {$file}]";
    }
    if ($wgDevelopmentWarnings) {
        trigger_error($msg, $level);
    } else {
        wfDebug("{$msg}\n");
    }
}
Пример #7
0
 private function getNext()
 {
     $content = array();
     $guestId = $this->getRequest()->getVal('guestId');
     $content['user_voter'] = UCIPatrol::getUserAvatar($this->getUser(), $guestId);
     $content['required_upvotes'] = UCIPatrol::UCI_UPVOTES;
     $content['required_downvotes'] = UCIPatrol::UCI_DOWNVOTES;
     $content['vote_mult'] = $this->getVoteMultiplier();
     $skipped = UCIPatrol::getSkipList();
     $count = UCIPatrol::getCount() - count($skipped);
     $content['uciCount'] = $count;
     $where = array();
     $where[] = "uci_downvotes < " . self::UCI_DOWNVOTES;
     $where[] = "uci_upvotes < " . self::UCI_UPVOTES;
     $where[] = "uci_copyright_violates = 0";
     $where[] = "uci_copyright_checked = 1";
     if ($skipped) {
         $where[] = "uci_article_id NOT IN ('" . implode("','", $skipped) . "')";
     }
     $dbr = wfGetDB(DB_SLAVE);
     $row = $dbr->selectRow('user_completed_images', array('*'), $where, __METHOD__, array("LIMIT" => 1));
     $content['pageId'] = $row->uci_article_id;
     $content['upvotes'] = $row->uci_upvotes;
     $content['downvotes'] = $row->uci_downvotes;
     //$content['sql' . $i] = $dbw->lastQuery();
     //$content['row'] = $row;
     if ($row === false) {
         MWDebug::log("no more images to patrol");
         return $content;
     }
     $title = Title::newFromText($row->uci_article_name);
     // check page id vs whitelist/blacklist
     if (!UCIPatrol::isUCIAllowed($title)) {
         MWDebug::log("not allowed title: " . $title);
         $this->skipById($row->uci_article_id);
         return $this->getNext();
     }
     $content['articleTitle'] = $title->getText();
     $content['articleURL'] = $title->getPartialUrl();
     if (!$title) {
         MWDebug::log("no title: " . $title);
         $content['error'] = "notitle";
         return $content;
     }
     // get data about the completion image
     $file = UCIPatrol::fileFromRow($row);
     if (!$file) {
         MWDebug::warning("no file with image name " . $row->uci_image_name);
         $content['error'] = "filenotfound";
         return $content;
     }
     $content['uci_image_name'] = $row->uci_image_name;
     // get info about the originating page the image was added for
     $revision = Revision::newFromTitle($title);
     if ($title->isRedirect()) {
         MWDebug::log("is a redirect: " . $title);
         $wtContent = $revision->getContent();
         $title = $wtContent->getUltimateRedirectTarget();
         // edge case if there are just too many redirects, just skip this
         if ($title->isRedirect()) {
             MWDebug::log("too many redirects..skipping" . $title);
             $content['error'] = "redirect";
             return $content;
         }
         $revision = Revision::newFromTitle($title);
         $content['articleTitle'] = $title->getText();
         $content['articleURL'] = $title->getPartialUrl();
         UCIPatrol::updateArticleName($row, $title->getText());
     }
     $popts = $this->getOutput()->parserOptions();
     $popts->setTidy(true);
     $parserOutput = $this->getOutput()->parse($revision->getText(), $title, $popts);
     $magic = WikihowArticleHTML::grabTheMagic($revision->getText());
     $content['article'] = WikihowArticleHTML::processArticleHTML($parserOutput, array('no-ads' => true, 'ns' => NS_MAIN, 'magic-word' => $magic));
     $width = $file->getWidth();
     // scale width so that the height is no greater than PATROL_THUMB_HEIGHT
     if ($file->getHeight() > self::PATROL_THUMB_HEIGHT) {
         $ratio = self::PATROL_THUMB_HEIGHT / $file->getHeight();
         $width = floor($width * $ratio);
     }
     // now that we have possibly scaled the width down to fit our max height..
     // we also will potentially scale down the width if it is still larger
     // than will fit on the patrol page
     $width = $width < self::PATROL_THUMB_WIDTH ? $width : self::PATROL_THUMB_WIDTH;
     $thumb = $file->getThumbnail($width);
     $content['thumb_url'] = $thumb->getUrl();
     $content['width'] = $thumb->getWidth();
     $content['height'] = $thumb->getHeight();
     // this is the page id of the image file itself not the same as articleTitle
     // used for skipping
     $voters = UCIPatrol::getVoters($row->uci_article_id);
     $content['voters'] = $voters;
     return $content;
 }