/** * @param ResourceLoaderContext $context * @return array */ protected function getConfigSettings($context) { $hash = $context->getHash(); if (isset($this->configVars[$hash])) { return $this->configVars[$hash]; } global $wgContLang; $mainPage = Title::newMainPage(); /** * Namespace related preparation * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces. * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive. */ $namespaceIds = $wgContLang->getNamespaceIds(); $caseSensitiveNamespaces = array(); foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) { $namespaceIds[$wgContLang->lc($name)] = $index; if (!MWNamespace::isCapitalized($index)) { $caseSensitiveNamespaces[] = $index; } } $conf = $this->getConfig(); // Build list of variables $vars = array('wgLoadScript' => wfScript('load'), 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $conf->get('StylePath'), 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $conf->get('ArticlePath'), 'wgScriptPath' => $conf->get('ScriptPath'), 'wgScriptExtension' => $conf->get('ScriptExtension'), 'wgScript' => wfScript(), 'wgSearchType' => $conf->get('SearchType'), 'wgVariantArticlePath' => $conf->get('VariantArticlePath'), 'wgActionPaths' => (object) $conf->get('ActionPaths'), 'wgServer' => $conf->get('Server'), 'wgServerName' => $conf->get('ServerName'), 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgVersion' => $conf->get('Version'), 'wgEnableAPI' => $conf->get('EnableAPI'), 'wgEnableWriteAPI' => $conf->get('EnableWriteAPI'), 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgContentNamespaces' => MWNamespace::getContentNamespaces(), 'wgSiteName' => $conf->get('Sitename'), 'wgFileExtensions' => array_values(array_unique($conf->get('FileExtensions'))), 'wgDBname' => $conf->get('DBname'), 'wgFileCanRotate' => SpecialUpload::rotationEnabled(), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $conf->get('ExtensionAssetsPath'), 'wgCookiePrefix' => $conf->get('CookiePrefix'), 'wgCookieDomain' => $conf->get('CookieDomain'), 'wgCookiePath' => $conf->get('CookiePath'), 'wgCookieExpiration' => $conf->get('CookieExpiration'), 'wgResourceLoaderMaxQueryLength' => $conf->get('ResourceLoaderMaxQueryLength'), 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass(Title::legalChars()), 'wgResourceLoaderStorageVersion' => $conf->get('ResourceLoaderStorageVersion'), 'wgResourceLoaderStorageEnabled' => $conf->get('ResourceLoaderStorageEnabled')); wfRunHooks('ResourceLoaderGetConfigVars', array(&$vars)); $this->configVars[$hash] = $vars; return $this->configVars[$hash]; }
/** * Show the special page. Let the parent handle most stuff, but handle a * successful upload ourselves * * @param $params Mixed: parameter(s) passed to the page or null */ public function execute($params) { global $wgUserProfileScripts; $out = $this->getOutput(); $out->addExtensionStyle($wgUserProfileScripts . '/UserProfile.css'); parent::execute($params); if ($this->mUploadSuccessful) { // Cancel redirect $out->redirect(''); $this->showSuccess($this->mUpload->mExtension); // Run a hook on avatar change wfRunHooks('NewAvatarUploaded', array($this->getUser())); } }
/** * Show the special page. Let the parent handle most stuff, but handle a * successful upload ourselves * * @param $params Mixed: parameter(s) passed to the page or null */ public function execute($params) { global $wgRequest, $wgOut, $wgUser, $wgUserProfileScripts; $wgOut->addExtensionStyle($wgUserProfileScripts . '/UserProfile.css'); parent::execute($params); if ($this->mUploadSuccessful) { // Cancel redirect $wgOut->redirect(''); $this->showSuccess($this->mUpload->mExtension); //this runs hook on avatar change wfRunHooks('NewAvatarUploaded', array($wgUser)); //end of hook } }
/** * Show the special page. Let the parent handle most stuff, but handle a * successful upload ourselves * * @param $params Mixed: parameter(s) passed to the page or null */ public function execute($params) { $out = $this->getOutput(); // Add CSS $out->addModuleStyles('ext.socialprofile.userprofile.css'); // Let the parent class do most of the heavy lifting. parent::execute($params); if ($this->mUploadSuccessful) { // Cancel redirect $out->redirect(''); $this->showSuccess($this->mUpload->mExtension); // Run a hook on avatar change wfRunHooks('NewAvatarUploaded', array($this->getUser())); } }
private function executeImage() { if (empty($this->mParams['tempName'])) { $this->dieUsageMsg('The tempName parameter must be set'); } $tempFile = new FakeLocalFile(Title::newFromText($this->mParams['tempName'], 6), RepoGroup::singleton()->getLocalRepo()); $duplicate = $this->getFileDuplicate($tempFile->getLocalRefPath()); if ($duplicate) { return array('title' => $duplicate->getTitle()->getText()); } else { $title = $this->getUniqueTitle(wfStripIllegalFilenameChars($this->mParams['title'])); if (isset($this->mParams['license'])) { $pageText = SpecialUpload::getInitialPageText('', $this->mParams['license']); } $file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo()); $file->upload($tempFile->getPath(), '', $pageText ? $pageText : ''); return array('title' => $file->getTitle()->getText()); } }
public function execute($par) { global $wgOut; $cacheManager = new \PageAttachment\Cache\CacheManager(); $pageFactory = new \PageAttachment\Session\PageFactory($cacheManager); $security = new \PageAttachment\Security\SecurityManager(); $session = new \PageAttachment\Session\Session($security, $pageFactory); $attachToPage = $session->getAttachToPage(); if (isset($attachToPage) && $attachToPage->getId() > 0) { $abort = false; if ($security->isDownloadRequestValid()) { // Subsequest Passes - Upload File parent::execute($par); } else { // First Pass - Display Form $protectedPage = $attachToPage->isProtected(); if ($security->isAttachmentAddUpdateRequireLogin($protectedPage) && !$security->isLoggedIn()) { $session->setStatusMessage('YouMustBeLoggedInToAddUpdateAttachments'); $abort = true; } elseif (!$security->isRequestValidationTokenValid()) { $session->setStatusMessage('UnableToAuthenticateYourRequest'); $abort = true; } if ($abort == true) { $title = \Title::newFromText($attachToPage->getPageTitle()); $wgOut->redirect($title->getFullURL()); } else { $security->setDownloadRequestValid(true); $session->setUploadAndAttachFileInitiated(true); parent::execute($par); } } } else { $session->setStatusMessage('UnableToDetermineAttachToPage'); $title = \Title::newFromText(\wfMsgForContent('mainpage')); $wgOut->redirect($title->getFullURL()); } }
/** * Get result information for an image revision * * @param File $file * @param array $prop Array of properties to get (in the keys) * @param ApiResult $result * @param array $thumbParams Containing 'width' and 'height' items, or null * @param array|bool|string $opts Options for data fetching. * This is an array consisting of the keys: * 'version': The metadata version for the metadata option * 'language': The language for extmetadata property * 'multilang': Return all translations in extmetadata property * 'revdelUser': User to use when checking whether to show revision-deleted fields. * @return array Result array */ static function getInfo($file, $prop, $result, $thumbParams = null, $opts = false) { global $wgContLang; $anyHidden = false; if (!$opts || is_string($opts)) { $opts = array('version' => $opts ?: 'latest', 'language' => $wgContLang, 'multilang' => false, 'extmetadatafilter' => array(), 'revdelUser' => null); } $version = $opts['version']; $vals = array(ApiResult::META_TYPE => 'assoc'); // Timestamp is shown even if the file is revdelete'd in interface // so do same here. if (isset($prop['timestamp'])) { $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $file->getTimestamp()); } // Handle external callers who don't pass revdelUser if (isset($opts['revdelUser']) && $opts['revdelUser']) { $revdelUser = $opts['revdelUser']; $canShowField = function ($field) use($file, $revdelUser) { return $file->userCan($field, $revdelUser); }; } else { $canShowField = function ($field) use($file) { return !$file->isDeleted($field); }; } $user = isset($prop['user']); $userid = isset($prop['userid']); if ($user || $userid) { if ($file->isDeleted(File::DELETED_USER)) { $vals['userhidden'] = true; $anyHidden = true; } if ($canShowField(File::DELETED_USER)) { if ($user) { $vals['user'] = $file->getUser(); } if ($userid) { $vals['userid'] = $file->getUser('id'); } if (!$file->getUser('id')) { $vals['anon'] = true; } } } // This is shown even if the file is revdelete'd in interface // so do same here. if (isset($prop['size']) || isset($prop['dimensions'])) { $vals['size'] = intval($file->getSize()); $vals['width'] = intval($file->getWidth()); $vals['height'] = intval($file->getHeight()); $pageCount = $file->pageCount(); if ($pageCount !== false) { $vals['pagecount'] = $pageCount; } // length as in how many seconds long a video is. $length = $file->getLength(); if ($length) { // Call it duration, because "length" can be ambiguous. $vals['duration'] = (double) $length; } } $pcomment = isset($prop['parsedcomment']); $comment = isset($prop['comment']); if ($pcomment || $comment) { if ($file->isDeleted(File::DELETED_COMMENT)) { $vals['commenthidden'] = true; $anyHidden = true; } if ($canShowField(File::DELETED_COMMENT)) { if ($pcomment) { $vals['parsedcomment'] = Linker::formatComment($file->getDescription(File::RAW), $file->getTitle()); } if ($comment) { $vals['comment'] = $file->getDescription(File::RAW); } } } $canonicaltitle = isset($prop['canonicaltitle']); $url = isset($prop['url']); $sha1 = isset($prop['sha1']); $meta = isset($prop['metadata']); $extmetadata = isset($prop['extmetadata']); $commonmeta = isset($prop['commonmetadata']); $mime = isset($prop['mime']); $mediatype = isset($prop['mediatype']); $archive = isset($prop['archivename']); $bitdepth = isset($prop['bitdepth']); $uploadwarning = isset($prop['uploadwarning']); if ($uploadwarning) { $vals['html'] = SpecialUpload::getExistsWarning(UploadBase::getExistsWarning($file)); } if ($file->isDeleted(File::DELETED_FILE)) { $vals['filehidden'] = true; $anyHidden = true; } if ($anyHidden && $file->isDeleted(File::DELETED_RESTRICTED)) { $vals['suppressed'] = true; } if (!$canShowField(File::DELETED_FILE)) { //Early return, tidier than indenting all following things one level return $vals; } if ($canonicaltitle) { $vals['canonicaltitle'] = $file->getTitle()->getPrefixedText(); } if ($url) { if (!is_null($thumbParams)) { $mto = $file->transform($thumbParams); self::$transformCount++; if ($mto && !$mto->isError()) { $vals['thumburl'] = wfExpandUrl($mto->getUrl(), PROTO_CURRENT); // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted // thumbnail sizes for the thumbnail actual size if ($mto->getUrl() !== $file->getUrl()) { $vals['thumbwidth'] = intval($mto->getWidth()); $vals['thumbheight'] = intval($mto->getHeight()); } else { $vals['thumbwidth'] = intval($file->getWidth()); $vals['thumbheight'] = intval($file->getHeight()); } if (isset($prop['thumbmime']) && $file->getHandler()) { list(, $mime) = $file->getHandler()->getThumbType($mto->getExtension(), $file->getMimeType(), $thumbParams); $vals['thumbmime'] = $mime; } } elseif ($mto && $mto->isError()) { $vals['thumberror'] = $mto->toText(); } } $vals['url'] = wfExpandUrl($file->getFullURL(), PROTO_CURRENT); $vals['descriptionurl'] = wfExpandUrl($file->getDescriptionUrl(), PROTO_CURRENT); } if ($sha1) { $vals['sha1'] = wfBaseConvert($file->getSha1(), 36, 16, 40); } if ($meta) { wfSuppressWarnings(); $metadata = unserialize($file->getMetadata()); wfRestoreWarnings(); if ($metadata && $version !== 'latest') { $metadata = $file->convertMetadataVersion($metadata, $version); } $vals['metadata'] = $metadata ? self::processMetaData($metadata, $result) : null; } if ($commonmeta) { $metaArray = $file->getCommonMetaArray(); $vals['commonmetadata'] = $metaArray ? self::processMetaData($metaArray, $result) : array(); } if ($extmetadata) { // Note, this should return an array where all the keys // start with a letter, and all the values are strings. // Thus there should be no issue with format=xml. $format = new FormatMetadata(); $format->setSingleLanguage(!$opts['multilang']); $format->getContext()->setLanguage($opts['language']); $extmetaArray = $format->fetchExtendedMetadata($file); if ($opts['extmetadatafilter']) { $extmetaArray = array_intersect_key($extmetaArray, array_flip($opts['extmetadatafilter'])); } $vals['extmetadata'] = $extmetaArray; } if ($mime) { $vals['mime'] = $file->getMimeType(); } if ($mediatype) { $vals['mediatype'] = $file->getMediaType(); } if ($archive && $file->isOld()) { $vals['archivename'] = $file->getArchiveName(); } if ($bitdepth) { $vals['bitdepth'] = $file->getBitDepth(); } return $vals; }
/** * Add upload JS to the OutputPage */ protected function addUploadJS() { $config = $this->getConfig(); $useAjaxDestCheck = $config->get('UseAjax') && $config->get('AjaxUploadDestCheck'); $useAjaxLicensePreview = $config->get('UseAjax') && $config->get('AjaxLicensePreview') && $config->get('EnableAPI'); $this->mMaxUploadSize['*'] = UploadBase::getMaxUploadSize(); $scriptVars = array('wgAjaxUploadDestCheck' => $useAjaxDestCheck, 'wgAjaxLicensePreview' => $useAjaxLicensePreview, 'wgUploadAutoFill' => !$this->mForReUpload && $this->mDestFile === '', 'wgUploadSourceIds' => $this->mSourceIds, 'wgCheckFileExtensions' => $config->get('CheckFileExtensions'), 'wgStrictFileExtensions' => $config->get('StrictFileExtensions'), 'wgFileExtensions' => array_values(array_unique($config->get('FileExtensions'))), 'wgCapitalizeUploads' => MWNamespace::isCapitalized(NS_FILE), 'wgMaxUploadSize' => $this->mMaxUploadSize, 'wgFileCanRotate' => SpecialUpload::rotationEnabled()); $out = $this->getOutput(); $out->addJsConfigVars($scriptVars); $out->addModules(array('mediawiki.action.edit', 'mediawiki.special.upload')); }
/** * Record a file upload in the upload log and the image table * @param string $oldver * @param string $desc * @param string $license * @param string $copyStatus * @param string $source * @param bool $watch * @param string|bool $timestamp * @param User|null $user User object or null to use $wgUser * @return bool */ function recordUpload($oldver, $desc, $license = '', $copyStatus = '', $source = '', $watch = false, $timestamp = false, User $user = null) { if (!$user) { global $wgUser; $user = $wgUser; } $pageText = SpecialUpload::getInitialPageText($desc, $license, $copyStatus, $source); if (!$this->recordUpload2($oldver, $desc, $pageText, false, $timestamp, $user)) { return false; } if ($watch) { $user->addWatch($this->getTitle()); } return true; }
$flags = 0; $publishOptions = array(); $handler = MediaHandler::getHandler($props['mime']); if ($handler) { $publishOptions['headers'] = $handler->getStreamHeaders($props['metadata']); } else { $publishOptions['headers'] = array(); } $archive = $image->publish($file, $flags, $publishOptions); if (!$archive->isGood()) { echo "failed. (" . $archive->getWikiText() . ")\n"; $failed++; continue; } } $commentText = SpecialUpload::getInitialPageText($commentText, $license); if (!isset($options['summary'])) { $summary = $commentText; } if (isset($options['dry'])) { echo "done.\n"; } elseif ($image->recordUpload2($archive->value, $summary, $commentText, $props, $timestamp)) { # We're done! echo "done.\n"; $doProtect = false; global $wgRestrictionLevels; $protectLevel = isset($options['protect']) ? $options['protect'] : null; if ($protectLevel && in_array($protectLevel, $wgRestrictionLevels)) { $doProtect = true; } if (isset($options['unprotect'])) {
/** * Get result information for an image revision * * @param $file File object * @param array $prop of properties to get (in the keys) * @param $result ApiResult object * @param array $thumbParams containing 'width' and 'height' items, or null * @param string $version Version of image metadata (for things like jpeg which have different versions). * @return Array: result array */ static function getInfo( $file, $prop, $result, $thumbParams = null, $version = 'latest' ) { $vals = array(); // Timestamp is shown even if the file is revdelete'd in interface // so do same here. if ( isset( $prop['timestamp'] ) ) { $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() ); } $user = isset( $prop['user'] ); $userid = isset( $prop['userid'] ); if ( $user || $userid ) { if ( $file->isDeleted( File::DELETED_USER ) ) { $vals['userhidden'] = ''; } else { if ( $user ) { $vals['user'] = $file->getUser(); } if ( $userid ) { $vals['userid'] = $file->getUser( 'id' ); } if ( !$file->getUser( 'id' ) ) { $vals['anon'] = ''; } } } // This is shown even if the file is revdelete'd in interface // so do same here. if ( isset( $prop['size'] ) || isset( $prop['dimensions'] ) ) { $vals['size'] = intval( $file->getSize() ); $vals['width'] = intval( $file->getWidth() ); $vals['height'] = intval( $file->getHeight() ); $pageCount = $file->pageCount(); if ( $pageCount !== false ) { $vals['pagecount'] = $pageCount; } } $pcomment = isset( $prop['parsedcomment'] ); $comment = isset( $prop['comment'] ); if ( $pcomment || $comment ) { if ( $file->isDeleted( File::DELETED_COMMENT ) ) { $vals['commenthidden'] = ''; } else { if ( $pcomment ) { $vals['parsedcomment'] = Linker::formatComment( $file->getDescription(), $file->getTitle() ); } if ( $comment ) { $vals['comment'] = $file->getDescription(); } } } $url = isset( $prop['url'] ); $sha1 = isset( $prop['sha1'] ); $meta = isset( $prop['metadata'] ); $mime = isset( $prop['mime'] ); $mediatype = isset( $prop['mediatype'] ); $archive = isset( $prop['archivename'] ); $bitdepth = isset( $prop['bitdepth'] ); $uploadwarning = isset( $prop['uploadwarning'] ); if ( ( $url || $sha1 || $meta || $mime || $mediatype || $archive || $bitdepth ) && $file->isDeleted( File::DELETED_FILE ) ) { $vals['filehidden'] = ''; //Early return, tidier than indenting all following things one level return $vals; } if ( $url ) { if ( !is_null( $thumbParams ) ) { $mto = $file->transform( $thumbParams ); self::$transformCount++; if ( $mto && !$mto->isError() ) { $vals['thumburl'] = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT ); // bug 23834 - If the URL's are the same, we haven't resized it, so shouldn't give the wanted // thumbnail sizes for the thumbnail actual size if ( $mto->getUrl() !== $file->getUrl() ) { $vals['thumbwidth'] = intval( $mto->getWidth() ); $vals['thumbheight'] = intval( $mto->getHeight() ); } else { $vals['thumbwidth'] = intval( $file->getWidth() ); $vals['thumbheight'] = intval( $file->getHeight() ); } if ( isset( $prop['thumbmime'] ) && $file->getHandler() ) { list( , $mime ) = $file->getHandler()->getThumbType( $mto->getExtension(), $file->getMimeType(), $thumbParams ); $vals['thumbmime'] = $mime; } } elseif ( $mto && $mto->isError() ) { $vals['thumberror'] = $mto->toText(); } } $vals['url'] = wfExpandUrl( $file->getFullURL(), PROTO_CURRENT ); $vals['descriptionurl'] = wfExpandUrl( $file->getDescriptionUrl(), PROTO_CURRENT ); } if ( $sha1 ) { $vals['sha1'] = wfBaseConvert( $file->getSha1(), 36, 16, 40 ); } if ( $meta ) { wfSuppressWarnings(); $metadata = unserialize( $file->getMetadata() ); wfRestoreWarnings(); if ( $metadata && $version !== 'latest' ) { $metadata = $file->convertMetadataVersion( $metadata, $version ); } $vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null; } if ( $mime ) { $vals['mime'] = $file->getMimeType(); } if ( $mediatype ) { $vals['mediatype'] = $file->getMediaType(); } if ( $archive && $file->isOld() ) { $vals['archivename'] = $file->getArchiveName(); } if ( $bitdepth ) { $vals['bitdepth'] = $file->getBitDepth(); } if ( $uploadwarning ) { $vals['html'] = SpecialUpload::getExistsWarning( UploadBase::getExistsWarning( $file ) ); } return $vals; }
/** * Construct a warning and a gallery from an array of duplicate files. * Override because the original doesn't say which file is a dupe */ public static function getDupeWarning($dupes, $dupeTitle = null) { $result = parent::getDupeWarning($dupes); return preg_replace('@<li>@', "<li>{$dupeTitle->getText()}", $result); }
private function uploadWarning($warnings) { $msg = '<h2>' . wfMsgHtml('uploadwarning') . '</h2><ul class="warning">'; foreach ($warnings as $warning => $args) { if ($warning == 'exists') { $msg .= "\t<li>" . SpecialUpload::getExistsWarning($args) . "</li>\n"; } elseif ($warning == 'duplicate') { $msg .= SpecialUpload::getDupeWarning($args); } elseif ($warning == 'duplicate-archive') { $msg .= "\t<li>" . wfMsgExt('file-deleted-duplicate', 'parseinline', array(Title::makeTitle(NS_FILE, $args)->getPrefixedText())) . "</li>\n"; } else { if ($args === true) { $args = array(); } elseif (!is_array($args)) { $args = array($args); } $msg .= "\t<li>" . wfMsgExt($warning, 'parseinline', $args) . "</li>\n"; } } $msg .= '</ul>'; return $msg; }
public function __construct($request = null) { parent::__construct($request); }