Ejemplo n.º 1
0
 private function createTitleForEntity(Entity $entity)
 {
     // NOTE: needs database access
     $this->entityStore->assignFreshId($entity);
     $titleLookup = WikibaseRepo::getDefaultInstance()->getEntityTitleLookup();
     $title = $titleLookup->getTitleForId($entity->getId());
     if (!$title->exists()) {
         $store = WikibaseRepo::getDefaultInstance()->getEntityStore();
         $store->saveEntity($entity, 'test', $GLOBALS['wgUser']);
         // $title lies, make a new one
         $title = Title::makeTitleSafe($title->getNamespace(), $title->getText());
     }
     // sanity check - page must exist now
     $this->assertGreaterThan(0, $title->getArticleID(), 'sanity check: getArticleID()');
     $this->assertTrue($title->exists(), 'sanity check: exists()');
     return $title;
 }
 /**
  * @see ApiBase::execute()
  *
  * @since 0.1
  */
 public function execute()
 {
     $params = $this->extractRequestParams();
     $user = $this->getUser();
     $this->flags = 0;
     $this->validateParameters($params);
     // Try to find the entity or fail and create it, or die in the process
     $entityRev = $this->getEntityRevisionFromApiParams($params);
     if (is_null($entityRev)) {
         $entity = $this->createEntity($params['new']);
         $entityRevId = 0;
         // HACK: We need to assign an ID early, for things like the ClaimIdGenerator.
         if ($entity->getId() === null) {
             $this->entityStore->assignFreshId($entity);
         }
     } else {
         $entity = $entityRev->getEntity();
         $entityRevId = $entityRev->getRevisionId();
     }
     if ($entity->getId() === null) {
         throw new LogicException('The Entity should have an ID at this point!');
     }
     // At this point only change/edit rights should be checked
     $status = $this->checkPermissions($entity, $user);
     if (!$status->isOK()) {
         $this->errorReporter->dieError('You do not have sufficient permissions', 'permissiondenied');
     }
     $summary = $this->modifyEntity($entity, $params, $entityRevId);
     if (!$summary) {
         //XXX: This could rather be used for "silent" failure, i.e. in cases where
         //     there was simply nothing to do.
         $this->errorReporter->dieError('Attempted modification of the item failed', 'failed-modify');
     }
     $this->addFlags($entity->getId() === null);
     //NOTE: EDIT_NEW will not be set automatically. If the entity doesn't exist, and EDIT_NEW was
     //      not added to $this->flags explicitly, the save will fail.
     $status = $this->attemptSaveEntity($entity, $summary, $this->flags);
     $this->addToOutput($entity, $status, $entityRevId);
 }