Merge "Followup Ifb005e7c: some cleanup in comments."
[lhc/web/wiklou.git] / includes / Skin.php
index 1aa1f05..b714886 100644 (file)
@@ -25,7 +25,7 @@
  */
 
 /**
- * The main skin class that provide methods and properties for all other skins.
+ * The main skin class which provides methods and properties for all other skins.
  * This base class is also the "Standard" skin.
  *
  * See docs/skin.txt for more information.
@@ -82,13 +82,15 @@ abstract class Skin extends ContextSource {
        static function getSkinNameMessages() {
                $messages = array();
                foreach ( self::getSkinNames() as $skinKey => $skinName ) {
+                       // Give grep a chance to find the usages:
+                       // skinname-cologneblue, skinname-monobook, skinname-modern, skinname-vector
                        $messages[] = "skinname-$skinKey";
                }
                return $messages;
        }
 
        /**
-        * Fetch the list of usable skins in regards to $wgSkipSkins.
+        * Fetch the list of user-selectable skins in regards to $wgSkipSkins.
         * Useful for Special:Preferences and other places where you
         * only want to show skins users _can_ use.
         * @return array of strings
@@ -96,13 +98,13 @@ abstract class Skin extends ContextSource {
        public static function getUsableSkins() {
                global $wgSkipSkins;
 
-               $usableSkins = self::getSkinNames();
+               $allowedSkins = self::getSkinNames();
 
                foreach ( $wgSkipSkins as $skip ) {
-                       unset( $usableSkins[$skip] );
+                       unset( $allowedSkins[$skip] );
                }
 
-               return $usableSkins;
+               return $allowedSkins;
        }
 
        /**
@@ -162,23 +164,19 @@ abstract class Skin extends ContextSource {
                $className = "Skin{$skinName}";
 
                # Grab the skin class and initialise it.
-               if ( !MWInit::classExists( $className ) ) {
+               if ( !class_exists( $className ) ) {
 
-                       if ( !defined( 'MW_COMPILED' ) ) {
-                               require_once( "{$wgStyleDirectory}/{$skinName}.php" );
-                       }
+                       require_once "{$wgStyleDirectory}/{$skinName}.php";
 
                        # Check if we got if not fallback to default skin
-                       if ( !MWInit::classExists( $className ) ) {
+                       if ( !class_exists( $className ) ) {
                                # DO NOT die if the class isn't found. This breaks maintenance
                                # scripts and can cause a user account to be unrecoverable
                                # except by SQL manipulation if a previously valid skin name
                                # is no longer valid.
                                wfDebug( "Skin class does not exist: $className\n" );
                                $className = 'SkinVector';
-                               if ( !defined( 'MW_COMPILED' ) ) {
-                                       require_once( "{$wgStyleDirectory}/Vector.php" );
-                               }
+                               require_once "{$wgStyleDirectory}/Vector.php";
                        }
                }
                $skin = new $className( $key );
@@ -201,6 +199,68 @@ abstract class Skin extends ContextSource {
                wfProfileOut( __METHOD__ );
        }
 
+       /**
+        * Defines the ResourceLoader modules that should be added to the skin
+        * It is recommended that skins wishing to override call parent::getDefaultModules()
+        * and substitute out any modules they wish to change by using a key to look them up
+        * @return Array of modules with helper keys for easy overriding
+        */
+       public function getDefaultModules() {
+               global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax,
+                       $wgAjaxWatch, $wgEnableAPI, $wgEnableWriteAPI;
+
+               $out = $this->getOutput();
+               $user = $out->getUser();
+               $modules = array(
+                       // modules that enhance the page content in some way
+                       'content' => array(
+                               'mediawiki.page.ready',
+                       ),
+                       // modules that exist for legacy reasons
+                       'legacy' => array(),
+                       // modules relating to search functionality
+                       'search' => array(),
+                       // modules relating to functionality relating to watching an article
+                       'watch' => array(),
+                       // modules which relate to the current users preferences
+                       'user' => array(),
+               );
+               if ( $wgIncludeLegacyJavaScript ) {
+                       $modules['legacy'][] = 'mediawiki.legacy.wikibits';
+               }
+
+               if ( $wgPreloadJavaScriptMwUtil ) {
+                       $modules['legacy'][] = 'mediawiki.util';
+               }
+
+               // Add various resources if required
+               if ( $wgUseAjax ) {
+                       $modules['legacy'][] = 'mediawiki.legacy.ajax';
+
+                       if ( $wgEnableAPI ) {
+                               if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn()
+                                       && $user->isAllowed( 'writeapi' )
+                               ) {
+                                       $modules['watch'][] = 'mediawiki.page.watch.ajax';
+                               }
+
+                               if ( !$user->getOption( 'disablesuggest', false ) ) {
+                                       $modules['search'][] = 'mediawiki.searchSuggest';
+                               }
+                       }
+               }
+
+               if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
+                       $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
+               }
+
+               // Crazy edit-on-double-click stuff
+               if ( $out->isArticle() && $user->getOption( 'editondblclick' ) ) {
+                       $modules['user'][] = 'mediawiki.action.view.dblClickEdit';
+               }
+               return $modules;
+       }
+
        /**
         * Preload the existence of three commonly-requested pages in a single query
         */
@@ -1525,31 +1585,12 @@ abstract class Skin extends ContextSource {
                        array( 'noclasses', 'known' )
                );
 
-               # Run the old hook.  This takes up half of the function . . . hopefully
-               # we can rid of it someday.
-               $attribs = '';
-               if ( $tooltip ) {
-                       $attribs = wfMessage( 'editsectionhint' )->rawParams( $tooltip )
-                               ->inLanguage( $lang )->escaped();
-                       $attribs = " title=\"$attribs\"";
-               }
-               $result = null;
-               wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result, $lang ) );
-               if ( !is_null( $result ) ) {
-                       # For reverse compatibility, add the brackets *after* the hook is
-                       # run, and even add them to hook-provided text.  (This is the main
-                       # reason that the EditSectionLink hook is deprecated in favor of
-                       # DoEditSectionLink: it can't change the brackets or the span.)
-                       $result = wfMessage( 'editsection-brackets' )->rawParams( $result )
-                               ->inLanguage( $lang )->escaped();
-                       return "<span class=\"mw-editsection\">$result</span>";
-               }
-
-               # Add the brackets and the span, and *then* run the nice new hook, with
-               # clean and non-redundant arguments.
-               $result = wfMessage( 'editsection-brackets' )->rawParams( $link )
-                       ->inLanguage( $lang )->escaped();
-               $result = "<span class=\"mw-editsection\">$result</span>";
+               # Add the brackets and the span and run the hook.
+               $result = '<span class="mw-editsection">'
+                       . '<span class="mw-editsection-bracket">[</span>'
+                       . $link
+                       . '<span class="mw-editsection-bracket">]</span>'
+                       . '</span>';
 
                wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result, $lang ) );
                return $result;