Surround edit notices with appropriate classes
authorDouglas Gardner <douglas@chippy.ch>
Sat, 16 Aug 2014 11:29:04 +0000 (12:29 +0100)
committerDouglas Gardner <douglas@chippy.ch>
Sat, 16 Aug 2014 12:46:28 +0000 (13:46 +0100)
This commit adds a <div> around edit notices with relevant classes to aid in the
creation of user scripts, following an earlier change (bug 30959) for
edit intros.

It adds an .mw-editnotice class to each edit notice, and because classes are fairly
cheap, a second mirroring the edit notice's message key, and a third depending
on the edit notice type:
.mw-editnotice-namespace for a namespace-wide edit notice
.mw-editnotice-base for a edit notice for the subpage's base page
.mw-editnotice-page for an edit notice set explicitly for the page

Classes are sanitized where required.

Bug: 68749
Change-Id: Idf44f2a344d64893f799286914bda3f8d4aff6bf

includes/Title.php

index a1b2352..b25676c 100644 (file)
@@ -5007,7 +5007,9 @@ class Title {
                $editnotice_ns = 'editnotice-' . $this->getNamespace();
                $editnotice_ns_message = wfMessage( $editnotice_ns );
                if ( $editnotice_ns_message->exists() ) {
-                       $notices[$editnotice_ns] = $editnotice_ns_message->parseAsBlock();
+                       $notices[$editnotice_ns] = '<div class="mw-editnotice mw-editnotice-namespace ' .
+                               Sanitizer::escapeClass( "mw-$editnotice_ns" ) . '">' .
+                               $editnotice_ns_message->parseAsBlock() . '</div>';
                }
                if ( MWNamespace::hasSubpages( $this->getNamespace() ) ) {
                        $parts = explode( '/', $this->getDBkey() );
@@ -5016,7 +5018,9 @@ class Title {
                                $editnotice_base .= '-' . array_shift( $parts );
                                $editnotice_base_msg = wfMessage( $editnotice_base );
                                if ( $editnotice_base_msg->exists() ) {
-                                       $notices[$editnotice_base] = $editnotice_base_msg->parseAsBlock();
+                                       $notices[$editnotice_base] = '<div class="mw-editnotice mw-editnotice-base ' .
+                                               Sanitizer::escapeClass( "mw-$editnotice_base" ) . '">' .
+                                               $editnotice_base_msg->parseAsBlock() . '</div>';
                                }
                        }
                } else {
@@ -5024,7 +5028,9 @@ class Title {
                        $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->getDBkey() );
                        $editnoticeMsg = wfMessage( $editnoticeText );
                        if ( $editnoticeMsg->exists() ) {
-                               $notices[$editnoticeText] = $editnoticeMsg->parseAsBlock();
+                               $notices[$editnoticeText] = '<div class="mw-editnotice mw-editnotice-page ' .
+                                       Sanitizer::escapeClass( "mw-$editnoticeText" ) . '">' .
+                                       $editnoticeMsg->parseAsBlock() . '</div>';
                        }
                }