X-Git-Url: http://git.cyclocoop.org/%24action?a=blobdiff_plain;f=includes%2FArticle.php;h=0950e6163ccd3cfc52ddcd3c8ffd860c4e9be4c8;hb=d815ca352f8fde14bc00f84b2eec11c1fef7f066;hp=a0a0f8d787e5df14ef9fda10c1f87640209ec3d9;hpb=21568fd37d9fd6506ee5f24589f7577406aafba9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Article.php b/includes/Article.php index a0a0f8d787..0950e6163c 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -142,7 +142,8 @@ class Article { /** 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 + . */ function getPreloadedText($preload) { if($preload) { @@ -150,7 +151,9 @@ class Article { 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; } } } @@ -227,16 +230,6 @@ class Article { } - /** - * 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 @@ -307,8 +300,7 @@ class Article { * @access private */ function pageData( &$dbr, $conditions ) { - return $dbr->selectRow( 'page', - array( + $fields = array( 'page_id', 'page_namespace', 'page_title', @@ -319,9 +311,14 @@ class Article { '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 ) { @@ -431,15 +428,17 @@ class Article { 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; + } } } } @@ -681,9 +680,9 @@ class Article { * 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'; @@ -703,7 +702,7 @@ class Article { 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(); @@ -759,14 +758,21 @@ class Article { $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid ); $wgOut->setRobotpolicy( 'noindex,follow' ); } + $wasRedirected = false; if ( '' != $this->mRedirectedFrom ) { if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) { $sk = $wgUser->getSkin(); $redir = $sk->makeKnownLink( $this->mRedirectedFrom, '', 'redirect=no' ); $s = wfMsg( 'redirectedfrom', $redir ); $wgOut->setSubtitle( $s ); - # Can't cache redirects - $pcache = false; + + // 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; @@ -775,9 +781,12 @@ class Article { $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 ( @@ -788,12 +797,16 @@ class Article { $wgOut->addHTML( '
'.htmlspecialchars($this->mContent)."\n
" ); } 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( '#REDIRECT' . + $wgOut->addHTML( '#REDIRECT' . ''.$link.'' ); $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser)); @@ -802,6 +815,7 @@ class Article { $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 @@ -810,6 +824,7 @@ class Article { if( !$this->isCurrent() ) { $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false ); } + $wgOut->setRevisionId( $this->getRevIdFetched() ); $wgOut->addWikiText( $text ); if( !$this->isCurrent() ) { @@ -844,9 +859,6 @@ class Article { if ($wgUseTrackbacks) $this->addTrackbacks(); - # Put link titles into the link cache - $wgOut->transformBuffer(); - # Add link titles as META keywords $wgOut->addMetaTags() ; @@ -915,6 +927,38 @@ class Article { $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', + "
\n" . + "\n" . + "
\n", $msg ); + + $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); + $wgOut->setRobotpolicy( 'noindex,nofollow' ); + $wgOut->addHTML( $msg ); + } + } /** * Insert a new empty page record for this article. @@ -944,6 +988,7 @@ class 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(); @@ -1034,8 +1079,7 @@ class Article { * @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 ); @@ -1106,7 +1150,7 @@ class Article { $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, @@ -1118,6 +1162,9 @@ class Article { $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 ); @@ -1129,6 +1176,11 @@ class Article { $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') { @@ -1212,9 +1264,8 @@ class Article { * 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 ); @@ -1347,7 +1398,7 @@ class Article { @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, @@ -1361,8 +1412,8 @@ class Article { * 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'; @@ -1378,14 +1429,11 @@ class Article { } } - # 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 @@ -1409,8 +1457,8 @@ class Article { 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 ); + $enotif = new EmailNotification (); + $enotif->notifyOnPageChange( $this->mTitle, $now, $summary, $me2, $oldid ); } wfProfileOut( $fname ); } @@ -1649,7 +1697,7 @@ class Article { $formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par ); } - $confirm = htmlspecialchars( wfMsg( 'confirm' ) ); + $confirm = htmlspecialchars( wfMsg( 'protectpage' ) ); $token = htmlspecialchars( $wgUser->editToken() ); $wgOut->addHTML( " @@ -1699,7 +1747,7 @@ class Article { * 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' ) ); @@ -1825,7 +1873,7 @@ class Article { $formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par ); - $confirm = htmlspecialchars( wfMsg( 'confirm' ) ); + $confirm = htmlspecialchars( wfMsg( 'deletepage' ) ); $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) ); $token = htmlspecialchars( $wgUser->editToken() ); @@ -1887,9 +1935,8 @@ class Article { * 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" ); @@ -2071,15 +2118,17 @@ class Article { ); } - # 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( '

' . htmlspecialchars( $newcomment ) . "

\n
\n" ); + $wgOut->addHTML( '

' . htmlspecialchars( $newComment ) . "

\n
\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(); @@ -2092,7 +2141,7 @@ class Article { * @private */ function viewUpdates() { - global $wgDeferredUpdateList, $wgUseEnotif; + global $wgDeferredUpdateList; if ( 0 != $this->getID() ) { global $wgDisableCounters; @@ -2103,24 +2152,9 @@ class Article { } } - # 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 ); } /** @@ -2130,11 +2164,9 @@ class Article { * @param string $text */ function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) { - global $wgDeferredUpdateList, $wgDBname, $wgMemc; - global $wgMessageCache, $wgUser, $wgUseEnotif; + global $wgDeferredUpdateList, $wgMessageCache, $wgUser; - - if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', &$this ) ) { + if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) { wfSeedRandom(); if ( 0 == mt_rand( 0, 999 ) ) { # Periodically flush old entries from the recentchanges table. @@ -2163,21 +2195,14 @@ class Article { # 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 ); } }