Add second param to Title::newFromText warning so that called from works correctly
[lhc/web/wiklou.git] / includes / Title.php
index b04bf04..86e9746 100644 (file)
@@ -29,8 +29,6 @@
  *       however, it does so inefficiently.
  * @note Consider using a TitleValue object instead. TitleValue is more lightweight
  *       and does not rely on global state or the database.
- *
- * @internal documentation reviewed 15 Mar 2010
  */
 class Title {
        /** @var MapCacheLRU */
@@ -258,12 +256,14 @@ class Title {
         *   by a prefix.  If you want to force a specific namespace even if
         *   $text might begin with a namespace prefix, use makeTitle() or
         *   makeTitleSafe().
-        * @throws MWException
+        * @throws InvalidArgumentException
         * @return Title|null Title or null on an error.
         */
        public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
                if ( is_object( $text ) ) {
-                       throw new MWException( 'Title::newFromText given an object' );
+                       throw new InvalidArgumentException( '$text must be a string.' );
+               } elseif ( !is_string( $text ) ) {
+                       wfWarn( __METHOD__ . ': $text must be a string. This will throw an InvalidArgumentException in future.', 2 );
                }
 
                $cache = self::getTitleCache();
@@ -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
+                                       );
+                               }
                        }
                }