Make ApiEditPage use Article::newFromWikiPage() and add user to context
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Sun, 24 Feb 2013 10:34:50 +0000 (11:34 +0100)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Sun, 24 Feb 2013 10:34:50 +0000 (11:34 +0100)
- Changed the creation of the Article object in ApiEditPage::execute() to
  use Article::newFromWikiPage(), this allows to re-use the already-existing
  WikiPage object in that method instead of having to create a new one.
  Article::newFromTitle() was used before, but for some reason this got
  reverted back to "new Article" with the merge of the Wikidata branch.
- Removed the call to WikiPage::clear() added in I1d28164d (2c27926); no
  longer needed since the WikiPage object is now already up to date after
  the edit.
- Added WikiPage and User objects to the context passed to the created
  Article object; follow-up to I74394282 (078334f).

Change-Id: I53088a42ef7592aaba7449ef3f84f77f2e07b2f5

includes/api/ApiEditPage.php

index 1d6dc66..b642c6d 100644 (file)
@@ -303,12 +303,12 @@ class ApiEditPage extends ApiBase {
                // TODO: Make them not or check if they still do
                $wgTitle = $titleObj;
 
-               $articleObject = new Article( $titleObj );
-
                $articleContext = new RequestContext;
                $articleContext->setRequest( $req );
-               $articleContext->setTitle( $titleObj );
-               $articleObject->setContext( $articleContext );
+               $articleContext->setWikiPage( $pageObj );
+               $articleContext->setUser( $this->getUser() );
+
+               $articleObject = Article::newFromWikiPage( $pageObj, $articleContext );
 
                $ep = new EditPage( $articleObject );
 
@@ -409,7 +409,6 @@ class ApiEditPage extends ApiBase {
                                } else {
                                        $r['oldrevid'] = intval( $oldRevId );
                                        $r['newrevid'] = intval( $newRevId );
-                                       $pageObj->clear();
                                        $r['newtimestamp'] = wfTimestamp( TS_ISO_8601,
                                                $pageObj->getTimestamp() );
                                }