Example #1
0
 function getRelatedImagesWidget($title)
 {
     global $wgUser;
     $exceptions = wfMsg('ih_exceptions');
     $imageExceptions = split("\n", $exceptions);
     $articles = ImageHelper::getLinkedArticles($title);
     $images = array();
     foreach ($articles as $t) {
         $results = ImageHelper::getImages($t->getArticleID());
         if (count($results) <= 1) {
             continue;
         }
         $titleDb = $title->getDBkey();
         foreach ($results as $row) {
             if ($row['il_to'] != $titleDb && !in_array($row['il_to'], $imageExceptions)) {
                 $images[] = $row['il_to'];
             }
         }
     }
     $count = 0;
     $maxLoc = count($images);
     $maxImages = $maxLoc;
     $finalImages = array();
     while ($count < 6 && $count < $maxImages) {
         $loc = rand(0, $maxLoc);
         if ($images[$loc] != null) {
             $image = Title::newFromText("Image:" . $images[$loc]);
             if ($image && $image->getArticleID() > 0) {
                 $file = wfFindFile($image);
                 if ($file && isset($file)) {
                     $finalImages[] = array('title' => $image, 'file' => $file);
                     $images[$loc] = null;
                     $count++;
                 } else {
                     $maxImages--;
                 }
             } else {
                 $maxImages--;
             }
             $images[$loc] = null;
         }
     }
     if (count($finalImages) > 0) {
         $html = '<div><h3>' . wfMsg('ih_relatedimages_widget') . '</h3><table style="margin-top:10px" class="image_siderelated">';
         $count = 0;
         foreach ($finalImages as $imageObject) {
             $image = $imageObject['title'];
             $file = $imageObject['file'];
             if ($count % 2 == 0) {
                 $html .= "<tr>";
             }
             $heightPreference = ImageHelper::heightPreference(127, 140, $file);
             $thumb = $file->getThumbnail(127, 140, true, true, $heightPreference);
             $imageUrl = $image->getFullURL();
             $thumbUrl = $thumb->url;
             $imageTitle = $imageName;
             $html .= "<td valign='top'>\n\t\t\t\t\t\t\t<a href='" . $imageUrl . "' title='" . $imageTitle . "' class='image'>\n\t\t\t\t\t\t\t<img border='0' class='mwimage101' src='" . wfGetPad($thumbUrl) . "' alt='" . $imageTitle . "'>\n\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t</td>";
             if ($count % 2 == 2) {
                 $html .= "</tr>";
             }
             $count++;
         }
         if ($count % 3 != 2) {
             $html .= "</tr>";
         }
         $html .= "</table></div>";
         return $html;
     }
 }
 public function execute()
 {
     global $IP;
     require_once "{$IP}/extensions/wikihow/common/S3.php";
     define('WH_USE_BACKUP_DB', true);
     $pageIds = array();
     // allow for the input files to be specified on the command line
     if ($this->getOption('stream')) {
         $data = stream_get_contents(STDIN);
         $data = array_map('trim', explode("\n", $data));
         foreach ($data as $inputTitle) {
             $title = Title::newFromText($inputTitle, 6);
             if (!$title) {
                 continue;
             }
             $id = $title->getArticleID();
             $pageIds[] = $id;
         }
     }
     // if provided title, add that to the array
     $titleText = $this->getOption('title');
     if ($titleText) {
         $title = Title::newFromText($titleText, 6);
         $id = $title->getArticleID();
         $pageIds[] = $id;
     }
     // if there is a start, add articles to the array
     $start = $this->getOption('start');
     if ($start) {
         $dbr = wfGetDB(DB_SLAVE);
         $options = array("page_id > {$start}", "page_namespace = 6");
         $stop = $this->getOption('stop');
         if ($stop) {
             $options[] = "page_id < {$stop}";
         }
         $res = $dbr->select("page", "page_id", $options, __FILE__);
         // put them all into an array first
         foreach ($res as $row) {
             $pageIds[] = $row->page_id;
         }
     }
     $purgeTitles = array();
     $filesToPurgeFromCDN = array();
     foreach ($pageIds as $pageId) {
         $title = Title::newFromID($pageId);
         $file = wfLocalFile($title);
         if (!$file) {
             continue;
         }
         $userName = $file->getUser("text");
         if (WatermarkSupport::isWikihowCreator($userName)) {
             decho("file", $title->getText(), false);
             if ($this->getOption('s3')) {
                 decho("will purge from s3", false, false);
                 self::purgeThumbnailsFromS3($file);
             }
             if ($this->getOption('regenerate')) {
                 decho("will regenerate thumbnails", $file->getThumbnails(), false);
                 WatermarkSupport::recreateThumbnails($file);
                 decho("regeneration of thumbnails complete", false, false);
             }
             if ($this->getOption('purgelocal')) {
                 decho("will purge local cache thumbnails", $file->getThumbnails(), false);
                 $file->purgeCache();
                 // get titles that point here so we can purge them and
                 // regenerate those pages so the thumbnails come back
                 $purgeTitles = array_unique(array_merge($purgeTitles, ImageHelper::getLinkedArticles($title)));
                 decho("purging of thumbnails complete", false, false);
             }
             if ($this->getOption('cdn')) {
                 $filesToPurgeFromCDN[] = $file;
             }
         }
     }
     //purge the titles that have linked to these images
     foreach ($purgeTitles as $linkedTitle) {
         decho('will purge', $linkedTitle, false);
         // will now get the parser output to refresh the thumbnail
         // or else cdn may get reset before the thumbnails are regenerated
         $wp = new WikiPage($linkedTitle);
         $wp->doPurge();
         $po = ParserOptions::newFromUser($wgUser);
         $wp->getParserOutput($po);
     }
     if ($this->getOption('cdn')) {
         decho("will purge from cdn", false, false);
         $this->purgeThumbnailsFromCDNetworks($filesToPurgeFromCDN);
     }
 }
Example #3
0
 static function getCurrentTitleMetaDescription()
 {
     global $wgTitle;
     static $titleTest = null;
     $return = '';
     if ($wgTitle->getNamespace() == NS_MAIN && $wgTitle->getFullText() == wfMsg('mainpage')) {
         $return = wfMsg('mainpage_meta_description');
     } elseif ($wgTitle->getNamespace() == NS_MAIN) {
         $desc = '';
         if (!$titleTest) {
             $titleTest = TitleTests::newFromTitle($wgTitle);
             if ($titleTest) {
                 $desc = $titleTest->getMetaDescription();
             }
         }
         if (!$desc) {
             if (!self::$wgTitleAMIcache) {
                 self::$wgTitleAMIcache = new ArticleMetaInfo($wgTitle);
             }
             $ami = self::$wgTitleAMIcache;
             $desc = $ami->getDescription();
         }
         if (!$desc) {
             $return = wfMsg('article_meta_description', $wgTitle->getText());
         } else {
             $return = $desc;
         }
     } elseif ($wgTitle->getNamespace() == NS_CATEGORY) {
         // get keywords
         $subcats = self::getMetaSubcategories($wgTitle, 3);
         $keywords = implode(", ", $subcats);
         if ($keywords) {
             $return = wfMsg('category_meta_description', $wgTitle->getText(), $keywords);
         } else {
             $return = wfMsg('subcategory_meta_description', $wgTitle->getText(), $keywords);
         }
     } elseif ($wgTitle->getNamespace() == NS_USER) {
         $desc = ProfileBox::getMetaDesc();
         $return = $desc;
     } elseif ($wgTitle->getNamespace() == NS_IMAGE) {
         $articles = ImageHelper::getLinkedArticles($wgTitle);
         if (count($articles) && $articles[0]) {
             $articleTitle = wfMsg('howto', $articles[0]);
             if (preg_match('@Step (\\d+)@', $wgTitle->getText(), $m)) {
                 $imageNum = '#' . $m[1];
             } else {
                 $imageNum = '';
             }
             $return = wfMsg('image_meta_description', $articleTitle, $imageNum);
         } else {
             $return = wfMsg('image_meta_description_no_article', $wgTitle->getText());
         }
     } elseif ($wgTitle->getNamespace() == NS_SPECIAL && $wgTitle->getText() == "Popularpages") {
         $return = wfMsg('popularpages_meta_description');
     }
     return $return;
 }
Example #4
0
 function view()
 {
     global $wgOut, $wgShowEXIF, $wgRequest, $wgUser, $wgTitle;
     $startTime = strtotime('November 5, 2013');
     $oneWeek = 7 * 24 * 60 * 60;
     $rolloutArticle = Misc::percentileRollout($startTime, $oneWeek);
     $ua = @$_SERVER['HTTP_USER_AGENT'];
     if (!$rolloutArticle && preg_match('@msnbot@', $ua)) {
         header('HTTP/1.1 503 Service Temporarily Unavailable');
         echo "Sorry, not now MSNBOT!";
         exit;
     }
     $sk = $wgUser->getSkin();
     $diff = $wgRequest->getVal('diff');
     $diffOnly = $wgRequest->getBool('diffonly', $wgUser->getOption('diffonly'));
     if ($this->mTitle->getNamespace() != NS_IMAGE || isset($diff) && $diffOnly) {
         return Article::view();
     }
     if ($wgShowEXIF && $this->img->exists()) {
         // FIXME: bad interface, see note on MediaHandler::formatMetadata().
         $formattedMetadata = $this->img->formatMetadata();
         $showmeta = $formattedMetadata !== false;
     } else {
         $showmeta = false;
     }
     //NEW
     //if ($this->img->exists())
     //$wgOut->addHTML($this->showTOC($showmeta));
     $this->openShowImage();
     ImageHelper::showDescription($this->mTitle);
     $lastUser = $this->current->getUser();
     $userLink = $sk->makeLinkObj(Title::makeTitle(NS_USER, $lastUser), $lastUser);
     $wgOut->addHTML("<div style='margin-bottom:20px'></div>");
     //ImageHelper::getSummaryInfo($this->img);
     # Show shared description, if needed
     if ($this->mExtraDescription) {
         $fol = wfMsgNoTrans('shareddescriptionfollows');
         if ($fol != '-' && !wfEmptyMsg('shareddescriptionfollows', $fol)) {
             $wgOut->addWikiText($fol);
         }
         $wgOut->addHTML('<div id="shared-image-desc">' . $this->mExtraDescription . '</div>');
     }
     $this->closeShowImage();
     $currentHTML = $wgOut->getHTML();
     $wgOut->clearHTML();
     Article::view();
     $articleContent = $wgOut->getHTML();
     $wgOut->clearHTML();
     $wgOut->addHTML($currentHTML);
     $diffSeparator = "<h2>" . wfMsg('currentrev') . "</h2>";
     $articleParts = explode($diffSeparator, $articleContent);
     if (count($articleParts) > 1) {
         $wgOut->addHTML($articleParts[0]);
     }
     $articles = ImageHelper::getLinkedArticles($this->mTitle);
     if (ImageHelper::IMAGES_ON) {
         ImageHelper::getConnectedImages($articles, $this->mTitle);
         ImageHelper::getRelatedWikiHows($this->mTitle);
     }
     ImageHelper::addSideWidgets($this->mTitle);
     # No need to display noarticletext, we use our own message, output in openShowImage()
     if ($this->getID()) {
     } else {
         # Just need to set the right headers
         $wgOut->setArticleFlag(true);
         $wgOut->setRobotpolicy('noindex,nofollow');
         $wgOut->setPageTitle($this->mTitle->getPrefixedText());
         $this->viewUpdates();
     }
     if ($wgUser && !$wgUser->isAnon()) {
         $this->imageHistory();
     }
     ImageHelper::displayBottomAds();
     if ($showmeta) {
         global $wgStylePath, $wgStyleVersion;
         $expand = htmlspecialchars(wfEscapeJsString(wfMsg('metadata-expand')));
         $collapse = htmlspecialchars(wfEscapeJsString(wfMsg('metadata-collapse')));
         $wgOut->addHTML(Xml::element('h2', array('id' => 'metadata'), wfMsg('metadata')) . "\n");
         $wgOut->addWikiText($this->makeMetadataTable($formattedMetadata));
         $wgOut->addHTML("<script type=\"text/javascript\" src=\"{$wgStylePath}/common/metadata.js?{$wgStyleVersion}\"></script>\n" . "<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '{$expand}', '{$collapse}');</script>\n");
     }
 }
 function view()
 {
     global $wgShowEXIF, $wgRequest, $wgUser;
     $out = $this->getContext()->getOutput();
     $sk = $this->getContext()->getSkin();
     $diff = $wgRequest->getVal('diff');
     $diffOnly = $wgRequest->getBool('diffonly', $wgUser->getOption('diffonly'));
     if ($this->mTitle->getNamespace() != NS_IMAGE || isset($diff) && $diffOnly) {
         return Article::view();
     }
     if ($wgShowEXIF && $this->getDisplayedFile()->exists()) {
         // FIXME: bad interface, see note on MediaHandler::formatMetadata().
         $formattedMetadata = $this->getDisplayedFile()->formatMetadata();
         $showmeta = $formattedMetadata !== false;
     } else {
         $showmeta = false;
     }
     $this->openShowImage();
     ImageHelper::showDescription($this->mTitle);
     $lastUser = $this->getDisplayedFile()->getUser();
     $userLink = Linker::makeLinkObj(Title::makeTitle(NS_USER, $lastUser), $lastUser);
     $out->addHTML("<div style='margin-bottom:20px'></div>");
     # Show shared description, if needed
     if ($this->mExtraDescription) {
         $fol = wfMsgNoTrans('shareddescriptionfollows');
         if ($fol != '-' && !wfEmptyMsg('shareddescriptionfollows', $fol)) {
             $out->addWikiText($fol);
         }
         $out->addHTML('<div id="shared-image-desc">' . $this->mExtraDescription . '</div>');
     }
     $this->closeShowImage();
     $currentHTML = $out->getHTML();
     $out->clearHTML();
     Article::view();
     $articleContent = $out->getHTML();
     $out->clearHTML();
     $out->addHTML($currentHTML);
     $diffSeparator = "<h2>" . wfMessage('currentrev')->text() . "</h2>";
     $articleParts = explode($diffSeparator, $articleContent);
     if (count($articleParts) > 1) {
         $out->addHTML($articleParts[0]);
     }
     $ih = new ImageHelper();
     $articles = $ih->getLinkedArticles($this->mTitle);
     if (ImageHelper::IMAGES_ON) {
         $ih->getConnectedImages($articles, $this->mTitle);
         $ih->getRelatedWikiHows($this->mTitle, $sk);
     }
     $ih->addSideWidgets($this, $this->mTitle, $this->getDisplayedFile());
     # No need to display noarticletext, we use our own message, output in openShowImage()
     if ($this->getID()) {
     } else {
         # Just need to set the right headers
         $out->setArticleFlag(true);
         $out->setRobotpolicy('noindex,nofollow');
         $out->setPageTitle($this->mTitle->getPrefixedText());
         //$this->viewUpdates();
     }
     if ($wgUser && !$wgUser->isAnon()) {
         $this->imageHistory();
     }
     ImageHelper::displayBottomAds();
     if ($showmeta) {
         $out->addHTML(Xml::element('h2', array('id' => 'metadata'), wfMessage('metadata')->text()) . "\n");
         $out->addWikiText($this->makeMetadataTable($formattedMetadata));
         $out->addModules(array('mediawiki.action.view.metadata'));
     }
 }