コード例 #1
0
 /**
  * Create a redirect that is also valid JavaScript
  *
  * @param Title $destination
  * @param string $text ignored
  * @return JavaScriptContent
  */
 public function makeRedirectContent(Title $destination, $text = '')
 {
     // The parameters are passed as a string so the / is not url-encoded by wfArrayToCgi
     $url = $destination->getFullURL('action=raw&ctype=text/javascript', false, PROTO_RELATIVE);
     $class = $this->getContentClass();
     return new $class('/* #REDIRECT */' . Xml::encodeJsCall('mw.loader.load', [$url]));
 }
コード例 #2
0
 /**
  * @param ResourceLoaderContext $context
  * @return string JavaScript code
  */
 public function getScript(ResourceLoaderContext $context)
 {
     $fileScript = parent::getScript($context);
     $tagData = Sanitizer::getRecognizedTagData();
     $parserDefaults = array();
     $parserDefaults['allowedHtmlElements'] = array_merge(array_keys($tagData['htmlpairs']), array_diff(array_keys($tagData['htmlsingle']), array_keys($tagData['htmlsingleonly'])));
     $dataScript = Xml::encodeJsCall('mw.jqueryMsg.setParserDefaults', array($parserDefaults));
     return $fileScript . $dataScript;
 }
コード例 #3
0
 /**
  * @param $context ResourceLoaderContext
  * @return string
  */
 public function getScript(ResourceLoaderContext $context)
 {
     global $wgUser;
     /* Wikia change begin - @author: macbre */
     $options = $wgUser->getOptions();
     wfRunHooks('ResourceLoaderUserOptionsModuleGetOptions', array($context, &$options));
     /* Wikia change end */
     return Xml::encodeJsCall('mw.user.options.set', array($options));
 }
 /**
  * Processes messages which have been marked as needing parsing
  *
  * @return string JavaScript code
  */
 public function addParsedMessages()
 {
     $js = "\n";
     foreach ($this->parsedMessages as $key) {
         $value = wfMessage($key)->parse();
         $js .= Xml::encodeJsCall('mw.messages.set', array($key, $value));
     }
     return $js;
 }
コード例 #5
0
ファイル: EditPage.php プロジェクト: OrBin/mediawiki
 /**
  * Shows a bulletin board style toolbar for common editing functions.
  * It can be disabled in the user preferences.
  *
  * @param $title Title object for the page being edited (optional)
  * @return string
  */
 static function getEditToolbar($title = null)
 {
     global $wgContLang, $wgOut;
     global $wgEnableUploads, $wgForeignFileRepos;
     $imagesAvailable = $wgEnableUploads || count($wgForeignFileRepos);
     $showSignature = true;
     if ($title) {
         $showSignature = MWNamespace::wantSignatures($title->getNamespace());
     }
     /**
      * $toolarray is an array of arrays each of which includes the
      * opening tag, the closing tag, optionally a sample text that is
      * inserted between the two when no selection is highlighted
      * and.  The tip text is shown when the user moves the mouse
      * over the button.
      *
      * Images are defined in ResourceLoaderEditToolbarModule.
      */
     $toolarray = array(array('id' => 'mw-editbutton-bold', 'open' => '\'\'\'', 'close' => '\'\'\'', 'sample' => wfMessage('bold_sample')->text(), 'tip' => wfMessage('bold_tip')->text()), array('id' => 'mw-editbutton-italic', 'open' => '\'\'', 'close' => '\'\'', 'sample' => wfMessage('italic_sample')->text(), 'tip' => wfMessage('italic_tip')->text()), array('id' => 'mw-editbutton-link', 'open' => '[[', 'close' => ']]', 'sample' => wfMessage('link_sample')->text(), 'tip' => wfMessage('link_tip')->text()), array('id' => 'mw-editbutton-extlink', 'open' => '[', 'close' => ']', 'sample' => wfMessage('extlink_sample')->text(), 'tip' => wfMessage('extlink_tip')->text()), array('id' => 'mw-editbutton-headline', 'open' => "\n== ", 'close' => " ==\n", 'sample' => wfMessage('headline_sample')->text(), 'tip' => wfMessage('headline_tip')->text()), $imagesAvailable ? array('id' => 'mw-editbutton-image', 'open' => '[[' . $wgContLang->getNsText(NS_FILE) . ':', 'close' => ']]', 'sample' => wfMessage('image_sample')->text(), 'tip' => wfMessage('image_tip')->text()) : false, $imagesAvailable ? array('id' => 'mw-editbutton-media', 'open' => '[[' . $wgContLang->getNsText(NS_MEDIA) . ':', 'close' => ']]', 'sample' => wfMessage('media_sample')->text(), 'tip' => wfMessage('media_tip')->text()) : false, array('id' => 'mw-editbutton-nowiki', 'open' => "<nowiki>", 'close' => "</nowiki>", 'sample' => wfMessage('nowiki_sample')->text(), 'tip' => wfMessage('nowiki_tip')->text()), $showSignature ? array('id' => 'mw-editbutton-signature', 'open' => '--~~~~', 'close' => '', 'sample' => '', 'tip' => wfMessage('sig_tip')->text()) : false, array('id' => 'mw-editbutton-hr', 'open' => "\n----\n", 'close' => '', 'sample' => '', 'tip' => wfMessage('hr_tip')->text()));
     $script = 'mw.loader.using("mediawiki.toolbar", function () {';
     foreach ($toolarray as $tool) {
         if (!$tool) {
             continue;
         }
         $params = array(false, $tool['tip'], $tool['open'], $tool['close'], $tool['sample'], $tool['id']);
         $script .= Xml::encodeJsCall('mw.toolbar.addButton', $params, ResourceLoader::inDebugMode());
     }
     $script .= '});';
     $wgOut->addScript(ResourceLoader::makeInlineScript($script));
     $toolbar = '<div id="toolbar"></div>';
     Hooks::run('EditPageBeforeEditToolbar', array(&$toolbar));
     return $toolbar;
 }
コード例 #6
0
 /**
  * Shows a bulletin board style toolbar for common editing functions.
  * It can be disabled in the user preferences.
  * The necessary JavaScript code can be found in skins/common/edit.js.
  *
  * @return string
  */
 static function getEditToolbar()
 {
     global $wgStylePath, $wgContLang, $wgLang, $wgOut;
     global $wgUseTeX, $wgEnableUploads, $wgForeignFileRepos;
     $imagesAvailable = $wgEnableUploads || count($wgForeignFileRepos);
     /**
      * $toolarray is an array of arrays each of which includes the
      * filename of the button image (without path), the opening
      * tag, the closing tag, optionally a sample text that is
      * inserted between the two when no selection is highlighted
      * and.  The tip text is shown when the user moves the mouse
      * over the button.
      *
      * Also here: accesskeys (key), which are not used yet until
      * someone can figure out a way to make them work in
      * IE. However, we should make sure these keys are not defined
      * on the edit page.
      */
     $toolarray = array(array('image' => $wgLang->getImageFile('button-bold'), 'id' => 'mw-editbutton-bold', 'open' => '\'\'\'', 'close' => '\'\'\'', 'sample' => wfMsg('bold_sample'), 'tip' => wfMsg('bold_tip'), 'key' => 'B'), array('image' => $wgLang->getImageFile('button-italic'), 'id' => 'mw-editbutton-italic', 'open' => '\'\'', 'close' => '\'\'', 'sample' => wfMsg('italic_sample'), 'tip' => wfMsg('italic_tip'), 'key' => 'I'), array('image' => $wgLang->getImageFile('button-link'), 'id' => 'mw-editbutton-link', 'open' => '[[', 'close' => ']]', 'sample' => wfMsg('link_sample'), 'tip' => wfMsg('link_tip'), 'key' => 'L'), array('image' => $wgLang->getImageFile('button-extlink'), 'id' => 'mw-editbutton-extlink', 'open' => '[', 'close' => ']', 'sample' => wfMsg('extlink_sample'), 'tip' => wfMsg('extlink_tip'), 'key' => 'X'), array('image' => $wgLang->getImageFile('button-headline'), 'id' => 'mw-editbutton-headline', 'open' => "\n== ", 'close' => " ==\n", 'sample' => wfMsg('headline_sample'), 'tip' => wfMsg('headline_tip'), 'key' => 'H'), $imagesAvailable ? array('image' => $wgLang->getImageFile('button-image'), 'id' => 'mw-editbutton-image', 'open' => '[[' . $wgContLang->getNsText(NS_FILE) . ':', 'close' => ']]', 'sample' => wfMsg('image_sample'), 'tip' => wfMsg('image_tip'), 'key' => 'D') : false, $imagesAvailable ? array('image' => $wgLang->getImageFile('button-media'), 'id' => 'mw-editbutton-media', 'open' => '[[' . $wgContLang->getNsText(NS_MEDIA) . ':', 'close' => ']]', 'sample' => wfMsg('media_sample'), 'tip' => wfMsg('media_tip'), 'key' => 'M') : false, $wgUseTeX ? array('image' => $wgLang->getImageFile('button-math'), 'id' => 'mw-editbutton-math', 'open' => "<math>", 'close' => "</math>", 'sample' => wfMsg('math_sample'), 'tip' => wfMsg('math_tip'), 'key' => 'C') : false, array('image' => $wgLang->getImageFile('button-nowiki'), 'id' => 'mw-editbutton-nowiki', 'open' => "<nowiki>", 'close' => "</nowiki>", 'sample' => wfMsg('nowiki_sample'), 'tip' => wfMsg('nowiki_tip'), 'key' => 'N'), array('image' => $wgLang->getImageFile('button-sig'), 'id' => 'mw-editbutton-signature', 'open' => '--~~~~', 'close' => '', 'sample' => '', 'tip' => wfMsg('sig_tip'), 'key' => 'Y'), array('image' => $wgLang->getImageFile('button-hr'), 'id' => 'mw-editbutton-hr', 'open' => "\n----\n", 'close' => '', 'sample' => '', 'tip' => wfMsg('hr_tip'), 'key' => 'R'));
     $script = 'mw.loader.using("mediawiki.action.edit", function() {';
     foreach ($toolarray as $tool) {
         if (!$tool) {
             continue;
         }
         $params = array($image = $wgStylePath . '/common/images/' . $tool['image'], $tip = $tool['tip'], $open = $tool['open'], $close = $tool['close'], $sample = $tool['sample'], $cssId = $tool['id']);
         $script .= Xml::encodeJsCall('mw.toolbar.addButton', $params);
     }
     // This used to be called on DOMReady from mediawiki.action.edit, which
     // ended up causing race conditions with the setup code above.
     $script .= "\n" . "// Create button bar\n" . "\$(function() { mw.toolbar.init(); } );\n";
     $script .= '});';
     $wgOut->addScript(Html::inlineScript(ResourceLoader::makeLoaderConditionalScript($script)));
     $toolbar = '<div id="toolbar"></div>';
     wfRunHooks('EditPageBeforeEditToolbar', array(&$toolbar));
     return $toolbar;
 }
コード例 #7
0
 /**
  * @param ResourceLoaderContext $context
  * @return string
  */
 public function getScript(ResourceLoaderContext $context)
 {
     return Xml::encodeJsCall('mw.user.options.set', [$context->getUserObj()->getOptions(User::GETOPTIONS_EXCLUDE_DEFAULTS)], ResourceLoader::inDebugMode());
 }
コード例 #8
0
 /**
  * @param ResourceLoaderContext $context
  * @return string
  */
 public function getScript(ResourceLoaderContext $context)
 {
     return Xml::encodeJsCall('mw.user.options.set', array(User::getDefaultOptions()), ResourceLoader::inDebugMode());
 }
コード例 #9
0
 /**
  * @param ResourceLoaderContext $context
  * @return string
  */
 public function getScript(ResourceLoaderContext $context)
 {
     global $IP, $wgLegacyJavaScriptGlobals;
     $out = file_get_contents("{$IP}/resources/src/startup.js");
     if ($context->getOnly() === 'scripts') {
         // Startup function
         $configuration = $this->getConfig($context);
         $registrations = self::getModuleRegistrations($context);
         // Fix indentation
         $registrations = str_replace("\n", "\n\t", trim($registrations));
         $out .= "var startUp = function () {\n" . "\tmw.config = new " . Xml::encodeJsCall('mw.Map', array($wgLegacyJavaScriptGlobals)) . "\n" . "\t{$registrations}\n" . "\t" . Xml::encodeJsCall('mw.config.set', array($configuration)) . "};\n";
         // Conditional script injection
         $scriptTag = Html::linkedScript(self::getStartupModulesUrl($context));
         $out .= "if ( isCompatible() ) {\n" . "\t" . Xml::encodeJsCall('document.write', array($scriptTag)) . "}";
     }
     return $out;
 }
コード例 #10
0
ファイル: ResourceLoader.php プロジェクト: seedbank/old-repo
 /**
  * Returns JS code which will set the MediaWiki configuration array to
  * the given value.
  *
  * @param $configuration Array: List of configuration values keyed by variable name
  *
  * @return string
  */
 public static function makeConfigSetScript(array $configuration)
 {
     return Xml::encodeJsCall('mw.config.set', array($configuration));
 }
コード例 #11
0
ファイル: ResourceLoader.php プロジェクト: agothro/mediawiki
 /**
  * Returns JS code which will set the MediaWiki configuration array to
  * the given value.
  *
  * @param array $configuration List of configuration values keyed by variable name
  * @return string
  */
 public static function makeConfigSetScript(array $configuration)
 {
     return Xml::encodeJsCall('mw.config.set', array($configuration), ResourceLoader::inDebugMode()) . ResourceLoader::FILTER_NOMIN;
 }
コード例 #12
0
<?php 
// This is a stub entry point to load.php This is need to support valid paths for the stand alone 
// mwEmbed module html test files. 

// This is useful for running stand alone test of mwEmbed components in the TimedMediaHandler
// extension. ( ie MwEmbedModules/EmbedPlayer/tests/*.html files )

$_GET['modules'] = 'startup';
$_GET['only'] = 'scripts';

// NOTE this won't work so well with symbolic links
$loaderPath = dirname(__FILE__) . '/../../load.php';
if( is_file( $loaderPath ) ){	
	chdir( dirname( $loaderPath ) );
	include_once( $loaderPath );
} else {
	print "if( console && typeof console.log == 'function' ){ console.log('Error can't find load.php for stand alone tests' ) }";
}
// Bootstrap some js code to make the "loader" work in stand alone tests: 
// Note this has to be wrapped in a document.write to run after other document.writes
$pageStartupScript = Html::inlineScript(
	ResourceLoader::makeLoaderConditionalScript(
		Xml::encodeJsCall( 'mw.loader.go', array() )
	)
);
echo Xml::encodeJsCall( 'document.write', array( $pageStartupScript ) );
コード例 #13
0
 /**
  * @param $context ResourceLoaderContext
  * @return string JavaScript code
  */
 public function getScript(ResourceLoaderContext $context)
 {
     return Xml::encodeJsCall('mw.language.setData', array($context->getLanguage(), 'languageNames', $this->getData($context)));
 }
コード例 #14
0
function wfEditPageBeforeEditToolbar(&$toolbar)
{
    global $wgStylePath, $wgOut, $wgLanguageCode;
    $params = array($image = $wgStylePath . '/owl/images/1x1_transparent.gif', $tip = 'Weave links', $open = '', $close = '', $sample = '', $cssId = 'weave_button');
    $script = Xml::encodeJsCall('mw.toolbar.addButton', $params);
    $wgOut->addScript(Html::inlineScript(ResourceLoader::makeLoaderConditionalScript($script)));
    $params = array($image = $wgStylePath . '/owl/images/1x1_transparent.gif', $tip = 'Add Image', $open = '', $close = '', $sample = '', $cssId = 'easyimageupload_button', $onclick = "easyImageUpload.doEIUModal('advanced');return false;");
    $script = Xml::encodeJsCall('mw.toolbar.addButton', $params);
    $wgOut->addScript(Html::inlineScript(ResourceLoader::makeLoaderConditionalScript($script)));
    $wgOut->addJScode('advj');
    $wgOut->addJScode('eiuj');
    if (in_array($wgLanguageCode, array('en', 'de', 'es', 'pt'))) {
        $popbox = PopBox::getPopBoxJSAdvanced() . PopBox::getPopBoxCSS();
        $popbox_div = PopBox::getPopBoxDiv();
        $wgOut->addHTML($popbox_div . $popbox);
        $wgOut->addHTML(Easyimageupload::getUploadBoxJS(true));
    }
    return true;
}
コード例 #15
0
 /**
  * @param $context ResourceLoaderContext
  * @return string
  */
 public function getScript(ResourceLoaderContext $context)
 {
     global $wgUser;
     return Xml::encodeJsCall('mw.user.options.set', array($wgUser->getOptions()));
 }
コード例 #16
0
ファイル: load.mock.php プロジェクト: claudinec/galan-wiki
 * 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
 * @package MediaWiki
 * @author Lupo
 * @since 1.20
 */
header('Content-Type: text/javascript; charset=utf-8');
require_once __DIR__ . '/../../../includes/json/FormatJson.php';
require_once __DIR__ . '/../../../includes/Xml.php';
$moduleImplementations = ['testUsesMissing' => "\nmw.loader.implement( 'testUsesMissing', function () {\n\tQUnit.ok( false, 'Module usesMissing script should not run.' );\n\tQUnit.start();\n}, {}, {});\n", 'testUsesNestedMissing' => "\nmw.loader.implement( 'testUsesNestedMissing', function () {\n\tQUnit.ok( false, 'Module testUsesNestedMissing script should not run.' );\n\tQUnit.start();\n}, {}, {});\n", 'testSkipped' => "\nmw.loader.implement( 'testSkipped', function () {\n\tQUnit.ok( false, 'Module testSkipped was supposed to be skipped.' );\n}, {}, {});\n", 'testNotSkipped' => "\nmw.loader.implement( 'testNotSkipped', function () {}, {}, {});\n", 'testUsesSkippable' => "\nmw.loader.implement( 'testUsesSkippable', function () {}, {}, {});\n"];
$response = '';
// Only support for non-encoded module names, full module names expected
if (isset($_GET['modules'])) {
    $modules = explode(',', $_GET['modules']);
    foreach ($modules as $module) {
        if (isset($moduleImplementations[$module])) {
            $response .= $moduleImplementations[$module];
        } else {
            $response .= Xml::encodeJsCall('mw.loader.state', [$module, 'missing'], true);
        }
    }
}
echo $response;
コード例 #17
0
 /**
  * @param $context ResourceLoaderContext
  * @return string
  */
 public function getScript(ResourceLoaderContext $context)
 {
     global $IP, $wgScriptPath, $wgLoadScript, $wgLegacyJavaScriptGlobals;
     $out = file_get_contents("{$IP}/{$wgScriptPath}/resources/startup.js");
     if ($context->getOnly() === 'scripts') {
         // The core modules:
         $modules = array('jquery', 'mediawiki');
         wfRunHooks('ResourceLoaderGetStartupModules', array(&$modules));
         // Get the latest version
         $version = 0;
         foreach ($modules as $moduleName) {
             $version = max($version, $context->getResourceLoader()->getModule($moduleName)->getModifiedTime($context));
         }
         // Build load query for StartupModules
         $query = array('modules' => ResourceLoader::makePackedModulesString($modules), 'only' => 'scripts', 'lang' => $context->getLanguage(), 'skin' => $context->getSkin(), 'debug' => $context->getDebug() ? 'true' : 'false', 'version' => wfTimestamp(TS_ISO_8601_BASIC, $version));
         // Ensure uniform query order
         ksort($query);
         // Startup function
         $configuration = $this->getConfig($context);
         $registrations = self::getModuleRegistrations($context);
         $out .= "var startUp = function() {\n" . "\tmw.config = new " . Xml::encodeJsCall('mw.Map', array($wgLegacyJavaScriptGlobals)) . "\n" . "\t{$registrations}\n" . "\t" . Xml::encodeJsCall('mw.config.set', array($configuration)) . "};\n";
         $fauxRequest = new WebRequest();
         $modulesToLoad = array();
         $resourceLoader = $context->getResourceLoader();
         foreach ($modules as $moduleName) {
             $modulesToLoad[$moduleName] = $resourceLoader->getModule($moduleName);
         }
         $s = $context->getResourceLoader()->makeModuleResponse(new MwEmbedResourceLoaderContext($context->getResourceLoader(), $fauxRequest), $modulesToLoad, array());
         $out .= $s;
         //			// Conditional script injection
         //			$out .= "if ( isCompatible() ) {\n" .
         //				"\t" . Xml::encodeJsCall( 'writeScript', array(  $wgLoadScript . '?' . wfArrayToCGI( $query )  ) ) .
         //				"}\n" .
         //				"delete isCompatible;";
     }
     return $out;
 }
コード例 #18
0
    /**
     * Run the test suite on the Special page.
     *
     * Rendered by OutputPage and Skin.
     */
    private function viewQUnit()
    {
        $out = $this->getOutput();
        $modules = $out->getResourceLoader()->getTestModuleNames('qunit');
        $baseHtml = <<<HTML
<div class="mw-content-ltr">
<div id="qunit"></div>
</div>
HTML;
        $out->addHtml($this->getSummaryHtml() . $baseHtml);
        // The testrunner configures QUnit and essentially depends on it. However, test suites
        // are reusable in environments that preload QUnit (or a compatibility interface to
        // another framework). Therefore we have to load it ourselves.
        $out->addHtml(ResourceLoader::makeInlineScript(Xml::encodeJsCall('mw.loader.using', array(array('jquery.qunit', 'jquery.qunit.completenessTest'), new XmlJsCode('function () {' . Xml::encodeJsCall('mw.loader.load', array($modules)) . '}')))));
    }
コード例 #19
0
 /**
  * @param $context ResourceLoaderContext
  * @return string
  */
 public function getScript(ResourceLoaderContext $context)
 {
     global $IP, $wgLoadScript, $wgLegacyJavaScriptGlobals;
     $out = file_get_contents("{$IP}/resources/startup.js");
     if ($context->getOnly() === 'scripts') {
         // The core modules:
         $moduleNames = array('jquery', 'mediawiki');
         wfRunHooks('ResourceLoaderGetStartupModules', array(&$moduleNames));
         // Get the latest version
         $loader = $context->getResourceLoader();
         $version = 0;
         foreach ($moduleNames as $moduleName) {
             $version = max($version, $loader->getModule($moduleName)->getModifiedTime($context));
         }
         // Build load query for StartupModules
         $query = array('modules' => ResourceLoader::makePackedModulesString($moduleNames), 'only' => 'scripts', 'lang' => $context->getLanguage(), 'skin' => $context->getSkin(), 'debug' => $context->getDebug() ? 'true' : 'false', 'version' => wfTimestamp(TS_ISO_8601_BASIC, $version));
         // Ensure uniform query order
         ksort($query);
         // Startup function
         $configuration = $this->getConfig($context);
         $registrations = self::getModuleRegistrations($context);
         $registrations = str_replace("\n", "\n\t", trim($registrations));
         // fix indentation
         $out .= "var startUp = function() {\n" . "\tmw.config = new " . Xml::encodeJsCall('mw.Map', array($wgLegacyJavaScriptGlobals)) . "\n" . "\t{$registrations}\n" . "\t" . Xml::encodeJsCall('mw.config.set', array($configuration)) . "};\n";
         // Conditional script injection
         $scriptTag = Html::linkedScript($wgLoadScript . '?' . wfArrayToCGI($query));
         $out .= "if ( isCompatible() ) {\n" . "\t" . Xml::encodeJsCall('document.write', array($scriptTag)) . "}\n" . "delete isCompatible;";
     }
     return $out;
 }
コード例 #20
0
ファイル: EditPage.php プロジェクト: whysasse/kmwiki
 /**
  * Shows a bulletin board style toolbar for common editing functions.
  * It can be disabled in the user preferences.
  *
  * @return string
  */
 static function getEditToolbar()
 {
     global $wgContLang, $wgOut;
     global $wgEnableUploads, $wgForeignFileRepos;
     $imagesAvailable = $wgEnableUploads || count($wgForeignFileRepos);
     /**
      * $toolarray is an array of arrays each of which includes the
      * opening tag, the closing tag, optionally a sample text that is
      * inserted between the two when no selection is highlighted
      * and.  The tip text is shown when the user moves the mouse
      * over the button.
      *
      * Images are defined in ResourceLoaderEditToolbarModule.
      */
     $toolarray = array(array('id' => 'mw-editbutton-bold', 'open' => '\'\'\'', 'close' => '\'\'\'', 'sample' => wfMessage('bold_sample')->text(), 'tip' => wfMessage('bold_tip')->text()), array('id' => 'mw-editbutton-italic', 'open' => '\'\'', 'close' => '\'\'', 'sample' => wfMessage('italic_sample')->text(), 'tip' => wfMessage('italic_tip')->text()), array('id' => 'mw-editbutton-link', 'open' => '[[', 'close' => ']]', 'sample' => wfMessage('link_sample')->text(), 'tip' => wfMessage('link_tip')->text()), array('id' => 'mw-editbutton-extlink', 'open' => '[', 'close' => ']', 'sample' => wfMessage('extlink_sample')->text(), 'tip' => wfMessage('extlink_tip')->text()), array('id' => 'mw-editbutton-headline', 'open' => "\n== ", 'close' => " ==\n", 'sample' => wfMessage('headline_sample')->text(), 'tip' => wfMessage('headline_tip')->text()), $imagesAvailable ? array('id' => 'mw-editbutton-image', 'open' => '[[' . $wgContLang->getNsText(NS_FILE) . ':', 'close' => ']]', 'sample' => wfMessage('image_sample')->text(), 'tip' => wfMessage('image_tip')->text()) : false, $imagesAvailable ? array('id' => 'mw-editbutton-media', 'open' => '[[' . $wgContLang->getNsText(NS_MEDIA) . ':', 'close' => ']]', 'sample' => wfMessage('media_sample')->text(), 'tip' => wfMessage('media_tip')->text()) : false, array('id' => 'mw-editbutton-nowiki', 'open' => "<nowiki>", 'close' => "</nowiki>", 'sample' => wfMessage('nowiki_sample')->text(), 'tip' => wfMessage('nowiki_tip')->text()), array('id' => 'mw-editbutton-signature', 'open' => '--~~~~', 'close' => '', 'sample' => '', 'tip' => wfMessage('sig_tip')->text()), array('id' => 'mw-editbutton-hr', 'open' => "\n----\n", 'close' => '', 'sample' => '', 'tip' => wfMessage('hr_tip')->text()));
     $script = 'mw.loader.using("mediawiki.action.edit", function() {';
     foreach ($toolarray as $tool) {
         if (!$tool) {
             continue;
         }
         $params = array(false, $tool['tip'], $tool['open'], $tool['close'], $tool['sample'], $tool['id']);
         $script .= Xml::encodeJsCall('mw.toolbar.addButton', $params);
     }
     // This used to be called on DOMReady from mediawiki.action.edit, which
     // ended up causing race conditions with the setup code above.
     $script .= "\n" . "// Create button bar\n" . "\$(function() { mw.toolbar.init(); } );\n";
     $script .= '});';
     $wgOut->addScript(Html::inlineScript(ResourceLoader::makeLoaderConditionalScript($script)));
     $toolbar = '<div id="toolbar"></div>';
     wfRunHooks('EditPageBeforeEditToolbar', array(&$toolbar));
     return $toolbar;
 }
コード例 #21
0
 * 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
 * @package MediaWiki
 * @author Lupo
 * @since 1.20
 */
header('Content-Type: text/javascript; charset=utf-8');
require_once '../../../includes/Xml.php';
$moduleImplementations = array('testUsesMissing' => "\nmw.loader.implement( 'testUsesMissing', function () {\n\tQUnit.ok( false, 'Module test.usesMissing script should not run.');\n\tQUnit.start();\n}, {}, {});\n", 'testUsesNestedMissing' => "\nmw.loader.implement( 'testUsesNestedMissing', function () {\n\tQUnit.ok( false, 'Module testUsesNestedMissing script should not run.');\n}, {}, {});\n");
$response = '';
// Only support for non-encoded module names, full module names expected
if (isset($_GET['modules'])) {
    $modules = explode(',', $_GET['modules']);
    foreach ($modules as $module) {
        if (isset($moduleImplementations[$module])) {
            $response .= $moduleImplementations[$module];
        } else {
            $response .= Xml::encodeJsCall('mw.loader.state', array($module, 'missing'));
        }
    }
}
echo $response;
コード例 #22
0
 /**
  * Generate self-sufficient JavaScript payload to run the tests elsewhere.
  *
  * Includes startup module to request modules from ResourceLoader.
  *
  * Note: This modifies the registry to replace 'jquery.qunit' with an
  * empty module to allow external environment to preload QUnit with any
  * neccecary framework adapters (e.g. Karma). Loading it again would
  * re-define QUnit and dereference event handlers from Karma.
  */
 private function exportQUnit()
 {
     $out = $this->getOutput();
     $out->disable();
     $rl = $out->getResourceLoader();
     $query = array('lang' => $this->getLanguage()->getCode(), 'skin' => $this->getSkin()->getSkinName(), 'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false');
     $embedContext = new ResourceLoaderContext($rl, new FauxRequest($query));
     $query['only'] = 'scripts';
     $startupContext = new ResourceLoaderContext($rl, new FauxRequest($query));
     $modules = $rl->getTestModuleNames('qunit');
     // The below is essentially a pure-javascript version of OutputPage::getHeadScripts.
     $startup = $rl->makeModuleResponse($startupContext, array('startup' => $rl->getModule('startup')));
     // Embed page-specific mw.config variables.
     // The current Special page shouldn't be relevant to tests, but various modules (which
     // are loaded before the test suites), reference mw.config while initialising.
     $code = ResourceLoader::makeConfigSetScript($out->getJSVars());
     // Embed private modules as they're not allowed to be loaded dynamically
     $code .= $rl->makeModuleResponse($embedContext, array('user.options' => $rl->getModule('user.options'), 'user.tokens' => $rl->getModule('user.tokens')));
     $code .= Xml::encodeJsCall('mw.loader.load', array($modules));
     header('Content-Type: text/javascript; charset=utf-8');
     header('Cache-Control: private, no-cache, must-revalidate');
     header('Pragma: no-cache');
     echo $startup;
     echo "\n";
     // Note: The following has to be wrapped in a script tag because the startup module also
     // writes a script tag (the one loading mediawiki.js). Script tags are synchronous, block
     // each other, and run in order. But they don't nest. The code appended after the startup
     // module runs before the added script tag is parsed and executed.
     echo Xml::encodeJsCall('document.write', array(Html::inlineScript($code)));
 }
コード例 #23
0
    /**
     * @param $context ResourceLoaderContext
     * @return string
     */
    public function getScript(ResourceLoaderContext $context)
    {
        global $IP, $wgLoadScript, $wgLegacyJavaScriptGlobals;
        $out = file_get_contents("{$IP}/resources/startup.js");
        if ($context->getOnly() === 'scripts') {
            // The core modules:
            $modules = array('jquery', 'mediawiki');
            wfRunHooks('ResourceLoaderGetStartupModules', array(&$modules));
            // Get the latest version
            $version = 0;
            foreach ($modules as $moduleName) {
                $version = max($version, $context->getResourceLoader()->getModule($moduleName)->getModifiedTime($context));
            }
            // Build load query for StartupModules
            $query = array('modules' => ResourceLoader::makePackedModulesString($modules), 'only' => 'scripts', 'lang' => $context->getLanguage(), 'skin' => $context->getSkin(), 'debug' => $context->getDebug() ? 'true' : 'false', 'version' => wfTimestamp(TS_ISO_8601_BASIC, $version));
            // Ensure uniform query order
            ksort($query);
            // Startup function
            $configuration = $this->getConfig($context);
            $registrations = self::getModuleRegistrations($context);
            $out .= "var startUp = function() {\n" . "\tmw.config = new " . Xml::encodeJsCall('mw.Map', array($wgLegacyJavaScriptGlobals)) . "\n" . "\t{$registrations}\n" . "\t" . Xml::encodeJsCall('mw.config.set', array($configuration)) . "\t" . Xml::encodeJsCall('mw.loader.state', array(array('jquery' => 'ready'))) . "};\n";
            // Conditional script injection
            // Wikia change - begin - @author: wladek
            //			$scriptTag = Html::linkedScript( $wgLoadScript . '?' . wfArrayToCGI( $query ) );
            // get jquery from CDN if we have wsl and getJqueryUrl loaded
            $scriptTagJquery = Xml::encodeJsVar(Html::linkedScript(ResourceLoader::makeLoaderURL($modules, $query['lang'], $query['skin'], null, $query['version'], $context->getDebug(), 'scripts')));
            $scriptTagNoJquery = Xml::encodeJsVar(Html::linkedScript(ResourceLoader::makeLoaderURL(array('mediawiki'), $query['lang'], $query['skin'], null, $query['version'], $context->getDebug(), 'scripts')));
            $scriptTag = <<<ENDSCRIPT
( (window.wsl && window.getJqueryUrl && window.wgJqueryUrl) ? (wsl.buildScript(window.getJqueryUrl()) + {$scriptTagNoJquery}) : ({$scriptTagJquery}) )
ENDSCRIPT;
            $scriptTag = new XmlJsCode($scriptTag);
            // Wikia change - end
            $out .= "if ( isCompatible() ) {\n" . "\t" . Xml::encodeJsCall('document.write', array($scriptTag)) . "}\n" . "delete isCompatible;";
        }
        return $out;
    }
コード例 #24
0
 /**
  * @param $context ResourceLoaderContext
  * @return string
  */
 public function getScript(ResourceLoaderContext $context)
 {
     return Xml::encodeJsCall('mw.user.tokens.set', array($this->contextUserTokens()), ResourceLoader::inDebugMode());
 }
コード例 #25
0
ファイル: OutputPage.php プロジェクト: eFFemeer/seizamcore
 /**
  * JS stuff to put at the bottom of the <body>: modules marked with position 'bottom',
  * legacy scripts ($this->mScripts), user preferences, site JS and user JS
  *
  * @param $sk Skin
  *
  * @return string
  */
 function getBottomScripts(Skin $sk)
 {
     global $wgUseSiteJs, $wgAllowUserJs;
     // Script and Messages "only" requests marked for bottom inclusion
     // Messages should go first
     $scripts = $this->makeResourceLoaderLink($sk, $this->getModuleMessages(true, 'bottom'), ResourceLoaderModule::TYPE_MESSAGES);
     $scripts .= $this->makeResourceLoaderLink($sk, $this->getModuleScripts(true, 'bottom'), ResourceLoaderModule::TYPE_SCRIPTS);
     // Modules requests - let the client calculate dependencies and batch requests as it likes
     // Only load modules that have marked themselves for loading at the bottom
     $modules = $this->getModules(true, 'bottom');
     if ($modules) {
         $scripts .= Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(Xml::encodeJsCall('mw.loader.load', array($modules))));
     }
     // Legacy Scripts
     $scripts .= "\n" . $this->mScripts;
     $userScripts = array('user.options', 'user.tokens');
     // Add site JS if enabled
     if ($wgUseSiteJs) {
         $scripts .= $this->makeResourceLoaderLink($sk, 'site', ResourceLoaderModule::TYPE_SCRIPTS);
         if ($this->getUser()->isLoggedIn()) {
             $userScripts[] = 'user.groups';
         }
     }
     // Add user JS if enabled
     if ($wgAllowUserJs && $this->getUser()->isLoggedIn()) {
         $action = $this->getRequest()->getVal('action', 'view');
         if ($this->getTitle() && $this->getTitle()->isJsSubpage() && $sk->userCanPreview($action)) {
             # XXX: additional security check/prompt?
             $scripts .= Html::inlineScript("\n" . $this->getRequest()->getText('wpTextbox1') . "\n") . "\n";
         } else {
             # @todo FIXME: This means that User:Me/Common.js doesn't load when previewing
             # User:Me/Vector.js, and vice versa (bug26283)
             $userScripts[] = 'user';
         }
     }
     $scripts .= $this->makeResourceLoaderLink($sk, $userScripts, ResourceLoaderModule::TYPE_SCRIPTS);
     return $scripts;
 }
コード例 #26
0
 /**
  * JS stuff to put at the 'bottom', which can either be the bottom of the
  * "<body>" or the bottom of the "<head>" depending on
  * $wgResourceLoaderExperimentalAsyncLoading: modules marked with position
  * 'bottom', legacy scripts ($this->mScripts), user preferences, site JS
  * and user JS.
  *
  * @param bool $inHead If true, this HTML goes into the "<head>",
  *   if false it goes into the "<body>".
  * @return string
  */
 function getScriptsForBottomQueue($inHead)
 {
     // Scripts "only" requests marked for bottom inclusion
     // If we're in the <head>, use load() calls rather than <script src="..."> tags
     $links = array();
     $links[] = $this->makeResourceLoaderLink($this->getModuleScripts(true, 'bottom'), ResourceLoaderModule::TYPE_SCRIPTS, false, array(), $inHead);
     $links[] = $this->makeResourceLoaderLink($this->getModuleStyles(true, 'bottom'), ResourceLoaderModule::TYPE_STYLES, false, array(), $inHead);
     // Modules requests - let the client calculate dependencies and batch requests as it likes
     // Only load modules that have marked themselves for loading at the bottom
     $modules = $this->getModules(true, 'bottom');
     if ($modules) {
         $links[] = ResourceLoader::makeInlineScript(Xml::encodeJsCall('mw.loader.load', array($modules, null, true)));
     }
     // Legacy Scripts
     $links[] = "\n" . $this->mScripts;
     // Add site JS if enabled
     $links[] = $this->makeResourceLoaderLink('site', ResourceLoaderModule::TYPE_SCRIPTS, false, array(), $inHead);
     // Add user JS if enabled
     if ($this->getConfig()->get('AllowUserJs') && $this->getUser()->isLoggedIn() && $this->getTitle() && $this->getTitle()->isJsSubpage() && $this->userCanPreview()) {
         # XXX: additional security check/prompt?
         // We're on a preview of a JS subpage
         // Exclude this page from the user module in case it's in there (bug 26283)
         $links[] = $this->makeResourceLoaderLink('user', ResourceLoaderModule::TYPE_SCRIPTS, false, array('excludepage' => $this->getTitle()->getPrefixedDBkey()), $inHead);
         // Load the previewed JS
         $links[] = Html::inlineScript("\n" . $this->getRequest()->getText('wpTextbox1') . "\n") . "\n";
         // FIXME: If the user is previewing, say, ./vector.js, his ./common.js will be loaded
         // asynchronously and may arrive *after* the inline script here. So the previewed code
         // may execute before ./common.js runs. Normally, ./common.js runs before ./vector.js...
     } else {
         // Include the user module normally, i.e., raw to avoid it being wrapped in a closure.
         $links[] = $this->makeResourceLoaderLink('user', ResourceLoaderModule::TYPE_SCRIPTS, false, array(), $inHead);
     }
     // Group JS is only enabled if site JS is enabled.
     $links[] = $this->makeResourceLoaderLink('user.groups', ResourceLoaderModule::TYPE_COMBINED, false, array(), $inHead);
     return self::getHtmlFromLoaderLinks($links);
 }
 /**
  * @param ResourceLoaderContext $context
  * @return string JavaScript code
  */
 public function getScript(ResourceLoaderContext $context)
 {
     return Xml::encodeJsCall('mw.language.setSpecialCharacters', array($this->getData()), ResourceLoader::inDebugMode());
 }
コード例 #28
0
 /**
  * JS stuff to put at the 'bottom', which goes at the bottom of the `<body>`.
  * These are modules marked with position 'bottom', legacy scripts ($this->mScripts),
  * site JS, and user JS.
  *
  * @param bool $unused Previously used to let this method change its output based
  *  on whether it was called by getExternalHeadScripts() or getBottomScripts().
  * @return string
  */
 function getScriptsForBottomQueue($unused = null)
 {
     // Scripts "only" requests marked for bottom inclusion
     // If we're in the <head>, use load() calls rather than <script src="..."> tags
     $links = array();
     $links[] = $this->makeResourceLoaderLink($this->getModuleScripts(true, 'bottom'), ResourceLoaderModule::TYPE_SCRIPTS);
     // Modules requests - let the client calculate dependencies and batch requests as it likes
     // Only load modules that have marked themselves for loading at the bottom
     $modules = $this->getModules(true, 'bottom');
     if ($modules) {
         $links[] = ResourceLoader::makeInlineScript(Xml::encodeJsCall('mw.loader.load', array($modules)));
     }
     // Legacy Scripts
     $links[] = $this->mScripts;
     // Add user JS if enabled
     // This must use TYPE_COMBINED instead of only=scripts so that its request is handled by
     // mw.loader.implement() which ensures that execution is scheduled after the "site" module.
     if ($this->getConfig()->get('AllowUserJs') && $this->getUser()->isLoggedIn() && $this->getTitle() && $this->getTitle()->isJsSubpage() && $this->userCanPreview()) {
         // We're on a preview of a JS subpage. Exclude this page from the user module (T28283)
         // and include the draft contents as a raw script instead.
         $links[] = $this->makeResourceLoaderLink('user', ResourceLoaderModule::TYPE_COMBINED, array('excludepage' => $this->getTitle()->getPrefixedDBkey()));
         // Load the previewed JS
         $links[] = ResourceLoader::makeInlineScript(Xml::encodeJsCall('mw.loader.using', array(array('user', 'site'), new XmlJsCode('function () {' . Xml::encodeJsCall('$.globalEval', array($this->getRequest()->getText('wpTextbox1'))) . '}'))));
         // FIXME: If the user is previewing, say, ./vector.js, his ./common.js will be loaded
         // asynchronously and may arrive *after* the inline script here. So the previewed code
         // may execute before ./common.js runs. Normally, ./common.js runs before ./vector.js.
         // Similarly, when previewing ./common.js and the user module does arrive first,
         // it will arrive without common.js and the inline script runs after.
         // Thus running common after the excluded subpage.
     } else {
         // Include the user module normally, i.e., raw to avoid it being wrapped in a closure.
         $links[] = $this->makeResourceLoaderLink('user', ResourceLoaderModule::TYPE_COMBINED);
     }
     // Group JS is only enabled if site JS is enabled.
     $links[] = $this->makeResourceLoaderLink('user.groups', ResourceLoaderModule::TYPE_COMBINED);
     return self::getHtmlFromLoaderLinks($links);
 }
コード例 #29
0
ファイル: ResourceLoader.php プロジェクト: ErdemA/mediawiki
 /**
  * Returns JS code which will set the MediaWiki configuration array to
  * the given value.
  *
  * @param array $configuration List of configuration values keyed by variable name
  * @return string
  */
 public static function makeConfigSetScript(array $configuration)
 {
     if (ResourceLoader::inDebugMode()) {
         return Xml::encodeJsCall('mw.config.set', array($configuration), true);
     }
     $config = RequestContext::getMain()->getConfig();
     $js = Xml::encodeJsCall('mw.config.set', array($configuration), false);
     return self::applyFilter('minify-js', $js, $config);
 }
コード例 #30
-1
 function buildCleanupScript()
 {
     global $wgCascadingRestrictionLevels, $wgOut;
     $cascadeableLevels = $wgCascadingRestrictionLevels;
     $options = array('tableId' => 'mwProtectSet', 'labelText' => wfMessage('protect-unchain-permissions')->plain(), 'numTypes' => count($this->mApplicableTypes), 'existingMatch' => count(array_unique($this->mExistingExpiry)) === 1);
     $wgOut->addJsConfigVars('wgCascadeableLevels', $cascadeableLevels);
     $script = Xml::encodeJsCall('ProtectionForm.init', array($options));
     return Html::inlineScript(ResourceLoader::makeLoaderConditionalScript($script));
 }