2010-10-19 18:25:42 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-04-30 07:16:10 +00:00
|
|
|
* Abstraction for resource loader modules which pull from wiki pages.
|
|
|
|
|
*
|
2010-10-19 18:25:42 +00:00
|
|
|
* 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
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @author Trevor Parscal
|
|
|
|
|
* @author Roan Kattouw
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Abstraction for resource loader modules which pull from wiki pages
|
2011-10-14 08:06:54 +00:00
|
|
|
*
|
|
|
|
|
* This can only be used for wiki pages in the MediaWiki and User namespaces,
|
|
|
|
|
* because of its dependence on the functionality of
|
2011-12-13 11:54:02 +00:00
|
|
|
* Title::isCssJsSubpage.
|
2010-10-19 18:25:42 +00:00
|
|
|
*/
|
|
|
|
|
abstract class ResourceLoaderWikiModule extends ResourceLoaderModule {
|
2011-10-14 08:06:54 +00:00
|
|
|
|
2010-10-19 18:25:42 +00:00
|
|
|
/* Protected Members */
|
2011-02-04 16:39:17 +00:00
|
|
|
|
|
|
|
|
# Origin is user-supplied code
|
|
|
|
|
protected $origin = self::ORIGIN_USER_SITEWIDE;
|
2011-10-14 08:06:54 +00:00
|
|
|
|
2011-02-19 17:07:05 +00:00
|
|
|
// In-object cache for title mtimes
|
|
|
|
|
protected $titleMtimes = array();
|
2011-10-14 08:06:54 +00:00
|
|
|
|
2010-10-19 18:25:42 +00:00
|
|
|
/* Abstract Protected Methods */
|
2011-10-14 08:06:54 +00:00
|
|
|
|
|
|
|
|
/**
|
2012-12-18 08:31:59 +00:00
|
|
|
* Subclasses should return an associative array of resources in the module.
|
|
|
|
|
* Keys should be the title of a page in the MediaWiki or User namespace.
|
|
|
|
|
*
|
|
|
|
|
* Values should be a nested array of options. The supported keys are 'type' and
|
|
|
|
|
* (CSS only) 'media'.
|
|
|
|
|
*
|
|
|
|
|
* For scripts, 'type' should be 'script'.
|
|
|
|
|
*
|
|
|
|
|
* For stylesheets, 'type' should be 'style'.
|
|
|
|
|
* There is an optional media key, the value of which can be the
|
|
|
|
|
* medium ('screen', 'print', etc.) of the stylesheet.
|
|
|
|
|
*
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2012-12-18 08:31:59 +00:00
|
|
|
* @return array
|
2011-10-14 08:06:54 +00:00
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
abstract protected function getPages( ResourceLoaderContext $context );
|
2011-10-14 08:06:54 +00:00
|
|
|
|
2010-10-19 18:25:42 +00:00
|
|
|
/* Protected Methods */
|
2011-10-14 08:06:54 +00:00
|
|
|
|
2011-08-02 15:47:30 +00:00
|
|
|
/**
|
|
|
|
|
* Get the Database object used in getTitleMTimes(). Defaults to the local slave DB
|
2011-11-02 15:04:34 +00:00
|
|
|
* but subclasses may want to override this to return a remote DB object, or to return
|
|
|
|
|
* null if getTitleMTimes() shouldn't access the DB at all.
|
2011-10-14 08:06:54 +00:00
|
|
|
*
|
2011-08-02 15:47:30 +00:00
|
|
|
* NOTE: This ONLY works for getTitleMTimes() and getModifiedTime(), NOT FOR ANYTHING ELSE.
|
|
|
|
|
* In particular, it doesn't work for getting the content of JS and CSS pages. That functionality
|
|
|
|
|
* will use the local DB irrespective of the return value of this method.
|
2011-10-14 08:06:54 +00:00
|
|
|
*
|
2011-11-02 15:04:34 +00:00
|
|
|
* @return DatabaseBase|null
|
2011-08-02 15:47:30 +00:00
|
|
|
*/
|
|
|
|
|
protected function getDB() {
|
|
|
|
|
return wfGetDB( DB_SLAVE );
|
|
|
|
|
}
|
2011-02-08 23:09:22 +00:00
|
|
|
|
|
|
|
|
/**
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param Title $title
|
2011-02-08 23:09:22 +00:00
|
|
|
* @return null|string
|
|
|
|
|
*/
|
2011-02-08 06:34:38 +00:00
|
|
|
protected function getContent( $title ) {
|
2011-08-02 16:00:42 +00:00
|
|
|
if ( !$title->isCssJsSubpage() && !$title->isCssOrJsPage() ) {
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
2012-09-05 15:50:13 +00:00
|
|
|
$revision = Revision::newFromTitle( $title, false, Revision::READ_NORMAL );
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
if ( !$revision ) {
|
|
|
|
|
return null;
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
2012-06-08 06:31:28 +00:00
|
|
|
|
|
|
|
|
$content = $revision->getContent( Revision::RAW );
|
2012-10-24 13:00:13 +00:00
|
|
|
|
|
|
|
|
if ( !$content ) {
|
2013-05-02 02:13:13 +00:00
|
|
|
wfDebugLog( 'resourceloader', __METHOD__ . ': failed to load content of JS/CSS page!' );
|
2012-10-24 13:00:13 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 06:31:28 +00:00
|
|
|
$model = $content->getModel();
|
|
|
|
|
|
|
|
|
|
if ( $model !== CONTENT_MODEL_CSS && $model !== CONTENT_MODEL_JAVASCRIPT ) {
|
2013-05-02 02:13:13 +00:00
|
|
|
wfDebugLog( 'resourceloader', __METHOD__ . ': bad content model $model for JS/CSS page!' );
|
2012-06-08 06:31:28 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $content->getNativeData(); //NOTE: this is safe, we know it's JS or CSS
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
2011-10-14 08:06:54 +00:00
|
|
|
|
2010-10-19 18:25:42 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2011-05-21 17:45:20 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getScript( ResourceLoaderContext $context ) {
|
|
|
|
|
$scripts = '';
|
2011-02-08 06:34:38 +00:00
|
|
|
foreach ( $this->getPages( $context ) as $titleText => $options ) {
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
if ( $options['type'] !== 'script' ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2011-02-08 06:34:38 +00:00
|
|
|
$title = Title::newFromText( $titleText );
|
2011-08-10 14:23:25 +00:00
|
|
|
if ( !$title || $title->isRedirect() ) {
|
2011-02-08 06:34:38 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$script = $this->getContent( $title );
|
|
|
|
|
if ( strval( $script ) !== '' ) {
|
2011-07-06 21:48:09 +00:00
|
|
|
$script = $this->validateScriptFile( $titleText, $script );
|
2014-04-12 08:16:42 +00:00
|
|
|
$scripts .= ResourceLoader::makeComment( $titleText ) . $script . "\n";
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $scripts;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2011-05-21 17:45:20 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getStyles( ResourceLoaderContext $context ) {
|
2011-02-11 22:57:32 +00:00
|
|
|
global $wgScriptPath;
|
2011-10-14 08:06:54 +00:00
|
|
|
|
2010-10-19 18:25:42 +00:00
|
|
|
$styles = array();
|
2011-02-08 06:34:38 +00:00
|
|
|
foreach ( $this->getPages( $context ) as $titleText => $options ) {
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
if ( $options['type'] !== 'style' ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2011-02-08 06:34:38 +00:00
|
|
|
$title = Title::newFromText( $titleText );
|
2013-02-03 18:30:03 +00:00
|
|
|
if ( !$title || $title->isRedirect() ) {
|
2011-02-08 06:34:38 +00:00
|
|
|
continue;
|
2011-10-14 08:06:54 +00:00
|
|
|
}
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
$media = isset( $options['media'] ) ? $options['media'] : 'all';
|
2011-02-08 06:34:38 +00:00
|
|
|
$style = $this->getContent( $title );
|
|
|
|
|
if ( strval( $style ) === '' ) {
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2010-12-16 19:31:48 +00:00
|
|
|
if ( $this->getFlip( $context ) ) {
|
|
|
|
|
$style = CSSJanus::transform( $style, true, false );
|
|
|
|
|
}
|
2011-02-11 22:57:32 +00:00
|
|
|
$style = CSSMin::remap( $style, false, $wgScriptPath, true );
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
if ( !isset( $styles[$media] ) ) {
|
ResourceLoader: Refactor style loading
Fixes:
* bug 31676: Work around IE stylesheet limit.
* bug 35562: @import styles broken in modules that combine
multiple stylesheets.
* bug 40498: Don't output empty "@media print { }" blocks.
* bug 40500: Don't ignore media-type for urls in debug mode.
Approach:
* Re-use the same <style> tag so that we stay under the 31
stylesheet limit in IE. Unless the to-be-added css text from
the being-loaded module contains @import, in which case we do
create a new <style> tag and then re-use that one from that
point on (bug 31676).
* Return stylesheets as arrays, instead of a concatenated string.
This fixes bug 35562, because @import only works when at the
top of a stylesheet. By not unconditionally concatenating files
within a module on the server side already, @import will work
in e.g. module 'site' that contains 2 wiki pages.
This is normalized in ResourceLoader::makeCombinedStyles(),
so far only ResourceLoaderWikiModule makes use of this.
Misc. clean up and bug fixes:
* Reducing usage of jQuery() and mw.html.element() where
native DOM would be very simple and faster. Aside from
simplicity and speed, this is also working towards a more
stand-alone ResourceLoader.
* Trim server output a little bit more
- Redundant new line after minify-css (it is now an array, so
no need to keep space afterwards)
- Redundant semi-colon after minify-js if it ends in a colon
* Allow space in styleTest.css.php
* Clean up and extend unit tests to cover for these features
and bug fixes.
* Don't set styleEl.rel = 'stylesheet'; that has no business
on a <style> tag.
* Fix bug in mw.loader's addStyleTag(). It turns out IE6
has an odd security measure that does not allow manipulation
of elements (at least style tags) that are created by a
different script (even if that script was served from the same
domain/origin etc.). We didn't ran into this before because
we only created new style tags, never appended to them. Now
that we do, this came up. Took a while to figure out because
it was created by mediawiki.js but it calls jQuery which did
the actual dom insertion. Odd thing is, we load jquery.js and
mediawiki.js in the same request even...
Without this all css-url related mw.loader tests would fail
in IE6.
* mediawiki.js and mediawiki.test.js now pass jshint again.
Tested (and passing qunit/?module=mediawiki; 123 of 123):
* Chrome 14, 21
* Firefox 3.0, 3.6, 4, 7, 14, 15, 16beta
* IE 6, 7, 8, 9
* Safari 4.0, 5.0, 5.1
* Opera 10.0, 11.1, 11.5, 11.6, 12.0, 12.5beta
* iPhone 3GS / iOS 3.0 / Mobile Safari 4.0
iPhone 4 / iOS 4.0.1 / Mobile Safari 4.0.5
iPhone 4S / iOS 6.0 Beta / Mobile Safari 6.0
Change-Id: I3e8227ddb87fd9441071ca935439fc6467751dab
2012-07-25 21:20:21 +00:00
|
|
|
$styles[$media] = array();
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
2014-04-12 08:16:42 +00:00
|
|
|
$style = ResourceLoader::makeComment( $titleText ) . $style;
|
ResourceLoader: Refactor style loading
Fixes:
* bug 31676: Work around IE stylesheet limit.
* bug 35562: @import styles broken in modules that combine
multiple stylesheets.
* bug 40498: Don't output empty "@media print { }" blocks.
* bug 40500: Don't ignore media-type for urls in debug mode.
Approach:
* Re-use the same <style> tag so that we stay under the 31
stylesheet limit in IE. Unless the to-be-added css text from
the being-loaded module contains @import, in which case we do
create a new <style> tag and then re-use that one from that
point on (bug 31676).
* Return stylesheets as arrays, instead of a concatenated string.
This fixes bug 35562, because @import only works when at the
top of a stylesheet. By not unconditionally concatenating files
within a module on the server side already, @import will work
in e.g. module 'site' that contains 2 wiki pages.
This is normalized in ResourceLoader::makeCombinedStyles(),
so far only ResourceLoaderWikiModule makes use of this.
Misc. clean up and bug fixes:
* Reducing usage of jQuery() and mw.html.element() where
native DOM would be very simple and faster. Aside from
simplicity and speed, this is also working towards a more
stand-alone ResourceLoader.
* Trim server output a little bit more
- Redundant new line after minify-css (it is now an array, so
no need to keep space afterwards)
- Redundant semi-colon after minify-js if it ends in a colon
* Allow space in styleTest.css.php
* Clean up and extend unit tests to cover for these features
and bug fixes.
* Don't set styleEl.rel = 'stylesheet'; that has no business
on a <style> tag.
* Fix bug in mw.loader's addStyleTag(). It turns out IE6
has an odd security measure that does not allow manipulation
of elements (at least style tags) that are created by a
different script (even if that script was served from the same
domain/origin etc.). We didn't ran into this before because
we only created new style tags, never appended to them. Now
that we do, this came up. Took a while to figure out because
it was created by mediawiki.js but it calls jQuery which did
the actual dom insertion. Odd thing is, we load jquery.js and
mediawiki.js in the same request even...
Without this all css-url related mw.loader tests would fail
in IE6.
* mediawiki.js and mediawiki.test.js now pass jshint again.
Tested (and passing qunit/?module=mediawiki; 123 of 123):
* Chrome 14, 21
* Firefox 3.0, 3.6, 4, 7, 14, 15, 16beta
* IE 6, 7, 8, 9
* Safari 4.0, 5.0, 5.1
* Opera 10.0, 11.1, 11.5, 11.6, 12.0, 12.5beta
* iPhone 3GS / iOS 3.0 / Mobile Safari 4.0
iPhone 4 / iOS 4.0.1 / Mobile Safari 4.0.5
iPhone 4S / iOS 6.0 Beta / Mobile Safari 6.0
Change-Id: I3e8227ddb87fd9441071ca935439fc6467751dab
2012-07-25 21:20:21 +00:00
|
|
|
$styles[$media][] = $style;
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
return $styles;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2011-05-21 17:45:20 +00:00
|
|
|
* @return int|mixed
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getModifiedTime( ResourceLoaderContext $context ) {
|
|
|
|
|
$modifiedTime = 1; // wfTimestamp() interprets 0 as "now"
|
2011-02-19 17:07:05 +00:00
|
|
|
$mtimes = $this->getTitleMtimes( $context );
|
|
|
|
|
if ( count( $mtimes ) ) {
|
|
|
|
|
$modifiedTime = max( $modifiedTime, max( $mtimes ) );
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
2013-10-18 13:34:50 +00:00
|
|
|
$modifiedTime = max(
|
|
|
|
|
$modifiedTime,
|
|
|
|
|
$this->getMsgBlobMtime( $context->getLanguage() ),
|
|
|
|
|
$this->getDefinitionMtime( $context )
|
|
|
|
|
);
|
2011-02-08 06:34:38 +00:00
|
|
|
return $modifiedTime;
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
2011-05-21 17:45:20 +00:00
|
|
|
|
2013-10-18 13:34:50 +00:00
|
|
|
/**
|
|
|
|
|
* Get the definition summary for this module.
|
|
|
|
|
*
|
2014-04-20 21:33:05 +00:00
|
|
|
* @return array
|
2013-10-18 13:34:50 +00:00
|
|
|
*/
|
|
|
|
|
public function getDefinitionSummary( ResourceLoaderContext $context ) {
|
|
|
|
|
return array(
|
|
|
|
|
'class' => get_class( $this ),
|
|
|
|
|
'pages' => $this->getPages( $context ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2011-05-21 17:45:20 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2011-02-19 17:07:05 +00:00
|
|
|
public function isKnownEmpty( ResourceLoaderContext $context ) {
|
|
|
|
|
return count( $this->getTitleMtimes( $context ) ) == 0;
|
|
|
|
|
}
|
2011-02-18 00:33:45 +00:00
|
|
|
|
2011-02-19 17:07:05 +00:00
|
|
|
/**
|
|
|
|
|
* Get the modification times of all titles that would be loaded for
|
|
|
|
|
* a given context.
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param ResourceLoaderContext $context Context object
|
2011-02-19 17:07:05 +00:00
|
|
|
* @return array( prefixed DB key => UNIX timestamp ), nonexistent titles are dropped
|
|
|
|
|
*/
|
|
|
|
|
protected function getTitleMtimes( ResourceLoaderContext $context ) {
|
2011-11-02 15:04:34 +00:00
|
|
|
$dbr = $this->getDB();
|
|
|
|
|
if ( !$dbr ) {
|
|
|
|
|
// We're dealing with a subclass that doesn't have a DB
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2012-09-05 15:50:13 +00:00
|
|
|
|
2011-02-19 17:07:05 +00:00
|
|
|
$hash = $context->getHash();
|
|
|
|
|
if ( isset( $this->titleMtimes[$hash] ) ) {
|
|
|
|
|
return $this->titleMtimes[$hash];
|
|
|
|
|
}
|
2011-10-14 08:06:54 +00:00
|
|
|
|
2011-02-19 17:07:05 +00:00
|
|
|
$this->titleMtimes[$hash] = array();
|
|
|
|
|
$batch = new LinkBatch;
|
|
|
|
|
foreach ( $this->getPages( $context ) as $titleText => $options ) {
|
|
|
|
|
$batch->addObj( Title::newFromText( $titleText ) );
|
|
|
|
|
}
|
2011-10-14 08:06:54 +00:00
|
|
|
|
2011-02-19 17:07:05 +00:00
|
|
|
if ( !$batch->isEmpty() ) {
|
|
|
|
|
$res = $dbr->select( 'page',
|
|
|
|
|
array( 'page_namespace', 'page_title', 'page_touched' ),
|
|
|
|
|
$batch->constructSet( 'page', $dbr ),
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
|
|
|
|
|
$this->titleMtimes[$hash][$title->getPrefixedDBkey()] =
|
|
|
|
|
wfTimestamp( TS_UNIX, $row->page_touched );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $this->titleMtimes[$hash];
|
|
|
|
|
}
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|