if ( !$isRedirect && !is_null( $lastRevIsRedirect ) && $lastRevIsRedirect === $isRedirect ) {
return true;
}
-
+
wfProfileIn( __METHOD__ );
if ( $isRedirect ) {
$this->insertRedirectEntry( $redirectTitle );
/**
* Returns "</$element>", except if $wgWellFormedXml is off, in which case
* it returns the empty string when that's guaranteed to be safe.
- *
+ *
* @since 1.17
* @param $element string Name of the element, e.g., 'a'
* @return string A closing tag, if required
*/
class MWHttpRequest {
const SUPPORTS_FILE_POSTS = false;
-
+
protected $content;
protected $timeout = 'default';
protected $headersOnly = null;
/**
* Generate a new request object
- * @param $url String: url to use
+ * @param $url String: url to use
* @param $options Array: (optional) extra params to pass (see Http::request())
* @see MWHttpRequest::__construct
*/
*/
class CurlHttpRequest extends MWHttpRequest {
const SUPPORTS_FILE_POSTS = true;
-
+
static $curlMessageMap = array(
6 => 'http-host-unreachable',
28 => 'http-timed-out'
if ( is_array( $this->postData ) ) {
$this->postData = wfArrayToCGI( $this->postData );
- }
+ }
// At least on Centos 4.8 with PHP 5.1.6, using max_redirects to follow redirects
// causes a segfault
* Dummy for now...
*/
public function importUpload( $revision ) {
- $revision->importUpload();
+ $revision->importUpload();
//$dbw = wfGetDB( DB_MASTER );
//return $dbw->deadlockLoop( array( $revision, 'importUpload' ) );
return false;
private function processUpload( $pageInfo, $uploadInfo ) {
$revision = new WikiRevision;
- $text = isset( $uploadInfo['text'] ) ? $uploadInfo['text'] : '';
+ $text = isset( $uploadInfo['text'] ) ? $uploadInfo['text'] : '';
$revision->setTitle( $pageInfo['_title'] );
- $revision->setID( $pageInfo['id'] );
+ $revision->setID( $pageInfo['id'] );
$revision->setTimestamp( $uploadInfo['timestamp'] );
- $revision->setText( $text );
+ $revision->setText( $text );
$revision->setFilename( $uploadInfo['filename'] );
$revision->setSrc( $uploadInfo['src'] );
$revision->setSize( intval( $uploadInfo['size'] ) );
$revision->setUserName( $uploadInfo['contributor']['username'] );
}
- return call_user_func( $this->mUploadCallback, $revision );
+ return call_user_func( $this->mUploadCallback, $revision );
}
private function handleContributor() {
$resultDetails = array( 'internal' => $status->getWikiText() );
*/
- // @todo Fixme: it may create a page without our desire, also wrong potentially.
+ // @todo Fixme: it may create a page without our desire, also wrong potentially.
// and, it will record a *current* upload, but we might want an archive version here
$file = wfLocalFile( $this->getTitle() );
return false;
}
- $user = User::newFromName( $this->user_text );
+ $user = User::newFromName( $this->user_text );
$status = $file->upload( $source,
$this->getComment(),
$this->getComment(), // Initial page, if none present...
File::DELETE_SOURCE,
false, // props...
- $this->getTimestamp(),
- is_object( $user ) ? ( $user->isLoggedIn() ? $user : null ) : null );
+ $this->getTimestamp(),
+ is_object( $user ) ? ( $user->isLoggedIn() ? $user : null ) : null );
if( $status->isGood() ) {
// yay?
# Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
# Check for this with iconv
$cp1252Password = iconv( 'UTF-8', 'WINDOWS-1252//TRANSLIT', $password );
- if ( $cp1252Password != $password &&
+ if ( $cp1252Password != $password &&
self::comparePasswords( $this->mPassword, $cp1252Password, $this->mId ) )
{
return true;
} else {
$this->clearWatchlist( $user );
$user->invalidateCache();
- $output->addHTML( wfMsgExt( 'watchlistedit-raw-removed', 'parse',
+ $output->addHTML( wfMsgExt( 'watchlistedit-raw-removed', 'parse',
$wgLang->formatNum( count( $current ) ) ) );
$this->showTitles( $current, $output, $wgUser->getSkin() );
}
}
public function __construct() {}
-
+
/**
* Returns the upload type. Should be overridden by child classes
- *
+ *
* @since 1.18
- * @return string
+ * @return string
*/
public function getSourceType() { return null; }
*/
$maxSize = self::getMaxUploadSize( $this->getSourceType() );
if( $this->mFileSize > $maxSize ) {
- return array(
+ return array(
'status' => self::FILE_TOO_LARGE,
'max' => $maxSize,
);
protected function verifyFile() {
global $wgAllowJavaUploads;
# get the title, even though we are doing nothing with it, because
- # we need to populate mFinalExtension
+ # we need to populate mFinalExtension
$this->getTitle();
-
+
$this->mFileProps = File::getPropsFromPath( $this->mTempPath, $this->mFinalExtension );
$this->checkMacBinary();
}
}
- # Check for Java applets, which if uploaded can bypass cross-site
+ # Check for Java applets, which if uploaded can bypass cross-site
# restrictions.
if ( !$wgAllowJavaUploads ) {
$this->mJavaDetected = false;
- $zipStatus = ZipDirectoryReader::read( $this->mTempPath,
+ $zipStatus = ZipDirectoryReader::read( $this->mTempPath,
array( $this, 'zipEntryCallback' ) );
if ( !$zipStatus->isOK() ) {
$errors = $zipStatus->getErrorsArray();
$names = array( $entry['name'] );
// If there is a null character, cut off the name at it, because JDK's
- // ZIP_GetEntry() uses strcmp() if the name hashes match. If a file name
- // were constructed which had ".class\0" followed by a string chosen to
- // make the hash collide with the truncated name, that file could be
+ // ZIP_GetEntry() uses strcmp() if the name hashes match. If a file name
+ // were constructed which had ".class\0" followed by a string chosen to
+ // make the hash collide with the truncated name, that file could be
// returned in response to a request for the .class file.
$nullPos = strpos( $entry['name'], "\000" );
if ( $nullPos !== false ) {
$names[] = substr( $entry['name'], 0, $nullPos );
}
- // If there is a trailing slash in the file name, we have to strip it,
+ // If there is a trailing slash in the file name, we have to strip it,
// because that's what ZIP_GetEntry() does.
if ( preg_grep( '!\.class/?$!', $names ) ) {
$this->mJavaDetected = true;
$permErrors = array_merge( $permErrors, wfArrayDiff2( $permErrorsCreate, $permErrors ) );
return $permErrors;
}
-
+
$overwriteError = $this->checkOverwrite( $user );
if ( $overwriteError !== true ) {
return array( array( $overwriteError ) );
}
-
+
return true;
}
* @return Status indicating the whether the upload succeeded.
*/
public function performUpload( $comment, $pageText, $watch, $user ) {
- $status = $this->getLocalFile()->upload(
- $this->mTempPath,
- $comment,
+ $status = $this->getLocalFile()->upload(
+ $this->mTempPath,
+ $comment,
$pageText,
File::DELETE_SOURCE,
- $this->mFileProps,
- false,
- $user
+ $this->mFileProps,
+ false,
+ $user
);
if( $status->isGood() ) {
$this->mFinalExtension = trim( $ext[count( $ext ) - 1] );
} else {
$this->mFinalExtension = '';
-
+
# No extension, try guessing one
$magic = MimeMagic::singleton();
$mime = $magic->guessMimeType( $this->mTempPath );
if ( $extList ) {
# Set the extension to the canonical extension
$this->mFinalExtension = strtok( $extList, ' ' );
-
+
# Fix up the other variables
$this->mFilteredName .= ".{$this->mFinalExtension}";
$nt = Title::makeTitleSafe( NS_FILE, $this->mFilteredName );
$ext = array( $this->mFinalExtension );
}
}
-
+
}
/* Don't allow users to override the blacklist (check file extension) */
global $wgCheckFileExtensions, $wgStrictFileExtensions;
global $wgFileExtensions, $wgFileBlacklist;
-
+
$blackListedExtensions = $this->checkFileExtensionList( $ext, $wgFileBlacklist );
-
+
if ( $this->mFinalExtension == '' ) {
$this->mTitleError = self::FILETYPE_MISSING;
return $this->mTitle = null;
*
* This method will stash a file in a temporary directory for later processing, and save the necessary descriptive info
* into the user's session.
- * This method returns the file object, which also has a 'sessionKey' property which can be passed through a form or
+ * This method returns the file object, which also has a 'sessionKey' property which can be passed through a form or
* API request to find this stashed file again.
*
* @param $key String: (optional) the session key used to find the file info again. If not supplied, a key will be autogenerated.
* @return UploadStashFile stashed file
*/
- public function stashSessionFile( $key = null ) {
+ public function stashSessionFile( $key = null ) {
$stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
- $data = array(
+ $data = array(
'mFileProps' => $this->mFileProps,
'mSourceType' => $this->getSourceType(),
);
}
/**
- * Gets image info about the file just uploaded.
+ * Gets image info about the file just uploaded.
*
- * Also has the effect of setting metadata to be an 'indexed tag name' in returned API result if
+ * Also has the effect of setting metadata to be an 'indexed tag name' in returned API result if
* 'metadata' was requested. Oddly, we have to pass the "result" object down just so it can do that
- * with the appropriate format, presumably.
+ * with the appropriate format, presumably.
*
* @param $result ApiResult:
* @return Array: image info
*/
public function getImageInfo( $result ) {
$file = $this->getLocalFile();
- // TODO This cries out for refactoring. We really want to say $file->getAllInfo(); here.
+ // TODO This cries out for refactoring. We really want to say $file->getAllInfo(); here.
// Perhaps "info" methods should be moved into files, and the API should just wrap them in queries.
if ( $file instanceof UploadStashFile ) {
$imParam = ApiQueryStashImageInfo::getPropertyNames();
unset( $code['status'] );
return Status::newFatal( $this->getVerificationErrorCode( $code ), $error );
}
-
+
public static function getMaxUploadSize( $forType = null ) {
global $wgMaxUploadSize;
-
+
if ( is_array( $wgMaxUploadSize ) ) {
- if ( !is_null( $forType ) && isset( $wgMaxUploadSize[$forType] ) ) {
+ if ( !is_null( $forType) && isset( $wgMaxUploadSize[$forType] ) ) {
return $wgMaxUploadSize[$forType];
} else {
return $wgMaxUploadSize['*'];
} else {
return intval( $wgMaxUploadSize );
}
-
+
}
}
<?php
-/**
+/**
* UploadStash is intended to accomplish a few things:
* - enable applications to temporarily stash files without publishing them to the wiki.
* - Several parts of MediaWiki do this in similar ways: UploadBase, UploadWizard, and FirefoggChunkedExtension
* And there are several that reimplement stashing from scratch, in idiosyncratic ways. The idea is to unify them all here.
* Mostly all of them are the same except for storing some custom fields, which we subsume into the data array.
- * - enable applications to find said files later, as long as the session or temp files haven't been purged.
+ * - enable applications to find said files later, as long as the session or temp files haven't been purged.
* - enable the uploading user (and *ONLY* the uploading user) to access said files, and thumbnails of said files, via a URL.
- * We accomplish this by making the session serve as a URL->file mapping, on the assumption that nobody else can access
+ * We accomplish this by making the session serve as a URL->file mapping, on the assumption that nobody else can access
* the session, even the uploading user. See SpecialUploadStash, which implements a web interface to some files stored this way.
*
*/
// repository that this uses to store temp files
// public because we sometimes need to get a LocalFile within the same repo.
- public $repo;
-
+ public $repo;
+
// array of initialized objects obtained from session (lazily initialized upon getFile())
private $files = array();
* Represents the session which contains temporarily stored files.
* Designed to be compatible with the session stashing code in UploadBase (should replace it eventually)
*/
- public function __construct( $repo ) {
+ public function __construct( $repo ) {
// this might change based on wiki's configuration.
$this->repo = $repo;
if ( !isset( $_SESSION[UploadBase::SESSION_KEYNAME] ) ) {
$_SESSION[UploadBase::SESSION_KEYNAME] = array();
}
-
+
}
/**
public function getFile( $key ) {
if ( ! preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
throw new UploadStashBadPathException( "key '$key' is not in a proper format" );
- }
-
+ }
+
if ( !isset( $this->files[$key] ) ) {
if ( !isset( $_SESSION[UploadBase::SESSION_KEYNAME][$key] ) ) {
throw new UploadStashFileNotFoundException( "key '$key' not found in stash" );
if ($data['version'] !== UploadBase::SESSION_VERSION ) {
throw new UploadStashBadVersionException( $data['version'] . " does not match current version " . UploadBase::SESSION_VERSION );
}
-
+
// separate the stashData into the path, and then the rest of the data
$path = $data['mTempPath'];
unset( $data['mTempPath'] );
wfDebug( "UploadStash: tried to stash file at '$path', but it doesn't exist\n" );
throw new UploadStashBadPathException( "path doesn't exist" );
}
- $fileProps = File::getPropsFromPath( $path );
+ $fileProps = File::getPropsFromPath( $path );
// we will be initializing from some tmpnam files that don't have extensions.
// most of MediaWiki assumes all uploaded files have good extensions. So, we fix this.
throw new UploadStashFileException( "couldn't rename $path to have a better extension at $pathWithGoodExtension" );
}
$path = $pathWithGoodExtension;
- }
+ }
// If no key was supplied, use content hash. Also has the nice property of collapsing multiple identical files
// uploaded this session, which could happen if uploads had failed.
if ( ! preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
throw new UploadStashBadPathException( "key '$key' is not in a proper format" );
- }
+ }
// if not already in a temporary area, put it there
$status = $this->repo->storeTemp( basename( $path ), $path );
// required info we always store. Must trump any other application info in $data
// 'mTempPath', 'mFileSize', and 'mFileProps' are arbitrary names
// chosen for compatibility with UploadBase's way of doing this.
- $requiredData = array(
+ $requiredData = array(
'mTempPath' => $stashPath,
'mFileSize' => $fileProps['size'],
'mFileProps' => $fileProps,
// UploadWizard wants different things than say FirefoggChunkedUpload.)
wfDebug( __METHOD__ . " storing under $key\n" );
$_SESSION[UploadBase::SESSION_KEYNAME][$key] = array_merge( $data, $requiredData );
-
+
return $this->getFile( $key );
}
/**
* Find or guess extension -- ensuring that our extension matches our mime type.
- * Since these files are constructed from php tempnames they may not start off
+ * Since these files are constructed from php tempnames they may not start off
* with an extension.
- * XXX this is somewhat redundant with the checks that ApiUpload.php does with incoming
+ * XXX this is somewhat redundant with the checks that ApiUpload.php does with incoming
* uploads versus the desired filename. Maybe we can get that passed to us...
*/
- public static function getExtensionForPath( $path ) {
+ public static function getExtensionForPath( $path ) {
// Does this have an extension?
$n = strrpos( $path, '.' );
$extension = null;
$magic = MimeMagic::singleton();
$mimeType = $magic->guessMimeType( $path );
$extensions = explode( ' ', MimeMagic::singleton()->getExtensionsForType( $mimeType ) );
- if ( count( $extensions ) ) {
- $extension = $extensions[0];
+ if ( count( $extensions ) ) {
+ $extension = $extensions[0];
}
}
* @throws UploadStashBadPathException
* @throws UploadStashFileNotFoundException
*/
- public function __construct( $stash, $repo, $path, $key, $data ) {
+ public function __construct( $stash, $repo, $path, $key, $data ) {
$this->sessionStash = $stash;
$this->sessionKey = $key;
$this->sessionData = $data;
// resolve mwrepo:// urls
if ( $repo->isVirtualUrl( $path ) ) {
- $path = $repo->resolveVirtualUrl( $path );
+ $path = $repo->resolveVirtualUrl( $path );
}
// check if path appears to be sane, no parent traversals, and is in this repo's temp zone.
$repoTempPath = $repo->getZonePath( 'temp' );
- if ( ( ! $repo->validateFilename( $path ) ) ||
+ if ( ( ! $repo->validateFilename( $path ) ) ||
( strpos( $path, $repoTempPath ) !== 0 ) ) {
wfDebug( "UploadStash: tried to construct an UploadStashFile from a file that should already exist at '$path', but path is not valid\n" );
throw new UploadStashBadPathException( 'path is not valid' );
/**
* Get the path for the thumbnail (actually any transformation of this file)
- * The actual argument is the result of thumbName although we seem to have
+ * The actual argument is the result of thumbName although we seem to have
* buggy code elsewhere that expects a boolean 'suffix'
*
* @param $thumbName String: name of thumbnail (e.g. "120px-123456.jpg" ), or false to just get the path
* @return String: path thumbnail should take on filesystem, or containing directory if thumbname is false
*/
- public function getThumbPath( $thumbName = false ) {
+ public function getThumbPath( $thumbName = false ) {
$path = dirname( $this->path );
if ( $thumbName !== false ) {
$path .= "/$thumbName";
}
/**
- * Return the file/url base name of a thumbnail with the specified parameters.
- * We override this because we want to use the pretty url name instead of the
+ * Return the file/url base name of a thumbnail with the specified parameters.
+ * We override this because we want to use the pretty url name instead of the
* ugly file name.
*
* @param $params Array: handler-specific parameters
/**
* Helper function -- given a 'subpage', return the local URL e.g. /wiki/Special:UploadStash/subpage
* @param {String} $subPage
- * @return {String} local URL for this subpage in the Special:UploadStash space.
+ * @return {String} local URL for this subpage in the Special:UploadStash space.
*/
private function getSpecialUrl( $subPage ) {
return SpecialPage::getTitleFor( 'UploadStash', $subPage )->getLocalURL();
}
- /**
- * Get a URL to access the thumbnail
- * This is required because the model of how files work requires that
+ /**
+ * Get a URL to access the thumbnail
+ * This is required because the model of how files work requires that
* the thumbnail urls be predictable. However, in our model the URL is not based on the filename
* (that's hidden in the session)
*
* @param $thumbName String: basename of thumbnail file -- however, we don't want to use the file exactly
* @return String: URL to access thumbnail, or URL with partial path
*/
- public function getThumbUrl( $thumbName = false ) {
+ public function getThumbUrl( $thumbName = false ) {
wfDebug( __METHOD__ . " getting for $thumbName \n" );
return $this->getSpecialUrl( 'thumb/' . $this->getUrlName() . '/' . $thumbName );
}
- /**
+ /**
* The basename for the URL, which we want to not be related to the filename.
* Will also be used as the lookup key for a thumbnail file.
*
* @return String: base url name, like '120px-123456.jpg'
*/
- public function getUrlName() {
+ public function getUrlName() {
if ( ! $this->urlName ) {
$this->urlName = $this->sessionKey;
}
}
/**
- * Parent classes use this method, for no obvious reason, to return the path (relative to wiki root, I assume).
+ * Parent classes use this method, for no obvious reason, to return the path (relative to wiki root, I assume).
* But with this class, the URL is unrelated to the path.
*
* @return String: url
*/
- public function getFullUrl() {
+ public function getFullUrl() {
return $this->getUrl();
}
'undelete-show-file-submit' => 'Yes',
# Namespace form on various pages
-'namespace' => 'Namespace:',
-'invert' => 'Invert selection',
+'namespace' => 'Namespace:',
+'invert' => 'Invert selection',
'namespace_association' => 'Associated namespace',
-'blanknamespace' => '(Main)',
+'blanknamespace' => '(Main)',
# Contributions
'contributions' => 'User contributions',