Title: Consider empty edit notices to not exist
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 12 Mar 2015 20:15:43 +0000 (21:15 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 12 Mar 2015 20:15:43 +0000 (21:15 +0100)
Don't include edit notices that parse to nothing in the output
array.

Similar filtering logic currently exists in VisualEditor. This
helps support systems like the one on English Wikipedia where an
Editnotice page may exist, but conditionally outputs the actual
notice.

Bug: T91715
Change-Id: Ic8fb038fd6acf18830cafdd09a8ca86f3950c7a5

includes/Title.php

index b04bf04..f47300c 100644 (file)
@@ -4685,15 +4685,18 @@ class Title {
                $msg = wfMessage( $editnotice_ns );
                if ( $msg->exists() ) {
                        $html = $msg->parseAsBlock();
-                       $notices[$editnotice_ns] = Html::rawElement(
-                               'div',
-                               array( 'class' => array(
-                                       'mw-editnotice',
-                                       'mw-editnotice-namespace',
-                                       Sanitizer::escapeClass( "mw-$editnotice_ns" )
-                               ) ),
-                               $html
-                       );
+                       // Edit notices may have complex logic, but output nothing (T91715)
+                       if ( trim( $html ) !== '' ) {
+                               $notices[$editnotice_ns] = Html::rawElement(
+                                       'div',
+                                       array( 'class' => array(
+                                               'mw-editnotice',
+                                               'mw-editnotice-namespace',
+                                               Sanitizer::escapeClass( "mw-$editnotice_ns" )
+                                       ) ),
+                                       $html
+                               );
+                       }
                }
 
                if ( MWNamespace::hasSubpages( $this->getNamespace() ) ) {
@@ -4705,15 +4708,17 @@ class Title {
                                $msg = wfMessage( $editnotice_base );
                                if ( $msg->exists() ) {
                                        $html = $msg->parseAsBlock();
-                                       $notices[$editnotice_base] = Html::rawElement(
-                                               'div',
-                                               array( 'class' => array(
-                                                       'mw-editnotice',
-                                                       'mw-editnotice-base',
-                                                       Sanitizer::escapeClass( "mw-$editnotice_base" )
-                                               ) ),
-                                               $html
-                                       );
+                                       if ( trim( $html ) !== '' ) {
+                                               $notices[$editnotice_base] = Html::rawElement(
+                                                       'div',
+                                                       array( 'class' => array(
+                                                               'mw-editnotice',
+                                                               'mw-editnotice-base',
+                                                               Sanitizer::escapeClass( "mw-$editnotice_base" )
+                                                       ) ),
+                                                       $html
+                                               );
+                                       }
                                }
                        }
                } else {
@@ -4722,15 +4727,17 @@ class Title {
                        $msg = wfMessage( $editnoticeText );
                        if ( $msg->exists() ) {
                                $html = $msg->parseAsBlock();
-                               $notices[$editnoticeText] = Html::rawElement(
-                                       'div',
-                                       array( 'class' => array(
-                                               'mw-editnotice',
-                                               'mw-editnotice-page',
-                                               Sanitizer::escapeClass( "mw-$editnoticeText" )
-                                       ) ),
-                                       $html
-                               );
+                               if ( trim( $html ) !== '' ) {
+                                       $notices[$editnoticeText] = Html::rawElement(
+                                               'div',
+                                               array( 'class' => array(
+                                                       'mw-editnotice',
+                                                       'mw-editnotice-page',
+                                                       Sanitizer::escapeClass( "mw-$editnoticeText" )
+                                               ) ),
+                                               $html
+                                       );
+                               }
                        }
                }