/** * @param ImagePage $imagePage */ public function __construct($imagePage) { global $wgShowArchiveThumbnails; $this->current = $imagePage->getPage()->getFile(); $this->img = $imagePage->getDisplayedFile(); $this->title = $imagePage->getTitle(); $this->imagePage = $imagePage; $this->showThumb = $wgShowArchiveThumbnails && $this->img->canRender(); $this->setContext($imagePage->getContext()); }
function efImageReviewDisplayStatus(ImagePage $imagePage, &$html) { global $wgCityId, $wgExternalDatawareDB, $wgUser; if (!$wgUser->isAllowed('imagereviewstats')) { return true; } if (!$imagePage->getTitle()->exists()) { return true; } $html .= Xml::element('h2', array(), wfMsg('imagereview-imagepage-header')); $reviews = array(); $headers = array(wfMessage('imagereview-imagepage-table-header-reviewer')->text(), wfMessage('imagereview-imagepage-table-header-state')->text(), wfMessage('imagereview-imagepage-table-header-time')->text()); $where = array('wiki_id' => $wgCityId, 'page_id' => $imagePage->getId()); $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalDatawareDB); $res = $dbr->select('image_review_stats', '*', $where); if ($dbr->numRows($res) == 0) { //check if image is in the queue at all! $imgCurState = $dbr->selectField('image_review', 'state', $where); if (false === $imgCurState) { /** * If the file is a local one and is older than 1 hour - send it to ImageReview * since it's probably been restored, and is not just a fresh file. */ $lastTouched = new DateTime($imagePage->getRevisionFetched()->getTimestamp()); $now = new DateTime(); $file = $imagePage->getDisplayedFile(); if ($file instanceof WikiaLocalFile && $lastTouched < $now->modify('-1 hour')) { $scribeEventProducer = new ScribeEventProducer('edit'); $user = User::newFromName($file->getUser()); if ($scribeEventProducer->buildEditPackage($imagePage, $user, null, null, $file)) { $logParams = ['cityId' => $wgCityId, 'pageId' => $imagePage->getID(), 'pageTitle' => $imagePage->getTitle()->getText(), 'uploadUser' => $user->getName()]; \Wikia\Logger\WikiaLogger::instance()->info('ImageReviewLog', ['message' => 'Image moved back to queue', 'params' => $logParams]); $scribeEventProducer->sendLog(); } } // oh oh, image is not in queue at all $html .= wfMsg('imagereview-imagepage-not-in-queue'); } else { // image is in the queue but not reviewed yet $html .= wfMsg('imagereview-state-0'); } } else { // go through the list and display review states while ($row = $dbr->fetchObject($res)) { $data = array(); $data[] = User::newFromId($row->reviewer_id)->getName(); $data[] = wfMsg('imagereview-state-' . $row->review_state); $data[] = $row->review_end . ' (UTC)'; $reviews[] = $data; } $html .= Xml::buildTable($reviews, array('class' => 'wikitable filehistory sortable', 'style' => 'width: 60%'), $headers); } return true; }
/** * change title tag for Video Page and Image Page * @author Jacek Jursza * @param ImagePage $imgPage * @param $html * @return bool */ static function onImagePageAfterImageLinks($imgPage, $html) { $file = $imgPage->getDisplayedFile(); /* @var $file LocalRepo */ $title = $imgPage->getTitle(); /* @var $title Title */ $newTitle = ''; if (!empty($file) && !empty($title) && !F::app()->checkSkin('monobook')) { if ((new WikiaFileHelper())->isFileTypeVideo($file)) { $newTitle = wfMsg('seotweaks-video') . ' - ' . $title->getBaseText(); } else { // It's not Video so lets check if it is Image if ($file instanceof LocalFile && $file->getHandler() instanceof BitmapHandler) { $newTitle = wfMsg('seotweaks-image') . ' - ' . $title->getBaseText(); } } if (!empty($newTitle)) { F::app()->wg->Out->setPageTitle($newTitle); } } return true; }
/** * Resolves the url of images provided as wiki page; leaves others alone. * * @since 1.0 * * @param string $file * * @return string */ public static function getFileUrl($file) { $title = Title::newFromText($file, NS_FILE); if (!is_null($title) && $title->getNamespace() == NS_FILE && $title->exists()) { $imagePage = new ImagePage($title); $file = $imagePage->getDisplayedFile()->getURL(); } return $file; }
/** * Fills the $markerData array with the locations and their meta data. * * @param unknown_type $parser */ private function setMarkerData( $parser ) { $this->coordinates = explode( ';', $this->coordinates ); $this->title = Xml::escapeJsString( $parser->recursiveTagParse( $this->title ) ); $this->label = Xml::escapeJsString( $parser->recursiveTagParse( $this->label ) ); foreach ( $this->coordinates as $coordinates ) { $args = explode( '~', $coordinates ); $markerData = array( 'location' => $args[0] ); if ( count( $args ) > 1 ) { // Parse and add the point specific title if it's present. $markerData['title'] = $parser->recursiveTagParse( $args[1] ); if ( count( $args ) > 2 ) { // Parse and add the point specific label if it's present. $markerData['label'] = $parser->recursiveTagParse( $args[2] ); if ( count( $args ) > 3 ) { // Add the point specific icon if it's present. $markerData['icon'] = $args[3]; } } } // If there is no point specific icon, use the general icon parameter when available. if ( ! array_key_exists( 'icon', $markerData ) && strlen( $this->icon ) > 0 ) $markerData['icon'] = $this->icon; // Get the url for the icon when there is one, else set the icon to an empty string. if ( array_key_exists( 'icon', $markerData ) ) { $icon_image_page = new ImagePage( Title::newFromText( $markerData['icon'] ) ); $markerData['icon'] = $icon_image_page->getDisplayedFile()->getURL(); } else { $markerData['icon'] = ''; } $this->markerData[] = $markerData; } }
/** * Pushes the image to the specified wiki. * * @since 0.5 * * @param Title $title * @param string $target * @param string $token */ protected function pushToTarget(Title $title, $target, $token) { global $egPushDirectFileUploads; $imagePage = new ImagePage($title); $requestData = array('action' => 'upload', 'format' => 'json', 'token' => $token, 'filename' => $title->getText(), 'ignorewarnings' => '1'); if ($egPushDirectFileUploads) { $requestData['file'] = '@' . $imagePage->getFile()->getPath(); } else { $requestData['url'] = $imagePage->getDisplayedFile()->getFullUrl(); } $reqArgs = array('method' => 'POST', 'timeout' => 'default', 'postData' => $requestData); if ($egPushDirectFileUploads) { if (!function_exists('curl_init')) { $this->dieUsage(wfMsg('push-api-err-nocurl'), 'image-push-nocurl'); } elseif (!defined('CurlHttpRequest::SUPPORTS_FILE_POSTS') || !CurlHttpRequest::SUPPORTS_FILE_POSTS) { $this->dieUsage(wfMsg('push-api-err-nofilesupport'), 'image-push-nofilesupport'); } else { $req = new CurlHttpRequest($target, $reqArgs); } } else { $req = PushFunctions::getHttpRequest($target, $reqArgs); } if (array_key_exists($target, $this->cookieJars)) { $req->setCookieJar($this->cookieJars[$target]); } $status = $req->execute(); if ($status->isOK()) { $response = $req->getContent(); $this->getResult()->addValue(null, null, FormatJson::decode($response)); wfRunHooks('PushAPIAfterImagePush', array($title, $target, $token, $response)); } else { $this->dieUsage(wfMsg('push-special-err-push-failed'), 'page-push-failed'); } }
/** * Resolves the url of images provided as wiki page; leaves others alone. * * @since 1.0 * @deprecated * * @param string $file * * @return string */ public static function getFileUrl($file) { $title = Title::makeTitle(NS_FILE, $file); if ($title !== null && $title->exists()) { $imagePage = new ImagePage($title); return $imagePage->getDisplayedFile()->getURL(); } return ''; }
static function getImageURL($image) { // stripe brackets... cant use them in the lookup $image = str_replace('[[', '', $image); $image = str_replace(']]', '', $image); // check to see if they passed in Image: or File: and add if needed if (stripos($image, 'Image:') === false && stripos($image, 'File:') === false) { $image = "File:" . $image; } $titleObj = Title::newFromText($image); if (!$titleObj) { return null; } if (!$titleObj->exists()) { return null; } $img = new ImagePage($titleObj); // we're good, return the URL return $img->getDisplayedFile()->getUrl(); }
public function setProperty($name, $value) { global $egMultiMaps_CoordinatesSeparator, $egMultiMaps_OptionsSeparator; if (strtolower($name) != 'icon') { return parent::setProperty($name, $value); } // Explode icon, it containt 'icon', 'size', 'anchor', 'shadow', 'shSize', 'shAnchor' $properties = array_map('trim', explode($egMultiMaps_CoordinatesSeparator, $value)); // Icon URL if (!empty($properties[0])) { $v = $properties[0]; if ($v[0] == '/' && $GLOBALS['egMultiMaps_IconAllowFromDirectory'] === true) { if (preg_match('#[^0-9a-zA-Zа-яА-Я/_=\\.\\+\\-]#', $v) || mb_strpos($v, '/../') !== false) { $this->errormessages[] = \wfMessage('multimaps-marker-incorrect-icon-url', $v)->escaped(); return false; } $v = $GLOBALS['wgServer'] . $GLOBALS['egMultiMaps_IconPath'] . $v; } else { $title = \Title::newFromText($v, NS_FILE); if (!is_null($title) && $title->exists()) { $imagePage = new \ImagePage($title); $v = $imagePage->getDisplayedFile()->getURL(); } else { $this->errormessages[] = \wfMessage('multimaps-marker-incorrect-icon', $v)->escaped(); return false; } } $this->properties['icon'] = htmlspecialchars($v, ENT_NOQUOTES); } // Icon size if (!empty($properties[1])) { $v = array_map('intval', explode($egMultiMaps_OptionsSeparator, $properties[1])); if (count($v) != 2) { $this->errormessages[] = \wfMessage('multimaps-marker-incorrect-icon-size', $v, $value)->escaped(); return false; } $this->properties['size'] = $v; } // Icon anchor if (!empty($properties[2])) { $v = array_map('intval', explode($egMultiMaps_OptionsSeparator, $properties[2])); if (count($v) != 2) { $this->errormessages[] = \wfMessage('multimaps-marker-incorrect-icon-anchor', $v, $value)->escaped(); return false; } $this->properties['anchor'] = $v; } // Shadow URL if (!empty($properties[3])) { $v = $properties[3]; if ($v[0] == '/' && $GLOBALS['egMultiMaps_IconAllowFromDirectory'] === true) { if (preg_match('#[^0-9a-zA-Zа-яА-Я./_=\\+\\-]#', $v) || preg_match('#/../#', $v)) { $this->errormessages[] = \wfMessage('multimaps-marker-incorrect-shadow-url', $v)->escaped(); return false; } $v = $GLOBALS['wgServer'] . $GLOBALS['egMultiMaps_IconPath'] . $v; } else { $title = \Title::newFromText($v, NS_FILE); if (!is_null($title) && $title->exists()) { $imagePage = new \ImagePage($title); $v = $imagePage->getDisplayedFile()->getURL(); } else { $this->errormessages[] = \wfMessage('multimaps-marker-incorrect-shadow-file', $v)->escaped(); return false; } } $this->properties['shadow'] = htmlspecialchars($v, ENT_NOQUOTES); } // Shadow size if (!empty($properties[4])) { $v = array_map('intval', explode($egMultiMaps_OptionsSeparator, $properties[4])); if (count($v) != 2) { $this->errormessages[] = \wfMessage('multimaps-marker-incorrect-shadow-size', $v, $value)->escaped(); return false; } $this->properties['shSize'] = $v; } // Shadow anchor if (!empty($properties[5])) { $v = array_map('intval', explode($egMultiMaps_OptionsSeparator, $properties[5])); if (count($v) != 2) { $this->errormessages[] = \wfMessage('multimaps-marker-incorrect-shadow-anchor', $v, $value)->escaped(); return false; } $this->properties['shAnchor'] = $v; } return true; }