Clean up VisualEditorDataModule and document ve.version

* Check in #getGitHeadHash now ensures a false value is
  cached as well.
* Made ve.version.id being false when invalid more stable
  since we now rely on this as of eeb3ac3b19.
* Added documentation for ve.version.

Change-Id: I164aa9ebaa7f8a4d1e8f2210af76e06b23abef09
This commit is contained in:
Timo Tijhof 2013-09-18 03:40:00 +02:00
parent c98a964d5f
commit e4662a65cd
3 changed files with 28 additions and 3 deletions

View file

@ -83,7 +83,7 @@
}, },
{ {
"name": "MediaWiki integration", "name": "MediaWiki integration",
"classes": ["ve.init.mw*"] "classes": ["ve.init.mw*", "ve.version"]
}, },
{ {
"name": "Stand-alone", "name": "Stand-alone",

View file

@ -35,3 +35,26 @@
* @class QUnit * @class QUnit
* @source <http://api.qunitjs.com/> * @source <http://api.qunitjs.com/>
*/ */
/**
* Provided by VisualEditorDataModule.php for the MediaWiki environment.
*
* @class ve.version
* @singleton
*/
/**
* @property {string|boolean} [id=false] Git commit hash (abbreviated to 7 characters)
*/
/**
* @property {string|boolean} [url=false] URL to git commit viewer for #id
*/
/**
* @property {number|boolean} [timestamp=false] Commit date (UNIX timestamp)
*/
/**
* @property {string} [dateString=""] Formatted date or empty string
*/

View file

@ -39,7 +39,8 @@ class VisualEditorDataModule extends ResourceLoaderModule {
// Version information // Version information
$language = Language::factory( $context->getLanguage() ); $language = Language::factory( $context->getLanguage() );
$id = substr( $this->getGitHeadHash(), 0, 7 ); $hash = $this->getGitHeadHash();
$id = $hash ? substr( $this->getGitHeadHash(), 0, 7 ) : false;
$url = $this->gitInfo->getHeadViewUrl(); $url = $this->gitInfo->getHeadViewUrl();
$date = $this->gitInfo->getHeadCommitDate(); $date = $this->gitInfo->getHeadCommitDate();
$dateString = $date ? $language->timeanddate( $date, true ) : ''; $dateString = $date ? $language->timeanddate( $date, true ) : '';
@ -53,6 +54,7 @@ class VisualEditorDataModule extends ResourceLoaderModule {
$messages, $messages,
ResourceLoader::inDebugMode() ResourceLoader::inDebugMode()
) . ');'. ) . ');'.
// Documented in .docs/external.json
've.version = ' . FormatJson::encode( 've.version = ' . FormatJson::encode(
array( array(
'id' => $id, 'id' => $id,
@ -161,7 +163,7 @@ class VisualEditorDataModule extends ResourceLoaderModule {
} }
protected function getGitHeadHash() { protected function getGitHeadHash() {
if ( !$this->gitHeadHash ) { if ( $this->gitHeadHash === null ) {
$this->gitHeadHash = $this->gitInfo->getHeadSHA1(); $this->gitHeadHash = $this->gitInfo->getHeadSHA1();
} }
return $this->gitHeadHash; return $this->gitHeadHash;