Replace deprecated wfMsg* calls with Message class calls.
[lhc/web/wiklou.git] / includes / WikiPage.php
index 9dc9c2c..1021767 100644 (file)
@@ -92,6 +92,7 @@ class WikiPage extends Page implements IDBAccessObject {
         * Create a WikiPage object of the appropriate class for the given title.
         *
         * @param $title Title
+        * @throws MWException
         * @return WikiPage object of the appropriate type
         */
        public static function factory( Title $title ) {
@@ -711,7 +712,7 @@ class WikiPage extends Page implements IDBAccessObject {
         * Determine whether a page would be suitable for being counted as an
         * article in the site_stats table based on the title & its content
         *
-        * @param $editInfo Object or false: object returned by prepareTextForEdit(),
+        * @param $editInfo Object|bool (false): object returned by prepareTextForEdit(),
         *        if false, the current database state will be used
         * @return Boolean
         */
@@ -891,10 +892,10 @@ class WikiPage extends Page implements IDBAccessObject {
                $tables = array( 'revision', 'user' );
 
                $fields = array(
-                       'rev_user as user_id',
-                       'rev_user_text AS user_name',
+                       'user_id' => 'rev_user',
+                       'user_name' => 'rev_user_text',
                        $realNameField,
-                       'MAX(rev_timestamp) AS timestamp',
+                       'timestamp' => 'MAX(rev_timestamp)',
                );
 
                $conds = array( 'rev_page' => $this->getId() );
@@ -1326,7 +1327,8 @@ class WikiPage extends Page implements IDBAccessObject {
 
                        if ( $section == 'new' ) {
                                # Inserting a new section
-                               $subject = $sectionTitle ? wfMsgForContent( 'newsectionheaderdefaultlevel', $sectionTitle ) . "\n\n" : '';
+                               $subject = $sectionTitle ? wfMessage( 'newsectionheaderdefaultlevel' )
+                                       ->rawParams( $sectionTitle )->inContentLanguage()->text() . "\n\n" : '';
                                if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) {
                                        $text = strlen( trim( $oldtext ) ) > 0
                                                ? "{$oldtext}\n\n{$subject}{$text}"
@@ -1389,9 +1391,10 @@ class WikiPage extends Page implements IDBAccessObject {
         * edit-already-exists error will be returned. These two conditions are also possible with
         * auto-detection due to MediaWiki's performance-optimised locking strategy.
         *
-        * @param $baseRevId int the revision ID this edit was based off, if any
+        * @param bool|int $baseRevId int the revision ID this edit was based off, if any
         * @param $user User the user doing the edit
         *
+        * @throws MWException
         * @return Status object. Possible errors:
         *     edit-hook-aborted:       The ArticleSave hook aborted the edit but didn't set the fatal flag of $status
         *     edit-gone-missing:       In update mode, but the article didn't exist
@@ -1930,12 +1933,15 @@ class WikiPage extends Page implements IDBAccessObject {
                        if ( $restrictions != '' ) {
                                $protectDescription .= $wgContLang->getDirMark() . "[$action=$restrictions] (";
                                if ( $encodedExpiry[$action] != 'infinity' ) {
-                                       $protectDescription .= wfMsgForContent( 'protect-expiring',
+                                       $protectDescription .= wfMessage(
+                                               'protect-expiring',
                                                $wgContLang->timeanddate( $expiry[$action], false, false ) ,
                                                $wgContLang->date( $expiry[$action], false, false ) ,
-                                               $wgContLang->time( $expiry[$action], false, false ) );
+                                               $wgContLang->time( $expiry[$action], false, false )
+                                       )->inContentLanguage()->text();
                                } else {
-                                       $protectDescription .= wfMsgForContent( 'protect-expiry-indefinite' );
+                                       $protectDescription .= wfMessage( 'protect-expiry-indefinite' )
+                                               ->inContentLanguage()->text();
                                }
 
                                $protectDescription .= ') ';
@@ -1976,7 +1982,12 @@ class WikiPage extends Page implements IDBAccessObject {
                        }
 
                        # Prepare a null revision to be added to the history
-                       $editComment = $wgContLang->ucfirst( wfMsgForContent( $revCommentMsg, $this->mTitle->getPrefixedText() ) );
+                       $editComment = $wgContLang->ucfirst(
+                               wfMessage(
+                                       $revCommentMsg,
+                                       $this->mTitle->getPrefixedText()
+                               )->inContentLanguage()->text()
+                       );
                        if ( $reason ) {
                                $editComment .= ": $reason";
                        }
@@ -1984,7 +1995,9 @@ class WikiPage extends Page implements IDBAccessObject {
                                $editComment .= " ($protectDescription)";
                        }
                        if ( $cascade ) {
-                               $editComment .= ' [' . wfMsgForContent( 'protect-summary-cascade' ) . ']';
+                               // FIXME: Should use 'brackets' message.
+                               $editComment .= ' [' . wfMessage( 'protect-summary-cascade' )
+                                       ->inContentLanguage()->text() . ']';
                        }
 
                        # Insert a null revision
@@ -2051,6 +2064,7 @@ class WikiPage extends Page implements IDBAccessObject {
         * Take an array of page restrictions and flatten it to a string
         * suitable for insertion into the page_restrictions field.
         * @param $limit Array
+        * @throws MWException
         * @return String
         */
        protected static function flattenRestrictions( $limit ) {
@@ -2078,11 +2092,8 @@ class WikiPage extends Page implements IDBAccessObject {
         * Deletes the article with database consistency, writes logs, purges caches
         *
         * @param $reason string delete reason for deletion log
-        * @param $suppress int bitfield
-        *      Revision::DELETED_TEXT
-        *      Revision::DELETED_COMMENT
-        *      Revision::DELETED_USER
-        *      Revision::DELETED_RESTRICTED
+        * @param $suppress boolean suppress all revisions and log the deletion in
+        *        the suppression log instead of the deletion log
         * @param $id int article ID
         * @param $commit boolean defaults to true, triggers transaction end
         * @param &$error Array of errors to append to
@@ -2100,13 +2111,11 @@ class WikiPage extends Page implements IDBAccessObject {
         * Back-end article deletion
         * Deletes the article with database consistency, writes logs, purges caches
         *
+        * @since 1.19
+        *
         * @param $reason string delete reason for deletion log
-        * @param $suppress int bitfield
-        *      Revision::DELETED_TEXT
-        *      Revision::DELETED_COMMENT
-        *      Revision::DELETED_USER
-        *      Revision::DELETED_RESTRICTED
-        * @param $id int article ID
+        * @param $suppress boolean suppress all revisions and log the deletion in
+        *        the suppression log instead of the deletion log
         * @param $commit boolean defaults to true, triggers transaction end
         * @param &$error Array of errors to append to
         * @param $user User The deleting user
@@ -2388,7 +2397,7 @@ class WikiPage extends Page implements IDBAccessObject {
                                array( /* WHERE */
                                        'rc_cur_id' => $current->getPage(),
                                        'rc_user_text' => $current->getUserText(),
-                                       "rc_timestamp > '{$s->rev_timestamp}'",
+                                       'rc_timestamp > ' . $dbw->addQuotes( $s->rev_timestamp ),
                                ), __METHOD__
                        );
                }
@@ -2397,9 +2406,9 @@ class WikiPage extends Page implements IDBAccessObject {
                $target = Revision::newFromId( $s->rev_id );
                if ( empty( $summary ) ) {
                        if ( $from == '' ) { // no public user name
-                               $summary = wfMsgForContent( 'revertpage-nouser' );
+                               $summary = wfMessage( 'revertpage-nouser' )->inContentLanguage()->text();
                        } else {
-                               $summary = wfMsgForContent( 'revertpage' );
+                               $summary = wfMessage( 'revertpage' )->inContentLanguage()->text();
                        }
                }
 
@@ -2411,6 +2420,9 @@ class WikiPage extends Page implements IDBAccessObject {
                );
                $summary = wfMsgReplaceArgs( $summary, $args );
 
+               # Truncate for whole multibyte characters.
+               $summary = $wgContLang->truncate( $summary, 255 );
+
                # Save
                $flags = EDIT_UPDATE;
 
@@ -2587,10 +2599,11 @@ class WikiPage extends Page implements IDBAccessObject {
                        $truncatedtext = $wgContLang->truncate(
                                str_replace( "\n", ' ', $newtext ),
                                max( 0, 255
-                                       - strlen( wfMsgForContent( 'autoredircomment' ) )
+                                       - strlen( wfMessage( 'autoredircomment' )->inContentLanguage()->text() )
                                        - strlen( $rt->getFullText() )
                                ) );
-                       return wfMsgForContent( 'autoredircomment', $rt->getFullText(), $truncatedtext );
+                       return wfMessage( 'autoredircomment', $rt->getFullText() )
+                               ->rawParams( $truncatedtext )->inContentLanguage()->text();
                }
 
                # New page autosummaries
@@ -2599,22 +2612,24 @@ class WikiPage extends Page implements IDBAccessObject {
 
                        $truncatedtext = $wgContLang->truncate(
                                str_replace( "\n", ' ', $newtext ),
-                               max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) ) );
+                               max( 0, 200 - strlen( wfMessage( 'autosumm-new' )->inContentLanguage()->text() ) ) );
 
-                       return wfMsgForContent( 'autosumm-new', $truncatedtext );
+                       return wfMessage( 'autosumm-new' )->rawParams( $truncatedtext )
+                               ->inContentLanguage()->text();
                }
 
                # Blanking autosummaries
                if ( $oldtext != '' && $newtext == '' ) {
-                       return wfMsgForContent( 'autosumm-blank' );
+                       return wfMessage( 'autosumm-blank' )->inContentLanguage()->text();
                } elseif ( strlen( $oldtext ) > 10 * strlen( $newtext ) && strlen( $newtext ) < 500 ) {
                        # Removing more than 90% of the article
 
                        $truncatedtext = $wgContLang->truncate(
                                $newtext,
-                               max( 0, 200 - strlen( wfMsgForContent( 'autosumm-replace' ) ) ) );
+                               max( 0, 200 - strlen( wfMessage( 'autosumm-replace' )->inContentLanguage()->text() ) ) );
 
-                       return wfMsgForContent( 'autosumm-replace', $truncatedtext );
+                       return wfMessage( 'autosumm-replace' )->rawParams( $truncatedtext )
+                               ->inContentLanguage()->text();
                }
 
                # If we reach this point, there's no applicable autosummary for our case, so our
@@ -2689,12 +2704,16 @@ class WikiPage extends Page implements IDBAccessObject {
                if ( $blank ) {
                        // The current revision is blank and the one before is also
                        // blank. It's just not our lucky day
-                       $reason = wfMsgForContent( 'exbeforeblank', '$1' );
+                       $reason = wfMessage( 'exbeforeblank', '$1' )->inContentLanguage()->text();
                } else {
                        if ( $onlyAuthor ) {
-                               $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
+                               $reason = wfMessage(
+                                       'excontentauthor',
+                                       '$1',
+                                       $onlyAuthor
+                               )->inContentLanguage()->text();
                        } else {
-                               $reason = wfMsgForContent( 'excontent', '$1' );
+                               $reason = wfMessage( 'excontent', '$1' )->inContentLanguage()->text();
                        }
                }
 
@@ -2948,6 +2967,7 @@ class WikiPage extends Page implements IDBAccessObject {
 
        /**
         * @deprecated since 1.18
+        * @param $oldid int
         * @return bool
         */
        public function useParserCache( $oldid ) {