/**
This function accepts a title string as parameter
($preload). If this string is non-empty, it attempts
- to fetch the current revision text.
+ to fetch the current revision text. It respects
+ <includeonly>.
*/
function getPreloadedText($preload) {
if($preload) {
if(isset($preloadTitle) && $preloadTitle->userCanRead()) {
$rev=Revision::newFromTitle($preloadTitle);
if($rev) {
- return $rev->getText();
+ $text=$rev->getText();
+ $text=preg_replace('/<\/?includeonly>/i','',$text);
+ return $text;
}
}
}
}
- /**
- * Return an array of the columns of the "cur"-table
- */
- function getContentFields() {
- return $wgArticleContentFields = array(
- 'old_text','old_flags',
- 'rev_timestamp','rev_user', 'rev_user_text', 'rev_comment','page_counter',
- 'page_namespace', 'page_title', 'page_restrictions','page_touched','page_is_redirect' );
- }
-
/**
* Return the oldid of the article that is to be shown.
* For requests with a "direction", this is not the oldid of the
* @access private
*/
function pageData( &$dbr, $conditions ) {
- return $dbr->selectRow( 'page',
- array(
+ $fields = array(
'page_id',
'page_namespace',
'page_title',
'page_random',
'page_touched',
'page_latest',
- 'page_len' ),
+ 'page_len' ) ;
+ wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
+ $row = $dbr->selectRow( 'page',
+ $fields,
$conditions,
'Article::pageData' );
+ wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) ) ;
+ return $row ;
}
function pageDataFromTitle( &$dbr, $title ) {
return false;
}
}
- $redirData = $this->pageDataFromTitle( $dbr, $rt );
- if( $redirData ) {
- $redirRev = Revision::newFromId( $redirData->page_latest );
- if( !is_null( $redirRev ) ) {
- $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
- $this->mTitle = $rt;
- $data = $redirData;
- $this->loadPageData( $data );
- $revision = $redirRev;
+ if( $rt->getInterwiki() == '' ) {
+ $redirData = $this->pageDataFromTitle( $dbr, $rt );
+ if( $redirData ) {
+ $redirRev = Revision::newFromId( $redirData->page_latest );
+ if( !is_null( $redirRev ) ) {
+ $this->mRedirectedFrom = $this->mTitle->getPrefixedText();
+ $this->mTitle = $rt;
+ $data = $redirData;
+ $this->loadPageData( $data );
+ $revision = $redirRev;
+ }
}
}
}
* the given title.
*/
function view() {
- global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgLang;
- global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
- global $wgEnotif, $wgParser, $wgParserCache, $wgUseTrackbacks;
+ global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgContLang;
+ global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
+ global $wgParserCache, $wgUseTrackbacks;
$sk = $wgUser->getSkin();
$fname = 'Article::view';
require_once( 'DifferenceEngine.php' );
$wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
- $de = new DifferenceEngine( $oldid, $diff, $rcid );
+ $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid );
// DifferenceEngine directly fetched the revision:
$this->mRevIdFetched = $de->mNewid;
$de->showDiffPage();
$this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
$wgOut->setRobotpolicy( 'noindex,follow' );
}
+ $wasRedirected = false;
if ( '' != $this->mRedirectedFrom ) {
- $sk = $wgUser->getSkin();
- $redir = $sk->makeKnownLink( $this->mRedirectedFrom, '',
- 'redirect=no' );
- $s = wfMsg( 'redirectedfrom', $redir );
- $wgOut->setSubtitle( $s );
-
- # Can't cache redirects
- $pcache = false;
+ if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
+ $sk = $wgUser->getSkin();
+ $redir = $sk->makeKnownLink( $this->mRedirectedFrom, '', 'redirect=no' );
+ $s = wfMsg( 'redirectedfrom', $redir );
+ $wgOut->setSubtitle( $s );
+
+ // Check the parser cache again, for the target page
+ if( $pcache ) {
+ if( $wgOut->tryParserCache( $this, $wgUser ) ) {
+ $outputDone = true;
+ }
+ }
+ $wasRedirected = true;
+ }
} elseif ( !empty( $rdfrom ) ) {
global $wgRedirectSources;
if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
$redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
$s = wfMsg( 'redirectedfrom', $redir );
$wgOut->setSubtitle( $s );
+ $wasRedirected = true;
}
}
-
+ }
+ if( !$outputDone ) {
+ wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
# wrap user css and user js in pre and don't parse
# XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
if (
$wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
} else if ( $rt = Title::newFromRedirect( $text ) ) {
# Display redirect
- $imageUrl = $wgStylePath.'/common/images/redirect.png';
+ $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
+ $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
+ if( !$wasRedirected ) {
+ $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
+ }
$targetUrl = $rt->escapeLocalURL();
$titleText = htmlspecialchars( $rt->getPrefixedText() );
$link = $sk->makeLinkObj( $rt );
- $wgOut->addHTML( '<img valign="center" src="'.$imageUrl.'" alt="#REDIRECT" />' .
+ $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
'<span class="redirectText">'.$link.'</span>' );
$parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser));
$skin = $wgUser->getSkin();
} else if ( $pcache ) {
# Display content and save to parser cache
+ $wgOut->setRevisionId( $this->getRevIdFetched() );
$wgOut->addPrimaryWikiText( $text, $this );
} else {
# Display content, don't attempt to save to parser cache
if( !$this->isCurrent() ) {
$oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false );
}
+ $wgOut->setRevisionId( $this->getRevIdFetched() );
$wgOut->addWikiText( $text );
if( !$this->isCurrent() ) {
if ($wgUseTrackbacks)
$this->addTrackbacks();
- # Put link titles into the link cache
- $wgOut->transformBuffer();
-
# Add link titles as META keywords
$wgOut->addMetaTags() ;
$wgOut->setArticleBodyOnly(true);
$this->view();
}
+
+ function purge() {
+ global $wgUser, $wgRequest, $wgOut, $wgUseSquid;
+
+ if ( $wgUser->isLoggedIn() || $wgRequest->wasPosted() ) {
+ // 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();
+ } else {
+ $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
+ $action = $this->mTitle->escapeLocalURL( 'action=purge' );
+ $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
+ $msg = str_replace( '$1',
+ "<form method=\"post\" action=\"$action\">\n" .
+ "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
+ "</form>\n", $msg );
+
+ $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
+ $wgOut->setRobotpolicy( 'noindex,nofollow' );
+ $wgOut->addHTML( $msg );
+ }
+ }
/**
* Insert a new empty page record for this article.
'page_random' => wfRandom(),
'page_touched' => $dbw->timestamp(),
'page_latest' => 0, # Fill this in shortly...
+ 'page_len' => 0, # Fill this in shortly...
), $fname );
$newid = $dbw->insertId();
* @private
*/
function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
- global $wgOut, $wgUser;
- global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
+ global $wgOut, $wgUser, $wgUseSquid;
$fname = 'Article::insertNewArticle';
wfProfileIn( $fname );
$this->editUpdates( $text, $summary, $isminor, $now );
$oldid = 0; # new article
- $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
+ $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid, $revisionId );
wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
$summary, $isminor,
$this->replaceSection( $section, $text, $summary, $edittime );
}
+ /**
+ * @return string Complete article text, or null if error
+ */
function replaceSection($section, $text, $summary = '', $edittime = NULL) {
$fname = 'Article::replaceSection';
wfProfileIn( $fname );
$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') {
* first set $wgUser, and clean up $wgDeferredUpdates after each edit.
*/
function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
- global $wgOut, $wgUser;
- global $wgDBtransactions, $wgMwRedir;
- global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList, $wgUseFileCache;
+ global $wgOut, $wgUser, $wgDBtransactions, $wgMwRedir, $wgUseSquid;
+ global $wgPostCommitUpdateList, $wgUseFileCache;
$fname = 'Article::updateArticle';
wfProfileIn( $fname );
$oldsize = strlen( $oldtext );
$newsize = strlen( $text );
$lastRevision = 0;
+ $revisionId = 0;
if ( 0 != strcmp( $text, $oldtext ) ) {
$this->mGoodAdjustment = $this->isCountable( $text )
RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary,
$lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
$revisionId );
- Article::onArticleEdit( $this->mTitle );
$dbw->commit();
+
+ // Update caches outside the main transaction
+ Article::onArticleEdit( $this->mTitle );
}
}
$this->editUpdates( $text, $summary, $minor, $now );
- $urls = array();
- # Template namespace
- # Purge all articles linking here
- if ( $this->mTitle->getNamespace() == NS_TEMPLATE) {
- $titles = $this->mTitle->getLinksTo();
- Title::touchArray( $titles );
- if ( $wgUseSquid ) {
- foreach ( $titles as $title ) {
- $urls[] = $title->getInternalURL();
- }
- }
- }
-
- # Squid updates
- if ( $wgUseSquid ) {
- $urls = array_merge( $urls, $this->mTitle->getSquidURLs() );
- $u = new SquidUpdate( $urls );
- array_push( $wgPostCommitUpdateList, $u );
- }
-
- # File cache
- if ( $wgUseFileCache ) {
- $cm = new CacheManager($this->mTitle);
- @unlink($cm->fileCacheName());
- }
-
- $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
+ $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision, $revisionId );
}
wfRunHooks( 'ArticleSaveComplete',
array( &$this, &$wgUser, $text,
* After we've either updated or inserted the article, update
* the link tables and redirect to the new page.
*/
- function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
- global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
+ function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid, $newid ) {
+ global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache;
global $wgUseEnotif;
$fname = 'Article::showArticle';
}
}
- # Parse the text and replace links with placeholders
+ # Parse the text and save it to the parser cache
$wgOut = new OutputPage();
-
- # Pass the current title along in case we're creating a wiki page
- # which is different than the currently displayed one (e.g. image
- # pages created on file uploads); otherwise, link updates will
- # go wrong.
- $wgOut->addWikiTextWithTitle( $text, $this->mTitle );
+ $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
+ $wgOut->setRevisionId( $newid );
+ $wgOut->addPrimaryWikiText( $text, $this );
if ( !$wgUseDumbLinkUpdate ) {
# Move the current links back to the second register
else
$r = '';
$wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
-
- if ( $wgUseEnotif ) {
- # this would be better as an extension hook
- include_once( "UserMailer.php" );
- $wgEnotif = new EmailNotification ();
- $wgEnotif->notifyOnPageChange( $this->mTitle, $now, $summary, $me2, $oldid );
- }
+
wfProfileOut( $fname );
}
$formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par );
}
- $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
+ $confirm = htmlspecialchars( wfMsg( 'protectpage' ) );
$token = htmlspecialchars( $wgUser->editToken() );
$wgOut->addHTML( "
* UI entry point for page deletion
*/
function delete() {
- global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
+ global $wgUser, $wgOut, $wgRequest;
$fname = 'Article::delete';
$confirm = $wgRequest->wasPosted() &&
$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
$formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
- $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
+ $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
$delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
$token = htmlspecialchars( $wgUser->editToken() );
* Returns success
*/
function doDeleteArticle( $reason ) {
- global $wgUser;
- global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
- global $wgUseTrackbacks;
+ global $wgUser, $wgUseSquid, $wgDeferredUpdateList;
+ global $wgPostCommitUpdateList, $wgUseTrackbacks;
$fname = 'Article::doDeleteArticle';
wfDebug( $fname."\n" );
);
}
- # Save it!
+ # Get the edit summary
$target = Revision::newFromId( $s->rev_id );
- $newcomment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
+ $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
+ $newComment = $wgRequest->getText( 'summary', $newComment );
+ # Save it!
$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
- $wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
+ $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
- $this->updateArticle( $target->getText(), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
+ $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle->userIsWatching(), $bot );
Article::onArticleEdit( $this->mTitle );
$dbw->commit();
* @private
*/
function viewUpdates() {
- global $wgDeferredUpdateList, $wgUseEnotif;
+ global $wgDeferredUpdateList;
if ( 0 != $this->getID() ) {
global $wgDisableCounters;
}
}
- # Update newtalk status if user is reading their own
- # talk page
-
+ # Update newtalk / watchlist notification status
global $wgUser;
- if ($this->mTitle->getNamespace() == NS_USER_TALK &&
- $this->mTitle->getText() == $wgUser->getName())
- {
- if ( $wgUseEnotif ) {
- require_once( 'UserTalkUpdate.php' );
- $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(), $this->mTitle->getDBkey(), false, false, false );
- } else {
- $wgUser->setNewtalk(0);
- $wgUser->saveNewtalk();
- }
- } elseif ( $wgUseEnotif ) {
- $wgUser->clearNotification( $this->mTitle );
- }
-
+ $wgUser->clearNotification( $this->mTitle );
}
/**
* @param string $text
*/
function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
- global $wgDeferredUpdateList, $wgDBname, $wgMemc;
- global $wgMessageCache, $wgUser, $wgUseEnotif;
-
- wfSeedRandom();
- if ( 0 == mt_rand( 0, 999 ) ) {
- # Periodically flush old entries from the recentchanges table.
- global $wgRCMaxAge;
- $dbw =& wfGetDB( DB_MASTER );
- $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
- $recentchanges = $dbw->tableName( 'recentchanges' );
- $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
- //$dbw->query( $sql ); // HACK: disabled for now, slowness
-
- // re-enabled for commit of unrelated live changes -- TS
- $dbw->query( $sql );
+ global $wgDeferredUpdateList, $wgMessageCache, $wgUser;
+
+ if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
+ wfSeedRandom();
+ if ( 0 == mt_rand( 0, 999 ) ) {
+ # Periodically flush old entries from the recentchanges table.
+ global $wgRCMaxAge;
+
+ $dbw =& wfGetDB( DB_MASTER );
+ $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
+ $recentchanges = $dbw->tableName( 'recentchanges' );
+ $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
+ $dbw->query( $sql );
+ }
}
-
+
$id = $this->getID();
$title = $this->mTitle->getPrefixedDBkey();
$shortTitle = $this->mTitle->getDBkey();
# If this is another user's talk page, update newtalk
if ($this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getName()) {
- if ( $wgUseEnotif ) {
- require_once( 'UserTalkUpdate.php' );
- $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle, $summary,
- $minoredit, $timestamp_of_pagechange);
- } else {
- $other = User::newFromName( $shortTitle );
- if( is_null( $other ) && User::isIP( $shortTitle ) ) {
- // An anonymous user
- $other = new User();
- $other->setName( $shortTitle );
- }
- if( $other ) {
- $other->setNewtalk(1);
- $other->saveNewtalk();
- }
+ $other = User::newFromName( $shortTitle );
+ if( is_null( $other ) && User::isIP( $shortTitle ) ) {
+ // An anonymous user
+ $other = new User();
+ $other->setName( $shortTitle );
+ }
+ if( $other ) {
+ $other->setNewtalk( true );
}
}
}
}
- function onArticleEdit($title_obj) {
- // This would be an appropriate place to purge caches.
- // Why's this not in here now?
+ /**
+ * Purge caches on page update etc
+ */
+ function onArticleEdit( $title ) {
+ global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
+
+ $urls = array();
+
+ // Template namespace? Purge all articles linking here.
+ // FIXME: When a templatelinks table arrives, use it for all includes.
+ if ( $title->getNamespace() == NS_TEMPLATE) {
+ $titles = $title->getLinksTo();
+ Title::touchArray( $titles );
+ if ( $wgUseSquid ) {
+ foreach ( $titles as $link ) {
+ $urls[] = $link->getInternalURL();
+ }
+ }
+ }
+
+ # Squid updates
+ if ( $wgUseSquid ) {
+ $urls = array_merge( $urls, $title->getSquidURLs() );
+ $u = new SquidUpdate( $urls );
+ array_push( $wgPostCommitUpdateList, $u );
+ }
+
+ # File cache
+ if ( $wgUseFileCache ) {
+ $cm = new CacheManager( $title );
+ @unlink( $cm->fileCacheName() );
+ }
}
/**#@-*/