Add a function that returns a list of categories the page is a member of
[lhc/web/wiklou.git] / includes / Skin.php
index 15b8545..de9c9dc 100644 (file)
@@ -197,6 +197,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
         */
@@ -1521,31 +1583,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;