Big oops - merged to wrong branch.
[lhc/web/wiklou.git] / includes / Linker.php
index 0381158..722df3a 100644 (file)
@@ -1,4 +1,25 @@
 <?php
+/**
+ * Methods to make links and related items.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
 /**
  * Some internal bits split of from Skin.php. These functions are used
  * for primarily page content: links, embedded images, table of contents. Links
@@ -397,6 +418,31 @@ class Linker {
                return "<strong class=\"selflink\">{$prefix}{$html}{$inside}</strong>{$trail}";
        }
 
+       /**
+        * Get a message saying that an invalid title was encountered.
+        * This should be called after a method like Title::makeTitleSafe() returned
+        * a value indicating that the title object is invalid.
+        *
+        * @param $context IContextSource context to use to get the messages
+        * @param $namespace int Namespace number
+        * @param $title string Text of the title, without the namespace part
+        */
+       public static function getInvalidTitleDescription( IContextSource $context, $namespace, $title ) {
+               global $wgContLang;
+
+               // First we check whether the namespace exists or not.
+               if ( MWNamespace::exists( $namespace ) ) {
+                       if ( $namespace == NS_MAIN ) {
+                               $name = $context->msg( 'blanknamespace' )->text();
+                       } else {
+                               $name = $wgContLang->getFormattedNsText( $namespace );
+                       }
+                       return $context->msg( 'invalidtitle-knownnamespace', $namespace, $name, $title )->text();
+               } else {
+                       return $context->msg( 'invalidtitle-unknownnamespace', $namespace, $title )->text();
+               }
+       }
+
        /**
         * @param $title Title
         * @return Title
@@ -995,7 +1041,7 @@ class Linker {
                wfRunHooks( 'UserToolLinksEdit', array( $userId, $userText, &$items ) );
 
                if ( $items ) {
-                       return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>';
+                       return ' <span class="mw-usertoollinks">' . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped() . '</span>';
                } else {
                        return '';
                }
@@ -1193,7 +1239,7 @@ class Linker {
                }
                if ( $pre ) {
                        # written summary $presep autocomment (summary /* section */)
-                       $auto = wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) ) . $auto;
+                       $pre .= wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) );
                }
                if ( $post ) {
                        # autocomment $postsep written summary (/* section */ summary)
@@ -1399,7 +1445,7 @@ class Linker {
                        return '';
                } else {
                        $formatted = self::formatComment( $comment, $title, $local );
-                       $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->plain();
+                       $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
                        return " <span class=\"comment\">$formatted</span>";
                }
        }
@@ -1441,7 +1487,7 @@ class Linker {
                } else {
                        global $wgLang;
                        $stxt = wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $size ) );
-                       $stxt = wfMessage( 'parentheses' )->rawParams( $stxt )->plain();
+                       $stxt = wfMessage( 'parentheses' )->rawParams( $stxt )->escaped();
                }
                $stxt = htmlspecialchars( $stxt );
                return "<span class=\"history-size\">$stxt</span>";
@@ -1595,9 +1641,9 @@ class Linker {
         * @return string
         */
        public static function generateRollback( $rev ) {
-               return '<span class="mw-rollback-link">['
-                       . self::buildRollbackLink( $rev )
-                       . ']</span>';
+               return '<span class="mw-rollback-link">'
+                       . wfMessage( 'brackets' )->rawParams( self::buildRollbackLink( $rev ) )->plain()
+                       . '</span>';
        }
 
        /**
@@ -1870,7 +1916,7 @@ class Linker {
                $html = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
                $tag = $restricted ? 'strong' : 'span';
                $link = self::link( $sp, $html, array(), $query, array( 'known', 'noclasses' ) );
-               return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), wfMessage( 'parentheses' )->rawParams( $link )->plain() );
+               return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), wfMessage( 'parentheses' )->rawParams( $link )->escaped() );
        }
 
        /**
@@ -1883,7 +1929,7 @@ class Linker {
         */
        public static function revDeleteLinkDisabled( $delete = true ) {
                $html = $delete ? wfMsgHtml( 'rev-delundel' ) : wfMsgHtml( 'rev-showdeleted' );
-               return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), wfMessage( 'parentheses' )->rawParams( $html )->plain() );
+               return Xml::tags( 'span', array( 'class' => 'mw-revdelundel-link' ), wfMessage( 'parentheses' )->rawParams( $html )->escaped() );
        }
 
        /* Deprecated methods */