/** * Move page to a title which is either a redirect to the * source page or nonexistent * * @param $nt Title the page to move to, which should be a redirect or nonexistent * @param $reason String The reason for the move * @param $createRedirect Bool Whether to leave a redirect at the old title. Ignored * if the user doesn't have the suppressredirect right */ private function moveToInternal(&$nt, $reason = '', $createRedirect = true) { global $wgUser, $wgContLang; $moveOverRedirect = $nt->exists(); $commentMsg = $moveOverRedirect ? '1movedto2_redir' : '1movedto2'; $comment = wfMsgForContent($commentMsg, $this->getPrefixedText(), $nt->getPrefixedText()); if ($reason) { $comment .= wfMsgForContent('colon-separator') . $reason; } # Truncate for whole multibyte characters. $comment = $wgContLang->truncate($comment, 255); $oldid = $this->getArticleID(); $latest = $this->getLatestRevID(); $dbw = wfGetDB(DB_MASTER); if ($moveOverRedirect) { $rcts = $dbw->timestamp($nt->getEarliestRevTime()); $newid = $nt->getArticleID(); $newns = $nt->getNamespace(); $newdbk = $nt->getDBkey(); # 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__); if (!$dbw->cascadingDeletes()) { $dbw->delete('revision', array('rev_page' => $newid), __METHOD__); global $wgUseTrackbacks; if ($wgUseTrackbacks) { $dbw->delete('trackbacks', array('tb_page' => $newid), __METHOD__); } $dbw->delete('pagelinks', array('pl_from' => $newid), __METHOD__); $dbw->delete('imagelinks', array('il_from' => $newid), __METHOD__); $dbw->delete('categorylinks', array('cl_from' => $newid), __METHOD__); $dbw->delete('templatelinks', array('tl_from' => $newid), __METHOD__); $dbw->delete('externallinks', array('el_from' => $newid), __METHOD__); $dbw->delete('langlinks', array('ll_from' => $newid), __METHOD__); $dbw->delete('iwlinks', array('iwl_from' => $newid), __METHOD__); $dbw->delete('redirect', array('rd_from' => $newid), __METHOD__); } // If the target page was recently created, it may have an entry in recentchanges still $dbw->delete('recentchanges', array('rc_timestamp' => $rcts, 'rc_namespace' => $newns, 'rc_title' => $newdbk, 'rc_new' => 1), __METHOD__); } # 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); $now = wfTimestampNow(); # Change the name of the target page: $dbw->update('page', array('page_touched' => $dbw->timestamp($now), 'page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey(), 'page_latest' => $nullRevId), array('page_id' => $oldid), __METHOD__); $nt->resetArticleID($oldid); $article = new Article($nt); wfRunHooks('NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $wgUser)); $article->setCachedLastEditTime($now); # Recreate the redirect, this time in the other direction. if ($createRedirect || !$wgUser->isAllowed('suppressredirect')) { $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)); # Now, we record the link from the redirect to the new title. # It should have no other outgoing links... $dbw->delete('pagelinks', array('pl_from' => $newid), __METHOD__); $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'); $logType = $moveOverRedirect ? 'move_redir' : 'move'; $log->addEntry($logType, $this, $reason, array(1 => $nt->getPrefixedText(), 2 => $redirectSuppressed)); # Purge caches for old and new titles if ($moveOverRedirect) { # A simple purge is enough when moving over a redirect $nt->purgeSquid(); } else { # Purge caches as per article creation, including any pages that link to this title Article::onArticleCreate($nt); } $this->purgeSquid(); }
/** * This is the meaty bit -- restores archived revisions of the given page * to the cur/old tables. If the page currently exists, all revisions will * be stuffed into old, otherwise the most recent will go into cur. * * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete. * @param string $comment * @param array $fileVersions * * @return int number of revisions restored */ private function undeleteRevisions($timestamps) { global $wgParser, $wgDBtype; $restoreAll = empty($timestamps); $dbw =& wfGetDB(DB_MASTER); extract($dbw->tableNames('page', 'archive')); # Does this page already exist? We'll have to update it... $article = new Article($this->title); $options = $wgDBtype == 'postgres' ? '' : 'FOR UPDATE'; $page = $dbw->selectRow('page', array('page_id', 'page_latest'), array('page_namespace' => $this->title->getNamespace(), 'page_title' => $this->title->getDBkey()), __METHOD__, $options); if ($page) { # Page already exists. Import the history, and if necessary # we'll update the latest revision field in the record. $newid = 0; $pageId = $page->page_id; $previousRevId = $page->page_latest; } else { # Have to create a new article... $newid = $article->insertOn($dbw); $pageId = $newid; $previousRevId = 0; } if ($restoreAll) { $oldones = '1 = 1'; # All revisions... } else { $oldts = implode(',', array_map(array(&$dbw, 'addQuotes'), array_map(array(&$dbw, 'timestamp'), $timestamps))); $oldones = "ar_timestamp IN ( {$oldts} )"; } /** * Restore each revision... */ $result = $dbw->select('archive', array('ar_rev_id', 'ar_text', 'ar_comment', 'ar_user', 'ar_user_text', 'ar_timestamp', 'ar_minor_edit', 'ar_flags', 'ar_text_id'), array('ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), $oldones), __METHOD__, array('ORDER BY' => 'ar_timestamp')); if ($dbw->numRows($result) < count($timestamps)) { wfDebug(__METHOD__ . ": couldn't find all requested rows\n"); return false; } $revision = null; $newRevId = $previousRevId; $restored = 0; while ($row = $dbw->fetchObject($result)) { if ($row->ar_text_id) { // Revision was deleted in 1.5+; text is in // the regular text table, use the reference. // Specify null here so the so the text is // dereferenced for page length info if needed. $revText = null; } else { // Revision was deleted in 1.4 or earlier. // Text is squashed into the archive row, and // a new text table entry will be created for it. $revText = Revision::getRevisionText($row, 'ar_'); } $revision = new Revision(array('page' => $pageId, 'id' => $row->ar_rev_id, 'text' => $revText, 'comment' => $row->ar_comment, 'user' => $row->ar_user, 'user_text' => $row->ar_user_text, 'timestamp' => $row->ar_timestamp, 'minor_edit' => $row->ar_minor_edit, 'text_id' => $row->ar_text_id)); $newRevId = $revision->insertOn($dbw); $restored++; } if ($revision) { # FIXME: Update latest if newer as well... if ($newid) { // Attach the latest revision to the page... $article->updateRevisionOn($dbw, $revision, $previousRevId); // Update site stats, link tables, etc $article->createUpdates($revision); } if ($newid) { Article::onArticleCreate($this->title); } else { Article::onArticleEdit($this->title); } } else { # Something went terribly wrong! } # Now that it's safely stored, take it out of the archive $dbw->delete('archive', array('ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), $oldones), __METHOD__); return $restored; }
protected function _createMainPageForWiki() { $db = $this->getDatabase(); $titleobj = Title::newFromText(wfMessage('mainpage')->inContentLanguage()->useDatabase(false)->plain()); $article = new Article($titleobj); $newid = $article->insertOn($db); $revision = new Revision(array('page' => $newid, 'text' => wfMsgForContent('farmernewwikimainpage'), 'comment' => '', 'user' => 0, 'user_text' => 'MediaWiki default')); $revid = $revision->insertOn($db); $article->updateRevisionOn($db, $revision); // site_stats table entry $db->insert('site_stats', array('ss_row_id' => 1, 'ss_total_views' => 0, 'ss_total_edits' => 0, 'ss_good_articles' => 0)); }
print "Invalid title\n"; exit(1); } $article = new Article($page); # Does this page already exist? We'll have to update it... $options = 'FOR UPDATE'; $page_r = $dbw->selectRow('page', array('page_id', 'page_latest'), array('page_namespace' => $page->getNamespace(), 'page_title' => $page->getDBkey()), __METHOD__, $options); if ($page_r) { # Page already exists. Import the history, and if necessary # we'll update the latest revision field in the record. $newid = 0; $pageId = $page_r->page_id; $previousRevId = $page_r->page_latest; } else { # Have to create a new article... $newid = $article->insertOn($dbw); $pageId = $newid; $previousRevId = 0; } $oldones = '1 = 1'; # All revisions... /** * Restore each revision... */ $result = $dbw->select('archive', array('ar_rev_id', 'ar_text', 'ar_comment', 'ar_user', 'ar_user_text', 'ar_timestamp', 'ar_minor_edit', 'ar_flags', 'ar_text_id', 'ar_page_id', 'ar_len'), array('ar_namespace' => $page->getNamespace(), 'ar_title' => $page->getDBkey(), $oldones), __METHOD__, array('ORDER BY' => 'ar_timestamp')); $revision = null; $restored = 0; while ($row = $dbw->fetchObject($result)) { if ($row->ar_text_id) { // Revision was deleted in 1.5+; text is in // the regular text table, use the reference.
/** * 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(); }
function importOldRevision() { $dbw = wfGetDB(DB_MASTER); # Sneak a single revision into place $user = User::newFromName($this->getUser()); if ($user) { $userId = intval($user->getId()); $userText = $user->getName(); } else { $userId = 0; $userText = $this->getUser(); } // avoid memory leak...? $linkCache = LinkCache::singleton(); $linkCache->clear(); $article = new Article($this->title); $pageId = $article->getId(); if ($pageId == 0) { # must create the page... $pageId = $article->insertOn($dbw); $created = true; } else { $created = false; $prior = $dbw->selectField('revision', '1', array('rev_page' => $pageId, 'rev_timestamp' => $dbw->timestamp($this->timestamp), 'rev_user_text' => $userText, 'rev_comment' => $this->getComment()), __METHOD__); if ($prior) { // FIXME: this could fail slightly for multiple matches :P wfDebug(__METHOD__ . ": skipping existing revision for [[" . $this->title->getPrefixedText() . "]], timestamp " . $this->timestamp . "\n"); return false; } } # FIXME: Use original rev_id optionally (better for backups) # Insert the row $revision = new Revision(array('page' => $pageId, 'text' => $this->getText(), 'comment' => $this->getComment(), 'user' => $userId, 'user_text' => $userText, 'timestamp' => $this->timestamp, 'minor_edit' => $this->minor)); $revId = $revision->insertOn($dbw); $changed = $article->updateIfNewerOn($dbw, $revision); # To be on the safe side... $tempTitle = $GLOBALS['wgTitle']; $GLOBALS['wgTitle'] = $this->title; if ($created) { wfDebug(__METHOD__ . ": running onArticleCreate\n"); Article::onArticleCreate($this->title); wfDebug(__METHOD__ . ": running create updates\n"); $article->createUpdates($revision); } elseif ($changed) { wfDebug(__METHOD__ . ": running onArticleEdit\n"); Article::onArticleEdit($this->title); wfDebug(__METHOD__ . ": running edit updates\n"); $article->editUpdates($this->getText(), $this->getComment(), $this->minor, $this->timestamp, $revId); } $GLOBALS['wgTitle'] = $tempTitle; return true; }
/** * This is the meaty bit -- restores archived revisions of the given page * to the cur/old tables. If the page currently exists, all revisions will * be stuffed into old, otherwise the most recent will go into cur. * * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete. * @param string $comment * @param array $fileVersions * * @return mixed number of revisions restored or false on failure */ private function undeleteRevisions($timestamps) { if (wfReadOnly()) { return false; } $restoreAll = empty($timestamps); $dbw = wfGetDB(DB_MASTER); # Does this page already exist? We'll have to update it... $article = new Article($this->title); $options = 'FOR UPDATE'; $page = $dbw->selectRow('page', array('page_id', 'page_latest'), array('page_namespace' => $this->title->getNamespace(), 'page_title' => $this->title->getDBkey()), __METHOD__, $options); if ($page) { # Page already exists. Import the history, and if necessary # we'll update the latest revision field in the record. $newid = 0; $pageId = $page->page_id; $previousRevId = $page->page_latest; } else { # Have to create a new article... $newid = $article->insertOn($dbw); $pageId = $newid; $previousRevId = 0; } if ($restoreAll) { $oldones = '1 = 1'; # All revisions... } else { $oldts = implode(',', array_map(array(&$dbw, 'addQuotes'), array_map(array(&$dbw, 'timestamp'), $timestamps))); $oldones = "ar_timestamp IN ( {$oldts} )"; } /** * Restore each revision... */ $result = $dbw->select('archive', array('ar_rev_id', 'ar_text', 'ar_comment', 'ar_user', 'ar_user_text', 'ar_timestamp', 'ar_minor_edit', 'ar_flags', 'ar_text_id', 'ar_page_id', 'ar_len'), array('ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), $oldones), __METHOD__, array('ORDER BY' => 'ar_timestamp')); if ($dbw->numRows($result) < count($timestamps)) { wfDebug(__METHOD__ . ": couldn't find all requested rows\n"); return false; } $revision = null; $restored = 0; while ($row = $dbw->fetchObject($result)) { if ($row->ar_text_id) { // Revision was deleted in 1.5+; text is in // the regular text table, use the reference. // Specify null here so the so the text is // dereferenced for page length info if needed. $revText = null; } else { // Revision was deleted in 1.4 or earlier. // Text is squashed into the archive row, and // a new text table entry will be created for it. $revText = Revision::getRevisionText($row, 'ar_'); } $revision = new Revision(array('page' => $pageId, 'id' => $row->ar_rev_id, 'text' => $revText, 'comment' => $row->ar_comment, 'user' => $row->ar_user, 'user_text' => $row->ar_user_text, 'timestamp' => $row->ar_timestamp, 'minor_edit' => $row->ar_minor_edit, 'text_id' => $row->ar_text_id, 'len' => $row->ar_len)); $revision->insertOn($dbw); $restored++; wfRunHooks('ArticleRevisionUndeleted', array(&$this->title, $revision, $row->ar_page_id)); } // Was anything restored at all? if ($restored == 0) { return 0; } if ($revision) { // Attach the latest revision to the page... $wasnew = $article->updateIfNewerOn($dbw, $revision, $previousRevId); if ($newid || $wasnew) { // Update site stats, link tables, etc $article->createUpdates($revision); } if ($newid) { wfRunHooks('ArticleUndelete', array(&$this->title, true)); Article::onArticleCreate($this->title); } else { wfRunHooks('ArticleUndelete', array(&$this->title, false)); Article::onArticleEdit($this->title); } if ($this->title->getNamespace() == NS_IMAGE) { $update = new HTMLCacheUpdate($this->title, 'imagelinks'); $update->doUpdate(); } } else { // Revision couldn't be created. This is very weird return self::UNDELETE_UNKNOWNERR; } # Now that it's safely stored, take it out of the archive $dbw->delete('archive', array('ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), $oldones), __METHOD__); return $restored; }
function importOldRevision() { $fname = "WikiImporter::importOldRevision"; $dbw =& wfGetDB(DB_MASTER); # Sneak a single revision into place $user = User::newFromName($this->getUser()); if ($user) { $userId = intval($user->getId()); $userText = $user->getName(); } else { $userId = 0; $userText = $this->getUser(); } // avoid memory leak...? $linkCache =& LinkCache::singleton(); $linkCache->clear(); $article = new Article($this->title); $pageId = $article->getId(); if ($pageId == 0) { # must create the page... $pageId = $article->insertOn($dbw); $created = true; } else { $created = false; } # FIXME: Check for exact conflicts # FIXME: Use original rev_id optionally # FIXME: blah blah blah #if( $numrows > 0 ) { # return wfMsg( "importhistoryconflict" ); #} # Insert the row $revision = new Revision(array('page' => $pageId, 'text' => $this->getText(), 'comment' => $this->getComment(), 'user' => $userId, 'user_text' => $userText, 'timestamp' => $this->timestamp, 'minor_edit' => $this->minor)); $revId = $revision->insertOn($dbw); $changed = $article->updateIfNewerOn($dbw, $revision); if ($created) { wfDebug(__METHOD__ . ": running onArticleCreate\n"); Article::onArticleCreate($this->title); } else { if ($changed) { wfDebug(__METHOD__ . ": running onArticleEdit\n"); Article::onArticleEdit($this->title); } } if ($created || $changed) { wfDebug(__METHOD__ . ": running edit updates\n"); $article->editUpdates($this->getText(), $this->getComment(), $this->minor, $this->timestamp, $revId); } return true; }
/** * 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 f**k 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; }
/** * Create the html body and (depending on the GET variables) creates the page. */ function execute( $par ) { global $wgRequest, $wgOut, $wgScript; $this->setHeaders(); # Get request data from, e.g. $action = $wgRequest->getText( 'action' ); $refname = htmlentities( $wgRequest->getText( 'refname' ) ); $author1 = htmlentities( $wgRequest->getText( 'author1' ), ENT_COMPAT, "UTF-8" ); $author2 = htmlentities( $wgRequest->getText( 'author2' ), ENT_COMPAT, "UTF-8" ); $author3 = htmlentities( $wgRequest->getText( 'author3' ), ENT_COMPAT, "UTF-8" ); $author4 = htmlentities( $wgRequest->getText( 'author4' ), ENT_COMPAT, "UTF-8" ); $author5 = htmlentities( $wgRequest->getText( 'author5' ), ENT_COMPAT, "UTF-8" ); $surname1 = htmlentities( $wgRequest->getText( 'surname1' ), ENT_COMPAT, "UTF-8" ); $surname2 = htmlentities( $wgRequest->getText( 'surname2' ), ENT_COMPAT, "UTF-8" ); $surname3 = htmlentities( $wgRequest->getText( 'surname3' ), ENT_COMPAT, "UTF-8" ); $surname4 = htmlentities( $wgRequest->getText( 'surname4' ), ENT_COMPAT, "UTF-8" ); $surname5 = htmlentities( $wgRequest->getText( 'surname5' ), ENT_COMPAT, "UTF-8" ); $pmid = htmlentities( $wgRequest->getText( 'pmid' ), ENT_COMPAT, "UTF-8" ); $articletitle = htmlentities( $wgRequest->getText( 'articletitle' ) ); $journal = htmlentities( $wgRequest->getText( 'journal' ) ); $volume = htmlentities( $wgRequest->getText( 'volume' ) ); $pages = htmlentities( $wgRequest->getText( 'pages' ) ); $year = htmlentities( $wgRequest->getText( 'year' ) ); $cat1 = htmlentities( $wgRequest->getText( 'cat1' ) ); $cat2 = htmlentities( $wgRequest->getText( 'cat2' ) ); $cat3 = htmlentities( $wgRequest->getText( 'cat3' ) ); $cat4 = htmlentities( $wgRequest->getText( 'cat4' ) ); $reqfilled = strlen( $author1 ) && strlen( $articletitle ) && strlen( $journal ) && strlen( $year ) && strlen( $refname ); if ( $action != "submit" || !$reqfilled ) { if ( strlen( $pmid ) ) { $result = RefSearch::query_pmid( $pmid ); $articletitle = $result["title"]; $journal = $result["journal"]; $volume = $result["volume"]; $pages = $result["pages"]; $year = $result["year"]; $auths = $result["authors"]; if ( isset( $auths[0] ) ) { $author1 = $auths[0][0]; $surname1 = $auths[0][1]; } if ( isset( $auths[1] ) ) { $author2 = $auths[1][0]; $surname2 = $auths[1][1]; } if ( isset( $auths[2] ) ) { $author3 = $auths[2][0]; $surname3 = $auths[2][1]; } if ( isset( $auths[3] ) ) { $author4 = $auths[3][0]; $surname4 = $auths[3][1]; } if ( isset( $auths[4] ) ) { $author5 = $auths[4][0]; $surname5 = $auths[4][1]; } } # Output $wgOut->addHTML( Xml::fieldset( wfMsg( self::MSG . 'refcreate_legend' ) ) . Xml::openElement( 'form', array( 'action' => $wgScript, 'id' => 'mw_create-ref-form' ) ) . Html::Hidden( 'title', $this->getTitle()->getPrefixedText() ) . Html::Hidden( 'action', 'submit' ) . Xml::openElement( 'table', array( 'id' => 'mw_create-ref-table' ) ) . Xml::openElement( 'tbody' ) ); $wgOut->addHTML( Xml::openElement( 'tr' ) . Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) . Xml::element( 'label', array( 'for' => 'inp_pastearea' ), wfMsg( self::MSG . 'label_workspace' ) . ":" ) . Xml::closeElement( 'td' ) . Xml::openElement( 'td' ) . Xml::textarea( 'inp_pastearea', '', 20, 5, array( 'oninput' => 'autoPopulateRefFields()' ) ) . Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' ) ); self::addTableRow( $wgOut, "pmid", $pmid, 'PMID', 15 ); self::add2ColTableRow( $wgOut, 'author1', 'surname1', $author1, $surname1, wfMsg( self::MSG . 'label_authorforename', '1' ), wfMsg( self::MSG . 'label_authorsurname', '1' ) ); self::add2ColTableRow( $wgOut, 'author2', 'surname2', $author2, $surname2, wfMsg( self::MSG . 'label_authorforename', '2' ), wfMsg( self::MSG . 'label_authorsurname', '2' ) ); self::add2ColTableRow( $wgOut, 'author3', 'surname3', $author3, $surname3, wfMsg( self::MSG . 'label_authorforename', '3' ), wfMsg( self::MSG . 'label_authorsurname', '3' ) ); self::add2ColTableRow( $wgOut, 'author4', 'surname4', $author4, $surname4, wfMsg( self::MSG . 'label_authorforename', '4' ), wfMsg( self::MSG . 'label_authorsurname', '4' ) ); self::add2ColTableRow( $wgOut, 'author5', 'surname5', $author5, $surname5, wfMsg( self::MSG . 'label_authorforename', '5' ), wfMsg( self::MSG . 'label_authorsurname', '5' ) ); self::addTableRow( $wgOut, "articletitle", $articletitle, wfMsg( self::MSG . 'title' ) ); self::addTableRow( $wgOut, "journal", $journal, wfMsg( self::MSG . 'journal' ) ); self::addTableRow( $wgOut, "pages", $pages, wfMsg( self::MSG . 'pages' ) ); self::addTableRow( $wgOut, "year", $year, wfMsg( self::MSG . 'year' ) ); self::addTableRow( $wgOut, "refname", $refname, wfMsg( self::MSG . 'refname' ) ); self::addTableRow( $wgOut, "cat1", $cat1, wfMsg( self::MSG . 'category', '1' ) ); self::addTableRow( $wgOut, "cat2", $cat2, wfMsg( self::MSG . 'category', '2' ) ); self::addTableRow( $wgOut, "cat3", $cat3, wfMsg( self::MSG . 'category', '3' ) ); self::addTableRow( $wgOut, "cat4", $cat4, wfMsg( self::MSG . 'category', '4' ) ); $wgOut->addHTML( Xml::openElement( 'tr' ) . Xml::openElement( 'td', array( 'class' => 'mw-submit' ) ) . Xml::element( 'input', array( 'value' => wfMsg( self::MSG . 'create' ), 'type' => 'submit' ) ) . Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' ) . Xml::closeElement( 'tbody' ) . Xml::closeElement( 'table' ) . Xml::closeElement( 'form' ) . Xml::closeElement( 'fieldset' ) ); } else { global $wgRefHelperCiteTemplate, $wgRefHelperPageTemplate, $wgRefHelperCiteNS; $db = wfGetDB( DB_MASTER ); $citeTitle = null; if ( strlen( $wgRefHelperCiteNS ) ) $citeTitle = Title::newFromText( "$wgRefHelperCiteNS:$refname" ); $pageTitle = Title::newFromText( $refname ); $paramtext = ''; $paramtext .= "| first1 = $author1\n"; $paramtext .= "| last1 = $surname1\n"; if ( strlen( $author2 ) || strlen( $surname2 ) ) { $paramtext .= "| first2 = $author2\n"; $paramtext .= "| last2 = $surname2\n"; } if ( strlen( $author3 ) || strlen( $surname3 ) ) { $paramtext .= "| first3 = $author3\n"; $paramtext .= "| last3 = $surname3\n"; } if ( strlen( $author4 ) || strlen( $surname4 ) ) { $paramtext .= "| first4 = $author4\n"; $paramtext .= "| last4 = $surname4\n"; } if ( strlen( $author5 ) || strlen( $surname5 ) ) { $paramtext .= "| first5 = $author5\n"; $paramtext .= "| last5 = $surname5\n"; } $paramtext .= "| refname = $refname\n"; $paramtext .= "| articletitle = $articletitle\n"; $paramtext .= "| titlelink = [[$refname|$articletitle]]\n"; $paramtext .= "| journal = $journal\n"; $paramtext .= "| volume = $volume\n"; $paramtext .= "| pages = $pages\n"; $paramtext .= "| pmid = $pmid\n"; $paramtext .= "| year = $year\n"; $paramtext .= "| lt = <\n"; // can be used to allow templates to create pages with onlyinclude, etc. $paramtext .= "| categories = "; if ( strlen( $cat1 ) ) $paramtext .= "[[Category:$cat1]]\n"; if ( strlen( $cat2 ) ) $paramtext .= "[[Category:$cat2]]\n"; if ( strlen( $cat3 ) ) $paramtext .= "[[Category:$cat3]]\n"; if ( strlen( $cat4 ) ) $paramtext .= "[[Category:$cat4]]\n"; if ( $citeTitle->exists() == false ) { $newcontent = '{{' . "$wgRefHelperCiteTemplate\n$paramtext}}\n"; $citePage = new Article( $citeTitle ); $citePage->doEdit( $newcontent, wfMsg( self::MSG . 'refcreate_autocomment' ) ); $rev_id = $citePage->insertOn( $db ); $wgOut->addWikiText( wfMsg( self::MSG . 'refcreate_success', array( "$wgRefHelperCiteNS:$refname" ) ) ); } else { $wgOut->addWikiText( wfMsg( self::MSG . 'refcreate_failure', array( "$wgRefHelperCiteNS:$refname" ) ) ); } if ( $pageTitle->exists() == false ) { $newcontent = '{{' . "$wgRefHelperPageTemplate\n$paramtext}}\n"; $newPage = new Article( $pageTitle ); $newPage->doEdit( $newcontent, wfMsg( self::MSG . 'refcreate_autocomment' ) ); $rev_id = $newPage->insertOn( $db ); $wgOut->addWikiText( wfMsg( self::MSG . 'refcreate_success', array( $refname ) ) ); } else { $wgOut->addWikiText( wfMsg( self::MSG . 'refcreate_failure', array( $refname ) ) ); } $wgOut->addWikiText( '[[Special:RefHelper|' . wfMsg( self::MSG . 'refcreate_another' ) . ']]' ); } }
/** * This is the meaty bit -- restores archived revisions of the given page * to the cur/old tables. If the page currently exists, all revisions will * be stuffed into old, otherwise the most recent will go into cur. * * @param $timestamps Array: pass an empty array to restore all revisions, otherwise list the ones to undelete. * @param $comment String * @param $unsuppress Boolean: remove all ar_deleted/fa_deleted restrictions of seletected revs * * @return Mixed: number of revisions restored or false on failure */ private function undeleteRevisions($timestamps, $unsuppress = false, $comment = '') { if (wfReadOnly()) { return false; } $restoreAll = empty($timestamps); $dbw = wfGetDB(DB_MASTER); # Does this page already exist? We'll have to update it... $article = new Article($this->title); # Load latest data for the current page (bug 31179) $article->loadPageData('fromdbmaster'); $oldcountable = $article->isCountable(); $options = 'FOR UPDATE'; // lock page $page = $dbw->selectRow('page', array('page_id', 'page_latest'), array('page_namespace' => $this->title->getNamespace(), 'page_title' => $this->title->getDBkey()), __METHOD__, $options); if ($page) { $makepage = false; # Page already exists. Import the history, and if necessary # we'll update the latest revision field in the record. $newid = 0; $pageId = $page->page_id; $previousRevId = $page->page_latest; # Get the time span of this page $previousTimestamp = $dbw->selectField('revision', 'rev_timestamp', array('rev_id' => $previousRevId), __METHOD__); if ($previousTimestamp === false) { wfDebug(__METHOD__ . ": existing page refers to a page_latest that does not exist\n"); return 0; } } else { # Have to create a new article... $makepage = true; $previousRevId = 0; $previousTimestamp = 0; } if ($restoreAll) { $oldones = '1 = 1'; # All revisions... } else { $oldts = implode(',', array_map(array(&$dbw, 'addQuotes'), array_map(array(&$dbw, 'timestamp'), $timestamps))); $oldones = "ar_timestamp IN ( {$oldts} )"; } /** * Select each archived revision... */ $result = $dbw->select('archive', array('ar_rev_id', 'ar_text', 'ar_comment', 'ar_user', 'ar_user_text', 'ar_timestamp', 'ar_minor_edit', 'ar_flags', 'ar_text_id', 'ar_deleted', 'ar_page_id', 'ar_len'), array('ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), $oldones), __METHOD__, array('ORDER BY' => 'ar_timestamp')); $ret = $dbw->resultObject($result); $rev_count = $dbw->numRows($result); if (!$rev_count) { wfDebug(__METHOD__ . ": no revisions to restore\n"); return false; // ??? } $ret->seek($rev_count - 1); // move to last $row = $ret->fetchObject(); // get newest archived rev $ret->seek(0); // move back if ($makepage) { // Check the state of the newest to-be version... if (!$unsuppress && $row->ar_deleted & Revision::DELETED_TEXT) { return false; // we can't leave the current revision like this! } // Safe to insert now... $newid = $article->insertOn($dbw); $pageId = $newid; } else { // Check if a deleted revision will become the current revision... if ($row->ar_timestamp > $previousTimestamp) { // Check the state of the newest to-be version... if (!$unsuppress && $row->ar_deleted & Revision::DELETED_TEXT) { return false; // we can't leave the current revision like this! } } } $revision = null; $restored = 0; foreach ($ret as $row) { // Check for key dupes due to shitty archive integrity. if ($row->ar_rev_id) { $exists = $dbw->selectField('revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__); if ($exists) { continue; // don't throw DB errors } } // Insert one revision at a time...maintaining deletion status // unless we are specifically removing all restrictions... $revision = Revision::newFromArchiveRow($row, array('page' => $pageId, 'deleted' => $unsuppress ? 0 : $row->ar_deleted)); $revision->insertOn($dbw); $restored++; wfRunHooks('ArticleRevisionUndeleted', array(&$this->title, $revision, $row->ar_page_id)); } # Now that it's safely stored, take it out of the archive $dbw->delete('archive', array('ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), $oldones), __METHOD__); // Was anything restored at all? if ($restored == 0) { return 0; } $created = (bool) $newid; // Attach the latest revision to the page... $wasnew = $article->updateIfNewerOn($dbw, $revision, $previousRevId); if ($created || $wasnew) { // Update site stats, link tables, etc $user = User::newFromName($revision->getRawUserText(), false); $article->doEditUpdates($revision, $user, array('created' => $created, 'oldcountable' => $oldcountable)); } wfRunHooks('ArticleUndelete', array(&$this->title, $created, $comment)); if ($this->title->getNamespace() == NS_FILE) { $update = new HTMLCacheUpdate($this->title, 'imagelinks'); $update->doUpdate(); } return $restored; }
/** * Create a redirect; fails if the title already exists; does * not notify RC * * @param Title $dest the destination of the redirect * @param string $comment the comment string describing the move * @return bool true on success * @access public */ function createRedirect($dest, $comment) { if ($this->getArticleID()) { return false; } $fname = 'Title::createRedirect'; $dbw =& wfGetDB(DB_MASTER); $article = new Article($this); $newid = $article->insertOn($dbw); $revision = new Revision(array('page' => $newid, 'comment' => $comment, 'text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n")); $revisionId = $revision->insertOn($dbw); $article->updateRevisionOn($dbw, $revision, 0); # Link table $dbw->insert('pagelinks', array('pl_from' => $newid, 'pl_namespace' => $dest->getNamespace(), 'pl_title' => $dest->getDbKey()), $fname); Article::onArticleCreate($this); return true; }
/** * This is the meaty bit -- restores archived revisions of the given page * to the cur/old tables. If the page currently exists, all revisions will * be stuffed into old, otherwise the most recent will go into cur. * The deletion log will be updated with an undeletion notice. * * Returns true on success. * * @param array $timestamps Pass an empty array to restore all revisions, otherwise list the ones to undelete. * @return bool */ function undelete($timestamps) { global $wgUser, $wgOut, $wgLang, $wgDeferredUpdateList; global $wgUseSquid, $wgInternalServer, $wgLinkCache; global $wgDBtype; $fname = "doUndeleteArticle"; $restoreAll = empty($timestamps); $restoreRevisions = count($timestamps); $dbw =& wfGetDB(DB_MASTER); extract($dbw->tableNames('page', 'archive')); # Does this page already exist? We'll have to update it... $article = new Article($this->title); $options = $wgDBtype == 'PostgreSQL' ? '' : 'FOR UPDATE'; $page = $dbw->selectRow('page', array('page_id', 'page_latest'), array('page_namespace' => $this->title->getNamespace(), 'page_title' => $this->title->getDBkey()), $fname, $options); if ($page) { # Page already exists. Import the history, and if necessary # we'll update the latest revision field in the record. $newid = 0; $pageId = $page->page_id; $previousRevId = $page->page_latest; $previousTimestamp = $page->rev_timestamp; } else { # Have to create a new article... $newid = $article->insertOn($dbw); $pageId = $newid; $previousRevId = 0; $previousTimestamp = 0; } if ($restoreAll) { $oldones = '1'; # All revisions... } else { $oldts = implode(',', array_map(array(&$dbw, 'addQuotes'), array_map(array(&$dbw, 'timestamp'), $timestamps))); $oldones = "ar_timestamp IN ( {$oldts} )"; } /** * Restore each revision... */ $result = $dbw->select('archive', array('ar_rev_id', 'ar_text', 'ar_comment', 'ar_user', 'ar_user_text', 'ar_timestamp', 'ar_minor_edit', 'ar_flags', 'ar_text_id'), array('ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), $oldones), $fname, array('ORDER BY' => 'ar_timestamp')); $revision = null; while ($row = $dbw->fetchObject($result)) { $revision = new Revision(array('page' => $pageId, 'id' => $row->ar_rev_id, 'text' => Revision::getRevisionText($row, 'ar_'), 'comment' => $row->ar_comment, 'user' => $row->ar_user, 'user_text' => $row->ar_user_text, 'timestamp' => $row->ar_timestamp, 'minor_edit' => $row->ar_minor_edit, 'text_id' => $row->ar_text_id)); $revision->insertOn($dbw); } if ($revision) { # FIXME: Update latest if newer as well... if ($newid) { # FIXME: update article count if changed... $article->updateRevisionOn($dbw, $revision, $previousRevId); # Finally, clean up the link tables $wgLinkCache = new LinkCache(); # Select for update $wgLinkCache->forUpdate(true); # Create a dummy OutputPage to update the outgoing links $dummyOut = new OutputPage(); $dummyOut->addWikiText($revision->getText()); $u = new LinksUpdate($newid, $this->title->getPrefixedDBkey()); array_push($wgDeferredUpdateList, $u); #TODO: SearchUpdate, etc. } if ($newid) { Article::onArticleCreate($this->title); } else { Article::onArticleEdit($this->title); } } else { # Something went terribly worong! } # Now that it's safely stored, take it out of the archive $dbw->delete('archive', array('ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), $oldones), $fname); # Touch the log! $log = new LogPage('delete'); if ($restoreAll) { $reason = ''; } else { $reason = wfMsgForContent('undeletedrevisions', $restoreRevisions); } $log->addEntry('restore', $this->title, $reason); return true; }
function importOldRevision() { $fname = "WikiImporter::importOldRevision"; $dbw =& wfGetDB(DB_MASTER); # Sneak a single revision into place $user = User::newFromName($this->getUser()); if ($user) { $userId = IntVal($user->getId()); $userText = $user->getName(); } else { $userId = 0; $userText = $this->getUser(); } // avoid memory leak...? global $wgLinkCache; $wgLinkCache->clear(); $article = new Article($this->title); $pageId = $article->getId(); if ($pageId == 0) { # must create the page... $pageId = $article->insertOn($dbw); } # FIXME: Check for exact conflicts # FIXME: Use original rev_id optionally # FIXME: blah blah blah #if( $numrows > 0 ) { # return wfMsg( "importhistoryconflict" ); #} # Insert the row $revision = new Revision(array('page' => $pageId, 'text' => $this->getText(), 'comment' => $this->getComment(), 'user' => $userId, 'user_text' => $userText, 'timestamp' => $this->timestamp, 'minor_edit' => $this->minor)); $revId = $revision->insertOn($dbw); $article->updateIfNewerOn($dbw, $revision); return true; }
/** * 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(); }
/** * 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(); }
function importOldRevision() { $dbw = wfGetDB(DB_MASTER); # Sneak a single revision into place $user = User::newFromName($this->getUser()); if ($user) { $userId = intval($user->getId()); $userText = $user->getName(); } else { $userId = 0; $userText = $this->getUser(); } // avoid memory leak...? $linkCache =& LinkCache::singleton(); $linkCache->clear(); $article = new Article($this->title); $pageId = $article->getId(); if ($pageId == 0) { # must create the page... $pageId = $article->insertOn($dbw); $created = true; } else { $created = false; $prior = Revision::loadFromTimestamp($dbw, $this->title, $this->timestamp); if (!is_null($prior)) { // FIXME: this could fail slightly for multiple matches :P wfDebug(__METHOD__ . ": skipping existing revision for [[" . $this->title->getPrefixedText() . "]], timestamp " . $this->timestamp . "\n"); return false; } } # FIXME: Use original rev_id optionally # FIXME: blah blah blah #if( $numrows > 0 ) { # return wfMsg( "importhistoryconflict" ); #} # Insert the row $revision = new Revision(array('page' => $pageId, 'text' => $this->getText(), 'comment' => $this->getComment(), 'user' => $userId, 'user_text' => $userText, 'timestamp' => $this->timestamp, 'minor_edit' => $this->minor)); $revId = $revision->insertOn($dbw); $changed = $article->updateIfNewerOn($dbw, $revision); if ($created) { wfDebug(__METHOD__ . ": running onArticleCreate\n"); Article::onArticleCreate($this->title); wfDebug(__METHOD__ . ": running create updates\n"); $article->createUpdates($revision); } elseif ($changed) { wfDebug(__METHOD__ . ": running onArticleEdit\n"); Article::onArticleEdit($this->title); wfDebug(__METHOD__ . ": running edit updates\n"); $article->editUpdates($this->getText(), $this->getComment(), $this->minor, $this->timestamp, $revId); } return true; }
$u->addToDatabase(); $u->setPassword($conf->getSysopPass()); $u->saveSettings(); $u->addGroup("sysop"); $u->addGroup("bureaucrat"); print "<li>Created sysop account <tt>" . htmlspecialchars($conf->SysopName) . "</tt>.</li>\n"; } else { print "<li>Could not create user - already exists!</li>\n"; } } } else { print "<li>Skipped sysop account creation, no name given.</li>\n"; } $titleobj = Title::newFromText(wfMsgNoDB("mainpage")); $article = new Article($titleobj); $newid = $article->insertOn($wgDatabase); $revision = new Revision(array('page' => $newid, 'text' => wfMsg('mainpagetext') . "\n\n" . wfMsgNoTrans('mainpagedocfooter'), 'comment' => '', 'user' => 0, 'user_text' => 'MediaWiki default')); $revid = $revision->insertOn($wgDatabase); $article->updateRevisionOn($wgDatabase, $revision); } /* Write out the config file now that all is well */ print "<li style=\"list-style: none\">\n"; print "<p>Creating LocalSettings.php...</p>\n\n"; $localSettings = "<" . "?php{$endl}{$local}"; // Fix up a common line-ending problem (due to CVS on Windows) $localSettings = str_replace("\r\n", "\n", $localSettings); $f = fopen("LocalSettings.php", 'xt'); if ($f == false) { print "</li>\n"; dieout("<p>Couldn't write out LocalSettings.php. Check that the directory permissions are correct and that there isn't already a file of that name here...</p>\n" . "<p>Here's the file that would have been written, try to paste it into place manually:</p>\n" . "<pre>\n" . htmlspecialchars($localSettings) . "</pre>\n"); }
function importOldRevision() { $dbw = wfGetDB(DB_MASTER); # Sneak a single revision into place $user = User::newFromName($this->getUser()); if ($user) { $userId = intval($user->getId()); $userText = $user->getName(); $userObj = $user; } else { $userId = 0; $userText = $this->getUser(); $userObj = new User(); } // avoid memory leak...? $linkCache = LinkCache::singleton(); $linkCache->clear(); $article = new Article($this->title); $pageId = $article->getId(); if ($pageId == 0) { # must create the page... $pageId = $article->insertOn($dbw); $created = true; $oldcountable = null; } else { $created = false; $prior = $dbw->selectField('revision', '1', array('rev_page' => $pageId, 'rev_timestamp' => $dbw->timestamp($this->timestamp), 'rev_user_text' => $userText, 'rev_comment' => $this->getComment()), __METHOD__); if ($prior) { // @todo FIXME: This could fail slightly for multiple matches :P wfDebug(__METHOD__ . ": skipping existing revision for [[" . $this->title->getPrefixedText() . "]], timestamp " . $this->timestamp . "\n"); return false; } $oldcountable = $article->isCountable(); } # @todo FIXME: Use original rev_id optionally (better for backups) # Insert the row $revision = new Revision(array('page' => $pageId, 'text' => $this->getText(), 'comment' => $this->getComment(), 'user' => $userId, 'user_text' => $userText, 'timestamp' => $this->timestamp, 'minor_edit' => $this->minor)); $revision->insertOn($dbw); $changed = $article->updateIfNewerOn($dbw, $revision); if ($changed !== false) { wfDebug(__METHOD__ . ": running updates\n"); $article->doEditUpdates($revision, $userObj, array('created' => $created, 'oldcountable' => $oldcountable)); } return true; }