mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-12 09:27:36 +00:00
Move models to their own modules
Change-Id: Ib3d32496bfbc174dc136a269abf0b66cf0ae475d
This commit is contained in:
parent
5e4a544133
commit
5b03c39c72
|
@ -31,6 +31,11 @@ $moduleInfoMMV = array(
|
|||
'remoteExtPath' => 'MultimediaViewer/resources/mmv',
|
||||
);
|
||||
|
||||
$moduleInfoMMVM = array(
|
||||
'localBasePath' => __DIR__ . '/resources/mmv/model',
|
||||
'remoteExtPath' => 'MultimediaViewer/resources/mmv/model',
|
||||
);
|
||||
|
||||
$moduleInfoMoment = array(
|
||||
'localBasePath' => __DIR__ . '/resources/momentjs',
|
||||
'remoteExtPath' => 'MultimediaViewer/resources/momentjs',
|
||||
|
@ -101,7 +106,38 @@ $wgResourceModules['mmv.model'] = array_merge( array(
|
|||
'mmv.base',
|
||||
'oojs',
|
||||
),
|
||||
), $moduleInfoMMV );
|
||||
), $moduleInfoMMVM );
|
||||
|
||||
$wgResourceModules['mmv.model.FileUsage'] = array_merge( array(
|
||||
'scripts' => array(
|
||||
'mmv.model.FileUsage.js',
|
||||
),
|
||||
|
||||
'dependencies' => array(
|
||||
'mmv.model',
|
||||
),
|
||||
), $moduleInfoMMVM );
|
||||
|
||||
$wgResourceModules['mmv.model.Image'] = array_merge( array(
|
||||
'scripts' => array(
|
||||
'mmv.model.Image.js',
|
||||
),
|
||||
|
||||
'dependencies' => array(
|
||||
'mmv.model',
|
||||
),
|
||||
), $moduleInfoMMVM );
|
||||
|
||||
$wgResourceModules['mmv.model.Repo'] = array_merge( array(
|
||||
'scripts' => array(
|
||||
'mmv.model.Repo.js',
|
||||
),
|
||||
|
||||
'dependencies' => array(
|
||||
'mmv.model',
|
||||
'oojs',
|
||||
),
|
||||
), $moduleInfoMMVM );
|
||||
|
||||
$wgResourceModules['mmv.provider'] = array_merge( array(
|
||||
'scripts' => array(
|
||||
|
@ -159,6 +195,9 @@ $wgResourceModules['mmv'] = array_merge( array(
|
|||
'jquery.ui.dialog',
|
||||
'jquery.hidpi',
|
||||
'mmv.model',
|
||||
'mmv.model.FileUsage',
|
||||
'mmv.model.Image',
|
||||
'mmv.model.Repo',
|
||||
'mmv.provider',
|
||||
'mediawiki.language',
|
||||
),
|
||||
|
|
92
resources/mmv/model/mmv.model.FileUsage.js
Normal file
92
resources/mmv/model/mmv.model.FileUsage.js
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* This file is part of the MediaWiki extension MultimediaViewer.
|
||||
*
|
||||
* MultimediaViewer is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MultimediaViewer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
( function ( mw ) {
|
||||
/**
|
||||
* @class mw.mmv.model.FileUsage
|
||||
* Represents information about the wiki pages using a given file
|
||||
* @constructor
|
||||
* @param {mw.Title} file see {@link mw.mmv.model.FileUsage#file}
|
||||
* @param {mw.mmv.model.FileUsage.Scope} scope see {@link mw.mmv.model.FileUsage#scope}
|
||||
* @param {{wiki: (string|null), page: mw.Title}[]} pages see {@link mw.mmv.model.FileUsage#pages}
|
||||
* @param {number} [totalCount] see {@link mw.mmv.model.FileUsage#totalCount}
|
||||
* @param {boolean} [totalCountIsLowerBound = false] see {@link mw.mmv.model.FileUsage#totalCountIsLowerBound} *
|
||||
*/
|
||||
function FileUsage(
|
||||
file,
|
||||
scope,
|
||||
pages,
|
||||
totalCount,
|
||||
totalCountIsLowerBound
|
||||
) {
|
||||
/**
|
||||
* The file in question.
|
||||
* @property {mw.Title}
|
||||
*/
|
||||
this.file = file;
|
||||
|
||||
/**
|
||||
* Shows what wikis we are interested in.
|
||||
* @property {mw.mmv.model.FileUsage.Scope}
|
||||
*/
|
||||
this.scope = scope;
|
||||
|
||||
/**
|
||||
* A list of pages which use this file. Each page is an object with a 'page' field
|
||||
* containing the wiki page (a Title object) and a 'wiki' field which is a domain name,
|
||||
* or null for local files.
|
||||
* @property {{wiki: (string|null), page: mw.Title}[]}
|
||||
*/
|
||||
this.pages = pages;
|
||||
|
||||
/**
|
||||
* Total number of pages where the file is used (the list passed in pages parameter might
|
||||
* be cut off at some limit).
|
||||
* @property {number} totalCount
|
||||
*/
|
||||
this.totalCount = totalCount || pages.length;
|
||||
|
||||
/**
|
||||
* For files which are used on a huge amount of pages, getting an exact count might be
|
||||
* impossible. In such a case this field tells us that the count is "fake". For example
|
||||
* if totalCount is 100 and totalCountIsLowerBound is true, a message about usage count
|
||||
* should be something like "this file is used on more than 100 pages". (This would happen
|
||||
* when we query the api with a limit of 100; the real usage count could be in the millions
|
||||
* for all we know.)
|
||||
* @property {boolean}
|
||||
*/
|
||||
this.totalCountIsLowerBound = !!totalCountIsLowerBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows which wikis are included in the file usage list.
|
||||
* @enum {string} mw.mmv.model.FileUsage.Scope
|
||||
*/
|
||||
FileUsage.Scope = {
|
||||
/**
|
||||
* Only pages from the local wiki (the one where the user is now)
|
||||
*/
|
||||
LOCAL: 'local',
|
||||
|
||||
/**
|
||||
* Only pages from other wikis
|
||||
*/
|
||||
GLOBAL: 'global'
|
||||
};
|
||||
|
||||
mw.mmv.model.FileUsage = FileUsage;
|
||||
}( mediaWiki ) );
|
|
@ -15,7 +15,7 @@
|
|||
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
( function ( mw, oo ) {
|
||||
( function ( mw ) {
|
||||
/**
|
||||
* @class mw.mmv.model.Image
|
||||
* Represents information about a single image
|
||||
|
@ -223,190 +223,5 @@
|
|||
this.longitude !== undefined && this.longitude !== null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class mw.mmv.model.Repo
|
||||
* Represents information about a single image repository
|
||||
* @constructor
|
||||
* @param {string} displayName
|
||||
* @param {string} favIcon URL to the repo's favicon
|
||||
* @param {boolean} isLocal
|
||||
*/
|
||||
function Repo(
|
||||
displayName,
|
||||
favIcon,
|
||||
isLocal
|
||||
) {
|
||||
/** @property {string} displayName Human-readable name of the repository */
|
||||
this.displayName = displayName;
|
||||
|
||||
/** @property {string} favIcon An icon that represents the repository */
|
||||
this.favIcon = favIcon;
|
||||
|
||||
/** @property {boolean} isLocal Whether the repository is the local wiki */
|
||||
this.isLocal = isLocal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @static
|
||||
* Creates a new object from repoInfo we found in an API response.
|
||||
* @param {Object} repoInfo
|
||||
* @returns {mw.mmv.model.Repo}
|
||||
*/
|
||||
Repo.newFromRepoInfo = function ( repoInfo ) {
|
||||
if ( repoInfo.apiurl ) {
|
||||
return new ForeignApiRepo(
|
||||
repoInfo.displayname,
|
||||
repoInfo.favicon,
|
||||
false,
|
||||
repoInfo.apiurl,
|
||||
repoInfo.server,
|
||||
repoInfo.articlepath
|
||||
);
|
||||
} else if ( repoInfo.descBaseUrl ) {
|
||||
return new ForeignDbRepo(
|
||||
repoInfo.displayname,
|
||||
repoInfo.favicon,
|
||||
false,
|
||||
repoInfo.descBaseUrl
|
||||
);
|
||||
} else {
|
||||
return new Repo( repoInfo.displayname, repoInfo.favicon, repoInfo.local );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @class mw.mmv.model.ForeignApiRepo
|
||||
* Represents information about a foreign API repository
|
||||
* @extends mw.mmv.model.Repo
|
||||
* @constructor
|
||||
* @inheritdoc
|
||||
* @param {string} apiUrl URL to the wiki's api.php
|
||||
* @param {string} server Hostname for the wiki
|
||||
* @param {string} articlePath Path to articles on the wiki, relative to the hostname.
|
||||
*/
|
||||
function ForeignApiRepo(
|
||||
displayName,
|
||||
favIcon,
|
||||
isLocal,
|
||||
apiUrl,
|
||||
server,
|
||||
articlePath
|
||||
) {
|
||||
Repo.call( this, displayName, favIcon, isLocal );
|
||||
|
||||
/** @property {string} apiUrl URL to the wiki's api.php */
|
||||
this.apiUrl = apiUrl;
|
||||
|
||||
/** @property {string} server Hostname for the wiki */
|
||||
this.server = server;
|
||||
|
||||
/** @property {string} articlePath Path to articles on the wiki, relative to the hostname */
|
||||
this.articlePath = articlePath;
|
||||
|
||||
/** @property {string} absoluteArticlePath Path to articles on the wiki, relative to nothing */
|
||||
this.absoluteArticlePath = server + articlePath;
|
||||
}
|
||||
|
||||
oo.inheritClass( ForeignApiRepo, Repo );
|
||||
|
||||
/**
|
||||
* @class mw.mmv.model.ForeignDbRepo
|
||||
* Represents information about a foreign, shared DB repository
|
||||
* @extends mw.mmv.model.Repo
|
||||
* @constructor
|
||||
* @inheritdoc
|
||||
*/
|
||||
function ForeignDbRepo(
|
||||
displayName,
|
||||
favIcon,
|
||||
isLocal,
|
||||
descBaseUrl
|
||||
) {
|
||||
Repo.call( this, displayName, favIcon, isLocal );
|
||||
|
||||
/** @property {string} descBaseUrl Base URL for descriptions on the wiki - append a file's title to this to get the description page */
|
||||
this.descBaseUrl = descBaseUrl;
|
||||
}
|
||||
|
||||
oo.inheritClass( ForeignDbRepo, Repo );
|
||||
|
||||
/**
|
||||
* @class mw.mmv.model.FileUsage
|
||||
* Represents information about the wiki pages using a given file
|
||||
* @constructor
|
||||
* @param {mw.Title} file see {@link mw.mmv.model.FileUsage#file}
|
||||
* @param {mw.mmv.model.FileUsage.Scope} scope see {@link mw.mmv.model.FileUsage#scope}
|
||||
* @param {{wiki: (string|null), page: mw.Title}[]} pages see {@link mw.mmv.model.FileUsage#pages}
|
||||
* @param {number} [totalCount] see {@link mw.mmv.model.FileUsage#totalCount}
|
||||
* @param {boolean} [totalCountIsLowerBound = false] see {@link mw.mmv.model.FileUsage#totalCountIsLowerBound} *
|
||||
*/
|
||||
function FileUsage(
|
||||
file,
|
||||
scope,
|
||||
pages,
|
||||
totalCount,
|
||||
totalCountIsLowerBound
|
||||
) {
|
||||
/**
|
||||
* The file in question.
|
||||
* @property {mw.Title}
|
||||
*/
|
||||
this.file = file;
|
||||
|
||||
/**
|
||||
* Shows what wikis we are interested in.
|
||||
* @property {mw.mmv.model.FileUsage.Scope}
|
||||
*/
|
||||
this.scope = scope;
|
||||
|
||||
/**
|
||||
* A list of pages which use this file. Each page is an object with a 'page' field
|
||||
* containing the wiki page (a Title object) and a 'wiki' field which is a domain name,
|
||||
* or null for local files.
|
||||
* @property {{wiki: (string|null), page: mw.Title}[]}
|
||||
*/
|
||||
this.pages = pages;
|
||||
|
||||
/**
|
||||
* Total number of pages where the file is used (the list passed in pages parameter might
|
||||
* be cut off at some limit).
|
||||
* @property {number} totalCount
|
||||
*/
|
||||
this.totalCount = totalCount || pages.length;
|
||||
|
||||
/**
|
||||
* For files which are used on a huge amount of pages, getting an exact count might be
|
||||
* impossible. In such a case this field tells us that the count is "fake". For example
|
||||
* if totalCount is 100 and totalCountIsLowerBound is true, a message about usage count
|
||||
* should be something like "this file is used on more than 100 pages". (This would happen
|
||||
* when we query the api with a limit of 100; the real usage count could be in the millions
|
||||
* for all we know.)
|
||||
* @property {boolean}
|
||||
*/
|
||||
this.totalCountIsLowerBound = !!totalCountIsLowerBound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows which wikis are included in the file usage list.
|
||||
* @enum {string} mw.mmv.model.FileUsage.Scope
|
||||
*/
|
||||
FileUsage.Scope = {
|
||||
/**
|
||||
* Only pages from the local wiki (the one where the user is now)
|
||||
*/
|
||||
LOCAL: 'local',
|
||||
|
||||
/**
|
||||
* Only pages from other wikis
|
||||
*/
|
||||
GLOBAL: 'global'
|
||||
};
|
||||
|
||||
mw.mmv.model = {};
|
||||
mw.mmv.model.Image = Image;
|
||||
mw.mmv.model.Repo = Repo;
|
||||
mw.mmv.model.ForeignApiRepo = ForeignApiRepo;
|
||||
mw.mmv.model.ForeignDbRepo = ForeignDbRepo;
|
||||
mw.mmv.model.FileUsage = FileUsage;
|
||||
}( mediaWiki, OO ) );
|
||||
}( mediaWiki ) );
|
130
resources/mmv/model/mmv.model.Repo.js
Normal file
130
resources/mmv/model/mmv.model.Repo.js
Normal file
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* This file is part of the MediaWiki extension MultimediaViewer.
|
||||
*
|
||||
* MultimediaViewer is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MultimediaViewer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
( function ( mw, oo ) {
|
||||
/**
|
||||
* @class mw.mmv.model.Repo
|
||||
* Represents information about a single image repository
|
||||
* @constructor
|
||||
* @param {string} displayName
|
||||
* @param {string} favIcon URL to the repo's favicon
|
||||
* @param {boolean} isLocal
|
||||
*/
|
||||
function Repo(
|
||||
displayName,
|
||||
favIcon,
|
||||
isLocal
|
||||
) {
|
||||
/** @property {string} displayName Human-readable name of the repository */
|
||||
this.displayName = displayName;
|
||||
|
||||
/** @property {string} favIcon An icon that represents the repository */
|
||||
this.favIcon = favIcon;
|
||||
|
||||
/** @property {boolean} isLocal Whether the repository is the local wiki */
|
||||
this.isLocal = isLocal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @static
|
||||
* Creates a new object from repoInfo we found in an API response.
|
||||
* @param {Object} repoInfo
|
||||
* @returns {mw.mmv.model.Repo}
|
||||
*/
|
||||
Repo.newFromRepoInfo = function ( repoInfo ) {
|
||||
if ( repoInfo.apiurl ) {
|
||||
return new ForeignApiRepo(
|
||||
repoInfo.displayname,
|
||||
repoInfo.favicon,
|
||||
false,
|
||||
repoInfo.apiurl,
|
||||
repoInfo.server,
|
||||
repoInfo.articlepath
|
||||
);
|
||||
} else if ( repoInfo.descBaseUrl ) {
|
||||
return new ForeignDbRepo(
|
||||
repoInfo.displayname,
|
||||
repoInfo.favicon,
|
||||
false,
|
||||
repoInfo.descBaseUrl
|
||||
);
|
||||
} else {
|
||||
return new Repo( repoInfo.displayname, repoInfo.favicon, repoInfo.local );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @class mw.mmv.model.ForeignApiRepo
|
||||
* Represents information about a foreign API repository
|
||||
* @extends mw.mmv.model.Repo
|
||||
* @constructor
|
||||
* @inheritdoc
|
||||
* @param {string} apiUrl URL to the wiki's api.php
|
||||
* @param {string} server Hostname for the wiki
|
||||
* @param {string} articlePath Path to articles on the wiki, relative to the hostname.
|
||||
*/
|
||||
function ForeignApiRepo(
|
||||
displayName,
|
||||
favIcon,
|
||||
isLocal,
|
||||
apiUrl,
|
||||
server,
|
||||
articlePath
|
||||
) {
|
||||
Repo.call( this, displayName, favIcon, isLocal );
|
||||
|
||||
/** @property {string} apiUrl URL to the wiki's api.php */
|
||||
this.apiUrl = apiUrl;
|
||||
|
||||
/** @property {string} server Hostname for the wiki */
|
||||
this.server = server;
|
||||
|
||||
/** @property {string} articlePath Path to articles on the wiki, relative to the hostname */
|
||||
this.articlePath = articlePath;
|
||||
|
||||
/** @property {string} absoluteArticlePath Path to articles on the wiki, relative to nothing */
|
||||
this.absoluteArticlePath = server + articlePath;
|
||||
}
|
||||
|
||||
oo.inheritClass( ForeignApiRepo, Repo );
|
||||
|
||||
/**
|
||||
* @class mw.mmv.model.ForeignDbRepo
|
||||
* Represents information about a foreign, shared DB repository
|
||||
* @extends mw.mmv.model.Repo
|
||||
* @constructor
|
||||
* @inheritdoc
|
||||
*/
|
||||
function ForeignDbRepo(
|
||||
displayName,
|
||||
favIcon,
|
||||
isLocal,
|
||||
descBaseUrl
|
||||
) {
|
||||
Repo.call( this, displayName, favIcon, isLocal );
|
||||
|
||||
/** @property {string} descBaseUrl Base URL for descriptions on the wiki - append a file's title to this to get the description page */
|
||||
this.descBaseUrl = descBaseUrl;
|
||||
}
|
||||
|
||||
oo.inheritClass( ForeignDbRepo, Repo );
|
||||
|
||||
mw.mmv.model.Repo = Repo;
|
||||
mw.mmv.model.ForeignApiRepo = ForeignApiRepo;
|
||||
mw.mmv.model.ForeignDbRepo = ForeignDbRepo;
|
||||
}( mediaWiki, OO ) );
|
20
resources/mmv/model/mmv.model.js
Normal file
20
resources/mmv/model/mmv.model.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* This file is part of the MediaWiki extension MultimediaViewer.
|
||||
*
|
||||
* MultimediaViewer is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MultimediaViewer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
( function ( mw ) {
|
||||
mw.mmv.model = {};
|
||||
}( mediaWiki ) );
|
Loading…
Reference in a new issue