r108303 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108302‎ | r108303 | r108304 >
Date:03:17, 7 January 2012
Author:aaron
Status:ok
Tags:
Comment:
Partially reverted bits from r108300. Not allowing underscores is too restrictive and breaks on default DB name value suggested by installer. Azure can use resolveContainerName() to enforce its extra restrictions. A new resolveWikiId() function was added to allow for it to mangle the wiki ID by translating underscores. Also restored previous size limit in isValidContainerName() since it makes sense to either go all the way lowest-common-denominator or not here (in this case not). Preserved "first char is a alphanumeric" check since it's pretty weird to have anything else.
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FileBackend.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/backend/FileBackend.php
@@ -43,6 +43,7 @@
4444 * $config includes:
4545 * 'name' : The unique name of this backend.
4646 * 'wikiId' : Prefix to container names that is unique to this wiki.
 47+ * This should consist of alphanumberic, '-', and '_' chars.
4748 * 'lockManager' : Registered name of a file lock manager to use.
4849 * 'readOnly' : Write operations are disallowed if this is a non-empty string.
4950 * It should be an explanation for the backend being read-only.
@@ -53,7 +54,8 @@
5455 $this->name = $config['name'];
5556 $this->wikiId = isset( $config['wikiId'] )
5657 ? $config['wikiId']
57 - : rtrim( wfWikiID(), '_' ); // "mywiki-en_" => "mywiki-en"
 58+ : wfWikiID(); // e.g. "my_wiki-en_"
 59+ $this->wikiId = $this->resolveWikiId( $this->wikiId );
5860 $this->lockManager = LockManagerGroup::singleton()->get( $config['lockManager'] );
5961 $this->readOnly = isset( $config['readOnly'] )
6062 ? (string)$config['readOnly']
@@ -61,6 +63,17 @@
6264 }
6365
6466 /**
 67+ * Normalize a wiki ID by replacing characters that are
 68+ * not supported by the backend as part of container names.
 69+ *
 70+ * @param $wikiId string
 71+ * @return string
 72+ */
 73+ protected function resolveWikiId( $wikiId ) {
 74+ return $wikiId;
 75+ }
 76+
 77+ /**
6578 * Get the unique backend name.
6679 *
6780 * We may have multiple different backends of the same type.
@@ -1104,10 +1117,11 @@
11051118 * @return bool
11061119 */
11071120 final protected static function isValidContainerName( $container ) {
1108 - // This accounts for Swift, S3, and Azure restrictions while
1109 - // leaving room for '.xxx' (hex shard chars) or '.seg' (segments).
1110 - // Note that matching strings URL encode to the same string.
1111 - return preg_match( '/^[a-z0-9][a-z0-9-]{2,55}$/i', $container );
 1121+ // This accounts for Swift and S3 restrictions while leaving room
 1122+ // for things like '.xxx' (hex shard chars) or '.seg' (segments).
 1123+ // Note that matching strings URL encode to the same string;
 1124+ // in Swift, the length resriction is *after* URL encoding.
 1125+ return preg_match( '/^[a-z0-9][a-z0-9-_]{0,199}$/i', $container );
11121126 }
11131127
11141128 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r110253* Split up process cache in FileBackend into separate arrays for expensive an...aaron19:23, 29 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108300In FileBackend/FileOp:...aaron01:33, 7 January 2012

Status & tagging log