Example #1
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;
 }