当前位置: 首页>>代码示例>>PHP>>正文


PHP Revision::newNullRevision方法代码示例

本文整理汇总了PHP中Revision::newNullRevision方法的典型用法代码示例。如果您正苦于以下问题:PHP Revision::newNullRevision方法的具体用法?PHP Revision::newNullRevision怎么用?PHP Revision::newNullRevision使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Revision的用法示例。


在下文中一共展示了Revision::newNullRevision方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateRestrictions

 /**
  * Update the article's restriction field, and leave a log entry.
  *
  * @param array $limit set of restriction keys
  * @param string $reason
  * @return bool true on success
  */
 function updateRestrictions($limit = array(), $reason = '', $cascade = 0, $expiry = null)
 {
     global $wgUser, $wgRestrictionTypes, $wgContLang;
     $id = $this->mTitle->getArticleID();
     if (array() != $this->mTitle->getUserPermissionsErrors('protect', $wgUser) || wfReadOnly() || $id == 0) {
         return false;
     }
     if (!$cascade) {
         $cascade = false;
     }
     // Take this opportunity to purge out expired restrictions
     Title::purgeExpiredRestrictions();
     # FIXME: Same limitations as described in ProtectionForm.php (line 37);
     # we expect a single selection, but the schema allows otherwise.
     $current = array();
     foreach ($wgRestrictionTypes as $action) {
         $current[$action] = implode('', $this->mTitle->getRestrictions($action));
     }
     $current = Article::flattenRestrictions($current);
     $updated = Article::flattenRestrictions($limit);
     $changed = $current != $updated;
     $changed = $changed || $this->mTitle->areRestrictionsCascading() != $cascade;
     $changed = $changed || $this->mTitle->mRestrictionsExpiry != $expiry;
     $protect = $updated != '';
     # If nothing's changed, do nothing
     if ($changed) {
         global $wgGroupPermissions;
         if (wfRunHooks('ArticleProtect', array(&$this, &$wgUser, $limit, $reason))) {
             $dbw = wfGetDB(DB_MASTER);
             $encodedExpiry = Block::encodeExpiry($expiry, $dbw);
             $expiry_description = '';
             if ($encodedExpiry != 'infinity') {
                 $expiry_description = ' (' . wfMsgForContent('protect-expiring', $wgContLang->timeanddate($expiry, false, false)) . ')';
             }
             # Prepare a null revision to be added to the history
             $modified = $current != '' && $protect;
             if ($protect) {
                 $comment_type = $modified ? 'modifiedarticleprotection' : 'protectedarticle';
             } else {
                 $comment_type = 'unprotectedarticle';
             }
             $comment = $wgContLang->ucfirst(wfMsgForContent($comment_type, $this->mTitle->getPrefixedText()));
             foreach ($limit as $action => $restrictions) {
                 # Check if the group level required to edit also can protect pages
                 # Otherwise, people who cannot normally protect can "protect" pages via transclusion
                 $cascade = $cascade && isset($wgGroupPermissions[$restrictions]['protect']) && $wgGroupPermissions[$restrictions]['protect'];
             }
             $cascade_description = '';
             if ($cascade) {
                 $cascade_description = ' [' . wfMsg('protect-summary-cascade') . ']';
             }
             if ($reason) {
                 $comment .= ": {$reason}";
             }
             if ($protect) {
                 $comment .= " [{$updated}]";
             }
             if ($expiry_description && $protect) {
                 $comment .= "{$expiry_description}";
             }
             if ($cascade) {
                 $comment .= "{$cascade_description}";
             }
             $rowsAffected = false;
             # Update restrictions table
             foreach ($limit as $action => $restrictions) {
                 if ($restrictions != '') {
                     $dbw->replace('page_restrictions', array(array('pr_page', 'pr_type')), array('pr_page' => $id, 'pr_type' => $action, 'pr_level' => $restrictions, 'pr_cascade' => $cascade ? 1 : 0, 'pr_expiry' => $encodedExpiry), __METHOD__);
                     if ($dbw->affectedRows() != 0) {
                         $rowsAffected = true;
                     }
                 } else {
                     $dbw->delete('page_restrictions', array('pr_page' => $id, 'pr_type' => $action), __METHOD__);
                     if ($dbw->affectedRows() != 0) {
                         $rowsAffected = true;
                     }
                 }
             }
             if (!$rowsAffected) {
                 // No change
                 return true;
             }
             # Insert a null revision
             $nullRevision = Revision::newNullRevision($dbw, $id, $comment, true);
             $nullRevId = $nullRevision->insertOn($dbw);
             # Update page record
             $dbw->update('page', array('page_touched' => $dbw->timestamp(), 'page_restrictions' => '', 'page_catinfo' => $this->mTitle->getCategoryMask(), 'page_latest' => $nullRevId), array('page_id' => $id), 'Article::protect');
             wfRunHooks('ArticleProtectComplete', array(&$this, &$wgUser, $limit, $reason));
             # Update the protection log
             $log = new LogPage('protect');
             if ($protect) {
                 $log->addEntry($modified ? 'modify' : 'protect', $this->mTitle, trim($reason . " [{$updated}]{$cascade_description}{$expiry_description}"));
             } else {
//.........这里部分代码省略.........
开发者ID:ErdemA,项目名称:wikihow,代码行数:101,代码来源:Article.php

示例2: moveToInternal

 /**
  * Move page to a title which is either a redirect to the
  * source page or nonexistent
  *
  * @param Title $nt The page to move to, which should be a redirect or nonexistent
  * @param string $reason The reason for the move
  * @param bool $createRedirect Whether to leave a redirect at the old title. Does not check
  *   if the user has the suppressredirect right
  * @throws MWException
  */
 private function moveToInternal(&$nt, $reason = '', $createRedirect = true)
 {
     global $wgUser, $wgContLang;
     if ($nt->exists()) {
         $moveOverRedirect = true;
         $logType = 'move_redir';
     } else {
         $moveOverRedirect = false;
         $logType = 'move';
     }
     if ($createRedirect) {
         if ($this->getNamespace() == NS_CATEGORY && !wfMessage('category-move-redirect-override')->inContentLanguage()->isDisabled()) {
             $redirectContent = new WikitextContent(wfMessage('category-move-redirect-override')->params($nt->getPrefixedText())->inContentLanguage()->plain());
         } else {
             $contentHandler = ContentHandler::getForTitle($this);
             $redirectContent = $contentHandler->makeRedirectContent($nt, wfMessage('move-redirect-text')->inContentLanguage()->plain());
         }
         // NOTE: If this page's content model does not support redirects, $redirectContent will be null.
     } else {
         $redirectContent = null;
     }
     // bug 57084: log_page should be the ID of the *moved* page
     $oldid = $this->getArticleID();
     $logTitle = clone $this;
     $logEntry = new ManualLogEntry('move', $logType);
     $logEntry->setPerformer($wgUser);
     $logEntry->setTarget($logTitle);
     $logEntry->setComment($reason);
     $logEntry->setParameters(array('4::target' => $nt->getPrefixedText(), '5::noredir' => $redirectContent ? '0' : '1'));
     $formatter = LogFormatter::newFromEntry($logEntry);
     $formatter->setContext(RequestContext::newExtraneousContext($this));
     $comment = $formatter->getPlainActionText();
     if ($reason) {
         $comment .= wfMessage('colon-separator')->inContentLanguage()->text() . $reason;
     }
     # Truncate for whole multibyte characters.
     $comment = $wgContLang->truncate($comment, 255);
     $dbw = wfGetDB(DB_MASTER);
     $newpage = WikiPage::factory($nt);
     if ($moveOverRedirect) {
         $newid = $nt->getArticleID();
         $newcontent = $newpage->getContent();
         # Delete the old redirect. We don't save it to history since
         # by definition if we've got here it's rather uninteresting.
         # We have to remove it so that the next step doesn't trigger
         # a conflict on the unique namespace+title index...
         $dbw->delete('page', array('page_id' => $newid), __METHOD__);
         $newpage->doDeleteUpdates($newid, $newcontent);
     }
     # Save a null revision in the page's history notifying of the move
     $nullRevision = Revision::newNullRevision($dbw, $oldid, $comment, true, $wgUser);
     if (!is_object($nullRevision)) {
         throw new MWException('No valid null revision produced in ' . __METHOD__);
     }
     $nullRevision->insertOn($dbw);
     # Change the name of the target page:
     $dbw->update('page', array('page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey()), array('page_id' => $oldid), __METHOD__);
     // clean up the old title before reset article id - bug 45348
     if (!$redirectContent) {
         WikiPage::onArticleDelete($this);
     }
     $this->resetArticleID(0);
     // 0 == non existing
     $nt->resetArticleID($oldid);
     $newpage->loadPageData(WikiPage::READ_LOCKING);
     // bug 46397
     $newpage->updateRevisionOn($dbw, $nullRevision);
     wfRunHooks('NewRevisionFromEditComplete', array($newpage, $nullRevision, $nullRevision->getParentId(), $wgUser));
     $newpage->doEditUpdates($nullRevision, $wgUser, array('changed' => false));
     if (!$moveOverRedirect) {
         WikiPage::onArticleCreate($nt);
     }
     # Recreate the redirect, this time in the other direction.
     if ($redirectContent) {
         $redirectArticle = WikiPage::factory($this);
         $redirectArticle->loadFromRow(false, WikiPage::READ_LOCKING);
         // bug 46397
         $newid = $redirectArticle->insertOn($dbw);
         if ($newid) {
             // sanity
             $this->resetArticleID($newid);
             $redirectRevision = new Revision(array('title' => $this, 'page' => $newid, 'user_text' => $wgUser->getName(), 'user' => $wgUser->getId(), 'comment' => $comment, 'content' => $redirectContent));
             $redirectRevision->insertOn($dbw);
             $redirectArticle->updateRevisionOn($dbw, $redirectRevision, 0);
             wfRunHooks('NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false, $wgUser));
             $redirectArticle->doEditUpdates($redirectRevision, $wgUser, array('created' => true));
         }
     }
     # Log the move
     $logid = $logEntry->insert();
//.........这里部分代码省略.........
开发者ID:Habatchii,项目名称:wikibase-for-mediawiki,代码行数:101,代码来源:Title.php

示例3: moveToNewTitle

 /**
  * Move page to non-existing title.
  * @param Title &$nt the new Title
  */
 private function moveToNewTitle(&$nt, $reason = '')
 {
     global $wgUseSquid;
     $fname = 'MovePageForm::moveToNewTitle';
     $comment = wfMsgForContent('1movedto2', $this->getPrefixedText(), $nt->getPrefixedText());
     if ($reason) {
         $comment .= ": {$reason}";
     }
     $newid = $nt->getArticleID();
     $oldid = $this->getArticleID();
     $dbw = wfGetDB(DB_MASTER);
     $now = $dbw->timestamp();
     $linkCache =& LinkCache::singleton();
     # Save a null revision in the page's history notifying of the move
     $nullRevision = Revision::newNullRevision($dbw, $oldid, $comment, true);
     $nullRevId = $nullRevision->insertOn($dbw);
     # Rename cur entry
     $dbw->update('page', array('page_touched' => $now, 'page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey(), 'page_latest' => $nullRevId), array('page_id' => $oldid), $fname);
     $linkCache->clearLink($nt->getPrefixedDBkey());
     # Insert redirect
     $mwRedir = MagicWord::get('redirect');
     $redirectText = $mwRedir->getSynonym(0) . ' [[' . $nt->getPrefixedText() . "]]\n";
     $redirectArticle = new Article($this);
     $newid = $redirectArticle->insertOn($dbw);
     $redirectRevision = new Revision(array('page' => $newid, 'comment' => $comment, 'text' => $redirectText));
     $redirectRevision->insertOn($dbw);
     $redirectArticle->updateRevisionOn($dbw, $redirectRevision, 0);
     $linkCache->clearLink($this->getPrefixedDBkey());
     # Log the move
     $log = new LogPage('move');
     $log->addEntry('move', $this, $reason, array(1 => $nt->getPrefixedText()));
     # Purge caches as per article creation
     Article::onArticleCreate($nt);
     # Record the just-created redirect's linking to the page
     $dbw->insert('pagelinks', array('pl_from' => $newid, 'pl_namespace' => $nt->getNamespace(), 'pl_title' => $nt->getDBkey()), $fname);
     # Purge old title from squid
     # The new title, and links to the new title, are purged in Article::onArticleCreate()
     $this->purgeSquid();
 }
开发者ID:arlendotcn,项目名称:ilias,代码行数:43,代码来源:Title.php

示例4: reportPage

 function reportPage($title, $origTitle, $revisionCount)
 {
     global $wgOut, $wgUser, $wgLang, $wgContLang;
     $skin = $wgUser->getSkin();
     $this->mPageCount++;
     $localCount = $wgLang->formatNum($revisionCount);
     $contentCount = $wgContLang->formatNum($revisionCount);
     $wgOut->addHtml("<li>" . $skin->makeKnownLinkObj($title) . " " . wfMsgHtml('import-revision-count', $localCount) . "</li>\n");
     $log = new LogPage('import');
     if ($this->mIsUpload) {
         $detail = wfMsgForContent('import-logentry-upload-detail', $contentCount);
         $log->addEntry('upload', $title, $detail);
     } else {
         $interwiki = '[[:' . $this->mInterwiki . ':' . $origTitle->getPrefixedText() . ']]';
         $detail = wfMsgForContent('import-logentry-interwiki-detail', $contentCount, $interwiki);
         $log->addEntry('interwiki', $title, $detail);
     }
     $comment = $detail;
     // quick
     $dbw = wfGetDB(DB_MASTER);
     $nullRevision = Revision::newNullRevision($dbw, $title->getArticleId(), $comment, true);
     $nullRevId = $nullRevision->insertOn($dbw);
 }
开发者ID:k-hasan-19,项目名称:wiki,代码行数:23,代码来源:SpecialImport.php

示例5: doUpdateRestrictions


//.........这里部分代码省略.........
             # action.
             if ($this->mTitle->getRestrictionExpiry($action) != $expiry[$action]) {
                 $changed = true;
             }
         }
     }
     if (!$changed && $protect && $this->mTitle->areRestrictionsCascading() != $cascade) {
         $changed = true;
     }
     # If nothing's changed, do nothing
     if (!$changed) {
         return Status::newGood();
     }
     if (!$protect) {
         # No protection at all means unprotection
         $revCommentMsg = 'unprotectedarticle';
         $logAction = 'unprotect';
     } elseif ($isProtected) {
         $revCommentMsg = 'modifiedarticleprotection';
         $logAction = 'modify';
     } else {
         $revCommentMsg = 'protectedarticle';
         $logAction = 'protect';
     }
     $encodedExpiry = array();
     $protectDescription = '';
     foreach ($limit as $action => $restrictions) {
         $encodedExpiry[$action] = $dbw->encodeExpiry($expiry[$action]);
         if ($restrictions != '') {
             $protectDescription .= $wgContLang->getDirMark() . "[{$action}={$restrictions}] (";
             if ($encodedExpiry[$action] != 'infinity') {
                 $protectDescription .= wfMessage('protect-expiring', $wgContLang->timeanddate($expiry[$action], false, false), $wgContLang->date($expiry[$action], false, false), $wgContLang->time($expiry[$action], false, false))->inContentLanguage()->text();
             } else {
                 $protectDescription .= wfMessage('protect-expiry-indefinite')->inContentLanguage()->text();
             }
             $protectDescription .= ') ';
         }
     }
     $protectDescription = trim($protectDescription);
     if ($id) {
         # Protection of existing page
         if (!wfRunHooks('ArticleProtect', array(&$this, &$user, $limit, $reason))) {
             return Status::newGood();
         }
         # Only restrictions with the 'protect' right can cascade...
         # Otherwise, people who cannot normally protect can "protect" pages via transclusion
         $editrestriction = isset($limit['edit']) ? array($limit['edit']) : $this->mTitle->getRestrictions('edit');
         # The schema allows multiple restrictions
         if (!in_array('protect', $editrestriction) && !in_array('sysop', $editrestriction)) {
             $cascade = false;
         }
         # Update restrictions table
         foreach ($limit as $action => $restrictions) {
             if ($restrictions != '') {
                 $dbw->replace('page_restrictions', array(array('pr_page', 'pr_type')), array('pr_page' => $id, 'pr_type' => $action, 'pr_level' => $restrictions, 'pr_cascade' => $cascade && $action == 'edit' ? 1 : 0, 'pr_expiry' => $encodedExpiry[$action]), __METHOD__);
             } else {
                 $dbw->delete('page_restrictions', array('pr_page' => $id, 'pr_type' => $action), __METHOD__);
             }
         }
         # Prepare a null revision to be added to the history
         $editComment = $wgContLang->ucfirst(wfMessage($revCommentMsg, $this->mTitle->getPrefixedText())->inContentLanguage()->text());
         if ($reason) {
             $editComment .= ": {$reason}";
         }
         if ($protectDescription) {
             $editComment .= " ({$protectDescription})";
         }
         if ($cascade) {
             // FIXME: Should use 'brackets' message.
             $editComment .= ' [' . wfMessage('protect-summary-cascade')->inContentLanguage()->text() . ']';
         }
         # Insert a null revision
         $nullRevision = Revision::newNullRevision($dbw, $id, $editComment, true);
         $nullRevId = $nullRevision->insertOn($dbw);
         $latest = $this->getLatest();
         # Update page record
         $dbw->update('page', array('page_touched' => $dbw->timestamp(), 'page_restrictions' => '', 'page_latest' => $nullRevId), array('page_id' => $id), __METHOD__);
         wfRunHooks('NewRevisionFromEditComplete', array($this, $nullRevision, $latest, $user));
         wfRunHooks('ArticleProtectComplete', array(&$this, &$user, $limit, $reason));
     } else {
         # Protection of non-existing page (also known as "title protection")
         # Cascade protection is meaningless in this case
         $cascade = false;
         if ($limit['create'] != '') {
             $dbw->replace('protected_titles', array(array('pt_namespace', 'pt_title')), array('pt_namespace' => $this->mTitle->getNamespace(), 'pt_title' => $this->mTitle->getDBkey(), 'pt_create_perm' => $limit['create'], 'pt_timestamp' => $dbw->encodeExpiry(wfTimestampNow()), 'pt_expiry' => $encodedExpiry['create'], 'pt_user' => $user->getId(), 'pt_reason' => $reason), __METHOD__);
         } else {
             $dbw->delete('protected_titles', array('pt_namespace' => $this->mTitle->getNamespace(), 'pt_title' => $this->mTitle->getDBkey()), __METHOD__);
         }
     }
     $this->mTitle->flushRestrictions();
     if ($logAction == 'unprotect') {
         $logParams = array();
     } else {
         $logParams = array($protectDescription, $cascade ? 'cascade' : '');
     }
     # Update the protection log
     $log = new LogPage('protect');
     $log->addEntry($logAction, $this->mTitle, trim($reason), $logParams, $user);
     return Status::newGood();
 }
开发者ID:nischayn22,项目名称:mediawiki-core,代码行数:101,代码来源:WikiPage.php

示例6: updateRestrictions


//.........这里部分代码省略.........
     foreach ($restrictionTypes as $action) {
         if (isset($expiry[$action])) {
             # Get current restrictions on $action
             $aLimits = $this->mTitle->getRestrictions($action);
             $current[$action] = implode('', $aLimits);
             # Are any actual restrictions being dealt with here?
             $aRChanged = count($aLimits) || !empty($limit[$action]);
             # If something changed, we need to log it. Checking $aRChanged
             # assures that "unprotecting" a page that is not protected does
             # not log just because the expiry was "changed".
             if ($aRChanged && $this->mTitle->mRestrictionsExpiry[$action] != $expiry[$action]) {
                 $changed = true;
             }
         }
     }
     $current = Article::flattenRestrictions($current);
     $changed = $changed || $current != $updated;
     $changed = $changed || $updated && $this->mTitle->areRestrictionsCascading() != $cascade;
     $protect = $updated != '';
     # If nothing's changed, do nothing
     if ($changed) {
         if (wfRunHooks('ArticleProtect', array(&$this, &$wgUser, $limit, $reason))) {
             $dbw = wfGetDB(DB_MASTER);
             # Prepare a null revision to be added to the history
             $modified = $current != '' && $protect;
             if ($protect) {
                 $comment_type = $modified ? 'modifiedarticleprotection' : 'protectedarticle';
             } else {
                 $comment_type = 'unprotectedarticle';
             }
             $comment = $wgContLang->ucfirst(wfMsgForContent($comment_type, $this->mTitle->getPrefixedText()));
             # Only restrictions with the 'protect' right can cascade...
             # Otherwise, people who cannot normally protect can "protect" pages via transclusion
             $editrestriction = isset($limit['edit']) ? array($limit['edit']) : $this->mTitle->getRestrictions('edit');
             # The schema allows multiple restrictions
             if (!in_array('protect', $editrestriction) && !in_array('sysop', $editrestriction)) {
                 $cascade = false;
             }
             $cascade_description = '';
             if ($cascade) {
                 $cascade_description = ' [' . wfMsgForContent('protect-summary-cascade') . ']';
             }
             if ($reason) {
                 $comment .= ": {$reason}";
             }
             $editComment = $comment;
             $encodedExpiry = array();
             $protect_description = '';
             foreach ($limit as $action => $restrictions) {
                 if (!isset($expiry[$action])) {
                     $expiry[$action] = Block::infinity();
                 }
                 $encodedExpiry[$action] = Block::encodeExpiry($expiry[$action], $dbw);
                 if ($restrictions != '') {
                     $protect_description .= "[{$action}={$restrictions}] (";
                     if ($encodedExpiry[$action] != 'infinity') {
                         $protect_description .= wfMsgForContent('protect-expiring', $wgContLang->timeanddate($expiry[$action], false, false), $wgContLang->date($expiry[$action], false, false), $wgContLang->time($expiry[$action], false, false));
                     } else {
                         $protect_description .= wfMsgForContent('protect-expiry-indefinite');
                     }
                     $protect_description .= ') ';
                 }
             }
             $protect_description = trim($protect_description);
             if ($protect_description && $protect) {
                 $editComment .= " ({$protect_description})";
             }
             if ($cascade) {
                 $editComment .= "{$cascade_description}";
             }
             # Update restrictions table
             foreach ($limit as $action => $restrictions) {
                 if ($restrictions != '') {
                     $dbw->replace('page_restrictions', array(array('pr_page', 'pr_type')), array('pr_page' => $id, 'pr_type' => $action, 'pr_level' => $restrictions, 'pr_cascade' => $cascade && $action == 'edit' ? 1 : 0, 'pr_expiry' => $encodedExpiry[$action]), __METHOD__);
                 } else {
                     $dbw->delete('page_restrictions', array('pr_page' => $id, 'pr_type' => $action), __METHOD__);
                 }
             }
             # Insert a null revision
             $nullRevision = Revision::newNullRevision($dbw, $id, $editComment, true);
             $nullRevId = $nullRevision->insertOn($dbw);
             $latest = $this->getLatest();
             # Update page record
             $dbw->update('page', array('page_touched' => $dbw->timestamp(), 'page_restrictions' => '', 'page_latest' => $nullRevId), array('page_id' => $id), 'Article::protect');
             wfRunHooks('NewRevisionFromEditComplete', array($this, $nullRevision, $latest, $wgUser));
             wfRunHooks('ArticleProtectComplete', array(&$this, &$wgUser, $limit, $reason));
             # Update the protection log
             $log = new LogPage('protect');
             if ($protect) {
                 $params = array($protect_description, $cascade ? 'cascade' : '');
                 $log->addEntry($modified ? 'modify' : 'protect', $this->mTitle, trim($reason), $params);
             } else {
                 $log->addEntry('unprotect', $this->mTitle, $reason);
             }
         }
         # End hook
     }
     # End "changed" check
     return true;
 }
开发者ID:GodelDesign,项目名称:Godel,代码行数:101,代码来源:Article.php

示例7: recordDownload

 /**
  * Record a file upload in the upload log and the image table
  */
 private function recordDownload($comment = '', $timestamp = false)
 {
     global $wgUser;
     $dbw = $this->repo->getMasterDB();
     if ($timestamp === false) {
         $timestamp = $dbw->timestamp();
     }
     list($major, $minor) = self::splitMime($this->mime);
     # Test to see if the row exists using INSERT IGNORE
     # This avoids race conditions by locking the row until the commit, and also
     # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
     $dbw->insert('ic_image', array('img_name' => $this->getName(), 'img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->type, 'img_major_mime' => $major, 'img_minor_mime' => $minor, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $wgUser->getID(), 'img_user_text' => $wgUser->getName(), 'img_metadata' => $this->metadata), __METHOD__, 'IGNORE');
     if ($dbw->affectedRows() == 0) {
         # Collision, this is an update of a file
         # Update the current image row
         $dbw->update('ic_image', array('img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $wgUser->getID(), 'img_user_text' => $wgUser->getName(), 'img_metadata' => $this->metadata), array('img_name' => $this->getName()), __METHOD__);
     } else {
         # This is a new file
         # Update the image count
         $site_stats = $dbw->tableName('site_stats');
         $dbw->query("UPDATE {$site_stats} SET ss_images=ss_images+1", __METHOD__);
     }
     $descTitle = $this->getTitle();
     $article = new Article($descTitle);
     # Add the log entry
     $log = new LogPage('icdownload');
     $log->addEntry('InstantCommons download', $descTitle, $comment);
     if ($descTitle->exists()) {
         # Create a null revision
         $nullRevision = Revision::newNullRevision($dbw, $descTitle->getArticleId(), $log->getRcComment(), false);
         $nullRevision->insertOn($dbw);
         $article->updateRevisionOn($dbw, $nullRevision);
         # Invalidate the cache for the description page
         $descTitle->invalidateCache();
         $descTitle->purgeSquid();
     }
     # Commit the transaction now, in case something goes wrong later
     # The most important thing is that files don't get lost, especially archives
     $dbw->immediateCommit();
     # Invalidate cache for all pages using this file
     $update = new HTMLCacheUpdate($this->getTitle(), 'imagelinks');
     $update->doUpdate();
     return true;
 }
开发者ID:BackupTheBerlios,项目名称:shoutwiki-svn,代码行数:47,代码来源:ICRepo.php

示例8: reportPage

 function reportPage($title, $origTitle, $revisionCount, $successCount)
 {
     global $wgOut, $wgUser, $wgLang, $wgContLang;
     $skin = $wgUser->getSkin();
     $this->mPageCount++;
     $localCount = $wgLang->formatNum($successCount);
     $contentCount = $wgContLang->formatNum($successCount);
     if ($successCount > 0) {
         $wgOut->addHTML("<li>" . $skin->makeKnownLinkObj($title) . " " . wfMsgExt('import-revision-count', array('parsemag', 'escape'), $localCount) . "</li>\n");
         $log = new LogPage('import');
         if ($this->mIsUpload) {
             $detail = wfMsgExt('import-logentry-upload-detail', array('content', 'parsemag'), $contentCount);
             if ($this->reason) {
                 $detail .= wfMsgForContent('colon-separator') . $this->reason;
             }
             $log->addEntry('upload', $title, $detail);
         } else {
             $interwiki = '[[:' . $this->mInterwiki . ':' . $origTitle->getPrefixedText() . ']]';
             $detail = wfMsgExt('import-logentry-interwiki-detail', array('content', 'parsemag'), $contentCount, $interwiki);
             if ($this->reason) {
                 $detail .= wfMsgForContent('colon-separator') . $this->reason;
             }
             $log->addEntry('interwiki', $title, $detail);
         }
         $comment = $detail;
         // quick
         $dbw = wfGetDB(DB_MASTER);
         $latest = $title->getLatestRevID();
         $nullRevision = Revision::newNullRevision($dbw, $title->getArticleId(), $comment, true);
         $nullRevision->insertOn($dbw);
         $article = new Article($title);
         # Update page record
         $article->updateRevisionOn($dbw, $nullRevision);
         wfRunHooks('NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $wgUser));
     } else {
         $wgOut->addHTML('<li>' . wfMsgHtml('import-nonewrevisions') . '</li>');
     }
 }
开发者ID:ruizrube,项目名称:spdef,代码行数:38,代码来源:SpecialImport.php

示例9: moveToNewTitle

 /**
  * Move page to non-existing title.
  * @param &$nt \type{Title} the new Title
  * @param $reason \type{\string} The reason for the move
  * @param $createRedirect \type{\bool} Whether to create a redirect from the old title to the new title
  *  Ignored if the user doesn't have the suppressredirect right
  */
 private function moveToNewTitle(&$nt, $reason = '', $createRedirect = true)
 {
     global $wgUseSquid, $wgUser;
     $fname = 'MovePageForm::moveToNewTitle';
     $comment = wfMsgForContent('1movedto2', $this->getPrefixedText(), $nt->getPrefixedText());
     if ($reason) {
         $comment .= wfMsgExt('colon-separator', array('escapenoentities', 'content'));
         $comment .= $reason;
     }
     $newid = $nt->getArticleID();
     $oldid = $this->getArticleID();
     $latest = $this->getLatestRevId();
     $dbw = wfGetDB(DB_MASTER);
     $now = $dbw->timestamp();
     # Save a null revision in the page's history notifying of the move
     $nullRevision = Revision::newNullRevision($dbw, $oldid, $comment, true);
     $nullRevId = $nullRevision->insertOn($dbw);
     $article = new Article($this);
     wfRunHooks('NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $wgUser));
     # Rename page entry
     $dbw->update('page', array('page_touched' => $now, 'page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey(), 'page_latest' => $nullRevId), array('page_id' => $oldid), $fname);
     $nt->resetArticleID($oldid);
     if ($createRedirect || !$wgUser->isAllowed('suppressredirect')) {
         # Insert redirect
         $mwRedir = MagicWord::get('redirect');
         $redirectText = $mwRedir->getSynonym(0) . ' [[' . $nt->getPrefixedText() . "]]\n";
         $redirectArticle = new Article($this);
         $newid = $redirectArticle->insertOn($dbw);
         $redirectRevision = new Revision(array('page' => $newid, 'comment' => $comment, 'text' => $redirectText));
         $redirectRevision->insertOn($dbw);
         $redirectArticle->updateRevisionOn($dbw, $redirectRevision, 0);
         wfRunHooks('NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false, $wgUser));
         # Record the just-created redirect's linking to the page
         $dbw->insert('pagelinks', array('pl_from' => $newid, 'pl_namespace' => $nt->getNamespace(), 'pl_title' => $nt->getDBkey()), $fname);
         $redirectSuppressed = false;
     } else {
         $this->resetArticleID(0);
         $redirectSuppressed = true;
     }
     # Move an image if this is a file
     if ($this->getNamespace() == NS_FILE) {
         $file = wfLocalFile($this);
         if ($file->exists()) {
             $status = $file->move($nt);
             if (!$status->isOk()) {
                 $dbw->rollback();
                 return $status->getErrorsArray();
             }
         }
     }
     # Log the move
     $log = new LogPage('move');
     $log->addEntry('move', $this, $reason, array(1 => $nt->getPrefixedText(), 2 => $redirectSuppressed));
     # Purge caches as per article creation
     Article::onArticleCreate($nt);
     # Purge old title from squid
     # The new title, and links to the new title, are purged in Article::onArticleCreate()
     $this->purgeSquid();
 }
开发者ID:josephdye,项目名称:wikireader,代码行数:66,代码来源:Title.php

示例10: duplicate

 /**
  * Duplicate one page to another, including full histories
  * Does some basic error-catching, but not as much as the code above [should]
  *
  * @param $source Title to duplicate
  * @param $dest Title to save to
  * @return bool
  */
 private function duplicate(&$source, &$dest)
 {
     global $wgUser, $wgBot;
     if (!$source->exists() || $dest->exists()) {
         return false;
     }
     # Source doesn't exist, or destination does
     $dbw = wfGetDB(DB_MASTER);
     $dbw->begin();
     $sid = $source->getArticleId();
     # Create an article representing the destination page and save it
     $destArticle = new Article($dest);
     $aid = $destArticle->insertOn($dbw);
     # Perform the revision duplication
     # An INSERT...SELECT here seems to fuck things up
     $res = $dbw->select('revision', '*', array('rev_page' => $sid), __METHOD__);
     if ($res && $dbw->numRows($res) > 0) {
         while ($row = $dbw->fetchObject($res)) {
             $values['rev_page'] = $aid;
             $values['rev_text_id'] = $row->rev_text_id;
             $values['rev_comment'] = $row->rev_comment;
             $values['rev_user'] = $row->rev_user;
             $values['rev_user_text'] = $row->rev_user_text;
             $values['rev_timestamp'] = $row->rev_timestamp;
             $values['rev_minor_edit'] = $row->rev_minor_edit;
             $values['rev_deleted'] = $row->rev_deleted;
             $dbw->insert('revision', $values, __METHOD__);
         }
         $dbw->freeResult($res);
     }
     # Update page record
     $latest = $dbw->selectField('revision', 'MAX(rev_id)', array('rev_page' => $aid), __METHOD__);
     $rev = Revision::newFromId($latest);
     $destArticle->updateRevisionOn($dbw, $rev);
     # Commit transaction
     $dbw->commit();
     # Create a null revision with an explanation; do cache clearances, etc.
     $dbw->begin();
     $comment = wfMsgForContent('duplicator-summary', $source->getPrefixedText());
     $nr = Revision::newNullRevision($dbw, $aid, $comment, true);
     $nid = $nr->insertOn($dbw);
     $destArticle->updateRevisionOn($dbw, $nr);
     $destArticle->createUpdates($nr);
     Article::onArticleCreate($dest);
     $bot = $wgUser->isAllowed('bot');
     RecentChange::notifyNew($nr->getTimestamp(), $dest, true, $wgUser, $comment, $bot);
     $dest->invalidateCache();
     $dbw->commit();
     return true;
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:58,代码来源:Duplicator.page.php

示例11: updateLogsAndHistory

 protected function updateLogsAndHistory(FlaggableWikiPage $article)
 {
     global $wgContLang;
     $newConfig = $this->getNewConfig();
     $oldConfig = $this->getOldConfig();
     $reason = $this->getReason();
     # Insert stability log entry...
     FlaggedRevsLog::updateStabilityLog($this->page, $newConfig, $oldConfig, $reason);
     # Build null-edit comment...<action: reason [settings] (expiry)>
     if (FRPageConfig::configIsReset($newConfig)) {
         $type = "stable-logentry-reset";
         $settings = '';
         // no level, expiry info
     } else {
         $type = "stable-logentry-config";
         // Settings message in text form (e.g. [x=a,y=b,z])
         $params = FlaggedRevsLog::stabilityLogParams($newConfig);
         $settings = FlaggedRevsLogView::stabilitySettings($params, true);
     }
     $comment = $wgContLang->ucfirst(wfMsgForContent($type, $this->page->getPrefixedText()));
     // action
     if ($reason != '') {
         $comment .= wfMsgForContent('colon-separator') . $reason;
         // add reason
     }
     if ($settings != '') {
         $comment .= " {$settings}";
         // add settings
     }
     # Insert a null revision...
     $dbw = wfGetDB(DB_MASTER);
     $nullRev = Revision::newNullRevision($dbw, $article->getId(), $comment, true);
     $nullRev->insertOn($dbw);
     # Update page record and touch page
     $oldLatest = $nullRev->getParentId();
     $article->updateRevisionOn($dbw, $nullRev, $oldLatest);
     wfRunHooks('NewRevisionFromEditComplete', array($article, $nullRev, $oldLatest, $this->user));
     # Return null Revision object for autoreview check
     return $nullRev;
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:40,代码来源:PageStabilityForm.php

示例12: doUpdateRestrictions


//.........这里部分代码省略.........
     # protect description text. Keep them in old format to avoid breaking compatibility.
     # TODO: Fix protection log to store structured description and format it on-the-fly.
     $protectDescriptionLog = '';
     foreach ($limit as $action => $restrictions) {
         $encodedExpiry[$action] = $dbw->encodeExpiry($expiry[$action]);
         if ($restrictions != '') {
             $protectDescriptionLog .= $wgContLang->getDirMark() . "[{$action}={$restrictions}] (";
             # $action is one of $wgRestrictionTypes = array( 'create', 'edit', 'move', 'upload' ).
             # All possible message keys are listed here for easier grepping:
             # * restriction-create
             # * restriction-edit
             # * restriction-move
             # * restriction-upload
             $actionText = wfMessage('restriction-' . $action)->inContentLanguage()->text();
             # $restrictions is one of $wgRestrictionLevels = array( '', 'autoconfirmed', 'sysop' ),
             # with '' filtered out. All possible message keys are listed below:
             # * protect-level-autoconfirmed
             # * protect-level-sysop
             $restrictionsText = wfMessage('protect-level-' . $restrictions)->inContentLanguage()->text();
             if ($encodedExpiry[$action] != 'infinity') {
                 $expiryText = wfMessage('protect-expiring', $wgContLang->timeanddate($expiry[$action], false, false), $wgContLang->date($expiry[$action], false, false), $wgContLang->time($expiry[$action], false, false))->inContentLanguage()->text();
             } else {
                 $expiryText = wfMessage('protect-expiry-indefinite')->inContentLanguage()->text();
             }
             if ($protectDescription !== '') {
                 $protectDescription .= wfMessage('word-separator')->inContentLanguage()->text();
             }
             $protectDescription .= wfMessage('protect-summary-desc')->params($actionText, $restrictionsText, $expiryText)->inContentLanguage()->text();
             $protectDescriptionLog .= $expiryText . ') ';
         }
     }
     $protectDescriptionLog = trim($protectDescriptionLog);
     if ($id) {
         // Protection of existing page
         if (!wfRunHooks('ArticleProtect', array(&$this, &$user, $limit, $reason))) {
             return Status::newGood();
         }
         // Only certain restrictions can cascade... Otherwise, users who cannot normally protect pages
         // could "protect" them by transcluding them on protected pages they are allowed to edit.
         $editrestriction = isset($limit['edit']) ? array($limit['edit']) : $this->mTitle->getRestrictions('edit');
         $cascadingRestrictionLevels = $wgCascadingRestrictionLevels;
         if (in_array('sysop', $cascadingRestrictionLevels)) {
             $cascadingRestrictionLevels[] = 'protect';
             // backwards compatibility
         }
         // The schema allows multiple restrictions
         if (!array_intersect($editrestriction, $cascadingRestrictionLevels)) {
             $cascade = false;
         }
         // Update restrictions table
         foreach ($limit as $action => $restrictions) {
             if ($restrictions != '') {
                 $dbw->replace('page_restrictions', array(array('pr_page', 'pr_type')), array('pr_page' => $id, 'pr_type' => $action, 'pr_level' => $restrictions, 'pr_cascade' => $cascade && $action == 'edit' ? 1 : 0, 'pr_expiry' => $encodedExpiry[$action]), __METHOD__);
             } else {
                 $dbw->delete('page_restrictions', array('pr_page' => $id, 'pr_type' => $action), __METHOD__);
             }
         }
         // Prepare a null revision to be added to the history
         $editComment = $wgContLang->ucfirst(wfMessage($revCommentMsg, $this->mTitle->getPrefixedText())->inContentLanguage()->text());
         if ($reason) {
             $editComment .= wfMessage('colon-separator')->inContentLanguage()->text() . $reason;
         }
         if ($protectDescription) {
             $editComment .= wfMessage('word-separator')->inContentLanguage()->text();
             $editComment .= wfMessage('parentheses')->params($protectDescription)->inContentLanguage()->text();
         }
         if ($cascade) {
             $editComment .= wfMessage('word-separator')->inContentLanguage()->text();
             $editComment .= wfMessage('brackets')->params(wfMessage('protect-summary-cascade')->inContentLanguage()->text())->inContentLanguage()->text();
         }
         // Insert a null revision
         $nullRevision = Revision::newNullRevision($dbw, $id, $editComment, true);
         $nullRevId = $nullRevision->insertOn($dbw);
         $latest = $this->getLatest();
         // Update page record
         $dbw->update('page', array('page_touched' => $dbw->timestamp(), 'page_restrictions' => '', 'page_latest' => $nullRevId), array('page_id' => $id), __METHOD__);
         wfRunHooks('NewRevisionFromEditComplete', array($this, $nullRevision, $latest, $user));
         wfRunHooks('ArticleProtectComplete', array(&$this, &$user, $limit, $reason));
     } else {
         // Protection of non-existing page (also known as "title protection")
         // Cascade protection is meaningless in this case
         $cascade = false;
         if ($limit['create'] != '') {
             $dbw->replace('protected_titles', array(array('pt_namespace', 'pt_title')), array('pt_namespace' => $this->mTitle->getNamespace(), 'pt_title' => $this->mTitle->getDBkey(), 'pt_create_perm' => $limit['create'], 'pt_timestamp' => $dbw->encodeExpiry(wfTimestampNow()), 'pt_expiry' => $encodedExpiry['create'], 'pt_user' => $user->getId(), 'pt_reason' => $reason), __METHOD__);
         } else {
             $dbw->delete('protected_titles', array('pt_namespace' => $this->mTitle->getNamespace(), 'pt_title' => $this->mTitle->getDBkey()), __METHOD__);
         }
     }
     $this->mTitle->flushRestrictions();
     InfoAction::invalidateCache($this->mTitle);
     if ($logAction == 'unprotect') {
         $logParams = array();
     } else {
         $logParams = array($protectDescriptionLog, $cascade ? 'cascade' : '');
     }
     // Update the protection log
     $log = new LogPage('protect');
     $log->addEntry($logAction, $this->mTitle, trim($reason), $logParams, $user);
     return Status::newGood();
 }
开发者ID:mangowi,项目名称:mediawiki,代码行数:101,代码来源:WikiPage.php

示例13: recordUpload2

 /**
  * Record a file upload in the upload log and the image table
  */
 function recordUpload2($oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null)
 {
     global $wgCityId;
     if (is_null($user)) {
         global $wgUser;
         $user = $wgUser;
     }
     $dbw = $this->repo->getMasterDB();
     $dbw->begin();
     if (!$props) {
         $props = $this->repo->getFileProps($this->getVirtualUrl());
     }
     if ($timestamp === false) {
         $timestamp = $dbw->timestamp();
     }
     $props['description'] = $comment;
     $props['user'] = $user->getId();
     $props['user_text'] = $user->getName();
     $props['timestamp'] = wfTimestamp(TS_MW, $timestamp);
     // DB -> TS_MW
     $this->setProps($props);
     # Fail now if the file isn't there
     if (!$this->fileExists) {
         wfDebug(__METHOD__ . ": File " . $this->getRel() . " went missing!\n");
         return false;
     }
     $reupload = false;
     # Test to see if the row exists using INSERT IGNORE
     # This avoids race conditions by locking the row until the commit, and also
     # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
     $dbw->insert('image', array('img_name' => $this->getName(), 'img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $this->metadata, 'img_sha1' => $this->sha1), __METHOD__, 'IGNORE');
     if ($dbw->affectedRows() == 0) {
         if ($oldver == '') {
             // XXX
             # (bug 34993) publish() can displace the current file and yet fail to save
             # a new one. The next publish attempt will treat the file as a brand new file
             # and pass an empty $oldver. Allow this bogus value so we can displace the
             # `image` row to `oldimage`, leaving room for the new current file `image` row.
             #throw new MWException( "Empty oi_archive_name. Database and storage out of sync?" );
             Wikia::logBacktrace(__METHOD__ . "::oi_archive_name - [{$this->getName()}]");
             // Wikia change (BAC-1068)
         }
         $reupload = true;
         # Collision, this is an update of a file
         # Insert previous contents into oldimage
         $dbw->insertSelect('oldimage', 'image', array('oi_name' => 'img_name', 'oi_archive_name' => $dbw->addQuotes($oldver), 'oi_size' => 'img_size', 'oi_width' => 'img_width', 'oi_height' => 'img_height', 'oi_bits' => 'img_bits', 'oi_timestamp' => 'img_timestamp', 'oi_description' => 'img_description', 'oi_user' => 'img_user', 'oi_user_text' => 'img_user_text', 'oi_metadata' => 'img_metadata', 'oi_media_type' => 'img_media_type', 'oi_major_mime' => 'img_major_mime', 'oi_minor_mime' => 'img_minor_mime', 'oi_sha1' => 'img_sha1'), array('img_name' => $this->getName()), __METHOD__);
         # Update the current image row
         $dbw->update('image', array('img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $this->metadata, 'img_sha1' => $this->sha1), array('img_name' => $this->getName()), __METHOD__);
     } else {
         # This is a new file
         # Update the image count
         $dbw->begin(__METHOD__);
         $dbw->update('site_stats', array('ss_images = ss_images+1'), '*', __METHOD__);
         $dbw->commit(__METHOD__);
     }
     $descTitle = $this->getTitle();
     $wikiPage = new WikiFilePage($descTitle);
     $wikiPage->setFile($this);
     # Add the log entry
     $log = new LogPage('upload');
     $action = $reupload ? 'overwrite' : 'upload';
     $log->addEntry($action, $descTitle, $comment, array(), $user);
     if ($descTitle->exists()) {
         # Create a null revision
         $latest = $descTitle->getLatestRevID();
         $nullRevision = Revision::newNullRevision($dbw, $descTitle->getArticleId(), $log->getRcComment(), false);
         if (!is_null($nullRevision)) {
             $nullRevision->insertOn($dbw);
             wfRunHooks('NewRevisionFromEditComplete', array($wikiPage, $nullRevision, $latest, $user));
             $wikiPage->updateRevisionOn($dbw, $nullRevision);
         }
         # Invalidate the cache for the description page
         $descTitle->invalidateCache();
         $descTitle->purgeSquid();
     } else {
         # New file; create the description page.
         # There's already a log entry, so don't make a second RC entry
         # Squid and file cache for the description page are purged by doEdit.
         $wikiPage->doEdit($pageText, $comment, EDIT_NEW | EDIT_SUPPRESS_RC, false, $user);
     }
     /* wikia change - begin (VID-1568) */
     // Update/Insert video info
     try {
         \VideoInfoHooksHelper::upsertVideoInfo($this, $reupload);
     } catch (\Exception $e) {
         $dbw->rollback();
         return false;
     }
     /* wikia change - end (VID-1568) */
     # Commit the transaction now, in case something goes wrong later
     # The most important thing is that files don't get lost, especially archives
     $dbw->commit();
     # Save to cache and purge the squid
     # We shall not saveToCache before the commit since otherwise
     # in case of a rollback there is an usable file from memcached
     # which in fact doesn't really exist (bug 24978)
     $this->saveToCache();
//.........这里部分代码省略.........
开发者ID:Tjorriemorrie,项目名称:app,代码行数:101,代码来源:LocalFile.php

示例14: recordUpload2

 /**
  * Record a file upload in the upload log and the image table
  */
 function recordUpload2($oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null)
 {
     if (is_null($user)) {
         global $wgUser;
         $user = $wgUser;
     }
     $dbw = $this->repo->getMasterDB();
     $dbw->begin();
     if (!$props) {
         $props = $this->repo->getFileProps($this->getVirtualUrl());
     }
     if ($timestamp === false) {
         $timestamp = $dbw->timestamp();
     }
     $props['description'] = $comment;
     $props['user'] = $user->getId();
     $props['user_text'] = $user->getName();
     $props['timestamp'] = wfTimestamp(TS_MW, $timestamp);
     // DB -> TS_MW
     $this->setProps($props);
     # Delete thumbnails
     $this->purgeThumbnails();
     # The file is already on its final location, remove it from the squid cache
     SquidUpdate::purge(array($this->getURL()));
     # Fail now if the file isn't there
     if (!$this->fileExists) {
         wfDebug(__METHOD__ . ": File " . $this->getRel() . " went missing!\n");
         return false;
     }
     $reupload = false;
     # Test to see if the row exists using INSERT IGNORE
     # This avoids race conditions by locking the row until the commit, and also
     # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
     $dbw->insert('image', array('img_name' => $this->getName(), 'img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $this->metadata, 'img_sha1' => $this->sha1), __METHOD__, 'IGNORE');
     if ($dbw->affectedRows() == 0) {
         $reupload = true;
         # Collision, this is an update of a file
         # Insert previous contents into oldimage
         $dbw->insertSelect('oldimage', 'image', array('oi_name' => 'img_name', 'oi_archive_name' => $dbw->addQuotes($oldver), 'oi_size' => 'img_size', 'oi_width' => 'img_width', 'oi_height' => 'img_height', 'oi_bits' => 'img_bits', 'oi_timestamp' => 'img_timestamp', 'oi_description' => 'img_description', 'oi_user' => 'img_user', 'oi_user_text' => 'img_user_text', 'oi_metadata' => 'img_metadata', 'oi_media_type' => 'img_media_type', 'oi_major_mime' => 'img_major_mime', 'oi_minor_mime' => 'img_minor_mime', 'oi_sha1' => 'img_sha1'), array('img_name' => $this->getName()), __METHOD__);
         # Update the current image row
         $dbw->update('image', array('img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $this->metadata, 'img_sha1' => $this->sha1), array('img_name' => $this->getName()), __METHOD__);
     } else {
         # This is a new file
         # Update the image count
         $dbw->begin();
         $site_stats = $dbw->tableName('site_stats');
         $dbw->query("UPDATE {$site_stats} SET ss_images=ss_images+1", __METHOD__);
         $dbw->commit();
     }
     $descTitle = $this->getTitle();
     $article = new ImagePage($descTitle);
     $article->setFile($this);
     # Add the log entry
     $log = new LogPage('upload');
     $action = $reupload ? 'overwrite' : 'upload';
     $log->addEntry($action, $descTitle, $comment, array(), $user);
     if ($descTitle->exists()) {
         # Create a null revision
         $latest = $descTitle->getLatestRevID();
         $nullRevision = Revision::newNullRevision($dbw, $descTitle->getArticleId(), $log->getRcComment(), false);
         $nullRevision->insertOn($dbw);
         wfRunHooks('NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $user));
         $article->updateRevisionOn($dbw, $nullRevision);
         # Invalidate the cache for the description page
         $descTitle->invalidateCache();
         $descTitle->purgeSquid();
     } else {
         # New file; create the description page.
         # There's already a log entry, so don't make a second RC entry
         # Squid and file cache for the description page are purged by doEdit.
         $article->doEdit($pageText, $comment, EDIT_NEW | EDIT_SUPPRESS_RC);
     }
     # Commit the transaction now, in case something goes wrong later
     # The most important thing is that files don't get lost, especially archives
     $dbw->commit();
     # Save to cache and purge the squid
     # We shall not saveToCache before the commit since otherwise
     # in case of a rollback there is an usable file from memcached
     # which in fact doesn't really exist (bug 24978)
     $this->saveToCache();
     # Hooks, hooks, the magic of hooks...
     wfRunHooks('FileUpload', array($this, $reupload, $descTitle->exists()));
     # Invalidate cache for all pages using this file
     $update = new HTMLCacheUpdate($this->getTitle(), 'imagelinks');
     $update->doUpdate();
     # Invalidate cache for all pages that redirects on this page
     $redirs = $this->getTitle()->getRedirectsHere();
     foreach ($redirs as $redir) {
         $update = new HTMLCacheUpdate($redir, 'imagelinks');
         $update->doUpdate();
     }
     return true;
 }
开发者ID:eFFemeer,项目名称:seizamcore,代码行数:96,代码来源:LocalFile.php

示例15: moveToNewTitle

 /**
  * Move page to non-existing title.
  *
  * @param $nt \type{Title} the new Title
  * @param $reason \type{\string} The reason for the move
  * @param $createRedirect \type{\bool} Whether to create a redirect from the old title to the new title
  *  Ignored if the user doesn't have the suppressredirect right
  */
 private function moveToNewTitle(&$nt, $reason = '', $createRedirect = true)
 {
     global $wgUser, $wgContLang;
     $comment = wfMsgForContent('1movedto2', $this->getPrefixedText(), $nt->getPrefixedText());
     if ($reason) {
         $comment .= wfMsgExt('colon-separator', array('escapenoentities', 'content'));
         $comment .= $reason;
     }
     # Truncate for whole multibyte characters. +5 bytes for ellipsis
     $comment = $wgContLang->truncate($comment, 250);
     $oldid = $this->getArticleID();
     $latest = $this->getLatestRevId();
     $dbw = wfGetDB(DB_MASTER);
     $now = $dbw->timestamp();
     # Save a null revision in the page's history notifying of the move
     $nullRevision = Revision::newNullRevision($dbw, $oldid, $comment, true);
     if (!is_object($nullRevision)) {
         throw new MWException('No valid null revision produced in ' . __METHOD__);
     }
     $nullRevId = $nullRevision->insertOn($dbw);
     $article = new Article($this);
     wfRunHooks('NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $wgUser));
     # Rename page entry
     $dbw->update('page', array('page_touched' => $now, 'page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey(), 'page_latest' => $nullRevId), array('page_id' => $oldid), __METHOD__);
     $nt->resetArticleID($oldid);
     if ($createRedirect || !$wgUser->isAllowed('suppressredirect')) {
         # Insert redirect
         $mwRedir = MagicWord::get('redirect');
         $redirectText = $mwRedir->getSynonym(0) . ' [[' . $nt->getPrefixedText() . "]]\n";
         $redirectArticle = new Article($this);
         $newid = $redirectArticle->insertOn($dbw);
         $redirectRevision = new Revision(array('page' => $newid, 'comment' => $comment, 'text' => $redirectText));
         $redirectRevision->insertOn($dbw);
         $redirectArticle->updateRevisionOn($dbw, $redirectRevision, 0);
         wfRunHooks('NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false, $wgUser));
         # Record the just-created redirect's linking to the page
         $dbw->insert('pagelinks', array('pl_from' => $newid, 'pl_namespace' => $nt->getNamespace(), 'pl_title' => $nt->getDBkey()), __METHOD__);
         $redirectSuppressed = false;
     } else {
         $this->resetArticleID(0);
         $redirectSuppressed = true;
     }
     # Log the move
     $log = new LogPage('move');
     $log->addEntry('move', $this, $reason, array(1 => $nt->getPrefixedText(), 2 => $redirectSuppressed));
     # Purge caches as per article creation
     Article::onArticleCreate($nt);
     # Purge old title from squid
     # The new title, and links to the new title, are purged in Article::onArticleCreate()
     $this->purgeSquid();
 }
开发者ID:GodelDesign,项目名称:Godel,代码行数:59,代码来源:Title.php


注:本文中的Revision::newNullRevision方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。