X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FArticle.php;h=c7f9649ab021cf1a6303cf1c66f9aa6d8b7b1702;hb=d238b93290c86e2495e3e67d99630d9cdace2471;hp=c7b43f39b0b0aee7e60529b8ebb0d96c183b97b6;hpb=c3093cdf1b05c1f1778fe24dd6e2e1be987bb7da;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Article.php b/includes/Article.php index c7b43f39b0..c7f9649ab0 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -34,6 +34,7 @@ class Article { var $mId, $mTable; var $mForUpdate; var $mOldId; + var $mRevIdFetched; /**#@-*/ /** @@ -68,6 +69,7 @@ class Article { $this->mTouched = '19700101000000'; $this->mForUpdate = false; $this->mIsRedirect = false; + $this->mRevIdFetched = 0; } /** @@ -426,7 +428,9 @@ class Article { $this->mComment = $revision->getComment(); $this->mTimestamp = wfTimestamp( TS_MW, $revision->getTimestamp() ); + $this->mRevIdFetched = $revision->getID(); $this->mContentLoaded = true; + return $this->mContent; } @@ -519,7 +523,7 @@ class Article { function isRedirect( $text = false ) { if ( $text === false ) { $this->loadContent(); - $titleObj = Title::newFromRedirect( $this->mText ); + $titleObj = Title::newFromRedirect( $this->fetchRevisionText() ); } else { $titleObj = Title::newFromRedirect( $text ); } @@ -575,6 +579,11 @@ class Article { $this->loadLastEdit(); return $this->mMinorEdit; } + + function getRevIdFetched() { + $this->loadLastEdit(); + return $this->mRevIdFetched; + } function getContributors($limit = 0, $offset = 0) { $fname = 'Article::getContributors'; @@ -637,8 +646,12 @@ class Article { if ( !is_null( $diff ) ) { require_once( 'DifferenceEngine.php' ); $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); + $de = new DifferenceEngine( $oldid, $diff, $rcid ); + // DifferenceEngine directly fetched the revision: + $this->mRevIdFetched = $de->mNewid; $de->showDiffPage(); + if( $diff == 0 ) { # Run view updates for current revision only $this->viewUpdates(); @@ -737,7 +750,12 @@ class Article { $wgOut->addWikiText( $text ); } } - $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); + /* title may have been set from the cache */ + $t = $wgOut->getPageTitle(); + if( empty( $t ) ) { + $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); + } + # If we have been passed an &rcid= parameter, we want to give the user a # chance to mark this new article as patrolled. if ( $wgUseRCPatrol && !is_null ( $rcid ) && $rcid != 0 && $wgUser->isLoggedIn() && @@ -875,7 +893,7 @@ class Article { * errors at some point. * @private */ - function insertNewArticle( $text, $summary, $isminor, $watchthis ) { + function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false ) { global $wgOut, $wgUser; global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer; @@ -887,6 +905,7 @@ class Article { $ttl = $this->mTitle->getDBkey(); $text = $this->preSaveTransform( $text ); $isminor = ( $isminor && $wgUser->isLoggedIn() ) ? 1 : 0; + $now = wfTimestampNow(); $dbw =& wfGetDB( DB_MASTER ); @@ -908,7 +927,9 @@ class Article { $this->updateRevisionOn( $dbw, $revision, 0 ); Article::onArticleCreate( $this->mTitle ); - RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary ); + if(!$suppressRC) { + RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary ); + } if ($watchthis) { if(!$this->mTitle->userIsWatching()) $this->watch(); @@ -1072,19 +1093,19 @@ class Article { $text = $this->preSaveTransform( $text ); $dbw =& wfGetDB( DB_MASTER ); + $now = wfTimestampNow(); # Update article, but only if changed. # It's important that we either rollback or complete, otherwise an attacker could # overwrite cur entries by sending precisely timed user aborts. Random bored users # could conceivably have the same effect, especially if cur is locked for long periods. - if( $wgDBtransactions ) { - $dbw->query( 'BEGIN', $fname ); - } else { + if( !$wgDBtransactions ) { $userAbort = ignore_user_abort( true ); } $oldtext = $this->getContent( true ); + $lastRevision = 0; if ( 0 != strcmp( $text, $oldtext ) ) { $this->mCountAdjustment = $this->isCountable( $text ) @@ -1111,15 +1132,13 @@ class Article { } else { # Update recentchanges and purge cache and whatnot $bot = (int)($wgUser->isBot() || $forceBot); - RecentChange::notifyEdit( $now, $this->mTitle, $me2, $wgUser, $summary, + RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary, $lastRevision, $this->getTimestamp(), $bot ); Article::onArticleEdit( $this->mTitle ); } } - if( $wgDBtransactions ) { - $dbw->query( 'COMMIT', $fname ); - } else { + if( !$wgDBtransactions ) { ignore_user_abort( $userAbort ); } @@ -1155,7 +1174,7 @@ class Article { array_push( $wgPostCommitUpdateList, $u ); } - $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $me2, $now, $summary, $lastRevision ); + $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision ); } return $good; } @@ -2258,6 +2277,35 @@ class Article { return array( 'edits' => $edits, 'authors' => $authors ); } + + /** + * Return a list of templates used by this article. + * Uses the links table to find the templates + * + * @return array + */ + function getUsedTemplates() { + $result = array(); + $id = $this->mTitle->getArticleID(); + + $db =& wfGetDB( DB_SLAVE ); + $page = $db->tableName( 'page' ); + $links = $db->tableName( 'links' ); + $sql = "SELECT page_title ". + "FROM $page,$links WHERE l_to=page_id AND l_from={$id} and page_namespace=".NS_TEMPLATE; + $res = $db->query( $sql, "Article:getUsedTemplates" ); + if ( false !== $res ) { + if ( $db->numRows( $res ) ) { + while ( $row = $db->fetchObject( $res ) ) { + $result[] = $row->page_title; + } + } + } + $db->freeResult( $res ); + return $result; + } + + }