article.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 2,311 行 · 第 1/5 页
PHP
2,311 行
"<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" . "</form>\n", $msg ); $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); $wgOut->addHTML( $msg ); } } /** * Perform the actions of a page purging */ function doPurge() { global $wgUseSquid; // Invalidate the cache $this->mTitle->invalidateCache(); if ( $wgUseSquid ) { // Commit the transaction before the purge is sent $dbw = wfGetDB( DB_MASTER ); $dbw->immediateCommit(); // Send purge $update = SquidUpdate::newSimplePurge( $this->mTitle ); $update->doUpdate(); } $this->view(); } /** * Insert a new empty page record for this article. * This *must* be followed up by creating a revision * and running $this->updateToLatest( $rev_id ); * or else the record will be left in a funky state. * Best if all done inside a transaction. * * @param Database $dbw * @param string $restrictions * @return int The newly created page_id key * @private */ function insertOn( &$dbw, $restrictions = '' ) { wfProfileIn( __METHOD__ ); $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' ); $dbw->insert( 'page', array( 'page_id' => $page_id, 'page_namespace' => $this->mTitle->getNamespace(), 'page_title' => $this->mTitle->getDBkey(), 'page_counter' => 0, 'page_restrictions' => $restrictions, 'page_is_redirect' => 0, # Will set this shortly... 'page_is_new' => 1, 'page_random' => wfRandom(), 'page_touched' => $dbw->timestamp(), 'page_latest' => 0, # Fill this in shortly... 'page_len' => 0, # Fill this in shortly... ), __METHOD__ ); $newid = $dbw->insertId(); $this->mTitle->resetArticleId( $newid ); wfProfileOut( __METHOD__ ); return $newid; } /** * Update the page record to point to a newly saved revision. * * @param Database $dbw * @param Revision $revision For ID number, and text used to set length and redirect status fields * @param int $lastRevision If given, will not overwrite the page field * when different from the currently set value. * Giving 0 indicates the new page flag should * be set on. * @return bool true on success, false on failure * @private */ function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) { wfProfileIn( __METHOD__ ); $conditions = array( 'page_id' => $this->getId() ); if( !is_null( $lastRevision ) ) { # An extra check against threads stepping on each other $conditions['page_latest'] = $lastRevision; } $text = $revision->getText(); $dbw->update( 'page', array( /* SET */ 'page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp(), 'page_is_new' => ($lastRevision === 0) ? 1 : 0, 'page_is_redirect' => Article::isRedirect( $text ) ? 1 : 0, 'page_len' => strlen( $text ), ), $conditions, __METHOD__ ); wfProfileOut( __METHOD__ ); return ( $dbw->affectedRows() != 0 ); } /** * If the given revision is newer than the currently set page_latest, * update the page record. Otherwise, do nothing. * * @param Database $dbw * @param Revision $revision */ function updateIfNewerOn( &$dbw, $revision ) { wfProfileIn( __METHOD__ ); $row = $dbw->selectRow( array( 'revision', 'page' ), array( 'rev_id', 'rev_timestamp' ), array( 'page_id' => $this->getId(), 'page_latest=rev_id' ), __METHOD__ ); if( $row ) { if( wfTimestamp(TS_MW, $row->rev_timestamp) >= $revision->getTimestamp() ) { wfProfileOut( __METHOD__ ); return false; } $prev = $row->rev_id; } else { # No or missing previous revision; mark the page as new $prev = 0; } $ret = $this->updateRevisionOn( $dbw, $revision, $prev ); wfProfileOut( __METHOD__ ); return $ret; } /** * @return string Complete article text, or null if error */ function replaceSection($section, $text, $summary = '', $edittime = NULL) { wfProfileIn( __METHOD__ ); if( $section == '' ) { // Whole-page edit; let the text through unmolested. } else { if( is_null( $edittime ) ) { $rev = Revision::newFromTitle( $this->mTitle ); } else { $dbw =& wfGetDB( DB_MASTER ); $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime ); } if( is_null( $rev ) ) { wfDebug( "Article::replaceSection asked for bogus section (page: " . $this->getId() . "; section: $section; edittime: $edittime)\n" ); return null; } $oldtext = $rev->getText(); if($section=='new') { if($summary) $subject="== {$summary} ==\n\n"; $text=$oldtext."\n\n".$subject.$text; } else { global $wgParser; $text = $wgParser->replaceSection( $oldtext, $section, $text ); } } wfProfileOut( __METHOD__ ); return $text; } /** * @deprecated use Article::doEdit() */ function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) { $flags = EDIT_NEW | EDIT_DEFER_UPDATES | ( $isminor ? EDIT_MINOR : 0 ) | ( $suppressRC ? EDIT_SUPPRESS_RC : 0 ); # If this is a comment, add the summary as headline if ( $comment && $summary != "" ) { $text = "== {$summary} ==\n\n".$text; } $this->doEdit( $text, $summary, $flags ); $dbw =& wfGetDB( DB_MASTER ); if ($watchthis) { if (!$this->mTitle->userIsWatching()) { $dbw->begin(); $this->doWatch(); $dbw->commit(); } } else { if ( $this->mTitle->userIsWatching() ) { $dbw->begin(); $this->doUnwatch(); $dbw->commit(); } } $this->doRedirect( $this->isRedirect( $text ) ); } /** * @deprecated use Article::doEdit() */ function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) { $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES | ( $minor ? EDIT_MINOR : 0 ) | ( $forceBot ? EDIT_FORCE_BOT : 0 ); $good = $this->doEdit( $text, $summary, $flags ); if ( $good ) { $dbw =& wfGetDB( DB_MASTER ); if ($watchthis) { if (!$this->mTitle->userIsWatching()) { $dbw->begin(); $this->doWatch(); $dbw->commit(); } } else { if ( $this->mTitle->userIsWatching() ) { $dbw->begin(); $this->doUnwatch(); $dbw->commit(); } } $this->doRedirect( $this->isRedirect( $text ), $sectionanchor ); } return $good; } /** * Article::doEdit() * * Change an existing article or create a new article. Updates RC and all necessary caches, * optionally via the deferred update array. * * $wgUser must be set before calling this function. * * @param string $text New text * @param string $summary Edit summary * @param integer $flags bitfield: * EDIT_NEW * Article is known or assumed to be non-existent, create a new one * EDIT_UPDATE * Article is known or assumed to be pre-existing, update it * EDIT_MINOR * Mark this edit minor, if the user is allowed to do so * EDIT_SUPPRESS_RC * Do not log the change in recentchanges * EDIT_FORCE_BOT * Mark the edit a "bot" edit regardless of user rights * EDIT_DEFER_UPDATES * Defer some of the updates until the end of index.php * * If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the article will be detected. * If EDIT_UPDATE is specified and the article doesn't exist, the function will return false. If * EDIT_NEW is specified and the article does exist, a duplicate key error will cause an exception * to be thrown from the Database. These two conditions are also possible with auto-detection due * to MediaWiki's performance-optimised locking strategy. * * @return bool success */ function doEdit( $text, $summary, $flags = 0 ) { global $wgUser, $wgDBtransactions; wfProfileIn( __METHOD__ ); $good = true; if ( !($flags & EDIT_NEW) && !($flags & EDIT_UPDATE) ) { $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE ); if ( $aid ) { $flags |= EDIT_UPDATE; } else { $flags |= EDIT_NEW; } } if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text, &$summary, $flags & EDIT_MINOR, null, null, &$flags ) ) ) { wfDebug( __METHOD__ . ": ArticleSave hook aborted save!\n" ); wfProfileOut( __METHOD__ ); return false; } # Silently ignore EDIT_MINOR if not allowed $isminor = ( $flags & EDIT_MINOR ) && $wgUser->isAllowed('minoredit'); $bot = $wgUser->isBot() || ( $flags & EDIT_FORCE_BOT ); $text = $this->preSaveTransform( $text ); $dbw =& wfGetDB( DB_MASTER ); $now = wfTimestampNow(); if ( $flags & EDIT_UPDATE ) { # Update article, but only if changed. # Make sure the revision is either completely inserted or not inserted at all if( !$wgDBtransactions ) { $userAbort = ignore_user_abort( true ); } $oldtext = $this->getContent(); $oldsize = strlen( $oldtext ); $newsize = strlen( $text ); $lastRevision = 0; $revisionId = 0; if ( 0 != strcmp( $text, $oldtext ) ) { $this->mGoodAdjustment = (int)$this->isCountable( $text ) - (int)$this->isCountable( $oldtext ); $this->mTotalAdjustment = 0; $lastRevision = $dbw->selectField( 'page', 'page_latest', array( 'page_id' => $this->getId() ) ); if ( !$lastRevision ) { # Article gone missing wfDebug( __METHOD__.": EDIT_UPDATE specified but article doesn't exist\n" ); wfProfileOut( __METHOD__ ); return false; } $revision = new Revision( array( 'page' => $this->getId(), 'comment' => $summary, 'minor_edit' => $isminor, 'text' => $text ) ); $dbw->begin(); $revisionId = $revision->insertOn( $dbw ); # Update page $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision ); if( !$ok ) { /* Belated edit conflict! Run away!! */ $good = false; $dbw->rollback(); } else { # Update recentchanges if( !( $flags & EDIT_SUPPRESS_RC ) ) { $rcid = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary, $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize, $revisionId ); # Mark as patrolled if the user can do so and has it set in their options if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) { RecentChange::markPatrolled( $rcid ); } } $dbw->commit(); } } else { // Keep the same revision ID, but do some updates on it $revisionId = $this->getRevIdFetched(); // Update page_touched, this is usually implicit in the page update // Other cache updates are done in onArticleEdit() $this->mTitle->invalidateCache(); } if( !$wgDBtransactions ) { ignore_user_abort( $userAbort ); } if ( $good ) { # Invalidate cache of this article and all pages using this article # as a template. Partly deferred. Article::onArticleEdit( $this->mTitle ); # Update links tables, site stats, etc. $changed = ( strcmp( $oldtext, $text ) != 0 ); $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed ); } } else { # Create new article # Set statistics members # We work out if it's countable after PST to avoid counter drift # when articles are created with {{subst:}} $this->mGoodAdjustment = (int)$this->isCountable( $text ); $this->mTotalAdjustment = 1; $dbw->begin(); # Add the page record; stake our claim on this title! # This will fail with a database query exception if the article already exists $newid = $this->insertOn( $dbw ); # Save the revision text... $revision = new Revision( array( 'page' => $newid, 'comment' => $summary, 'minor_edit' => $isminor, 'text' => $text ) ); $revisionId = $revision->insertOn( $dbw ); $this->mTitle->resetArticleID( $newid ); # Update the page record with revision data $this->updateRevisionOn( $dbw, $revision, 0 ); if( !( $flags & EDIT_SUPPRESS_RC ) ) { $rcid = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary, $bot, '', strlen( $text ), $revisionId ); # Mark as patrolled if the user can and has the option set if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) { RecentChange::markPatrolled( $rcid ); } } $dbw->commit(); # Update links, etc. $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true ); # Clear caches Article::onArticleCreate( $this->mTitle ); wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text, $summary, $flags & EDIT_MINOR, null, null, &$flags ) ); } if ( $good && !( $flags & EDIT_DEFER_UPDATES ) ) { wfDoUpdates(); } wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text, $summary, $flags & EDIT_MINOR, null, null, &$flags ) ); wfProfileOut( __METHOD__ ); return $good; } /** * @deprecated wrapper for doRedirect */ function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) { $this->doRedirect( $this->isRedirect( $text ), $sectionanchor ); } /** * Output a redirect back to the article. * This is typically used after an edit. * * @param boolean $noRedir Add redirect=no * @param string $sectionAnchor section to redirect to, including "#" */ function doRedirect( $noRedir = false, $sectionAnchor = '' ) { global $wgOut; if ( $noRedir ) { $query = 'redirect=no'; } else { $query = '';
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?