Return some more verbose error messages when editing fails using the API. Added wfDep...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Wed, 9 Jun 2010 19:52:11 +0000 (19:52 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Wed, 9 Jun 2010 19:52:11 +0000 (19:52 +0000)
includes/Article.php
includes/EditPage.php
includes/api/ApiEditPage.php

index af4aed4..6fb77ff 100644 (file)
@@ -1977,6 +1977,7 @@ class Article {
         * @deprecated use Article::doEdit()
         */
        function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
+               wfDeprecated( __METHOD__ );
                $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
                        ( $minor ? EDIT_MINOR : 0 ) |
                        ( $forceBot ? EDIT_FORCE_BOT : 0 );
index 8830a7d..33f5f50 100644 (file)
@@ -905,6 +905,8 @@ class EditPage {
 
                        $isComment = ( $this->section == 'new' );
 
+                       # FIXME: paste contents from Article::insertNewArticle here and 
+                       # actually handle errors it may return
                        $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
                                $this->minoredit, $this->watchthis, false, $isComment, $bot );
 
@@ -1051,14 +1053,20 @@ class EditPage {
                        return self::AS_MAX_ARTICLE_SIZE_EXCEEDED;
                }
 
-               # update the article here
-               if ( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
-                       $this->watchthis, $bot, $sectionanchor ) )
+               // Update the article here
+               $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
+                       ( $this->minoredit ? EDIT_MINOR : 0 ) |
+                       ( $bot ? EDIT_FORCE_BOT : 0 );
+               $status = $this->mArticle->doEdit( $text, $this->summary, $flags, 
+                       false, null, $this->watchthis, false, $sectionanchor, true );
+               
+               if ( $status->isOK() )
                {
                        wfProfileOut( __METHOD__ );
                        return self::AS_SUCCESS_UPDATE;
                } else {
                        $this->isConflict = true;
+                       $result = $status->getErrorsArray();
                }
                wfProfileOut( __METHOD__ );
                return self::AS_END;
index ad35b39..3879f75 100644 (file)
@@ -327,12 +327,13 @@ class ApiEditPage extends ApiBase {
 
                        case EditPage::AS_END:
                                // This usually means some kind of race condition
-                               // or DB weirdness occurred. Fall through to throw an unknown
-                               // error.
-
-                               // This needs fixing higher up, as Article::doEdit should be
-                               // used rather than Article::updateArticle, so that specific
-                               // error conditions can be returned
+                               // or DB weirdness occurred. 
+                               if ( is_array( $result ) && count( $result ) > 0 ) {
+                                       $this->dieUsageMsg( array( 'unknownerror', $result[0][0] ) );                                   
+                               }
+                               
+                               // Unknown error, but no specific error message
+                               // Fall through
                        default:
                                $this->dieUsageMsg( array( 'unknownerror', $retval ) );
                }