2010-09-04 04:00:09 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program 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.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-09-04 12:53:01 +00:00
|
|
|
*
|
2010-09-05 13:31:34 +00:00
|
|
|
* @file
|
2010-09-04 04:00:09 +00:00
|
|
|
* @author Trevor Parscal
|
|
|
|
|
* @author Roan Kattouw
|
|
|
|
|
*/
|
|
|
|
|
|
2010-09-24 17:31:40 +00:00
|
|
|
defined( 'MEDIAWIKI' ) || die( 1 );
|
|
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
2010-09-10 23:28:59 +00:00
|
|
|
* Abstraction for resource loader modules, with name registration and maxage functionality.
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
|
|
|
|
abstract class ResourceLoaderModule {
|
2010-09-24 18:49:19 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/* Protected Members */
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
protected $name = null;
|
2010-09-23 21:23:51 +00:00
|
|
|
|
|
|
|
|
// In-object cache for file dependencies
|
|
|
|
|
protected $fileDeps = array();
|
|
|
|
|
// In-object cache for message blob mtime
|
|
|
|
|
protected $msgBlobMtime = array();
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/* Methods */
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
|
|
|
|
* Get this module's name. This is set when the module is registered
|
|
|
|
|
* with ResourceLoader::register()
|
2010-09-05 13:31:34 +00:00
|
|
|
*
|
|
|
|
|
* @return Mixed: name (string) or null if no name was set
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
|
|
|
|
public function getName() {
|
|
|
|
|
return $this->name;
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
|
|
|
|
* Set this module's name. This is called by ResourceLodaer::register()
|
|
|
|
|
* when registering the module. Other code should not call this.
|
2010-09-05 13:31:34 +00:00
|
|
|
*
|
|
|
|
|
* @param $name String: name
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
|
|
|
|
public function setName( $name ) {
|
|
|
|
|
$this->name = $name;
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 10:53:57 +00:00
|
|
|
/**
|
|
|
|
|
* Get whether CSS for this module should be flipped
|
|
|
|
|
*/
|
|
|
|
|
public function getFlip( $context ) {
|
|
|
|
|
return $context->getDirection() === 'rtl';
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
|
|
|
|
* Get all JS for this module for a given language and skin.
|
|
|
|
|
* Includes all relevant JS except loader scripts.
|
2010-09-05 13:31:34 +00:00
|
|
|
*
|
|
|
|
|
* @param $context ResourceLoaderContext object
|
|
|
|
|
* @return String: JS
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
2010-09-11 03:26:15 +00:00
|
|
|
public function getScript( ResourceLoaderContext $context ) {
|
|
|
|
|
// Stub, override expected
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
|
|
|
|
* Get all CSS for this module for a given skin.
|
2010-09-05 13:31:34 +00:00
|
|
|
*
|
|
|
|
|
* @param $context ResourceLoaderContext object
|
2010-09-10 00:21:36 +00:00
|
|
|
* @return array: strings of CSS keyed by media type
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
2010-09-11 03:26:15 +00:00
|
|
|
public function getStyles( ResourceLoaderContext $context ) {
|
|
|
|
|
// Stub, override expected
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
|
|
|
|
* Get the messages needed for this module.
|
|
|
|
|
*
|
|
|
|
|
* To get a JSON blob with messages, use MessageBlobStore::get()
|
2010-09-05 13:31:34 +00:00
|
|
|
*
|
2010-09-04 04:00:09 +00:00
|
|
|
* @return array of message keys. Keys may occur more than once
|
|
|
|
|
*/
|
2010-09-11 03:26:15 +00:00
|
|
|
public function getMessages() {
|
|
|
|
|
// Stub, override expected
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2010-09-20 21:23:29 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the group this module is in.
|
|
|
|
|
*
|
|
|
|
|
* @return string of group name
|
|
|
|
|
*/
|
|
|
|
|
public function getGroup() {
|
|
|
|
|
// Stub, override expected
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
|
|
|
|
* Get the loader JS for this module, if set.
|
2010-09-05 13:31:34 +00:00
|
|
|
*
|
|
|
|
|
* @return Mixed: loader JS (string) or false if no custom loader set
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
2010-09-11 03:26:15 +00:00
|
|
|
public function getLoaderScript() {
|
|
|
|
|
// Stub, override expected
|
2010-09-20 21:23:29 +00:00
|
|
|
return false;
|
2010-09-11 03:26:15 +00:00
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of modules this module depends on.
|
|
|
|
|
*
|
|
|
|
|
* Dependency information is taken into account when loading a module
|
|
|
|
|
* on the client side. When adding a module on the server side,
|
|
|
|
|
* dependency information is NOT taken into account and YOU are
|
|
|
|
|
* responsible for adding dependent modules as well. If you don't do
|
|
|
|
|
* this, the client side loader will send a second request back to the
|
|
|
|
|
* server to fetch the missing modules, which kind of defeats the
|
|
|
|
|
* purpose of the resource loader.
|
|
|
|
|
*
|
|
|
|
|
* To add dependencies dynamically on the client side, use a custom
|
|
|
|
|
* loader script, see getLoaderScript()
|
2010-09-05 13:31:34 +00:00
|
|
|
* @return Array of module names (strings)
|
2010-09-04 04:00:09 +00:00
|
|
|
*/
|
2010-09-11 03:26:15 +00:00
|
|
|
public function getDependencies() {
|
|
|
|
|
// Stub, override expected
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2010-09-23 21:23:51 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the files this module depends on indirectly for a given skin.
|
|
|
|
|
* Currently these are only image files referenced by the module's CSS.
|
|
|
|
|
*
|
|
|
|
|
* @param $skin String: skin name
|
|
|
|
|
* @return array of files
|
|
|
|
|
*/
|
|
|
|
|
public function getFileDependencies( $skin ) {
|
|
|
|
|
// Try in-object cache first
|
|
|
|
|
if ( isset( $this->fileDeps[$skin] ) ) {
|
|
|
|
|
return $this->fileDeps[$skin];
|
|
|
|
|
}
|
2010-09-04 12:53:01 +00:00
|
|
|
|
2010-09-23 21:23:51 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
$deps = $dbr->selectField( 'module_deps', 'md_deps', array(
|
|
|
|
|
'md_module' => $this->getName(),
|
|
|
|
|
'md_skin' => $skin,
|
|
|
|
|
), __METHOD__
|
|
|
|
|
);
|
|
|
|
|
if ( !is_null( $deps ) ) {
|
2010-09-24 17:19:27 +00:00
|
|
|
return $this->fileDeps[$skin] = (array) FormatJson::decode( $deps, true );
|
2010-09-23 21:23:51 +00:00
|
|
|
}
|
2010-09-24 18:16:59 +00:00
|
|
|
return $this->fileDeps[$skin] = array();
|
2010-09-23 21:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set preloaded file dependency information. Used so we can load this
|
|
|
|
|
* information for all modules at once.
|
|
|
|
|
* @param $skin string Skin name
|
|
|
|
|
* @param $deps array Array of file names
|
|
|
|
|
*/
|
|
|
|
|
public function setFileDependencies( $skin, $deps ) {
|
|
|
|
|
$this->fileDeps[$skin] = $deps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the last modification timestamp of the message blob for this
|
|
|
|
|
* module in a given language.
|
|
|
|
|
* @param $lang string Language code
|
|
|
|
|
* @return int UNIX timestamp, or 0 if no blob found
|
|
|
|
|
*/
|
|
|
|
|
public function getMsgBlobMtime( $lang ) {
|
|
|
|
|
if ( !count( $this->getMessages() ) )
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
$msgBlobMtime = $dbr->selectField( 'msg_resource', 'mr_timestamp', array(
|
|
|
|
|
'mr_resource' => $this->getName(),
|
|
|
|
|
'mr_lang' => $lang
|
|
|
|
|
), __METHOD__
|
|
|
|
|
);
|
|
|
|
|
$this->msgBlobMtime[$lang] = $msgBlobMtime ? wfTimestamp( TS_UNIX, $msgBlobMtime ) : 0;
|
|
|
|
|
return $this->msgBlobMtime[$lang];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a preloaded message blob last modification timestamp. Used so we
|
|
|
|
|
* can load this information for all modules at once.
|
|
|
|
|
* @param $lang string Language code
|
|
|
|
|
* @param $mtime int UNIX timestamp or 0 if there is no such blob
|
|
|
|
|
*/
|
|
|
|
|
public function setMsgBlobMtime( $lang, $mtime ) {
|
|
|
|
|
$this->msgBlobMtime[$lang] = $mtime;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-11 03:26:15 +00:00
|
|
|
/* Abstract Methods */
|
|
|
|
|
|
2010-09-04 04:00:09 +00:00
|
|
|
/**
|
|
|
|
|
* Get this module's last modification timestamp for a given
|
|
|
|
|
* combination of language, skin and debug mode flag. This is typically
|
|
|
|
|
* the highest of each of the relevant components' modification
|
|
|
|
|
* timestamps. Whenever anything happens that changes the module's
|
|
|
|
|
* contents for these parameters, the mtime should increase.
|
2010-09-05 13:31:34 +00:00
|
|
|
*
|
|
|
|
|
* @param $context ResourceLoaderContext object
|
2010-09-04 04:00:09 +00:00
|
|
|
* @return int UNIX timestamp
|
|
|
|
|
*/
|
2010-09-29 23:25:07 +00:00
|
|
|
public function getModifiedTime( ResourceLoaderContext $context ) {
|
|
|
|
|
// 0 would mean now
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2010-09-04 04:00:09 +00:00
|
|
|
}
|