Add wikipage.categories hook
authorDerk-Jan Hartman <hartman.wiki@gmail.com>
Sun, 21 Jun 2015 16:59:20 +0000 (18:59 +0200)
committerJdlrobson <jrobson@wikimedia.org>
Tue, 5 Jan 2016 22:48:54 +0000 (22:48 +0000)
This will be especially useful for HotCat.

Bug: T53583
Change-Id: Id944029df180c80502840c118a58013ebb717e1f

includes/skins/Skin.php
resources/src/mediawiki.action/mediawiki.action.edit.preview.js
resources/src/mediawiki/page/ready.js

index dbb7c7f..83f119d 100644 (file)
@@ -560,7 +560,7 @@ abstract class Skin extends ContextSource {
                        $classes .= ' catlinks-allhidden';
                }
 
-               return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
+               return "<div id='catlinks' class='$classes' data-mw='interface'>{$catlinks}</div>";
        }
 
        /**
index 013d34f..1d4d0e9 100644 (file)
                                        );
                                }
                                if ( response.parse.categorieshtml ) {
-                                       $( '#catlinks' ).replaceWith( response.parse.categorieshtml[ '*' ] );
+                                       $content = $( $.parseHTML( response.parse.categorieshtml[ '*' ] ) );
+                                       mw.hook( 'wikipage.categories' ).fire( $content );
+                                       $( '.catlinks[data-mw="interface"]' ).replaceWith( $content );
                                }
                                if ( response.parse.templates ) {
                                        newList = [];
index 9505bdd..4385a2e 100644 (file)
                        } );
                }
 
+               $nodes = $( '.catlinks[data-mw="interface"]' );
+               if ( $nodes.length ) {
+                       /**
+                        * Fired when categories are being added to the DOM
+                        *
+                        * It is encouraged to fire it before the main DOM is changed (when $content
+                        * is still detached).  However, this order is not defined either way, so you
+                        * should only rely on $content itself.
+                        *
+                        * This includes the ready event on a page load (including post-edit loads)
+                        * and when content has been previewed with LivePreview.
+                        *
+                        * @event wikipage_categories
+                        * @member mw.hook
+                        * @param {jQuery} $content The most appropriate element containing the content,
+                        *   such as .catlinks
+                        */
+                       mw.hook( 'wikipage.categories' ).fire( $nodes );
+               }
        } );
 
 }( mediaWiki, jQuery ) );