Verify parameter for MapCacheLRU::has() can be passed to array_key_exists()
[lhc/web/wiklou.git] / includes / Title.php
index 2ef4ee4..9868b2e 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,12 @@ 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' );
+               if ( !is_string( $text ) ) {
+                       throw new InvalidArgumentException( 'Title::newFromText given something that isn\'t a string' );
                }
 
                $cache = self::getTitleCache();
@@ -3631,7 +3629,10 @@ class Title {
                $errors = array();
 
                $destFile = wfLocalFile( $nt );
-               if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destFile->exists() && wfFindFile( $nt ) ) {
+               $destFile->load( File::READ_LATEST );
+               if ( !$wgUser->isAllowed( 'reupload-shared' )
+                       && !$destFile->exists() && wfFindFile( $nt )
+               ) {
                        $errors[] = array( 'file-exists-sharedrepo' );
                }
 
@@ -3806,6 +3807,7 @@ class Title {
                # Is it an existing file?
                if ( $nt->getNamespace() == NS_FILE ) {
                        $file = wfLocalFile( $nt );
+                       $file->load( File::READ_LATEST );
                        if ( $file->exists() ) {
                                wfDebug( __METHOD__ . ": file exists\n" );
                                return false;
@@ -4676,34 +4678,64 @@ class Title {
        public function getEditNotices( $oldid = 0 ) {
                $notices = array();
 
-               # Optional notices on a per-namespace and per-page basis
+               // Optional notice for the entire namespace
                $editnotice_ns = 'editnotice-' . $this->getNamespace();
-               $editnotice_ns_message = wfMessage( $editnotice_ns );
-               if ( $editnotice_ns_message->exists() ) {
-                       $notices[$editnotice_ns] = '<div class="mw-editnotice mw-editnotice-namespace ' .
-                               Sanitizer::escapeClass( "mw-$editnotice_ns" ) . '">' .
-                               $editnotice_ns_message->parseAsBlock() . '</div>';
+               $msg = wfMessage( $editnotice_ns );
+               if ( $msg->exists() ) {
+                       $html = $msg->parseAsBlock();
+                       // 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() ) ) {
+                       // Optional notice for page itself and any parent page
                        $parts = explode( '/', $this->getDBkey() );
                        $editnotice_base = $editnotice_ns;
                        while ( count( $parts ) > 0 ) {
                                $editnotice_base .= '-' . array_shift( $parts );
-                               $editnotice_base_msg = wfMessage( $editnotice_base );
-                               if ( $editnotice_base_msg->exists() ) {
-                                       $notices[$editnotice_base] = '<div class="mw-editnotice mw-editnotice-base ' .
-                                               Sanitizer::escapeClass( "mw-$editnotice_base" ) . '">' .
-                                               $editnotice_base_msg->parseAsBlock() . '</div>';
+                               $msg = wfMessage( $editnotice_base );
+                               if ( $msg->exists() ) {
+                                       $html = $msg->parseAsBlock();
+                                       if ( trim( $html ) !== '' ) {
+                                               $notices[$editnotice_base] = Html::rawElement(
+                                                       'div',
+                                                       array( 'class' => array(
+                                                               'mw-editnotice',
+                                                               'mw-editnotice-base',
+                                                               Sanitizer::escapeClass( "mw-$editnotice_base" )
+                                                       ) ),
+                                                       $html
+                                               );
+                                       }
                                }
                        }
                } else {
-                       # Even if there are no subpages in namespace, we still don't want / in MW ns.
+                       // Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
                        $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->getDBkey() );
-                       $editnoticeMsg = wfMessage( $editnoticeText );
-                       if ( $editnoticeMsg->exists() ) {
-                               $notices[$editnoticeText] = '<div class="mw-editnotice mw-editnotice-page ' .
-                                       Sanitizer::escapeClass( "mw-$editnoticeText" ) . '">' .
-                                       $editnoticeMsg->parseAsBlock() . '</div>';
+                       $msg = wfMessage( $editnoticeText );
+                       if ( $msg->exists() ) {
+                               $html = $msg->parseAsBlock();
+                               if ( trim( $html ) !== '' ) {
+                                       $notices[$editnoticeText] = Html::rawElement(
+                                               'div',
+                                               array( 'class' => array(
+                                                       'mw-editnotice',
+                                                       'mw-editnotice-page',
+                                                       Sanitizer::escapeClass( "mw-$editnoticeText" )
+                                               ) ),
+                                               $html
+                                       );
+                               }
                        }
                }