Fix flush-like commit in DeferredUpdates.
[lhc/web/wiklou.git] / includes / WikiPage.php
index 6c7b335..770c37a 100644 (file)
@@ -198,7 +198,7 @@ class WikiPage extends Page implements IDBAccessObject {
         *
         * @return ContentHandler
         *
-        * @since 1.WD
+        * @since 1.21
         */
        public function getContentHandler() {
                return ContentHandler::getForModelID( $this->getContentModel() );
@@ -459,7 +459,7 @@ class WikiPage extends Page implements IDBAccessObject {
         *
         * @return String
         *
-        * @since 1.WD
+        * @since 1.21
         */
        public function getContentModel() {
                if ( $this->exists() ) {
@@ -604,11 +604,13 @@ class WikiPage extends Page implements IDBAccessObject {
         *      Revision::FOR_PUBLIC       to be displayed to all users
         *      Revision::FOR_THIS_USER    to be displayed to $wgUser
         *      Revision::RAW              get the text regardless of permissions
+        * @param $user User object to check for, only if FOR_THIS_USER is passed
+        *              to the $audience parameter
         * @return Content|null The content of the current revision
         *
-        * @since 1.WD
+        * @since 1.21
         */
-       public function getContent( $audience = Revision::FOR_PUBLIC ) {
+       public function getContent( $audience = Revision::FOR_PUBLIC, User $user = null ) {
                $this->loadLastEdit();
                if ( $this->mLastRevision ) {
                        return $this->mLastRevision->getContent( $audience );
@@ -621,17 +623,18 @@ class WikiPage extends Page implements IDBAccessObject {
         *
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the text regardless of permissions
+        * @param $user User object to check for, only if FOR_THIS_USER is passed
+        *              to the $audience parameter
         * @return String|false The text of the current revision
-        * @deprecated as of 1.WD, getContent() should be used instead.
+        * @deprecated as of 1.21, getContent() should be used instead.
         */
-       public function getText( $audience = Revision::FOR_PUBLIC ) { #@todo: deprecated, replace usage!
-               wfDeprecated( __METHOD__, '1.WD' );
-
+       public function getText( $audience = Revision::FOR_PUBLIC, User $user = null ) { #@todo: deprecated, replace usage!
+               wfDeprecated( __METHOD__, '1.21' );
                $this->loadLastEdit();
                if ( $this->mLastRevision ) {
-                       return $this->mLastRevision->getText( $audience );
+                       return $this->mLastRevision->getText( $audience, $user );
                }
                return false;
        }
@@ -640,10 +643,10 @@ class WikiPage extends Page implements IDBAccessObject {
         * Get the text of the current revision. No side-effects...
         *
         * @return String|bool The text of the current revision. False on failure
-        * @deprecated as of 1.WD, getContent() should be used instead.
+        * @deprecated as of 1.21, getContent() should be used instead.
         */
        public function getRawText() {
-               wfDeprecated( __METHOD__, '1.WD' );
+               wfDeprecated( __METHOD__, '1.21' );
 
                return $this->getText( Revision::RAW );
        }
@@ -672,14 +675,16 @@ class WikiPage extends Page implements IDBAccessObject {
        /**
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the text regardless of permissions
+        * @param $user User object to check for, only if FOR_THIS_USER is passed
+        *              to the $audience parameter
         * @return int user ID for the user that made the last article revision
         */
-       public function getUser( $audience = Revision::FOR_PUBLIC ) {
+       public function getUser( $audience = Revision::FOR_PUBLIC, User $user = null ) {
                $this->loadLastEdit();
                if ( $this->mLastRevision ) {
-                       return $this->mLastRevision->getUser( $audience );
+                       return $this->mLastRevision->getUser( $audience, $user );
                } else {
                        return -1;
                }
@@ -689,14 +694,16 @@ class WikiPage extends Page implements IDBAccessObject {
         * Get the User object of the user who created the page
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the text regardless of permissions
+        * @param $user User object to check for, only if FOR_THIS_USER is passed
+        *              to the $audience parameter
         * @return User|null
         */
-       public function getCreator( $audience = Revision::FOR_PUBLIC ) {
+       public function getCreator( $audience = Revision::FOR_PUBLIC, User $user = null ) {
                $revision = $this->getOldestRevision();
                if ( $revision ) {
-                       $userName = $revision->getUserText( $audience );
+                       $userName = $revision->getUserText( $audience, $user );
                        return User::newFromName( $userName, false );
                } else {
                        return null;
@@ -706,14 +713,16 @@ class WikiPage extends Page implements IDBAccessObject {
        /**
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the text regardless of permissions
+        * @param $user User object to check for, only if FOR_THIS_USER is passed
+        *              to the $audience parameter
         * @return string username of the user that made the last article revision
         */
-       public function getUserText( $audience = Revision::FOR_PUBLIC ) {
+       public function getUserText( $audience = Revision::FOR_PUBLIC, User $user = null ) {
                $this->loadLastEdit();
                if ( $this->mLastRevision ) {
-                       return $this->mLastRevision->getUserText( $audience );
+                       return $this->mLastRevision->getUserText( $audience, $user );
                } else {
                        return '';
                }
@@ -722,14 +731,16 @@ class WikiPage extends Page implements IDBAccessObject {
        /**
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the text regardless of permissions
+        * @param $user User object to check for, only if FOR_THIS_USER is passed
+        *              to the $audience parameter
         * @return string Comment stored for the last article revision
         */
-       public function getComment( $audience = Revision::FOR_PUBLIC ) {
+       public function getComment( $audience = Revision::FOR_PUBLIC, User $user = null ) {
                $this->loadLastEdit();
                if ( $this->mLastRevision ) {
-                       return $this->mLastRevision->getComment( $audience );
+                       return $this->mLastRevision->getComment( $audience, $user );
                } else {
                        return '';
                }
@@ -1345,20 +1356,20 @@ class WikiPage extends Page implements IDBAccessObject {
                return $ret;
        }
 
-    /**
-     * Get the content that needs to be saved in order to undo all revisions
-     * between $undo and $undoafter. Revisions must belong to the same page,
-     * must exist and must not be deleted
-     * @param $undo Revision
-     * @param $undoafter Revision Must be an earlier revision than $undo
-     * @return mixed string on success, false on failure
-     * @since 1.WD
-     * Before we had the Content object, this was done in getUndoText
-     */
-    public function getUndoContent( Revision $undo, Revision $undoafter = null ) {
-        $handler = $undo->getContentHandler();
-        return $handler->getUndoContent( $this->getRevision(), $undo, $undoafter );
-    }
+       /**
+        * Get the content that needs to be saved in order to undo all revisions
+        * between $undo and $undoafter. Revisions must belong to the same page,
+        * must exist and must not be deleted
+        * @param $undo Revision
+        * @param $undoafter Revision Must be an earlier revision than $undo
+        * @return mixed string on success, false on failure
+        * @since 1.21
+        * Before we had the Content object, this was done in getUndoText
+        */
+       public function getUndoContent( Revision $undo, Revision $undoafter = null ) {
+               $handler = $undo->getContentHandler();
+               return $handler->getUndoContent( $this->getRevision(), $undo, $undoafter );
+       }
 
        /**
         * Get the text that needs to be saved in order to undo all revisions
@@ -1367,10 +1378,10 @@ class WikiPage extends Page implements IDBAccessObject {
         * @param $undo Revision
         * @param $undoafter Revision Must be an earlier revision than $undo
         * @return mixed string on success, false on failure
-        * @deprecated since 1.WD: use ContentHandler::getUndoContent() instead.
+        * @deprecated since 1.21: use ContentHandler::getUndoContent() instead.
         */
        public function getUndoText( Revision $undo, Revision $undoafter = null ) {
-               wfDeprecated( __METHOD__, '1.WD' );
+               wfDeprecated( __METHOD__, '1.21' );
 
                $this->loadLastEdit();
 
@@ -1399,10 +1410,10 @@ class WikiPage extends Page implements IDBAccessObject {
         * @param $edittime String: revision timestamp or null to use the current revision
         * @return String new complete article text, or null if error
         *
-        * @deprecated since 1.WD, use replaceSectionContent() instead
+        * @deprecated since 1.21, use replaceSectionContent() instead
         */
        public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) {
-               wfDeprecated( __METHOD__, '1.WD' );
+               wfDeprecated( __METHOD__, '1.21' );
 
                if ( strval( $section ) == '' ) { //NOTE: keep condition in sync with condition in replaceSectionContent!
                        // Whole-page edit; let the whole text through
@@ -1441,7 +1452,7 @@ class WikiPage extends Page implements IDBAccessObject {
         *
         * @return Content new complete article content, or null if error
         *
-        * @since 1.WD
+        * @since 1.21
         */
        public function replaceSectionContent( $section, Content $sectionContent, $sectionTitle = '', $edittime = null ) {
                wfProfileIn( __METHOD__ );
@@ -1547,11 +1558,10 @@ class WikiPage extends Page implements IDBAccessObject {
         *
         *  Compatibility note: this function previously returned a boolean value indicating success/failure
         *
-        * @deprecated since 1.WD: use doEditContent() instead.
-        * @todo: use doEditContent() instead everywhere
+        * @deprecated since 1.21: use doEditContent() instead.
         */
        public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) {
-               wfDeprecated( __METHOD__, '1.WD' );
+               wfDeprecated( __METHOD__, '1.21' );
 
                $content = ContentHandler::makeContent( $text, $this->getTitle() );
 
@@ -1603,7 +1613,7 @@ class WikiPage extends Page implements IDBAccessObject {
         *     new:                     Boolean indicating if the function attempted to create a new article
         *     revision:                The revision object for the inserted revision, or null
         *
-        * @since 1.WD
+        * @since 1.21
         */
        public function doEditContent( Content $content, $summary, $flags = 0, $baseRevId = false,
                                                                   User $user = null, $serialisation_format = null ) {
@@ -1894,18 +1904,26 @@ class WikiPage extends Page implements IDBAccessObject {
 
        /**
         * Get parser options suitable for rendering the primary article wikitext
-        * @param User|string $user User object or 'canonical'
+        *
+        * @see ContentHandler::makeParserOptions
+        *
+        * @param IContextSource|User|string $context One of the following:
+        *        - IContextSource: Use the User and the Language of the provided
+        *          context
+        *        - User: Use the provided User object and $wgLang for the language,
+        *          so use an IContextSource object if possible.
+        *        - 'canonical': Canonical options (anonymous user with default
+        *          preferences and content language).
         * @return ParserOptions
         */
-       public function makeParserOptions( $user ) {
-               global $wgContLang;
-               if ( $user instanceof User ) { // settings per user (even anons)
-                       $options = ParserOptions::newFromUser( $user );
-               } else { // canonical settings
-                       $options = ParserOptions::newFromUserAndLang( new User, $wgContLang );
+       public function makeParserOptions( $context ) {
+               $options = $this->getContentHandler()->makeParserOptions( $context );
+
+               if ( $this->getTitle()->isConversionTable() ) {
+                       //@todo: ConversionTable should become a separate content model, so we don't need special cases like this one.
+                       $options->disableContentConversion();
                }
-               $options->enableLimitReport(); // show inclusion/loop reports
-               $options->setTidy( true ); // fix bad HTML
+
                return $options;
        }
 
@@ -1913,10 +1931,10 @@ class WikiPage extends Page implements IDBAccessObject {
         * Prepare text which is about to be saved.
         * Returns a stdclass with source, pst and output members
         *
-        * @deprecated in 1.WD: use prepareContentForEdit instead.
+        * @deprecated in 1.21: use prepareContentForEdit instead.
         */
        public function prepareTextForEdit( $text, $revid = null, User $user = null ) {
-               wfDeprecated( __METHOD__, '1.WD' );
+               wfDeprecated( __METHOD__, '1.21' );
                $content = ContentHandler::makeContent( $text, $this->getTitle() );
                return $this->prepareContentForEdit( $content, $revid , $user );
        }
@@ -1932,12 +1950,12 @@ class WikiPage extends Page implements IDBAccessObject {
         *
         * @return bool|object
         *
-        * @since 1.WD
+        * @since 1.21
         */
        public function prepareContentForEdit( Content $content, $revid = null, User $user = null, $serialization_format = null ) {
                global $wgParser, $wgContLang, $wgUser;
                $user = is_null( $user ) ? $wgUser : $user;
-               // @TODO fixme: check $user->getId() here???
+               //XXX: check $user->getId() here???
 
                if ( $this->mPreparedEdit
                        && $this->mPreparedEdit->newContent
@@ -2115,10 +2133,10 @@ class WikiPage extends Page implements IDBAccessObject {
         * @param $comment String: comment submitted
         * @param $minor Boolean: whereas it's a minor modification
         *
-        * @deprecated since 1.WD, use doEditContent() instead.
+        * @deprecated since 1.21, use doEditContent() instead.
         */
        public function doQuickEdit( $text, User $user, $comment = '', $minor = 0 ) {
-               wfDeprecated( __METHOD__, "1.WD" );
+               wfDeprecated( __METHOD__, "1.21" );
 
                $content = ContentHandler::makeContent( $text, $this->getTitle() );
                return $this->doQuickEditContent( $content, $user, $comment , $minor );
@@ -2556,7 +2574,7 @@ class WikiPage extends Page implements IDBAccessObject {
                        $dbw->commit( __METHOD__ );
                }
 
-               wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id ) );
+               wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id, $content, $logEntry ) );
                $status->value = $logid;
                return $status;
        }
@@ -2914,12 +2932,12 @@ class WikiPage extends Page implements IDBAccessObject {
        * @param $flags Int bitmask: a bitmask of flags submitted for the edit.
        * @return string An appropriate autosummary, or an empty string.
        *
-       * @deprecated since 1.WD, use ContentHandler::getAutosummary() instead
+       * @deprecated since 1.21, use ContentHandler::getAutosummary() instead
        */
        public static function getAutosummary( $oldtext, $newtext, $flags ) {
                # NOTE: stub for backwards-compatibility. assumes the given text is wikitext. will break horribly if it isn't.
 
-               wfDeprecated( __METHOD__, '1.WD' );
+               wfDeprecated( __METHOD__, '1.21' );
 
                $handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT );
                $oldContent = is_null( $oldtext ) ? null : $handler->unserializeContent( $oldtext );