Minor cleanups
[lhc/web/wiklou.git] / includes / OutputPage.php
index 5c146e4..cac89f4 100644 (file)
@@ -196,12 +196,6 @@ class OutputPage extends ContextSource {
 
        // Parser related.
 
-       /**
-        * @var int
-        * @todo Unused?
-        */
-       private $mContainsOldMagic = 0;
-
        /** @var int */
        protected $mContainsNewMagic = 0;
 
@@ -1379,7 +1373,8 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Add an array of indicators, with their identifiers as array keys and HTML contents as values.
+        * Add an array of indicators, with their identifiers as array
+        * keys and HTML contents as values.
         *
         * In case of duplicate keys, existing values are overwritten.
         *
@@ -1404,6 +1399,35 @@ class OutputPage extends ContextSource {
                return $this->mIndicators;
        }
 
+       /**
+        * Adds help link with an icon via page indicators.
+        * @param string $to
+        * @param bool $overrideBaseUrl
+        * @since 1.25
+        */
+       public function addHelpLink( $to, $overrideBaseUrl = false ) {
+               $this->addModuleStyles( 'mediawiki.helplink' );
+               $text = $this->msg( 'helppage-top-gethelp' )->escaped();
+
+               if ( $overrideBaseUrl ) {
+                       $helpUrl = $to;
+               } else {
+                       $toUrlencoded = wfUrlencode( str_replace( ' ', '_', $to ) );
+                       $helpUrl = "//www.mediawiki.org/wiki/Special:MyLanguage/$toUrlencoded";
+               }
+               $link = Html::rawElement(
+                       'a',
+                       array(
+                               'href' => $helpUrl,
+                               'target' => '_blank',
+                               'class' => 'mw-helplink',
+                       ),
+                       $text
+               );
+
+               $this->setIndicators( array( 'mw-helplink' => $link ) );
+       }
+
        /**
         * Do not allow scripts which can be modified by wiki users to load on this page;
         * only allow scripts bundled with, or generated by, the software.
@@ -2879,11 +2903,11 @@ class OutputPage extends ContextSource {
                                                );
                                        } else {
                                                $link = Html::linkedScript( $url );
-                                               if ( $context->getOnly() === 'scripts' && !$context->getRaw() && !$isRaw ) {
-                                                       // Wrap only=script requests in a conditional as browsers not supported
-                                                       // by the startup module would unconditionally execute this module.
-                                                       // Otherwise users will get "ReferenceError: mw is undefined" or
-                                                       // "jQuery is undefined" from e.g. a "site" module.
+                                               if ( !$context->getRaw() && !$isRaw ) {
+                                                       // Wrap only=script / only=combined requests in a conditional as
+                                                       // browsers not supported by the startup module would unconditionally
+                                                       // execute this module. Otherwise users will get "ReferenceError: mw is
+                                                       // undefined" or "jQuery is undefined" from e.g. a "site" module.
                                                        $link = Html::inlineScript(
                                                                ResourceLoader::makeLoaderConditionalScript(
                                                                        Xml::encodeJsCall( 'document.write', array( $link ) )
@@ -3082,7 +3106,7 @@ class OutputPage extends ContextSource {
                // This also enforces $.isReady to be true at </body> which fixes the
                // mw.loader bug in Firefox with using document.write between </body>
                // and the DOMContentReady event (bug 47457).
-               $html = Html::inlineScript( 'window.jQuery && jQuery.ready();' );
+               $html = Html::inlineScript( 'if(window.jQuery)jQuery.ready();' );
 
                if ( !$this->getConfig()->get( 'ResourceLoaderExperimentalAsyncLoading' ) ) {
                        $html .= $this->getScriptsForBottomQueue( false );
@@ -3264,6 +3288,10 @@ class OutputPage extends ContextSource {
                if ( !$this->getTitle()->isJsSubpage() && !$this->getTitle()->isCssSubpage() ) {
                        return false;
                }
+               if ( !$this->getTitle()->isSubpageOf( $this->getUser()->getUserPage() ) ) {
+                       // Don't execute another user's CSS or JS on preview (T85855)
+                       return false;
+               }
 
                return !count( $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getUser() ) );
        }