return true;
}
-
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow(
'category',
__METHOD__
);
-
if ( !$row ) {
# Okay, there were no contents. Nothing to initialize.
if ( $this->mTitle ) {
)
);
-
return $result;
}
}
}
-
$dbw = wfGetDB( DB_MASTER );
$dbw->startAtomic( __METHOD__ );
);
$dbw->endAtomic( __METHOD__ );
-
# Now we should update our local counts.
$this->mPages = $result->pages;
$this->mSubcats = $result->subcats;
return;
}
-
$this->isConflict = false;
// css / js subpages of user pages get a special treatment
$this->isCssJsSubpage = $this->mTitle->isCssJsSubpage();
function importFormData( &$request ) {
global $wgContLang, $wgUser;
-
# Section edit can come from either the form or a link
$this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
protected function getContentObject( $def_content = null ) {
global $wgOut, $wgRequest, $wgUser, $wgContLang;
-
$content = false;
// For message page not locally set, use the i18n message.
$status = Status::newGood();
-
if ( !Hooks::run( 'EditPage::attemptSave', array( $this ) ) ) {
wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
$status->fatal( 'hookaborted' );
$code = $wgUser->isAnon() ? self::AS_IMAGE_REDIRECT_ANON : self::AS_IMAGE_REDIRECT_LOGGED;
$status->setResult( false, $code );
-
return $status;
}
return $status;
}
-
# Load the page data from the master. If anything changes in the meantime,
# we detect it by using page_latest like a token in a 1 try compare-and-swap.
$this->mArticle->loadPageData( 'fromdbmaster' );
function showEditForm( $formCallback = null ) {
global $wgOut, $wgUser;
-
# need to parse the preview early so that we know which templates are used,
# otherwise users with "show preview after edit box" will get a blank list
# we parse this near the beginning so that setHeaders can do the title
return '';
}
-
$limitReport = Html::rawElement( 'div', array( 'class' => 'mw-limitReportExplanation' ),
wfMessage( 'limitreport-title' )->parseAsBlock()
);
Html::closeElement( 'table' ) .
Html::closeElement( 'div' );
-
return $limitReport;
}
global $wgOut, $wgUser, $wgRawHtml, $wgLang;
global $wgAllowUserCss, $wgAllowUserJs;
-
if ( $wgRawHtml && !$this->mTokenOk ) {
// Could be an offsite preview attempt. This is very unsafe if
// HTML is enabled, as it could be an attack.
$this->parseHeader();
$this->setStatus();
-
return $this->status;
}
}
fclose( $fh );
-
return $this->status;
}
}
) {
wfDeprecated( __METHOD__, '1.21' );
-
if ( $text == '' ) {
$text = self::linkText( $title );
}
private function performRequest() {
global $wgTitle;
-
$request = $this->context->getRequest();
$requestTitle = $title = $this->context->getTitle();
$output = $this->context->getOutput();
echo "Waiting for a database server: $lag seconds lagged\n";
}
-
exit;
}
}
private function main() {
global $wgTitle;
-
$request = $this->context->getRequest();
// Send Ajax requests to the Ajax dispatcher.
return; // recursion guard
}
-
if ( $jobRunRate < 1 ) {
$max = mt_getrandmax();
if ( mt_rand( 0, $max ) > $max * $jobRunRate ) {
) {
global $wgParser;
-
$popts = $this->parserOptions();
$oldTidy = $popts->setTidy( $tidy );
$popts->setInterfaceMessage( (bool)$interface );
return;
}
-
$response = $this->getRequest()->response();
$config = $this->getConfig();
public function headElement( Skin $sk, $includeStyle = true ) {
global $wgContLang;
-
$userdir = $this->getLanguage()->getDir();
$sitedir = $wgContLang->getDir();
public function insertOn( $dbw ) {
global $wgDefaultExternalStore, $wgContentHandlerUseDB;
-
$this->checkContentModel();
$data = $this->mText;
$wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
}
-
return $text;
}
public static function newNullRevision( $dbw, $pageId, $summary, $minor, $user = null ) {
global $wgContentHandlerUseDB;
-
$fields = array( 'page_latest', 'page_namespace', 'page_title',
'rev_text_id', 'rev_len', 'rev_sha1' );
static $htmlpairsStatic, $htmlsingle, $htmlsingleonly, $htmlnest, $tabletags,
$htmllist, $listtags, $htmlsingleallowed, $htmlelementsStatic, $staticInitialised;
-
// Base our staticInitialised variable off of the global config state so that if the globals
// are changed (like in the screwed up test system) we will re-initialise the settings.
$globalContext = implode( '-', compact( 'wgAllowMicrodataAttributes', 'wgAllowImageTag' ) );
return array( $this->mHasCascadingRestrictions, $pagerestrictions );
}
-
$dbr = wfGetDB( DB_SLAVE );
if ( $this->getNamespace() == NS_FILE ) {
public function checkPassword( $password ) {
global $wgAuth, $wgLegacyEncoding;
-
$this->loadPasswords();
// Certain authentication plugins do NOT want to save
$s = $this->getCredits( -1 );
}
-
return Html::rawElement( 'div', array( 'id' => 'mw-credits' ), $s );
}
}
}
-
return $s;
}
return; // Client cache fresh and headers sent, nothing more to do.
}
-
$this->preCacheMessages();
$config = $this->context->getConfig();
__METHOD__
);
-
return $result;
}
$popts->setIsSectionPreview( $params['sectionpreview'] );
$popts->setEditSection( !$params['disableeditsection'] );
-
return $popts;
}
public function addLinkObj( $nt ) {
global $wgContentHandlerUseDB;
-
$key = $nt->getPrefixedDBkey();
if ( $this->isBadLink( $key ) || $nt->isExternal() ) {
$id = 0;
}
-
return $id;
}
}
}
-
// The JSON format only supports messages, none of the other variables, so wrap the data
return array( 'messages' => $data );
}
$deps['plurals'] = new FileDependency( "$IP/languages/data/plurals.xml" );
$deps['plurals-mw'] = new FileDependency( "$IP/languages/data/plurals-mediawiki.xml" );
-
return $data;
}
$codeSequence = array_merge( array( $code ), $coreData['fallbackSequence'] );
$messageDirs = $this->getMessagesDirs();
-
# Load non-JSON localisation data for extensions
$extensionData = array_combine(
$codeSequence,
}
}
-
# Add cache dependencies for any referenced globals
$deps['wgExtensionMessagesFiles'] = new GlobalDependency( 'wgExtensionMessagesFiles' );
// $wgMessagesDirs is used in LocalisationCache::getMessagesDirs()
$success = true;
}
-
if ( $success ) {
# Done, no need to retry
break;
$this->saveToLocal( $serialized, $hash, $code );
}
-
return $success;
}
function get( $key, $useDB = true, $langcode = true, $isFullKey = false ) {
global $wgContLang;
-
if ( is_int( $key ) ) {
// Fix numerical strings that somehow become ints
// on their way here
$res = $parser->parse( $text, $title, $popts, $linestart );
$this->mInParser = false;
-
return $res;
}
$cacheEntry = $this->cacheEntryFactory->newFromRecentChange( $baseRC, $watched );
$this->addCacheEntry( $cacheEntry );
-
return $ret;
}
$this->rcCacheIndex++;
-
return $r;
}
$r .= "</td></tr></table>\n";
-
return $r;
}
return '';
}
-
$blockOut = '';
foreach ( $this->rc_cache as $block ) {
if ( count( $block ) < 2 ) {
}
}
-
return '<div>' . $blockOut . '</div>';
}
return false;
}
-
$dateheader = ''; // $html now contains only <li>...</li>, for hooks' convenience.
$this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
$newContent = new static( $text );
-
return $newContent;
}
$this->mPassword = $password;
$this->mDBname = $dbName;
-
# The kernel's default SYN retransmission period is far too slow for us,
# so we use a short timeout plus a manual retry. Retrying means that a small
# but finite rate of SYN packet loss won't cause user-visible errors.
}
$error = $this->restoreErrorHandler();
-
# Always log connection errors
if ( !$this->mConn ) {
if ( !$error ) {
"Server: $server, User: $user, Password: " .
substr( $password, 0, 3 ) . "..., error: " . $error . "\n" );
-
$this->reportConnectionError( $error );
}
wfDebug( "Error selecting database $dbName on server {$this->mServer} " .
"from client host " . wfHostname() . "\n" );
-
$this->reportConnectionError( "Error selecting database $dbName" );
}
}
}
}
-
return $status;
}
return $this->reportConnectionError();
}
-
return $conn;
}
return array( 0 => 0 );
}
-
$expiry = 5;
$requestRate = 10;
public static function doUpdates( $commit = '' ) {
global $wgDeferredUpdateList;
-
$updates = array_merge( $wgDeferredUpdateList, self::$updates );
// No need to get master connections in case of empty updates array
return;
}
-
$page = WikiPage::newFromID( $this->id, WikiPage::READ_LATEST );
foreach ( SearchEngine::getSearchTypes() as $type ) {
self::HTCPPurge( $urlArr );
}
-
// Remove duplicate URLs
$urlArr = array_unique( $urlArr );
// Maximum number of parallel connections per squid
wfDebug( __METHOD__ . ": $this->path NOT FOUND!\n" );
}
-
return $info;
}
$this->sha1Base36 = wfBaseConvert( $this->sha1Base36, 16, 36, 31 );
}
-
return $this->sha1Base36;
}
}
} while ( false );
-
return is_object( $thumb ) ? $thumb : false;
}
wfIncrStats( 'image_cache_miss' );
}
-
return $this->dataLoaded;
}
$dbw->commit( __METHOD__ ); // commit before anything bad can happen
}
-
if ( $reupload ) {
# Delete old thumbnails
$this->purgeThumbnails();
LinksUpdate::queueRecursiveJobsForTable( $this->getTitle(), 'imagelinks' );
}
-
return true;
}
$this->complete[$func]['subcalls'] = array();
}
- foreach( $this->hieraData as $key => $stats ) {
+ foreach ( $this->hieraData as $key => $stats ) {
list( $parent, $child ) = self::splitKey( $key );
if ( $parent !== null ) {
// Track call tree information
return $version;
}
-}
\ No newline at end of file
+}
global $wgEnotifWatchlist;
global $wgEnotifMinorEdits, $wgEnotifUserTalk;
-
# The following code is only run, if several conditions are met:
# 1. EmailNotification for pages (other than user_talk pages) must be enabled
# 2. minor edits (changes) are only regarded if the global flag indicates so
public function fetchExtendedMetadata( File $file ) {
global $wgMemc;
-
// If revision deleted, exit immediately
if ( $file->isDeleted( File::DELETED_FILE ) ) {
$wgMemc->set( $cacheKey, $valueToCache, $maxCacheTime );
}
-
return $extendedMetadata;
}
return $file->getExtendedMetadata() ?: array();
}
-
$uploadDate = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
$fileMetadata = array(
}
}
-
return $fileMetadata;
}
}
}
-
return $extendedMetadata;
}
return $this->mContent;
}
-
$content = $this->fetchContentObject();
if ( !$content ) {
$this->mContent = ContentHandler::getContentText( $content );
ContentHandler::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
-
return $this->mContent;
}
return $this->mContentObject;
}
-
$this->mContentLoaded = true;
$this->mContent = null;
Hooks::run( 'ArticleAfterFetchContentObject', array( &$this, &$this->mContentObject ) );
-
return $this->mContentObject;
}
public function view() {
global $wgUseFileCache, $wgUseETag, $wgDebugToolbar, $wgMaxRedirects;
-
# Get variables from query string
# As side effect this will load the revision and update the title
# in a revision ID is passed in the request, so this should remain
return false;
}
-
// New page patrol: Get the timestamp of the oldest revison which
// the revision table holds for the given page. Then we look
// whether it's within the RC lifespan and if it is, we try
$pool = new PoolWorkArticleView( $this, $parserOptions, $oldid, $useParserCache );
$pool->execute();
-
return $pool->getParserOutput();
}
) {
global $wgContentHandlerUseDB;
-
$content = $revision->getContent();
$len = $content ? $content->getSize() : 0;
$rt = $content ? $content->getUltimateRedirectTarget() : null;
throw new MWException( 'Something is trying to edit an article with an empty title' );
}
-
if ( !$content->getContentHandler()->canBeUsedOn( $this->getTitle() ) ) {
return Status::newFatal( 'content-not-allowed-here',
ContentHandler::getLocalizedName( $content->getModel() ),
public function doEditUpdates( Revision $revision, User $user, array $options = array() ) {
global $wgEnableParserCache;
-
$options += array(
'changed' => true,
'created' => false,
$this->replaceInternal( $text );
$this->replaceInterwiki( $text );
-
}
/**
}
$this->mFirstCall = false;
-
CoreParserFunctions::register( $this );
CoreTagHooks::register( $this );
$this->initialiseVariables();
$out = '';
}
-
return $out;
}
$wgCleanSignatures, $wgExternalLinkTarget, $wgExpensiveParserFunctionLimit,
$wgMaxGeneratedPPNodeCount, $wgDisableLangConversion, $wgDisableTitleConversion;
-
// *UPDATE* ParserOptions::matches() if any of this changes as needed
$this->mInterwikiMagic = $wgInterwikiMagic;
$this->mAllowExternalImages = $wgAllowExternalImages;
if ( $cacheable ) {
}
-
if ( !$result ) {
throw new MWException( __METHOD__ . ' generated invalid XML' );
}
$stack->rootAccum .= '</root>';
$xml = $stack->rootAccum;
-
return $xml;
}
}
* Class for handling function-scope profiling
*
* @since 1.22
+ * @deprecated 1.25 No-op now
*/
class ProfileSection {
- /** @var string $name Method name */
- protected $name;
- /** @var boolean $enabled Is profiling enabled? */
- protected $enabled = false;
-
/**
* Begin profiling of a function and return an object that ends profiling
* of the function when that object leaves scope. As long as the object is
*
* @param string $name Name of the function to profile
*/
- public function __construct( $name ) {
- $this->name = $name;
- // Use Profiler member variable directly to reduce overhead
- if ( Profiler::$__instance === null ) {
- Profiler::instance();
- }
- if ( !( Profiler::$__instance instanceof ProfilerStub ) ) {
- $this->enabled = true;
- Profiler::$__instance->profileIn( $this->name );
- }
- }
-
- function __destruct() {
- if ( $this->enabled ) {
- Profiler::$__instance->profileOut( $this->name );
- }
- }
+ public function __construct( $name ) {}
}
}
}
- /**
- * Called by wfProfieIn()
- *
- * @param string $functionname
- */
- abstract public function profileIn( $functionname );
-
- /**
- * Called by wfProfieOut()
- *
- * @param string $functionname
- */
- abstract public function profileOut( $functionname );
-
/**
* Mark the start of a custom profiling frame (e.g. DB queries).
* The frame ends when the result of this method falls out of scope.
/**
* Begin profiling of a function
* @param string $functionname Name of the function we will profile
+ * @deprecated 1.25
*/
function wfProfileIn( $functionname ) {
- // Use Profiler member variable directly to reduce overhead
- if ( Profiler::$__instance === null ) {
- Profiler::instance();
- }
- if ( !( Profiler::$__instance instanceof ProfilerStub ) ) {
- Profiler::$__instance->profileIn( $functionname );
- }
}
/**
* Stop profiling of a function
* @param string $functionname Name of the function we have profiled
+ * @deprecated 1.25
*/
function wfProfileOut( $functionname = 'missing' ) {
- // Use Profiler member variable directly to reduce overhead
- if ( Profiler::$__instance === null ) {
- Profiler::instance();
- }
- if ( !( Profiler::$__instance instanceof ProfilerStub ) ) {
- Profiler::$__instance->profileOut( $functionname );
- }
}
* @ingroup Profiler
*/
class ProfilerStub extends Profiler {
- public function profileIn( $fn ) {
- }
-
- public function profileOut( $fn ) {
- }
-
public function scopedProfileIn( $section ) {
return new ScopedCallback( null ); // no-op
}
$this->sprofiler = new SectionProfiler();
}
- /**
- * No-op for xhprof profiling.
- *
- * Use the 'include' configuration key instead if you need to constrain
- * the functions that are profiled.
- *
- * @param string $functionname
- */
- public function profileIn( $functionname ) {
- }
-
- /**
- * No-op for xhprof profiling.
- *
- * Use the 'include' configuration key instead if you need to constrain
- * the functions that are profiled.
- *
- * @param string $functionname
- */
- public function profileOut( $functionname ) {
- }
-
public function scopedProfileIn( $section ) {
return $this->sprofiler->scopedProfileIn( $section );
}
}
}
-
-
}
public function getExtractedInfo() {
$this->errors[] = self::formatExceptionNoComment( $e );
}
-
return $result;
}
public function __construct( Config $config = null ) {
global $IP;
-
if ( $config === null ) {
wfDebug( __METHOD__ . ' was called without providing a Config instance' );
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
. 'Edit your <code>LocalSettings.php</code> to enable it.' );
}
-
// Get core test suites
$testModules = array();
$testModules['qunit'] = array();
// See http://bugs.php.net/bug.php?id=36514
ob_start();
-
// Find out which modules are missing and instantiate the others
$modules = array();
$missing = array();
$this->errors[] = self::formatExceptionNoComment( $e );
}
-
// To send Last-Modified and support If-Modified-Since, we need to detect
// the last modified time
$mtime = wfTimestamp( TS_UNIX, $this->config->get( 'CacheEpoch' ) );
}
}
-
// If there's an If-Modified-Since header, respond with a 304 appropriately
if ( $this->tryRespondLastModified( $context, $mtime ) ) {
return; // output handled (buffers cleared)
no modules were requested. Max made me put this here. */";
}
-
$image = $context->getImageObj();
if ( $image ) {
$data = $image->getImageData( $context );
$all = $textExt + $otherExt; // these have disjunct key sets
-
// prepare regexps
foreach ( $terms as $index => $term ) {
// manually do upper/lowercase stuff for utf-8 since PHP won't do it
$pat1 = "/(" . $phrase . ")/ui";
$pat2 = "/$patPre(" . $anyterm . ")$patPost/ui";
-
$left = $contextlines;
$snippets = array();
}
}
-
return $extract;
}
function normalizeText( $string ) {
global $wgContLang;
-
$out = parent::normalizeText( $string );
// MySQL fulltext index doesn't grok utf-8, so we
"$1u82e$2",
$out );
-
return $out;
}
private function getCachedNotice( $name ) {
global $wgRenderHashAppend, $parserMemc, $wgContLang;
-
$needParse = false;
if ( $name === 'default' ) {
$this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
}
-
-
return $tpl;
}
$wgShowCreditsIfMax, $wgArticlePath,
$wgScriptPath, $wgServer;
-
$title = $this->getTitle();
$request = $this->getRequest();
$out = $this->getOutput();
$tpl->set( 'userlangattributes', $attrs );
}
-
$tpl->set( 'newtalk', $this->getNewtalks() );
$tpl->set( 'logo', $this->logoText() );
protected function buildContentNavigationUrls() {
global $wgDisableLangConversion;
-
// Display tabs for the relevant title rather than always the title itself
$title = $this->getRelevantTitle();
$onPage = $title->equals( $this->getTitle() );
);
}
-
// Checks if user can edit the current page if it exists or create it otherwise
if ( $title->quickUserCan( 'edit', $user )
&& ( $title->exists() || $title->quickUserCan( 'create', $user ) )
);
}
-
// Checks if the user is logged in
if ( $this->loggedin && $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
/**
}
}
-
return $content_navigation;
}
*/
private function buildContentActionUrls( $content_navigation ) {
-
// content_actions has been replaced with content_navigation for backwards
// compatibility and also for skins that just want simple tabs content_actions
// is now built by flattening the content_navigation arrays into one
}
}
-
return $content_actions;
}
protected function buildNavUrls() {
global $wgUploadNavigationUrl;
-
$out = $this->getOutput();
$request = $this->getRequest();
// Normalise message names so they look like page titles
$messageNames = array_map( array( $this->lang, 'ucfirst' ), $messageNames );
-
return $messageNames;
}
}
}
-
return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
}
$ret = Html::rawElement( 'li', array( 'class' => $classes ), $ret ) . "\n";
}
-
return $ret;
}
$ret = Html::rawElement( 'li', array(), $ret ) . "\n";
-
return $ret;
}
$this->userGroupCache = $cache;
// Add page of groups to link batch
- foreach( $groups as $group => $unused ) {
+ foreach ( $groups as $group => $unused ) {
$groupPage = User::getGroupPage( $group );
if ( $groupPage ) {
$batch->addObj( $groupPage );
$batch->execute();
$this->mResult->seek( 0 );
-
return '';
}
)->escaped();
}
-
// @todo i18n: This should use a comma separator instead of a hard coded comma, right?
return '<li>' . $lang->specialList( $link, implode( $description_items, ', ' ) ) . "</li>\n";
}
)->text();
}
-
return $version;
}
}
}
-
return $v;
}
return array( 'status' => self::HOOK_ABORTED, 'error' => $error );
}
-
return array( 'status' => self::OK );
}
}
}
-
return true;
}
return array( 'uploadvirus', $virus );
}
-
return true;
}
}
}
-
return $warnings;
}
$this->postProcessUpload();
}
-
return $status;
}
$file = $stash->stashFile( $this->mTempPath, $this->getSourceType() );
$this->mLocalFile = $file;
-
return $file;
}
wfDebug( __METHOD__ . ": FOUND VIRUS! scanner feedback: $output \n" );
}
-
return $output;
}
wfDebug( __METHOD__ . ": " . strlen( $buffer ) .
" bytes of randomness leftover in the buffer.\n" );
-
return $generated;
}
*
* @property {mw.Map} config
*/
- // Dummy placeholder. Re-assigned in ResourceLoaderStartupModule to an instance of `mw.Map`.
+ // Dummy placeholder. Re-assigned in ResourceLoaderStartUpModule to an instance of `mw.Map`.
config: null,
/**
--- /dev/null
+<?php
+
+class ResourceLoaderStartUpModuleTest extends ResourceLoaderTestCase {
+
+ public static function provideGetModuleRegistrations() {
+ return array(
+ array( array(
+ 'msg' => 'Empty registry',
+ 'modules' => array(),
+ 'out' => '
+mw.loader.addSource( {
+ "local": "/w/load.php"
+} );mw.loader.register( [] );'
+ ) ),
+ array( array(
+ 'msg' => 'Basic registry',
+ 'modules' => array(
+ 'test.blank' => new ResourceLoaderTestModule(),
+ ),
+ 'out' => '
+mw.loader.addSource( {
+ "local": "/w/load.php"
+} );mw.loader.register( [
+ [
+ "test.blank",
+ 1388534400
+ ]
+] );',
+ ) ),
+ array( array(
+ 'msg' => 'Group signature',
+ 'modules' => array(
+ 'test.blank' => new ResourceLoaderTestModule(),
+ 'test.group.foo' => new ResourceLoaderTestModule( array( 'group' => 'x-foo' ) ),
+ 'test.group.bar' => new ResourceLoaderTestModule( array( 'group' => 'x-bar' ) ),
+ ),
+ 'out' => '
+mw.loader.addSource( {
+ "local": "/w/load.php"
+} );mw.loader.register( [
+ [
+ "test.blank",
+ 1388534400
+ ],
+ [
+ "test.group.foo",
+ 1388534400,
+ [],
+ "x-foo"
+ ],
+ [
+ "test.group.bar",
+ 1388534400,
+ [],
+ "x-bar"
+ ]
+] );'
+ ) ),
+ array( array(
+ 'msg' => 'Different target (non-test should not be registered)',
+ 'modules' => array(
+ 'test.blank' => new ResourceLoaderTestModule(),
+ 'test.target.foo' => new ResourceLoaderTestModule( array( 'targets' => array( 'x-foo' ) ) ),
+ ),
+ 'out' => '
+mw.loader.addSource( {
+ "local": "/w/load.php"
+} );mw.loader.register( [
+ [
+ "test.blank",
+ 1388534400
+ ]
+] );'
+ ) ),
+ array( array(
+ 'msg' => 'Foreign source',
+ 'sources' => array(
+ 'example' => array(
+ 'loadScript' => 'http://example.org/w/load.php',
+ 'apiScript' => 'http://example.org/w/api.php',
+ ),
+ ),
+ 'modules' => array(
+ 'test.blank' => new ResourceLoaderTestModule( array( 'source' => 'example' ) ),
+ ),
+ 'out' => '
+mw.loader.addSource( {
+ "local": "/w/load.php",
+ "example": "http://example.org/w/load.php"
+} );mw.loader.register( [
+ [
+ "test.blank",
+ 1388534400,
+ [],
+ null,
+ "example"
+ ]
+] );'
+ ) ),
+ array( array(
+ 'msg' => 'Conditional dependency function',
+ 'modules' => array(
+ 'test.x.core' => new ResourceLoaderTestModule(),
+ 'test.x.polyfill' => new ResourceLoaderTestModule( array(
+ 'skipFunction' => 'return true;'
+ ) ),
+ 'test.y.polyfill' => new ResourceLoaderTestModule( array(
+ 'skipFunction' =>
+ 'return !!(' .
+ ' window.JSON &&' .
+ ' JSON.parse &&' .
+ ' JSON.stringify' .
+ ');'
+ ) ),
+ 'test.z.foo' => new ResourceLoaderTestModule( array(
+ 'dependencies' => array(
+ 'test.x.core',
+ 'test.x.polyfill',
+ 'test.y.polyfill',
+ ),
+ ) ),
+ ),
+ 'out' => '
+mw.loader.addSource( {
+ "local": "/w/load.php"
+} );mw.loader.register( [
+ [
+ "test.x.core",
+ 1388534400
+ ],
+ [
+ "test.x.polyfill",
+ 1388534400,
+ [],
+ null,
+ null,
+ "return true;"
+ ],
+ [
+ "test.y.polyfill",
+ 1388534400,
+ [],
+ null,
+ null,
+ "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
+ ],
+ [
+ "test.z.foo",
+ 1388534400,
+ [
+ 0,
+ 1,
+ 2
+ ]
+ ]
+] );',
+ ) ),
+ array( array(
+ // This may seem like an edge case, but a plain MediaWiki core install
+ // with a few extensions installed is likely far more complex than this
+ // even, not to mention an install like Wikipedia.
+ // TODO: Make this even more realistic.
+ 'msg' => 'Advanced (everything combined)',
+ 'sources' => array(
+ 'example' => array(
+ 'loadScript' => 'http://example.org/w/load.php',
+ 'apiScript' => 'http://example.org/w/api.php',
+ ),
+ ),
+ 'modules' => array(
+ 'test.blank' => new ResourceLoaderTestModule(),
+ 'test.x.core' => new ResourceLoaderTestModule(),
+ 'test.x.util' => new ResourceLoaderTestModule( array(
+ 'dependencies' => array(
+ 'test.x.core',
+ ),
+ ) ),
+ 'test.x.foo' => new ResourceLoaderTestModule( array(
+ 'dependencies' => array(
+ 'test.x.core',
+ ),
+ ) ),
+ 'test.x.bar' => new ResourceLoaderTestModule( array(
+ 'dependencies' => array(
+ 'test.x.core',
+ 'test.x.util',
+ ),
+ ) ),
+ 'test.x.quux' => new ResourceLoaderTestModule( array(
+ 'dependencies' => array(
+ 'test.x.foo',
+ 'test.x.bar',
+ 'test.x.util',
+ 'test.x.unknown',
+ ),
+ ) ),
+ 'test.group.foo.1' => new ResourceLoaderTestModule( array(
+ 'group' => 'x-foo',
+ ) ),
+ 'test.group.foo.2' => new ResourceLoaderTestModule( array(
+ 'group' => 'x-foo',
+ ) ),
+ 'test.group.bar.1' => new ResourceLoaderTestModule( array(
+ 'group' => 'x-bar',
+ ) ),
+ 'test.group.bar.2' => new ResourceLoaderTestModule( array(
+ 'group' => 'x-bar',
+ 'source' => 'example',
+ ) ),
+ 'test.target.foo' => new ResourceLoaderTestModule( array(
+ 'targets' => array( 'x-foo' ),
+ ) ),
+ 'test.target.bar' => new ResourceLoaderTestModule( array(
+ 'source' => 'example',
+ 'targets' => array( 'x-foo' ),
+ ) ),
+ ),
+ 'out' => '
+mw.loader.addSource( {
+ "local": "/w/load.php",
+ "example": "http://example.org/w/load.php"
+} );mw.loader.register( [
+ [
+ "test.blank",
+ 1388534400
+ ],
+ [
+ "test.x.core",
+ 1388534400
+ ],
+ [
+ "test.x.util",
+ 1388534400,
+ [
+ 1
+ ]
+ ],
+ [
+ "test.x.foo",
+ 1388534400,
+ [
+ 1
+ ]
+ ],
+ [
+ "test.x.bar",
+ 1388534400,
+ [
+ 2
+ ]
+ ],
+ [
+ "test.x.quux",
+ 1388534400,
+ [
+ 3,
+ 4,
+ "test.x.unknown"
+ ]
+ ],
+ [
+ "test.group.foo.1",
+ 1388534400,
+ [],
+ "x-foo"
+ ],
+ [
+ "test.group.foo.2",
+ 1388534400,
+ [],
+ "x-foo"
+ ],
+ [
+ "test.group.bar.1",
+ 1388534400,
+ [],
+ "x-bar"
+ ],
+ [
+ "test.group.bar.2",
+ 1388534400,
+ [],
+ "x-bar",
+ "example"
+ ]
+] );'
+ ) ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetModuleRegistrations
+ * @covers ResourceLoaderStartUpModule::compileUnresolvedDependencies
+ * @covers ResourceLoaderStartUpModule::getModuleRegistrations
+ * @covers ResourceLoader::makeLoaderSourcesScript
+ * @covers ResourceLoader::makeLoaderRegisterScript
+ */
+ public function testGetModuleRegistrations( $case ) {
+ if ( isset( $case['sources'] ) ) {
+ $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
+ }
+
+ $context = $this->getResourceLoaderContext();
+ $rl = $context->getResourceLoader();
+
+ $rl->register( $case['modules'] );
+
+ $module = new ResourceLoaderStartUpModule();
+ $this->assertEquals(
+ ltrim( $case['out'], "\n" ),
+ $module->getModuleRegistrations( $context ),
+ $case['msg']
+ );
+ }
+
+ public static function provideRegistrations() {
+ return array(
+ array( array(
+ 'test.blank' => new ResourceLoaderTestModule(),
+ 'test.min' => new ResourceLoaderTestModule( array(
+ 'skipFunction' =>
+ 'return !!(' .
+ ' window.JSON &&' .
+ ' JSON.parse &&' .
+ ' JSON.stringify' .
+ ');',
+ 'dependencies' => array(
+ 'test.blank',
+ ),
+ ) ),
+ ) )
+ );
+ }
+ /**
+ * @dataProvider provideRegistrations
+ */
+ public function testRegistrationsMinified( $modules ) {
+ $this->setMwGlobals( 'wgResourceLoaderDebug', false );
+
+ $context = $this->getResourceLoaderContext();
+ $rl = $context->getResourceLoader();
+ $rl->register( $modules );
+ $module = new ResourceLoaderStartUpModule();
+ $this->assertEquals(
+'mw.loader.addSource({"local":"/w/load.php"});'
+. 'mw.loader.register(['
+. '["test.blank",1388534400],'
+. '["test.min",1388534400,[0],null,null,'
+. '"return!!(window.JSON\u0026\u0026JSON.parse\u0026\u0026JSON.stringify);"'
+. ']]);',
+ $module->getModuleRegistrations( $context ),
+ 'Minified output'
+ );
+ }
+
+ /**
+ * @dataProvider provideRegistrations
+ */
+ public function testRegistrationsUnminified( $modules ) {
+ $context = $this->getResourceLoaderContext();
+ $rl = $context->getResourceLoader();
+ $rl->register( $modules );
+ $module = new ResourceLoaderStartUpModule();
+ $this->assertEquals(
+'mw.loader.addSource( {
+ "local": "/w/load.php"
+} );mw.loader.register( [
+ [
+ "test.blank",
+ 1388534400
+ ],
+ [
+ "test.min",
+ 1388534400,
+ [
+ 0
+ ],
+ null,
+ null,
+ "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
+ ]
+] );',
+ $module->getModuleRegistrations( $context ),
+ 'Unminified output'
+ );
+ }
+
+}
+++ /dev/null
-<?php
-
-class ResourceLoaderStartupModuleTest extends ResourceLoaderTestCase {
-
- public static function provideGetModuleRegistrations() {
- return array(
- array( array(
- 'msg' => 'Empty registry',
- 'modules' => array(),
- 'out' => '
-mw.loader.addSource( {
- "local": "/w/load.php"
-} );mw.loader.register( [] );'
- ) ),
- array( array(
- 'msg' => 'Basic registry',
- 'modules' => array(
- 'test.blank' => new ResourceLoaderTestModule(),
- ),
- 'out' => '
-mw.loader.addSource( {
- "local": "/w/load.php"
-} );mw.loader.register( [
- [
- "test.blank",
- 1388534400
- ]
-] );',
- ) ),
- array( array(
- 'msg' => 'Group signature',
- 'modules' => array(
- 'test.blank' => new ResourceLoaderTestModule(),
- 'test.group.foo' => new ResourceLoaderTestModule( array( 'group' => 'x-foo' ) ),
- 'test.group.bar' => new ResourceLoaderTestModule( array( 'group' => 'x-bar' ) ),
- ),
- 'out' => '
-mw.loader.addSource( {
- "local": "/w/load.php"
-} );mw.loader.register( [
- [
- "test.blank",
- 1388534400
- ],
- [
- "test.group.foo",
- 1388534400,
- [],
- "x-foo"
- ],
- [
- "test.group.bar",
- 1388534400,
- [],
- "x-bar"
- ]
-] );'
- ) ),
- array( array(
- 'msg' => 'Different target (non-test should not be registered)',
- 'modules' => array(
- 'test.blank' => new ResourceLoaderTestModule(),
- 'test.target.foo' => new ResourceLoaderTestModule( array( 'targets' => array( 'x-foo' ) ) ),
- ),
- 'out' => '
-mw.loader.addSource( {
- "local": "/w/load.php"
-} );mw.loader.register( [
- [
- "test.blank",
- 1388534400
- ]
-] );'
- ) ),
- array( array(
- 'msg' => 'Foreign source',
- 'sources' => array(
- 'example' => array(
- 'loadScript' => 'http://example.org/w/load.php',
- 'apiScript' => 'http://example.org/w/api.php',
- ),
- ),
- 'modules' => array(
- 'test.blank' => new ResourceLoaderTestModule( array( 'source' => 'example' ) ),
- ),
- 'out' => '
-mw.loader.addSource( {
- "local": "/w/load.php",
- "example": "http://example.org/w/load.php"
-} );mw.loader.register( [
- [
- "test.blank",
- 1388534400,
- [],
- null,
- "example"
- ]
-] );'
- ) ),
- array( array(
- 'msg' => 'Conditional dependency function',
- 'modules' => array(
- 'test.x.core' => new ResourceLoaderTestModule(),
- 'test.x.polyfill' => new ResourceLoaderTestModule( array(
- 'skipFunction' => 'return true;'
- ) ),
- 'test.y.polyfill' => new ResourceLoaderTestModule( array(
- 'skipFunction' =>
- 'return !!(' .
- ' window.JSON &&' .
- ' JSON.parse &&' .
- ' JSON.stringify' .
- ');'
- ) ),
- 'test.z.foo' => new ResourceLoaderTestModule( array(
- 'dependencies' => array(
- 'test.x.core',
- 'test.x.polyfill',
- 'test.y.polyfill',
- ),
- ) ),
- ),
- 'out' => '
-mw.loader.addSource( {
- "local": "/w/load.php"
-} );mw.loader.register( [
- [
- "test.x.core",
- 1388534400
- ],
- [
- "test.x.polyfill",
- 1388534400,
- [],
- null,
- null,
- "return true;"
- ],
- [
- "test.y.polyfill",
- 1388534400,
- [],
- null,
- null,
- "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
- ],
- [
- "test.z.foo",
- 1388534400,
- [
- 0,
- 1,
- 2
- ]
- ]
-] );',
- ) ),
- array( array(
- // This may seem like an edge case, but a plain MediaWiki core install
- // with a few extensions installed is likely far more complex than this
- // even, not to mention an install like Wikipedia.
- // TODO: Make this even more realistic.
- 'msg' => 'Advanced (everything combined)',
- 'sources' => array(
- 'example' => array(
- 'loadScript' => 'http://example.org/w/load.php',
- 'apiScript' => 'http://example.org/w/api.php',
- ),
- ),
- 'modules' => array(
- 'test.blank' => new ResourceLoaderTestModule(),
- 'test.x.core' => new ResourceLoaderTestModule(),
- 'test.x.util' => new ResourceLoaderTestModule( array(
- 'dependencies' => array(
- 'test.x.core',
- ),
- ) ),
- 'test.x.foo' => new ResourceLoaderTestModule( array(
- 'dependencies' => array(
- 'test.x.core',
- ),
- ) ),
- 'test.x.bar' => new ResourceLoaderTestModule( array(
- 'dependencies' => array(
- 'test.x.core',
- 'test.x.util',
- ),
- ) ),
- 'test.x.quux' => new ResourceLoaderTestModule( array(
- 'dependencies' => array(
- 'test.x.foo',
- 'test.x.bar',
- 'test.x.util',
- 'test.x.unknown',
- ),
- ) ),
- 'test.group.foo.1' => new ResourceLoaderTestModule( array(
- 'group' => 'x-foo',
- ) ),
- 'test.group.foo.2' => new ResourceLoaderTestModule( array(
- 'group' => 'x-foo',
- ) ),
- 'test.group.bar.1' => new ResourceLoaderTestModule( array(
- 'group' => 'x-bar',
- ) ),
- 'test.group.bar.2' => new ResourceLoaderTestModule( array(
- 'group' => 'x-bar',
- 'source' => 'example',
- ) ),
- 'test.target.foo' => new ResourceLoaderTestModule( array(
- 'targets' => array( 'x-foo' ),
- ) ),
- 'test.target.bar' => new ResourceLoaderTestModule( array(
- 'source' => 'example',
- 'targets' => array( 'x-foo' ),
- ) ),
- ),
- 'out' => '
-mw.loader.addSource( {
- "local": "/w/load.php",
- "example": "http://example.org/w/load.php"
-} );mw.loader.register( [
- [
- "test.blank",
- 1388534400
- ],
- [
- "test.x.core",
- 1388534400
- ],
- [
- "test.x.util",
- 1388534400,
- [
- 1
- ]
- ],
- [
- "test.x.foo",
- 1388534400,
- [
- 1
- ]
- ],
- [
- "test.x.bar",
- 1388534400,
- [
- 2
- ]
- ],
- [
- "test.x.quux",
- 1388534400,
- [
- 3,
- 4,
- "test.x.unknown"
- ]
- ],
- [
- "test.group.foo.1",
- 1388534400,
- [],
- "x-foo"
- ],
- [
- "test.group.foo.2",
- 1388534400,
- [],
- "x-foo"
- ],
- [
- "test.group.bar.1",
- 1388534400,
- [],
- "x-bar"
- ],
- [
- "test.group.bar.2",
- 1388534400,
- [],
- "x-bar",
- "example"
- ]
-] );'
- ) ),
- );
- }
-
- /**
- * @dataProvider provideGetModuleRegistrations
- * @covers ResourceLoaderStartupModule::compileUnresolvedDependencies
- * @covers ResourceLoaderStartUpModule::getModuleRegistrations
- * @covers ResourceLoader::makeLoaderSourcesScript
- * @covers ResourceLoader::makeLoaderRegisterScript
- */
- public function testGetModuleRegistrations( $case ) {
- if ( isset( $case['sources'] ) ) {
- $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
- }
-
- $context = $this->getResourceLoaderContext();
- $rl = $context->getResourceLoader();
-
- $rl->register( $case['modules'] );
-
- $module = new ResourceLoaderStartUpModule();
- $this->assertEquals(
- ltrim( $case['out'], "\n" ),
- $module->getModuleRegistrations( $context ),
- $case['msg']
- );
- }
-
- public static function provideRegistrations() {
- return array(
- array( array(
- 'test.blank' => new ResourceLoaderTestModule(),
- 'test.min' => new ResourceLoaderTestModule( array(
- 'skipFunction' =>
- 'return !!(' .
- ' window.JSON &&' .
- ' JSON.parse &&' .
- ' JSON.stringify' .
- ');',
- 'dependencies' => array(
- 'test.blank',
- ),
- ) ),
- ) )
- );
- }
- /**
- * @dataProvider provideRegistrations
- */
- public function testRegistrationsMinified( $modules ) {
- $this->setMwGlobals( 'wgResourceLoaderDebug', false );
-
- $context = $this->getResourceLoaderContext();
- $rl = $context->getResourceLoader();
- $rl->register( $modules );
- $module = new ResourceLoaderStartUpModule();
- $this->assertEquals(
-'mw.loader.addSource({"local":"/w/load.php"});'
-. 'mw.loader.register(['
-. '["test.blank",1388534400],'
-. '["test.min",1388534400,[0],null,null,'
-. '"return!!(window.JSON\u0026\u0026JSON.parse\u0026\u0026JSON.stringify);"'
-. ']]);',
- $module->getModuleRegistrations( $context ),
- 'Minified output'
- );
- }
-
- /**
- * @dataProvider provideRegistrations
- */
- public function testRegistrationsUnminified( $modules ) {
- $context = $this->getResourceLoaderContext();
- $rl = $context->getResourceLoader();
- $rl->register( $modules );
- $module = new ResourceLoaderStartUpModule();
- $this->assertEquals(
-'mw.loader.addSource( {
- "local": "/w/load.php"
-} );mw.loader.register( [
- [
- "test.blank",
- 1388534400
- ],
- [
- "test.min",
- 1388534400,
- [
- 0
- ],
- null,
- null,
- "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
- ]
-] );',
- $module->getModuleRegistrations( $context ),
- 'Unminified output'
- );
- }
-
-}