Merge "Add a test for named vs. positional parameter whitespace stripping"
[lhc/web/wiklou.git] / includes / WikiPage.php
index b1dd910..df3086a 100644 (file)
@@ -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.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,19 @@ 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.21, getContent() should be used instead.
         */
-       public function getText( $audience = Revision::FOR_PUBLIC ) { #@todo: deprecated, replace usage!
-               wfDeprecated( __METHOD__, '1.21' );
+       public function getText( $audience = Revision::FOR_PUBLIC, User $user = null ) { #@todo: deprecated, replace usage!
+               ContentHandler::deprecated( __METHOD__, '1.21' );
 
                $this->loadLastEdit();
                if ( $this->mLastRevision ) {
-                       return $this->mLastRevision->getText( $audience );
+                       return $this->mLastRevision->getText( $audience, $user );
                }
                return false;
        }
@@ -643,7 +647,7 @@ class WikiPage extends Page implements IDBAccessObject {
         * @deprecated as of 1.21, getContent() should be used instead.
         */
        public function getRawText() {
-               wfDeprecated( __METHOD__, '1.21' );
+               ContentHandler::deprecated( __METHOD__, '1.21' );
 
                return $this->getText( Revision::RAW );
        }
@@ -672,14 +676,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 +695,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 +714,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 +732,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 +1357,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.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 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
@@ -1370,7 +1382,7 @@ class WikiPage extends Page implements IDBAccessObject {
         * @deprecated since 1.21: use ContentHandler::getUndoContent() instead.
         */
        public function getUndoText( Revision $undo, Revision $undoafter = null ) {
-               wfDeprecated( __METHOD__, '1.21' );
+               ContentHandler::deprecated( __METHOD__, '1.21' );
 
                $this->loadLastEdit();
 
@@ -1402,7 +1414,7 @@ class WikiPage extends Page implements IDBAccessObject {
         * @deprecated since 1.21, use replaceSectionContent() instead
         */
        public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) {
-               wfDeprecated( __METHOD__, '1.21' );
+               ContentHandler::deprecated( __METHOD__, '1.21' );
 
                if ( strval( $section ) == '' ) { //NOTE: keep condition in sync with condition in replaceSectionContent!
                        // Whole-page edit; let the whole text through
@@ -1435,7 +1447,7 @@ class WikiPage extends Page implements IDBAccessObject {
 
        /**
         * @param $section null|bool|int or a section number (0, 1, 2, T1, T2...)
-        * @param $content Content: new content of the section
+        * @param $sectionContent Content: new content of the section
         * @param $sectionTitle String: new section's subject, only if $section is 'new'
         * @param $edittime String: revision timestamp or null to use the current revision
         *
@@ -1550,7 +1562,7 @@ class WikiPage extends Page implements IDBAccessObject {
         * @deprecated since 1.21: use doEditContent() instead.
         */
        public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) {
-               wfDeprecated( __METHOD__, '1.21' );
+               ContentHandler::deprecated( __METHOD__, '1.21' );
 
                $content = ContentHandler::makeContent( $text, $this->getTitle() );
 
@@ -1636,7 +1648,7 @@ class WikiPage extends Page implements IDBAccessObject {
                $hook_args = array( &$this, &$user, &$content, &$summary,
                                                        $flags & EDIT_MINOR, null, null, &$flags, &$status );
 
-               if ( !wfRunHooks( 'ArticleContentSave', $hook_args )
+               if ( !wfRunHooks( 'PageContentSave', $hook_args )
                        || !ContentHandler::runLegacyHooks( 'ArticleSave', $hook_args ) ) {
 
                        wfDebug( __METHOD__ . ": ArticleSave or ArticleSaveContent hook aborted save!\n" );
@@ -1696,6 +1708,7 @@ class WikiPage extends Page implements IDBAccessObject {
 
                        $revision = new Revision( array(
                                'page'       => $this->getId(),
+                               'title'      => $this->getTitle(), // for determining the default content model
                                'comment'    => $summary,
                                'minor_edit' => $isminor,
                                'text'       => $serialized,
@@ -1823,6 +1836,7 @@ class WikiPage extends Page implements IDBAccessObject {
                        # Save the revision text...
                        $revision = new Revision( array(
                                'page'       => $newid,
+                               'title'      => $this->getTitle(), // for determining the default content model
                                'comment'    => $summary,
                                'minor_edit' => $isminor,
                                'text'       => $serialized,
@@ -1867,7 +1881,7 @@ class WikiPage extends Page implements IDBAccessObject {
                                                                $flags & EDIT_MINOR, null, null, &$flags, $revision );
 
                        ContentHandler::runLegacyHooks( 'ArticleInsertComplete', $hook_args );
-                       wfRunHooks( 'ArticleContentInsertComplete', $hook_args );
+                       wfRunHooks( 'PageContentInsertComplete', $hook_args );
                }
 
                # Do updates right now unless deferral was requested
@@ -1882,7 +1896,7 @@ class WikiPage extends Page implements IDBAccessObject {
                                                        $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $baseRevId );
 
                ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $hook_args );
-               wfRunHooks( 'ArticleContentSaveComplete', $hook_args );
+               wfRunHooks( 'PageContentSaveComplete', $hook_args );
 
                # Promote user to any groups they meet the criteria for
                $user->addAutopromoteOnceGroups( 'onEdit' );
@@ -1923,7 +1937,7 @@ class WikiPage extends Page implements IDBAccessObject {
         * @deprecated in 1.21: use prepareContentForEdit instead.
         */
        public function prepareTextForEdit( $text, $revid = null, User $user = null ) {
-               wfDeprecated( __METHOD__, '1.21' );
+               ContentHandler::deprecated( __METHOD__, '1.21' );
                $content = ContentHandler::makeContent( $text, $this->getTitle() );
                return $this->prepareContentForEdit( $content, $revid , $user );
        }
@@ -2125,7 +2139,7 @@ class WikiPage extends Page implements IDBAccessObject {
         * @deprecated since 1.21, use doEditContent() instead.
         */
        public function doQuickEdit( $text, User $user, $comment = '', $minor = 0 ) {
-               wfDeprecated( __METHOD__, "1.21" );
+               ContentHandler::deprecated( __METHOD__, "1.21" );
 
                $content = ContentHandler::makeContent( $text, $this->getTitle() );
                return $this->doQuickEditContent( $content, $user, $comment , $minor );
@@ -2149,6 +2163,7 @@ class WikiPage extends Page implements IDBAccessObject {
 
                $dbw = wfGetDB( DB_MASTER );
                $revision = new Revision( array(
+                       'title'      => $this->getTitle(), // for determining the default content model
                        'page'       => $this->getId(),
                        'text'       => $serialized,
                        'length'     => $content->getSize(),
@@ -2438,6 +2453,7 @@ class WikiPage extends Page implements IDBAccessObject {
         * @param $reason string delete reason for deletion log
         * @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
         * @param $user User The deleting user
@@ -2926,7 +2942,7 @@ class WikiPage extends Page implements IDBAccessObject {
        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.21' );
+               ContentHandler::deprecated( __METHOD__, '1.21' );
 
                $handler = ContentHandler::getForModelID( CONTENT_MODEL_WIKITEXT );
                $oldContent = is_null( $oldtext ) ? null : $handler->unserializeContent( $oldtext );
@@ -3324,12 +3340,17 @@ class PoolWorkArticleView extends PoolCounterWork {
                        $content = $this->page->getContent( Revision::RAW );
                } else {
                        $rev = Revision::newFromTitle( $this->page->getTitle(), $this->revid );
+
                        if ( $rev === null ) {
-                               return false;
+                               $content = null;
+                       } else {
+                               #XXX: why use PUBLIC audience here (default), and RAW above?
+                               $content = $rev->getContent();
                        }
+               }
 
-                       #XXX: why use PUBLIC audience here (default), and RAW above?
-                       $content = $rev->getContent();
+               if ( $content === null ) {
+                       return false;
                }
 
                $time = - microtime( true );