Call Linker methods statically
[lhc/web/wiklou.git] / includes / api / ApiEditPage.php
index b9140b5..4cfa343 100644 (file)
@@ -50,7 +50,7 @@ class ApiEditPage extends ApiBase {
                                is_null( $params['prependtext'] ) &&
                                $params['undo'] == 0 )
                {
-                       $this->dieUsageMsg( array( 'missingtext' ) );
+                       $this->dieUsageMsg( 'missingtext' );
                }
 
                $titleObj = Title::newFromText( $params['title'] );
@@ -58,6 +58,8 @@ class ApiEditPage extends ApiBase {
                        $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
                }
 
+               $apiResult = $this->getResult();
+
                if ( $params['redirect'] ) {
                        if ( $titleObj->isRedirect() ) {
                                $oldTitle = $titleObj;
@@ -65,8 +67,6 @@ class ApiEditPage extends ApiBase {
                                $titles = Title::newFromRedirectArray( Revision::newFromTitle( $oldTitle )->getText( Revision::FOR_THIS_USER ) );
                                // array_shift( $titles );
 
-                               $this->getResult()->addValue( null, 'foo', $titles );
-
                                $redirValues = array();
                                foreach ( $titles as $id => $newTitle ) {
 
@@ -82,9 +82,8 @@ class ApiEditPage extends ApiBase {
                                        $titleObj = $newTitle;
                                }
 
-                               $this->getResult()->setIndexedTagName( $redirValues, 'r' );
-                               $this->getResult()->addValue( null, 'redirects', $redirValues );
-
+                               $apiResult->setIndexedTagName( $redirValues, 'r' );
+                               $apiResult->addValue( null, 'redirects', $redirValues );
                        }
                }
 
@@ -93,10 +92,10 @@ class ApiEditPage extends ApiBase {
                $wgTitle = $titleObj;
 
                if ( $params['createonly'] && $titleObj->exists() ) {
-                       $this->dieUsageMsg( array( 'createonly-exists' ) );
+                       $this->dieUsageMsg( 'createonly-exists' );
                }
                if ( $params['nocreate'] && !$titleObj->exists() ) {
-                       $this->dieUsageMsg( array( 'nocreate-missing' ) );
+                       $this->dieUsageMsg( 'nocreate-missing' );
                }
 
                // Now let's check whether we're even allowed to do this
@@ -164,7 +163,7 @@ class ApiEditPage extends ApiBase {
 
                        $newtext = $articleObj->getUndoText( $undoRev, $undoafterRev );
                        if ( $newtext === false ) {
-                               $this->dieUsageMsg( array( 'undo-failure' ) );
+                               $this->dieUsageMsg( 'undo-failure' );
                        }
                        $params['text'] = $newtext;
                        // If no summary was given and we only undid one rev,
@@ -176,7 +175,7 @@ class ApiEditPage extends ApiBase {
 
                // See if the MD5 hash checks out
                if ( !is_null( $params['md5'] ) && md5( $toMD5 ) !== $params['md5'] ) {
-                       $this->dieUsageMsg( array( 'hashcheckfailed' ) );
+                       $this->dieUsageMsg( 'hashcheckfailed' );
                }
 
                $ep = new EditPage( $articleObj );
@@ -256,10 +255,10 @@ class ApiEditPage extends ApiBase {
                if ( !wfRunHooks( 'APIEditBeforeSave', array( $ep, $ep->textbox1, &$r ) ) ) {
                        if ( count( $r ) ) {
                                $r['result'] = 'Failure';
-                               $this->getResult()->addValue( null, $this->getModuleName(), $r );
+                               $apiResult->addValue( null, $this->getModuleName(), $r );
                                return;
                        } else {
-                               $this->dieUsageMsg( array( 'hookaborted' ) );
+                               $this->dieUsageMsg( 'hookaborted' );
                        }
                }
 
@@ -267,65 +266,65 @@ class ApiEditPage extends ApiBase {
                $oldRevId = $articleObj->getRevIdFetched();
                $result = null;
                // Fake $wgRequest for some hooks inside EditPage
-               // FIXME: This interface SUCKS
+               // @todo FIXME: This interface SUCKS
                $oldRequest = $wgRequest;
                $wgRequest = $req;
 
-               $retval = $ep->internalAttemptSave( $result, $wgUser->isAllowed( 'bot' ) && $params['bot'] );
+               $status = $ep->internalAttemptSave( $result, $wgUser->isAllowed( 'bot' ) && $params['bot'] );
                $wgRequest = $oldRequest;
                global $wgMaxArticleSize;
 
-               switch( $retval ) {
+               switch( $status->value ) {
                        case EditPage::AS_HOOK_ERROR:
                        case EditPage::AS_HOOK_ERROR_EXPECTED:
-                               $this->dieUsageMsg( array( 'hookaborted' ) );
+                               $this->dieUsageMsg( 'hookaborted' );
 
                        case EditPage::AS_IMAGE_REDIRECT_ANON:
-                               $this->dieUsageMsg( array( 'noimageredirect-anon' ) );
+                               $this->dieUsageMsg( 'noimageredirect-anon' );
 
                        case EditPage::AS_IMAGE_REDIRECT_LOGGED:
-                               $this->dieUsageMsg( array( 'noimageredirect-logged' ) );
+                               $this->dieUsageMsg( 'noimageredirect-logged' );
 
                        case EditPage::AS_SPAM_ERROR:
                                $this->dieUsageMsg( array( 'spamdetected', $result['spam'] ) );
 
                        case EditPage::AS_FILTERING:
-                               $this->dieUsageMsg( array( 'filtered' ) );
+                               $this->dieUsageMsg( 'filtered' );
 
                        case EditPage::AS_BLOCKED_PAGE_FOR_USER:
-                               $this->dieUsageMsg( array( 'blockedtext' ) );
+                               $this->dieUsageMsg( 'blockedtext' );
 
                        case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED:
                        case EditPage::AS_CONTENT_TOO_BIG:
                                $this->dieUsageMsg( array( 'contenttoobig', $wgMaxArticleSize ) );
 
                        case EditPage::AS_READ_ONLY_PAGE_ANON:
-                               $this->dieUsageMsg( array( 'noedit-anon' ) );
+                               $this->dieUsageMsg( 'noedit-anon' );
 
                        case EditPage::AS_READ_ONLY_PAGE_LOGGED:
-                               $this->dieUsageMsg( array( 'noedit' ) );
+                               $this->dieUsageMsg( 'noedit' );
 
                        case EditPage::AS_READ_ONLY_PAGE:
                                $this->dieReadOnly();
 
                        case EditPage::AS_RATE_LIMITED:
-                               $this->dieUsageMsg( array( 'actionthrottledtext' ) );
+                               $this->dieUsageMsg( 'actionthrottledtext' );
 
                        case EditPage::AS_ARTICLE_WAS_DELETED:
-                               $this->dieUsageMsg( array( 'wasdeleted' ) );
+                               $this->dieUsageMsg( 'wasdeleted' );
 
                        case EditPage::AS_NO_CREATE_PERMISSION:
-                               $this->dieUsageMsg( array( 'nocreate-loggedin' ) );
+                               $this->dieUsageMsg( 'nocreate-loggedin' );
 
                        case EditPage::AS_BLANK_ARTICLE:
-                               $this->dieUsageMsg( array( 'blankpage' ) );
+                               $this->dieUsageMsg( 'blankpage' );
 
                        case EditPage::AS_CONFLICT_DETECTED:
-                               $this->dieUsageMsg( array( 'editconflict' ) );
+                               $this->dieUsageMsg( 'editconflict' );
 
                        // case EditPage::AS_SUMMARY_NEEDED: Can't happen since we set wpIgnoreBlankSummary
                        case EditPage::AS_TEXTBOX_EMPTY:
-                               $this->dieUsageMsg( array( 'emptynewsection' ) );
+                               $this->dieUsageMsg( 'emptynewsection' );
 
                        case EditPage::AS_SUCCESS_NEW_ARTICLE:
                                $r['new'] = '';
@@ -351,20 +350,17 @@ class ApiEditPage extends ApiBase {
                                break;
 
                        case EditPage::AS_SUMMARY_NEEDED:
-                               $this->dieUsageMsg( array( 'summaryrequired' ) );
+                               $this->dieUsageMsg( 'summaryrequired' );
 
                        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
+                               // $status came from WikiPage::doEdit()
+                               $errors = $status->getErrorsArray();
+                               $this->dieUsageMsg( $errors[0] ); // TODO: Add new errors to message map
+                               break;
                        default:
-                               $this->dieUsageMsg( array( 'unknownerror', $retval ) );
+                               $this->dieUsageMsg( array( 'unknownerror', $status->value ) );
                }
-               $this->getResult()->addValue( null, $this->getModuleName(), $r );
+               $apiResult->addValue( null, $this->getModuleName(), $r );
        }
 
        public function mustBePosted() {
@@ -375,7 +371,7 @@ class ApiEditPage extends ApiBase {
                return true;
        }
 
-       protected function getDescription() {
+       public function getDescription() {
                return 'Create and edit pages.';
        }
 
@@ -411,10 +407,12 @@ class ApiEditPage extends ApiBase {
                        array( 'unknownerror', 'retval' ),
                        array( 'code' => 'nosuchsection', 'info' => 'There is no section section.' ),
                        array( 'code' => 'invalidsection', 'info' => 'The section parameter must be set to an integer or \'new\'' ),
+                       array( 'customcssprotected' ),
+                       array( 'customjsprotected' ),
                ) );
        }
 
-       protected function getAllowedParams() {
+       public function getAllowedParams() {
                return array(
                        'title' => array(
                                ApiBase::PARAM_TYPE => 'string',
@@ -467,18 +465,20 @@ class ApiEditPage extends ApiBase {
                );
        }
 
-       protected function getParamDescription() {
+       public function getParamDescription() {
                $p = $this->getModulePrefix();
                return array(
                        'title' => 'Page title',
                        'section' => 'Section number. 0 for the top section, \'new\' for a new section',
                        'text' => 'Page content',
-                       'token' => 'Edit token. You can get one of these through prop=info',
+                       'token' => array( 'Edit token. You can get one of these through prop=info.',
+                                               'The token should always be sent as the last parameter, or at least, after the text parameter'
+                       ),
                        'summary' => 'Edit summary. Also section title when section=new',
                        'minor' => 'Minor edit',
                        'notminor' => 'Non-minor edit',
                        'bot' => 'Mark this edit as bot',
-                       'basetimestamp' => array( 'Timestamp of the base revision (gotten through prop=revisions&rvprop=timestamp).',
+                       'basetimestamp' => array( 'Timestamp of the base revision (obtained through prop=revisions&rvprop=timestamp).',
                                                'Used to detect edit conflicts; leave unset to ignore conflicts.'
                        ),
                        'starttimestamp' => array( 'Timestamp when you obtained the edit token.',
@@ -493,7 +493,7 @@ class ApiEditPage extends ApiBase {
                        'captchaid' => 'CAPTCHA ID from previous request',
                        'captchaword' => 'Answer to the CAPTCHA',
                        'md5' => array( "The MD5 hash of the {$p}text parameter, or the {$p}prependtext and {$p}appendtext parameters concatenated.",
-                                       'If set, the edit won\'t be done unless the hash is correct' ),
+                                       'If set, the edit won\'t be done unless the hash is correct' ),
                        'prependtext' => "Add this text to the beginning of the page. Overrides {$p}text",
                        'appendtext' => "Add this text to the end of the page. Overrides {$p}text",
                        'undo' => "Undo this revision. Overrides {$p}text, {$p}prependtext and {$p}appendtext",
@@ -510,7 +510,7 @@ class ApiEditPage extends ApiBase {
                return '';
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'Edit a page (anonymous user):',
                        '    api.php?action=edit&title=Test&summary=test%20summary&text=article%20content&basetimestamp=20070824123454&token=%2B\\',
@@ -521,6 +521,10 @@ class ApiEditPage extends ApiBase {
                );
        }
 
+       public function getHelpUrls() {
+               return 'http://www.mediawiki.org/wiki/API:Edit';
+       }
+
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }