function isUploadEnabled()
 {
     if (\UploadBase::isEnabled() == true) {
         return true;
     } else {
         return false;
     }
 }
 private function execute3rdPartyVideo($url)
 {
     if (empty(F::app()->wg->allowNonPremiumVideos)) {
         $this->dieUsage('Only premium videos are allowed', 'onlyallowpremium');
     }
     if (!preg_match('/^https?:\\/\\//', $url)) {
         $url = 'http://' . $url;
     }
     try {
         $apiwrapper = ApiWrapperFactory::getInstance()->getApiWrapper($url);
     } catch (Exception $e) {
         $this->dieUsage('There was an issue with ApiWrapper', 'apiwrapper-error');
     }
     if (empty($apiwrapper)) {
         $this->dieUsageMsg('The supplied video does not exist');
     }
     $duplicate = $this->getVideoDuplicate($apiwrapper->getProvider(), $apiwrapper->getVideoId());
     $result = array('provider' => $apiwrapper->getProvider(), 'videoId' => $apiwrapper->getVideoId());
     if ($duplicate) {
         $result['title'] = $duplicate->getTitle()->getText();
         $result['url'] = $duplicate->getUrl();
     } else {
         // Check whether upload is enabled
         if (!UploadBase::isEnabled()) {
             $this->dieUsageMsg('uploaddisabled');
         }
         F::app()->wg->DisableProxy = true;
         $this->mUpload = new UploadFromUrl();
         $this->mUpload->initializeFromRequest(new FauxRequest(array('wpUpload' => 1, 'wpSourceType' => 'web', 'wpUploadFileURL' => $apiwrapper->getThumbnailUrl()), true));
         $this->mUpload->fetchFile();
         $this->checkPermissions();
         $this->verifyUpload();
         $tempFile = $this->createTempFile($this->mUpload->getTempPath());
         $result['title'] = $apiwrapper->getTitle();
         $result['tempUrl'] = $tempFile->getUrl();
         $result['tempName'] = $tempFile->getName();
     }
     return $result;
 }
	public function execute() {
		global $wgUser;

		// Check whether upload is enabled
		if ( !UploadBase::isEnabled() ) {
			$this->dieUsageMsg( array( 'uploaddisabled' ) );
		}

		$this->mParams = $this->extractRequestParams();

		$this->validateParams( $this->mParams );

		$request = $this->getMain()->getRequest();
		$this->mUpload = new ResumableUploadHandler;

		$status = $this->mUpload->initialize(
			$request->getVal( 'done', null ),
			$request->getVal( 'offset', null ),
			$request->getVal( 'filename', null ),
			$request->getVal( 'chunksession', null ),
			$request->getFileTempName( 'chunk' ),
			$request->getFileSize( 'chunk' ),
			$request->getSessionData( UploadBase::getSessionKeyname() )
		);

		if ( $status !== true ) {
			$this->dieUsage(  $status, 'chunk-init-error' );
		}

		$ret = $this->performUpload( );

		if(is_array($ret)) {
			foreach($ret as $key => $val) {
				$this->getResult()->addValue(null, $key, $val);
			}
		} else {
			$this->dieUsage($ret, 'error');
		}
	}
Beispiel #4
0
 function topLinks()
 {
     global $wgOut, $wgUser;
     $sep = " |\n";
     $s = $this->mainPageLink() . $sep . $this->specialLink('Recentchanges');
     if ($wgOut->isArticle()) {
         $s .= $sep . '<strong>' . $this->editThisPage() . '</strong>' . $sep . $this->historyLink();
     }
     /* show links to different language variants */
     $s .= $this->variantLinks();
     $s .= $this->extensionTabLinks();
     if ($wgUser->isAnon()) {
         $s .= $sep . $this->specialLink('Userlogin');
     } else {
         /* show user page and user talk links */
         $s .= $sep . $this->link($wgUser->getUserPage(), wfMsgHtml('mypage'));
         $s .= $sep . $this->link($wgUser->getTalkPage(), wfMsgHtml('mytalk'));
         if ($wgUser->getNewtalk()) {
             $s .= ' *';
         }
         /* show watchlist link */
         $s .= $sep . $this->specialLink('Watchlist');
         /* show my contributions link */
         $s .= $sep . $this->link(SpecialPage::getSafeTitleFor('Contributions', $wgUser->getName()), wfMsgHtml('mycontris'));
         /* show my preferences link */
         $s .= $sep . $this->specialLink('Preferences');
         /* show upload file link */
         if (UploadBase::isEnabled() && UploadBase::isAllowed($wgUser) === true) {
             $s .= $sep . $this->getUploadLink();
         }
         /* show log out link */
         $s .= $sep . $this->specialLink('Userlogout');
     }
     $s .= $sep . $this->specialPagesList();
     return $s;
 }
 /**
  * Checks if the upload from URL feature is enabled
  * @return bool
  */
 public static function isEnabled()
 {
     global $wgAllowCopyUploads;
     return $wgAllowCopyUploads && parent::isEnabled();
 }
 public function execute()
 {
     // Check whether upload is enabled
     if (!UploadBase::isEnabled()) {
         $this->dieUsageMsg('uploaddisabled');
     }
     $user = $this->getUser();
     // Parameter handling
     $this->mParams = $this->extractRequestParams();
     $request = $this->getMain()->getRequest();
     // Add the uploaded file to the params array
     $this->mParams['file'] = $request->getFileName('file');
     $this->mParams['chunk'] = $request->getFileName('chunk');
     // Copy the session key to the file key, for backward compatibility.
     if (!$this->mParams['filekey'] && $this->mParams['sessionkey']) {
         $this->mParams['filekey'] = $this->mParams['sessionkey'];
     }
     // Select an upload module
     if (!$this->selectUploadModule()) {
         // This is not a true upload, but a status request or similar
         return;
     }
     if (!isset($this->mUpload)) {
         $this->dieUsage('No upload module set', 'nomodule');
     }
     // First check permission to upload
     $this->checkPermissions($user);
     // Fetch the file
     $status = $this->mUpload->fetchFile();
     if (!$status->isGood()) {
         $errors = $status->getErrorsArray();
         $error = array_shift($errors[0]);
         $this->dieUsage('Error fetching file from remote source', $error, 0, $errors[0]);
     }
     // Check if the uploaded file is sane
     if ($this->mParams['chunk']) {
         $maxSize = $this->mUpload->getMaxUploadSize();
         if ($this->mParams['filesize'] > $maxSize) {
             $this->dieUsage('The file you submitted was too large', 'file-too-large');
         }
     } else {
         $this->verifyUpload();
     }
     // Check if the user has the rights to modify or overwrite the requested title
     // (This check is irrelevant if stashing is already requested, since the errors
     //  can always be fixed by changing the title)
     if (!$this->mParams['stash']) {
         $permErrors = $this->mUpload->verifyTitlePermissions($user);
         if ($permErrors !== true) {
             $this->dieRecoverableError($permErrors[0], 'filename');
         }
     }
     // Get the result based on the current upload context:
     $result = $this->getContextResult();
     if ($result['result'] === 'Success') {
         $result['imageinfo'] = $this->mUpload->getImageInfo($this->getResult());
     }
     $this->getResult()->addValue(null, $this->getModuleName(), $result);
     // Cleanup any temporary mess
     $this->mUpload->cleanupTempFile();
 }
 public function execute()
 {
     global $wgUser;
     // Check whether upload is enabled
     if (!UploadBase::isEnabled()) {
         $this->dieUsageMsg('uploaddisabled');
     }
     // Parameter handling
     $this->mParams = $this->extractRequestParams();
     $request = $this->getMain()->getRequest();
     // Add the uploaded file to the params array
     $this->mParams['file'] = $request->getFileName('file');
     // Copy the session key to the file key, for backward compatibility.
     if (!$this->mParams['filekey'] && $this->mParams['sessionkey']) {
         $this->mParams['filekey'] = $this->mParams['sessionkey'];
     }
     // Select an upload module
     if (!$this->selectUploadModule()) {
         // This is not a true upload, but a status request or similar
         return;
     }
     if (!isset($this->mUpload)) {
         $this->dieUsage('No upload module set', 'nomodule');
     }
     // First check permission to upload
     $this->checkPermissions($wgUser);
     // Fetch the file
     $status = $this->mUpload->fetchFile();
     if (!$status->isGood()) {
         $errors = $status->getErrorsArray();
         $error = array_shift($errors[0]);
         $this->dieUsage('Error fetching file from remote source', $error, 0, $errors[0]);
     }
     // Check if the uploaded file is sane
     $this->verifyUpload();
     // Check if the user has the rights to modify or overwrite the requested title
     // (This check is irrelevant if stashing is already requested, since the errors
     //  can always be fixed by changing the title)
     if (!$this->mParams['stash']) {
         $permErrors = $this->mUpload->verifyTitlePermissions($wgUser);
         if ($permErrors !== true) {
             $this->dieRecoverableError($permErrors[0], 'filename');
         }
     }
     // Prepare the API result
     $result = array();
     $warnings = $this->getApiWarnings();
     if ($warnings) {
         $result['result'] = 'Warning';
         $result['warnings'] = $warnings;
         // in case the warnings can be fixed with some further user action, let's stash this upload
         // and return a key they can use to restart it
         try {
             $result['filekey'] = $this->performStash();
             $result['sessionkey'] = $result['filekey'];
             // backwards compatibility
         } catch (MWException $e) {
             $result['warnings']['stashfailed'] = $e->getMessage();
         }
     } elseif ($this->mParams['stash']) {
         // Some uploads can request they be stashed, so as not to publish them immediately.
         // In this case, a failure to stash ought to be fatal
         try {
             $result['result'] = 'Success';
             $result['filekey'] = $this->performStash();
             $result['sessionkey'] = $result['filekey'];
             // backwards compatibility
         } catch (MWException $e) {
             $this->dieUsage($e->getMessage(), 'stashfailed');
         }
     } else {
         // This is the most common case -- a normal upload with no warnings
         // $result will be formatted properly for the API already, with a status
         $result = $this->performUpload();
     }
     if ($result['result'] === 'Success') {
         $result['imageinfo'] = $this->mUpload->getImageInfo($this->getResult());
     }
     $this->getResult()->addValue(null, $this->getModuleName(), $result);
     // Cleanup any temporary mess
     $this->mUpload->cleanupTempFile();
 }
Beispiel #8
0
 /**
  * Compute the sidebar
  * @access private
  *
  * @return string
  */
 function quickBar()
 {
     $s = "\n<div id='quickbar'>";
     $sep = '<br />';
     $s .= $this->menuHead('qbfind');
     $s .= $this->searchForm();
     $s .= $this->menuHead('qbbrowse');
     # Use the first heading from the Monobook sidebar as the "browse" section
     $bar = $this->getSkin()->buildSidebar();
     unset($bar['SEARCH']);
     unset($bar['LANGUAGES']);
     unset($bar['TOOLBOX']);
     $barnumber = 1;
     foreach ($bar as $heading => $browseLinks) {
         if ($barnumber > 1) {
             $headingMsg = wfMessage($heading);
             if ($headingMsg->exists()) {
                 $h = $headingMsg->text();
             } else {
                 $h = $heading;
             }
             $s .= "\n<h6>" . htmlspecialchars($h) . "</h6>";
         }
         if (is_array($browseLinks)) {
             foreach ($browseLinks as $link) {
                 if ($link['text'] != '-') {
                     $s .= "<a href=\"{$link['href']}\">" . htmlspecialchars($link['text']) . '</a>' . $sep;
                 }
             }
         }
         $barnumber++;
     }
     $user = $this->getSkin()->getUser();
     if ($this->data['isarticle']) {
         $s .= $this->menuHead('qbedit');
         $s .= '<strong>' . $this->editThisPage() . '</strong>';
         $s .= $sep . Linker::linkKnown(Title::newFromText(wfMsgForContent('edithelppage')), wfMsg('edithelp'));
         if ($this->data['loggedin']) {
             $s .= $sep . $this->moveThisPage();
         }
         if ($user->isAllowed('delete')) {
             $dtp = $this->deleteThisPage();
             if ($dtp != '') {
                 $s .= $sep . $dtp;
             }
         }
         if ($user->isAllowed('protect')) {
             $ptp = $this->protectThisPage();
             if ($ptp != '') {
                 $s .= $sep . $ptp;
             }
         }
         $s .= $sep;
         $s .= $this->menuHead('qbpageoptions');
         $s .= $this->talkLink() . $sep . $this->commentLink() . $sep . $this->printableLink();
         if ($this->data['loggedin']) {
             $s .= $sep . $this->watchThisPage();
         }
         $s .= $sep;
         $s .= $this->menuHead('qbpageinfo') . $this->historyLink() . $sep . $this->whatLinksHere() . $sep . $this->watchPageLinksLink();
         $title = $this->getSkin()->getTitle();
         $tns = $title->getNamespace();
         if ($tns == NS_USER || $tns == NS_USER_TALK) {
             $id = User::idFromName($title->getText());
             if ($id != 0) {
                 $s .= $sep . $this->userContribsLink();
                 if ($this->getSkin()->showEmailUser($id)) {
                     $s .= $sep . $this->emailUserLink();
                 }
             }
         }
         $s .= $sep;
     }
     $s .= $this->menuHead('qbmyoptions');
     if ($this->data['loggedin']) {
         $tl = Linker::link($user->getTalkPage(), wfMsg('mytalk'), array(), array(), array('known', 'noclasses'));
         if ($user->getNewtalk()) {
             $tl .= ' *';
         }
         $s .= Linker::link($user->getUserPage(), wfMsg('mypage'), array(), array(), array('known', 'noclasses')) . $sep . $tl . $sep . Linker::specialLink('Watchlist') . $sep . Linker::link(SpecialPage::getSafeTitleFor('Contributions', $user->getName()), wfMsg('mycontris'), array(), array(), array('known', 'noclasses')) . $sep . Linker::specialLink('Preferences') . $sep . Linker::specialLink('Userlogout');
     } else {
         $s .= Linker::specialLink('Userlogin');
     }
     $s .= $this->menuHead('qbspecialpages') . Linker::specialLink('Newpages') . $sep . Linker::specialLink('Listfiles') . $sep . Linker::specialLink('Statistics');
     if (UploadBase::isEnabled() && UploadBase::isAllowed($user) === true) {
         $s .= $sep . $this->getUploadLink();
     }
     global $wgSiteSupportPage;
     if ($wgSiteSupportPage) {
         $s .= $sep . '<a href="' . htmlspecialchars($wgSiteSupportPage) . '" class="internal">' . wfMsg('sitesupport') . '</a>';
     }
     $s .= $sep . Linker::link(SpecialPage::getTitleFor('Specialpages'), wfMsg('moredotdotdot'), array(), array(), array('known', 'noclasses'));
     $s .= $sep . "\n</div>\n";
     return $s;
 }
Beispiel #9
0
 public function execute()
 {
     global $wgUser, $wgAllowCopyUploads;
     // Check whether upload is enabled
     if (!UploadBase::isEnabled()) {
         $this->dieUsageMsg(array('uploaddisabled'));
     }
     $this->mParams = $this->extractRequestParams();
     $request = $this->getMain()->getRequest();
     // Add the uploaded file to the params array
     $this->mParams['file'] = $request->getFileName('file');
     // One and only one of the following parameters is needed
     $this->requireOnlyOneParameter($this->mParams, 'sessionkey', 'file', 'url');
     if ($this->mParams['sessionkey']) {
         /**
          * Upload stashed in a previous request
          */
         // Check the session key
         if (!isset($_SESSION['wsUploadData'][$this->mParams['sessionkey']])) {
             $this->dieUsageMsg(array('invalid-session-key'));
         }
         $this->mUpload = new UploadFromStash();
         $this->mUpload->initialize($this->mParams['filename'], $this->mParams['sessionkey'], $_SESSION['wsUploadData'][$this->mParams['sessionkey']]);
     } elseif (isset($this->mParams['filename'])) {
         /**
          * Upload from url, etc
          * Parameter filename is required
          */
         if (isset($this->mParams['file'])) {
             $this->mUpload = new UploadFromFile();
             $this->mUpload->initialize($this->mParams['filename'], $request->getFileTempName('file'), $request->getFileSize('file'));
         } elseif (isset($this->mParams['url'])) {
             // make sure upload by url is enabled:
             if (!$wgAllowCopyUploads) {
                 $this->dieUsageMsg(array('uploaddisabled'));
             }
             // make sure the current user can upload
             if (!$wgUser->isAllowed('upload_by_url')) {
                 $this->dieUsageMsg(array('badaccess-groups'));
             }
             $this->mUpload = new UploadFromUrl();
             $this->mUpload->initialize($this->mParams['filename'], $this->mParams['url']);
             $status = $this->mUpload->fetchFile();
             if (!$status->isOK()) {
                 $this->dieUsage($status->getWikiText(), 'fetchfileerror');
             }
         }
     } else {
         $this->dieUsageMsg(array('missingparam', 'filename'));
     }
     if (!isset($this->mUpload)) {
         $this->dieUsage('No upload module set', 'nomodule');
     }
     // Check whether the user has the appropriate permissions to upload anyway
     $permission = $this->mUpload->isAllowed($wgUser);
     if ($permission !== true) {
         if (!$wgUser->isLoggedIn()) {
             $this->dieUsageMsg(array('mustbeloggedin', 'upload'));
         } else {
             $this->dieUsageMsg(array('badaccess-groups'));
         }
     }
     // Perform the upload
     $result = $this->performUpload();
     // Cleanup any temporary mess
     $this->mUpload->cleanupTempFile();
     $this->getResult()->addValue(null, $this->getModuleName(), $result);
 }
Beispiel #10
0
 /**
  * @return string
  */
 function topLinks()
 {
     $sep = " |\n";
     $s = $this->getSkin()->mainPageLink() . $sep . Linker::specialLink('Recentchanges');
     if ($this->data['isarticle']) {
         $s .= $sep . '<strong>' . $this->editThisPage() . '</strong>' . $sep . $this->talkLink() . $sep . $this->historyLink();
     }
     /* show links to different language variants */
     $s .= $this->variantLinks();
     $s .= $this->extensionTabLinks();
     if (!$this->data['loggedin']) {
         $s .= $sep . Linker::specialLink('Userlogin');
     } else {
         /* show user page and user talk links */
         $user = $this->getSkin()->getUser();
         $s .= $sep . Linker::link($user->getUserPage(), wfMessage('mypage')->escaped());
         $s .= $sep . Linker::link($user->getTalkPage(), wfMessage('mytalk')->escaped());
         if ($user->getNewtalk()) {
             $s .= ' *';
         }
         /* show watchlist link */
         $s .= $sep . Linker::specialLink('Watchlist');
         /* show my contributions link */
         $s .= $sep . Linker::link(SpecialPage::getSafeTitleFor('Contributions', $this->data['username']), wfMessage('mycontris')->escaped());
         /* show my preferences link */
         $s .= $sep . Linker::specialLink('Preferences');
         /* show upload file link */
         if (UploadBase::isEnabled() && UploadBase::isAllowed($user) === true) {
             $s .= $sep . $this->getUploadLink();
         }
         /* show log out link */
         $s .= $sep . Linker::specialLink('Userlogout');
     }
     $s .= $sep . $this->specialPagesList();
     return $s;
 }
 /**
  * Check if anyone can upload (or if other sitewide config prevents this)
  * Side effect: will print error page to wgOut if cannot upload.
  * @return boolean -- true if can upload
  */
 private function isUploadAllowed()
 {
     global $wgEnableAPI;
     // Check uploading enabled
     if (!UploadBase::isEnabled()) {
         $this->getOutput()->showErrorPage('uploaddisabled', 'uploaddisabledtext');
         return false;
     }
     // XXX does wgEnableAPI affect all uploads too?
     // Check whether we actually want to allow changing stuff
     if (wfReadOnly()) {
         $this->getOutput()->readOnlyPage();
         return false;
     }
     // we got all the way here, so it must be okay to upload
     return true;
 }
 /**
  * Whether the user is allowed to upload
  * @return boolean
  */
 public function userCanUpload()
 {
     $config = $this->getMFConfig();
     $user = $this->getUser();
     // check if upload is enabled local or to remote location (to commons e.g.)
     // TODO: what if the user cannot upload to the destination wiki in $wgMFPhotoUploadEndpoint?
     $uploadEnabled = UploadBase::isEnabled() && UploadBase::isallowed($user) || $config->get('MFPhotoUploadEndpoint');
     if ($uploadEnabled) {
         // Make sure the user is either in desktop mode or meets the special
         // conditions necessary for uploading in mobile mode.
         if (!$this->shouldDisplayMobileView() || $user->isAllowed('mf-uploadbutton') && $user->getEditCount() >= $config->get('MFUploadMinEdits')) {
             return true;
         }
     }
     return false;
 }
 protected function appendGeneralInfo($property)
 {
     global $wgContLang;
     $config = $this->getConfig();
     $data = [];
     $mainPage = Title::newMainPage();
     $data['mainpage'] = $mainPage->getPrefixedText();
     $data['base'] = wfExpandUrl($mainPage->getFullURL(), PROTO_CURRENT);
     $data['sitename'] = $config->get('Sitename');
     // wgLogo can either be a relative or an absolute path
     // make sure we always return an absolute path
     $data['logo'] = wfExpandUrl($config->get('Logo'), PROTO_RELATIVE);
     $data['generator'] = "MediaWiki {$config->get('Version')}";
     $data['phpversion'] = PHP_VERSION;
     $data['phpsapi'] = PHP_SAPI;
     if (defined('HHVM_VERSION')) {
         $data['hhvmversion'] = HHVM_VERSION;
     }
     $data['dbtype'] = $config->get('DBtype');
     $data['dbversion'] = $this->getDB()->getServerVersion();
     $allowFrom = [''];
     $allowException = true;
     if (!$config->get('AllowExternalImages')) {
         $data['imagewhitelistenabled'] = (bool) $config->get('EnableImageWhitelist');
         $allowFrom = $config->get('AllowExternalImagesFrom');
         $allowException = !empty($allowFrom);
     }
     if ($allowException) {
         $data['externalimages'] = (array) $allowFrom;
         ApiResult::setIndexedTagName($data['externalimages'], 'prefix');
     }
     $data['langconversion'] = !$config->get('DisableLangConversion');
     $data['titleconversion'] = !$config->get('DisableTitleConversion');
     if ($wgContLang->linkPrefixExtension()) {
         $linkPrefixCharset = $wgContLang->linkPrefixCharset();
         $data['linkprefixcharset'] = $linkPrefixCharset;
         // For backwards compatibility
         $data['linkprefix'] = "/^((?>.*[^{$linkPrefixCharset}]|))(.+)\$/sDu";
     } else {
         $data['linkprefixcharset'] = '';
         $data['linkprefix'] = '';
     }
     $linktrail = $wgContLang->linkTrail();
     $data['linktrail'] = $linktrail ?: '';
     $data['legaltitlechars'] = Title::legalChars();
     $data['invalidusernamechars'] = $config->get('InvalidUsernameCharacters');
     global $IP;
     $git = SpecialVersion::getGitHeadSha1($IP);
     if ($git) {
         $data['git-hash'] = $git;
         $data['git-branch'] = SpecialVersion::getGitCurrentBranch($GLOBALS['IP']);
     }
     // 'case-insensitive' option is reserved for future
     $data['case'] = $config->get('CapitalLinks') ? 'first-letter' : 'case-sensitive';
     $data['lang'] = $config->get('LanguageCode');
     $fallbacks = [];
     foreach ($wgContLang->getFallbackLanguages() as $code) {
         $fallbacks[] = ['code' => $code];
     }
     $data['fallback'] = $fallbacks;
     ApiResult::setIndexedTagName($data['fallback'], 'lang');
     if ($wgContLang->hasVariants()) {
         $variants = [];
         foreach ($wgContLang->getVariants() as $code) {
             $variants[] = ['code' => $code, 'name' => $wgContLang->getVariantname($code)];
         }
         $data['variants'] = $variants;
         ApiResult::setIndexedTagName($data['variants'], 'lang');
     }
     $data['rtl'] = $wgContLang->isRTL();
     $data['fallback8bitEncoding'] = $wgContLang->fallback8bitEncoding();
     $data['readonly'] = wfReadOnly();
     if ($data['readonly']) {
         $data['readonlyreason'] = wfReadOnlyReason();
     }
     $data['writeapi'] = (bool) $config->get('EnableWriteAPI');
     $tz = $config->get('Localtimezone');
     $offset = $config->get('LocalTZoffset');
     if (is_null($tz)) {
         $tz = 'UTC';
         $offset = 0;
     } elseif (is_null($offset)) {
         $offset = 0;
     }
     $data['timezone'] = $tz;
     $data['timeoffset'] = intval($offset);
     $data['articlepath'] = $config->get('ArticlePath');
     $data['scriptpath'] = $config->get('ScriptPath');
     $data['script'] = $config->get('Script');
     $data['variantarticlepath'] = $config->get('VariantArticlePath');
     $data[ApiResult::META_BC_BOOLS][] = 'variantarticlepath';
     $data['server'] = $config->get('Server');
     $data['servername'] = $config->get('ServerName');
     $data['wikiid'] = wfWikiID();
     $data['time'] = wfTimestamp(TS_ISO_8601, time());
     $data['misermode'] = (bool) $config->get('MiserMode');
     $data['uploadsenabled'] = UploadBase::isEnabled();
     $data['maxuploadsize'] = UploadBase::getMaxUploadSize();
     $data['minuploadchunksize'] = (int) $this->getConfig()->get('MinUploadChunkSize');
     $data['thumblimits'] = $config->get('ThumbLimits');
     ApiResult::setArrayType($data['thumblimits'], 'BCassoc');
     ApiResult::setIndexedTagName($data['thumblimits'], 'limit');
     $data['imagelimits'] = [];
     ApiResult::setArrayType($data['imagelimits'], 'BCassoc');
     ApiResult::setIndexedTagName($data['imagelimits'], 'limit');
     foreach ($config->get('ImageLimits') as $k => $limit) {
         $data['imagelimits'][$k] = ['width' => $limit[0], 'height' => $limit[1]];
     }
     $favicon = $config->get('Favicon');
     if (!empty($favicon)) {
         // wgFavicon can either be a relative or an absolute path
         // make sure we always return an absolute path
         $data['favicon'] = wfExpandUrl($favicon, PROTO_RELATIVE);
     }
     $data['centralidlookupprovider'] = $this->getConfig()->get('CentralIdLookupProvider');
     $providerIds = array_keys($this->getConfig()->get('CentralIdLookupProviders'));
     $data['allcentralidlookupproviders'] = $providerIds;
     Hooks::run('APIQuerySiteInfoGeneralInfo', [$this, &$data]);
     return $this->getResult()->addValue('query', $property, $data);
 }
 /**
  * build array of common navigation links
  * @return array
  * @private
  */
 protected function buildNavUrls(OutputPage $out)
 {
     global $wgUseTrackbacks, $wgUser, $wgRequest;
     global $wgUploadNavigationUrl;
     wfProfileIn(__METHOD__);
     $action = $wgRequest->getVal('action', 'view');
     $nav_urls = array();
     $nav_urls['mainpage'] = array('href' => self::makeMainPageUrl());
     if ($wgUploadNavigationUrl) {
         $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl);
     } elseif (UploadBase::isEnabled() && UploadBase::isAllowed($wgUser) === true) {
         $nav_urls['upload'] = array('href' => self::makeSpecialUrl('Upload'));
     } else {
         $nav_urls['upload'] = false;
     }
     $nav_urls['specialpages'] = array('href' => self::makeSpecialUrl('Specialpages'));
     // default permalink to being off, will override it as required below.
     $nav_urls['permalink'] = false;
     // A print stylesheet is attached to all pages, but nobody ever
     // figures that out. :)  Add a link...
     if ($this->iscontent && ($action == 'view' || $action == 'purge')) {
         if (!$out->isPrintable()) {
             $nav_urls['print'] = array('text' => wfMsg('printableversion'), 'href' => $this->getTitle()->getLocalURL($wgRequest->appendQueryValue('printable', 'yes', true)));
         }
         // Also add a "permalink" while we're at it
         $revid = $this->getRevisionId();
         if ($revid) {
             $nav_urls['permalink'] = array('text' => wfMsg('permalink'), 'href' => $out->getTitle()->getLocalURL("oldid={$revid}"));
         }
         // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
         wfRunHooks('SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array(&$this, &$nav_urls, &$revid, &$revid));
     }
     if ($this->getTitle()->getNamespace() != NS_SPECIAL) {
         $wlhTitle = SpecialPage::getTitleFor('Whatlinkshere', $this->thispage);
         $nav_urls['whatlinkshere'] = array('href' => $wlhTitle->getLocalUrl());
         if ($this->getTitle()->getArticleId()) {
             $rclTitle = SpecialPage::getTitleFor('Recentchangeslinked', $this->thispage);
             $nav_urls['recentchangeslinked'] = array('href' => $rclTitle->getLocalUrl());
         } else {
             $nav_urls['recentchangeslinked'] = false;
         }
         if ($wgUseTrackbacks) {
             $nav_urls['trackbacklink'] = array('href' => $out->getTitle()->trackbackURL());
         }
     }
     $user = $this->getRelevantUser();
     if ($user) {
         $id = $user->getID();
         $ip = $user->isAnon();
         $rootUser = $user->getName();
     } else {
         $id = 0;
         $ip = false;
         $rootUser = null;
     }
     if ($id || $ip) {
         # both anons and non-anons have contribs list
         $nav_urls['contributions'] = array('href' => self::makeSpecialUrlSubpage('Contributions', $rootUser));
         if ($id) {
             $logPage = SpecialPage::getTitleFor('Log');
             $nav_urls['log'] = array('href' => $logPage->getLocalUrl(array('user' => $rootUser)));
         } else {
             $nav_urls['log'] = false;
         }
         if ($wgUser->isAllowed('block')) {
             $nav_urls['blockip'] = array('href' => self::makeSpecialUrlSubpage('Block', $rootUser));
         } else {
             $nav_urls['blockip'] = false;
         }
     } else {
         $nav_urls['contributions'] = false;
         $nav_urls['log'] = false;
         $nav_urls['blockip'] = false;
     }
     $nav_urls['emailuser'] = false;
     if ($this->showEmailUser($id)) {
         $nav_urls['emailuser'] = array('href' => self::makeSpecialUrlSubpage('Emailuser', $rootUser));
     }
     wfProfileOut(__METHOD__);
     return $nav_urls;
 }
	/**
	 * Special page entry point
	 *
	 * What was changed here: the setArticleBodyOnly() line below was added,
	 * and some bits of code were entirely removed.
	 */
	public function execute( $par ) {
		global $wgUser, $wgOut, $wgRequest;

		// Disable the skin etc.
		$wgOut->setArticleBodyOnly( true );

		# Check that uploading is enabled
		if( !UploadBase::isEnabled() ) {
			$wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
			return;
		}

		# Check permissions
		global $wgGroupPermissions;
		if( !$wgUser->isAllowed( 'upload' ) ) {
			if( !$wgUser->isLoggedIn() && ( $wgGroupPermissions['user']['upload']
				|| $wgGroupPermissions['autoconfirmed']['upload'] ) ) {
				// Custom message if logged-in users without any special rights can upload
				$wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
			} else {
				$wgOut->permissionRequired( 'upload' );
			}
			return;
		}

		# Check blocks
		if( $wgUser->isBlocked() ) {
			$wgOut->blockedPage();
			return;
		}

		# Check whether we actually want to allow changing stuff
		if( wfReadOnly() ) {
			$wgOut->readOnlyPage();
			return;
		}

		# Unsave the temporary file in case this was a cancelled upload
		if ( $this->mCancelUpload ) {
			if ( !$this->unsaveUploadedFile() ) {
				# Something went wrong, so unsaveUploadedFile showed a warning
				return;
			}
		}

		# Process upload or show a form
		if ( $this->mTokenOk && !$this->mCancelUpload && ( $this->mUpload && $this->mUploadClicked ) ) {
			$this->processUpload();
		} else {
			$this->showUploadForm( $this->getUploadForm() );
		}

		# Cleanup
		if ( $this->mUpload ) {
			$this->mUpload->cleanupTempFile();
		}
	}
 /**
  * build array of common navigation links
  * @return array
  */
 protected function buildNavUrls()
 {
     global $wgUploadNavigationUrl;
     $out = $this->getOutput();
     $request = $this->getRequest();
     $nav_urls = array();
     $nav_urls['mainpage'] = array('href' => self::makeMainPageUrl());
     if ($wgUploadNavigationUrl) {
         $nav_urls['upload'] = array('href' => $wgUploadNavigationUrl);
     } elseif (UploadBase::isEnabled() && UploadBase::isAllowed($this->getUser()) === true) {
         $nav_urls['upload'] = array('href' => self::makeSpecialUrl('Upload'));
     } else {
         $nav_urls['upload'] = false;
     }
     $nav_urls['specialpages'] = array('href' => self::makeSpecialUrl('Specialpages'));
     $nav_urls['print'] = false;
     $nav_urls['permalink'] = false;
     $nav_urls['info'] = false;
     $nav_urls['whatlinkshere'] = false;
     $nav_urls['recentchangeslinked'] = false;
     $nav_urls['contributions'] = false;
     $nav_urls['log'] = false;
     $nav_urls['blockip'] = false;
     $nav_urls['emailuser'] = false;
     $nav_urls['userrights'] = false;
     // A print stylesheet is attached to all pages, but nobody ever
     // figures that out. :)  Add a link...
     if (!$out->isPrintable() && ($out->isArticle() || $this->getTitle()->isSpecialPage())) {
         $nav_urls['print'] = array('text' => $this->msg('printableversion')->text(), 'href' => $this->getTitle()->getLocalURL($request->appendQueryValue('printable', 'yes', true)));
     }
     if ($out->isArticle()) {
         // Also add a "permalink" while we're at it
         $revid = $this->getRevisionId();
         if ($revid) {
             $nav_urls['permalink'] = array('text' => $this->msg('permalink')->text(), 'href' => $this->getTitle()->getLocalURL("oldid={$revid}"));
         }
         // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
         Hooks::run('SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array(&$this, &$nav_urls, &$revid, &$revid));
     }
     if ($out->isArticleRelated()) {
         $nav_urls['whatlinkshere'] = array('href' => SpecialPage::getTitleFor('Whatlinkshere', $this->thispage)->getLocalURL());
         $nav_urls['info'] = array('text' => $this->msg('pageinfo-toolboxlink')->text(), 'href' => $this->getTitle()->getLocalURL("action=info"));
         if ($this->getTitle()->exists()) {
             $nav_urls['recentchangeslinked'] = array('href' => SpecialPage::getTitleFor('Recentchangeslinked', $this->thispage)->getLocalURL());
         }
     }
     $user = $this->getRelevantUser();
     if ($user) {
         $rootUser = $user->getName();
         $nav_urls['contributions'] = array('text' => $this->msg('contributions', $rootUser)->text(), 'href' => self::makeSpecialUrlSubpage('Contributions', $rootUser));
         $nav_urls['log'] = array('href' => self::makeSpecialUrlSubpage('Log', $rootUser));
         if ($this->getUser()->isAllowed('block')) {
             $nav_urls['blockip'] = array('text' => $this->msg('blockip', $rootUser)->text(), 'href' => self::makeSpecialUrlSubpage('Block', $rootUser));
         }
         if ($this->showEmailUser($user)) {
             $nav_urls['emailuser'] = array('href' => self::makeSpecialUrlSubpage('Emailuser', $rootUser));
         }
         if (!$user->isAnon()) {
             $sur = new UserrightsPage();
             $sur->setContext($this->getContext());
             if ($sur->userCanExecute($this->getUser())) {
                 $nav_urls['userrights'] = array('href' => self::makeSpecialUrlSubpage('Userrights', $rootUser));
             }
         }
     }
     return $nav_urls;
 }
Beispiel #17
0
 function quickBar()
 {
     global $wgOut, $wgUser, $wgRequest, $wgContLang;
     wfProfileIn(__METHOD__);
     $action = $wgRequest->getText('action');
     $wpPreview = $wgRequest->getBool('wpPreview');
     $tns = $this->getSkin()->getTitle()->getNamespace();
     $s = "\n<div id='quickbar'>";
     $s .= "\n" . $this->getSkin()->logoText() . "\n<hr class='sep' />";
     $sep = "\n<br />";
     # Use the first heading from the Monobook sidebar as the "browse" section
     $bar = $this->getSkin()->buildSidebar();
     unset($bar['SEARCH']);
     unset($bar['LANGUAGES']);
     unset($bar['TOOLBOX']);
     $barnumber = 1;
     foreach ($bar as $browseLinks) {
         if (is_array($browseLinks)) {
             if ($barnumber > 1) {
                 $s .= "\n<hr class='sep' />";
             }
             foreach ($browseLinks as $link) {
                 if ($link['text'] != '-') {
                     $s .= "<a href=\"{$link['href']}\">" . htmlspecialchars($link['text']) . '</a>' . $sep;
                 }
             }
         }
         if ($barnumber == 1) {
             // only show watchlist link if logged in
             if ($wgUser->isLoggedIn()) {
                 $s .= Linker::specialLink('Watchlist');
                 $s .= $sep . Linker::linkKnown(SpecialPage::getTitleFor('Contributions'), wfMsg('mycontris'), array(), array('target' => $wgUser->getName()));
             }
         }
         $barnumber = $barnumber + 1;
     }
     $s .= "\n<hr class='sep' />";
     $articleExists = $this->getSkin()->getTitle()->getArticleId();
     if ($wgOut->isArticle() || $action == 'edit' || $action == 'history' || $wpPreview) {
         if ($wgOut->isArticle()) {
             $s .= '<strong>' . $this->editThisPage() . '</strong>';
         } else {
             # backlink to the article in edit or history mode
             if ($articleExists) {
                 # no backlink if no article
                 switch ($tns) {
                     case NS_TALK:
                     case NS_USER_TALK:
                     case NS_PROJECT_TALK:
                     case NS_FILE_TALK:
                     case NS_MEDIAWIKI_TALK:
                     case NS_TEMPLATE_TALK:
                     case NS_HELP_TALK:
                     case NS_CATEGORY_TALK:
                         $text = wfMsg('viewtalkpage');
                         break;
                     case NS_MAIN:
                         $text = wfMsg('articlepage');
                         break;
                     case NS_USER:
                         $text = wfMsg('userpage');
                         break;
                     case NS_PROJECT:
                         $text = wfMsg('projectpage');
                         break;
                     case NS_FILE:
                         $text = wfMsg('imagepage');
                         break;
                     case NS_MEDIAWIKI:
                         $text = wfMsg('mediawikipage');
                         break;
                     case NS_TEMPLATE:
                         $text = wfMsg('templatepage');
                         break;
                     case NS_HELP:
                         $text = wfMsg('viewhelppage');
                         break;
                     case NS_CATEGORY:
                         $text = wfMsg('categorypage');
                         break;
                     default:
                         $text = wfMsg('articlepage');
                 }
                 $link = $this->getSkin()->getTitle()->getText();
                 $nstext = $wgContLang->getNsText($tns);
                 if ($nstext) {
                     # add namespace if necessary
                     $link = $nstext . ':' . $link;
                 }
                 $s .= Linker::link(Title::newFromText($link), $text);
             } elseif ($this->getSkin()->getTitle()->getNamespace() != NS_SPECIAL) {
                 # we just throw in a "New page" text to tell the user that he's in edit mode,
                 # and to avoid messing with the separator that is prepended to the next item
                 $s .= '<strong>' . wfMsg('newpage') . '</strong>';
             }
         }
         # "Post a comment" link
         if (($this->getSkin()->getTitle()->isTalkPage() || $wgOut->showNewSectionLink()) && $action != 'edit' && !$wpPreview) {
             $s .= '<br />' . $this->getSkin()->link($this->getSkin()->getTitle(), wfMsg('postcomment'), array(), array('action' => 'edit', 'section' => 'new'), array('known', 'noclasses'));
         }
         /*
         watching could cause problems in edit mode:
         if user edits article, then loads "watch this article" in background and then saves
         article with "Watch this article" checkbox disabled, the article is transparently
         unwatched. Therefore we do not show the "Watch this page" link in edit mode
         */
         if ($wgUser->isLoggedIn() && $articleExists) {
             if ($action != 'edit' && $action != 'submit') {
                 $s .= $sep . $this->watchThisPage();
             }
             if ($this->getSkin()->getTitle()->userCan('edit')) {
                 $s .= $sep . $this->moveThisPage();
             }
         }
         if ($wgUser->isAllowed('delete') && $articleExists) {
             $s .= $sep . $this->deleteThisPage() . $sep . $this->protectThisPage();
         }
         $s .= $sep . $this->talkLink();
         if ($articleExists && $action != 'history') {
             $s .= $sep . $this->historyLink();
         }
         $s .= $sep . $this->whatLinksHere();
         if ($wgOut->isArticleRelated()) {
             $s .= $sep . $this->watchPageLinksLink();
         }
         if (NS_USER == $this->getSkin()->getTitle()->getNamespace() || $this->getSkin()->getTitle()->getNamespace() == NS_USER_TALK) {
             $id = User::idFromName($this->getSkin()->getTitle()->getText());
             $ip = User::isIP($this->getSkin()->getTitle()->getText());
             if ($id || $ip) {
                 $s .= $sep . $this->userContribsLink();
             }
             if ($this->getSkin()->showEmailUser($id)) {
                 $s .= $sep . $this->emailUserLink();
             }
         }
         $s .= "\n<br /><hr class='sep' />";
     }
     if (UploadBase::isEnabled() && UploadBase::isAllowed($wgUser) === true) {
         $s .= $this->getUploadLink() . $sep;
     }
     $s .= Linker::specialLink('Specialpages');
     global $wgSiteSupportPage;
     if ($wgSiteSupportPage) {
         $s .= "\n<br /><a href=\"" . htmlspecialchars($wgSiteSupportPage) . '" class="internal">' . wfMsg('sitesupport') . '</a>';
     }
     $s .= "\n<br /></div>\n";
     wfProfileOut(__METHOD__);
     return $s;
 }
Beispiel #18
0
 public function execute()
 {
     // Check whether upload is enabled
     if (!UploadBase::isEnabled()) {
         $this->dieUsageMsg('uploaddisabled');
     }
     $user = $this->getUser();
     // Parameter handling
     $this->mParams = $this->extractRequestParams();
     $request = $this->getMain()->getRequest();
     // Check if async mode is actually supported (jobs done in cli mode)
     $this->mParams['async'] = $this->mParams['async'] && $this->getConfig()->get('EnableAsyncUploads');
     // Add the uploaded file to the params array
     $this->mParams['file'] = $request->getFileName('file');
     $this->mParams['chunk'] = $request->getFileName('chunk');
     // Copy the session key to the file key, for backward compatibility.
     if (!$this->mParams['filekey'] && $this->mParams['sessionkey']) {
         $this->mParams['filekey'] = $this->mParams['sessionkey'];
     }
     // Select an upload module
     try {
         if (!$this->selectUploadModule()) {
             return;
             // not a true upload, but a status request or similar
         } elseif (!isset($this->mUpload)) {
             $this->dieUsage('No upload module set', 'nomodule');
         }
     } catch (UploadStashException $e) {
         // XXX: don't spam exception log
         $this->handleStashException($e);
     }
     // First check permission to upload
     $this->checkPermissions($user);
     // Fetch the file (usually a no-op)
     /** @var $status Status */
     $status = $this->mUpload->fetchFile();
     if (!$status->isGood()) {
         $errors = $status->getErrorsArray();
         $error = array_shift($errors[0]);
         $this->dieUsage('Error fetching file from remote source', $error, 0, $errors[0]);
     }
     // Check if the uploaded file is sane
     if ($this->mParams['chunk']) {
         $maxSize = UploadBase::getMaxUploadSize();
         if ($this->mParams['filesize'] > $maxSize) {
             $this->dieUsage('The file you submitted was too large', 'file-too-large');
         }
         if (!$this->mUpload->getTitle()) {
             $this->dieUsage('Invalid file title supplied', 'internal-error');
         }
     } elseif ($this->mParams['async'] && $this->mParams['filekey']) {
         // defer verification to background process
     } else {
         wfDebug(__METHOD__ . " about to verify\n");
         $this->verifyUpload();
     }
     // Check if the user has the rights to modify or overwrite the requested title
     // (This check is irrelevant if stashing is already requested, since the errors
     //  can always be fixed by changing the title)
     if (!$this->mParams['stash']) {
         $permErrors = $this->mUpload->verifyTitlePermissions($user);
         if ($permErrors !== true) {
             $this->dieRecoverableError($permErrors[0], 'filename');
         }
     }
     // Get the result based on the current upload context:
     try {
         $result = $this->getContextResult();
         if ($result['result'] === 'Success') {
             $result['imageinfo'] = $this->mUpload->getImageInfo($this->getResult());
         }
     } catch (UploadStashException $e) {
         // XXX: don't spam exception log
         $this->handleStashException($e);
     }
     $this->getResult()->addValue(null, $this->getModuleName(), $result);
     // Cleanup any temporary mess
     $this->mUpload->cleanupTempFile();
 }
 /**
  * Special page entry point
  */
 public function execute($par)
 {
     global $wgUser, $wgOut, $wgRequest;
     $this->setHeaders();
     $this->outputHeader();
     # Check uploading enabled
     if (!UploadBase::isEnabled()) {
         $wgOut->showErrorPage('uploaddisabled', 'uploaddisabledtext');
         return;
     }
     # Check permissions
     global $wgGroupPermissions;
     if (!$wgUser->isAllowed('upload')) {
         if (!$wgUser->isLoggedIn() && ($wgGroupPermissions['user']['upload'] || $wgGroupPermissions['autoconfirmed']['upload'])) {
             // Custom message if logged-in users without any special rights can upload
             $wgOut->showErrorPage('uploadnologin', 'uploadnologintext');
         } else {
             $wgOut->permissionRequired('upload');
         }
         return;
     }
     # Check blocks
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage();
         return;
     }
     # Check whether we actually want to allow changing stuff
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     }
     # Unsave the temporary file in case this was a cancelled upload
     if ($this->mCancelUpload) {
         if (!$this->unsaveUploadedFile()) {
             # Something went wrong, so unsaveUploadedFile showed a warning
             return;
         }
     }
     # Process upload or show a form
     if ($this->mTokenOk && !$this->mCancelUpload && ($this->mUpload && $this->mUploadClicked)) {
         $this->processUpload();
     } else {
         # Backwards compatibility hook
         if (!wfRunHooks('UploadForm:initial', array(&$this))) {
             wfDebug("Hook 'UploadForm:initial' broke output of the upload form");
             return;
         }
         $this->showUploadForm($this->getUploadForm());
     }
     # Cleanup
     if ($this->mUpload) {
         $this->mUpload->cleanupTempFile();
     }
 }
Beispiel #20
0
 /**
  * Special page entry point
  * @param string $par
  * @throws ErrorPageError
  * @throws Exception
  * @throws FatalError
  * @throws MWException
  * @throws PermissionsError
  * @throws ReadOnlyError
  * @throws UserBlockedError
  */
 public function execute($par)
 {
     $this->setHeaders();
     $this->outputHeader();
     # Check uploading enabled
     if (!UploadBase::isEnabled()) {
         throw new ErrorPageError('uploaddisabled', 'uploaddisabledtext');
     }
     $this->addHelpLink('Help:Managing files');
     # Check permissions
     $user = $this->getUser();
     $permissionRequired = UploadBase::isAllowed($user);
     if ($permissionRequired !== true) {
         throw new PermissionsError($permissionRequired);
     }
     # Check blocks
     if ($user->isBlocked()) {
         throw new UserBlockedError($user->getBlock());
     }
     # Check whether we actually want to allow changing stuff
     $this->checkReadOnly();
     $this->loadRequest();
     # Unsave the temporary file in case this was a cancelled upload
     if ($this->mCancelUpload) {
         if (!$this->unsaveUploadedFile()) {
             # Something went wrong, so unsaveUploadedFile showed a warning
             return;
         }
     }
     # Process upload or show a form
     if ($this->mTokenOk && !$this->mCancelUpload && ($this->mUpload && $this->mUploadClicked)) {
         $this->processUpload();
     } else {
         # Backwards compatibility hook
         if (!Hooks::run('UploadForm:initial', array(&$this))) {
             wfDebug("Hook 'UploadForm:initial' broke output of the upload form\n");
             return;
         }
         $this->showUploadForm($this->getUploadForm());
     }
     # Cleanup
     if ($this->mUpload) {
         $this->mUpload->cleanupTempFile();
     }
 }
Beispiel #21
0
 /**
  * This page can be shown if uploading is enabled.
  * Handle permission checking elsewhere in order to be able to show
  * custom error messages.
  *
  * @param User $user
  * @return bool
  */
 public function userCanExecute(User $user)
 {
     return UploadBase::isEnabled() && parent::userCanExecute($user);
 }