X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FArticle.php;h=560a26125ff686780731f7b71a8d1e02138ca691;hb=a90c8f87b2e7c2d26d148b1d2679e02441539291;hp=adea10cd91cf44b08cf476a898a1cc1e562d7197;hpb=39ab3cfc9ff796125d73878a6214bef99e104895;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Article.php b/includes/Article.php index adea10cd91..560a26125f 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -40,7 +40,7 @@ class Article { var $mTouched = '19700101000000'; // !< var $mUser = -1; // !< Not loaded var $mUserText = ''; // !< username from Revision if set - var $mParserOptions; // !< ParserOptions object for $wgUser articles + var $mParserOptions; // !< ParserOptions object var $mParserOutput; // !< ParserCache object if set /**@}}*/ @@ -159,7 +159,7 @@ class Article { * * @param $text string article content containing redirect info * @return mixed false, Title of in-wiki target, or string with URL - * @deprecated @since 1.17 + * @deprecated since 1.17 */ public function followRedirectText( $text ) { // recurse through to only get the final target @@ -249,7 +249,7 @@ class Article { * @return Return the text of this revision */ public function getContent() { - global $wgUser, $wgContLang, $wgMessageCache; + global $wgUser; wfProfileIn( __METHOD__ ); @@ -257,12 +257,10 @@ class Article { # If this is a MediaWiki:x message, then load the messages # and return the message value for x. if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { - # If this is a system message, get the default text. - list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) ); - $text = wfMsgGetKey( $message, false, $lang, false ); - - if ( wfEmptyMsg( $message, $text ) ) + $text = $this->mTitle->getDefaultMessageText(); + if ( $text === false ) { $text = ''; + } } else { $text = wfMsgExt( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon', 'parsemag' ); } @@ -836,6 +834,32 @@ class Article { # Get variables from query string $oldid = $this->getOldID(); + + # getOldID may want us to redirect somewhere else + if ( $this->mRedirectUrl ) { + $wgOut->redirect( $this->mRedirectUrl ); + wfDebug( __METHOD__ . ": redirecting due to oldid\n" ); + wfProfileOut( __METHOD__ ); + + return; + } + + $wgOut->setArticleFlag( true ); + # Set page title (may be overridden by DISPLAYTITLE) + $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); + + # If we got diff in the query, we want to see a diff page instead of the article. + if ( $wgRequest->getCheck( 'diff' ) ) { + wfDebug( __METHOD__ . ": showing diff page\n" ); + $this->showDiffPage(); + wfProfileOut( __METHOD__ ); + + return; + } + + # Allow frames by default + $wgOut->allowClickjacking(); + $parserCache = ParserCache::singleton(); $parserOptions = $this->getParserOptions(); @@ -871,31 +895,6 @@ class Article { } } - # getOldID may want us to redirect somewhere else - if ( $this->mRedirectUrl ) { - $wgOut->redirect( $this->mRedirectUrl ); - wfDebug( __METHOD__ . ": redirecting due to oldid\n" ); - wfProfileOut( __METHOD__ ); - - return; - } - - $wgOut->setArticleFlag( true ); - # Set page title (may be overridden by DISPLAYTITLE) - $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); - - # If we got diff in the query, we want to see a diff page instead of the article. - if ( $wgRequest->getCheck( 'diff' ) ) { - wfDebug( __METHOD__ . ": showing diff page\n" ); - $this->showDiffPage(); - wfProfileOut( __METHOD__ ); - - return; - } - - # Allow frames by default - $wgOut->allowClickjacking(); - if ( !$wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) { $parserOptions->setEditSection( false ); } @@ -1035,10 +1034,11 @@ class Article { # tents of 'pagetitle-view-mainpage' instead of the default (if # that's not empty). # This message always exists because it is in the i18n files - if ( $this->mTitle->equals( Title::newMainPage() ) - && ( $m = wfMsgForContent( 'pagetitle-view-mainpage' ) ) !== '' ) - { - $wgOut->setHTMLTitle( $m ); + if ( $this->mTitle->equals( Title::newMainPage() ) ) { + $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage(); + if ( !$msg->isDisabled() ) { + $wgOut->setHTMLTitle( $msg->title( $this->mTitle )->text() ); + } } # Now that we've filled $this->mParserOutput, we know whether @@ -1071,9 +1071,7 @@ class Article { $this->mRevIdFetched = $de->mNewid; $de->showDiffPage( $diffOnly ); - // Needed to get the page's current revision - $this->loadPageData(); - if ( $diff == 0 || $diff == $this->mLatest ) { + if ( $diff == 0 || $diff == $this->getLatest() ) { # Run view updates for current revision only $this->viewUpdates(); } @@ -1117,8 +1115,7 @@ class Article { if ( $ns == NS_USER || $ns == NS_USER_TALK ) { # Don't index user and user talk pages for blocked users (bug 11443) if ( !$this->mTitle->isSubpage() ) { - $block = new Block(); - if ( $block->load( $this->mTitle->getText() ) ) { + if ( Block::newFromTarget( null, $this->mTitle->getText() ) instanceof Block ) { return array( 'index' => 'noindex', 'follow' => 'nofollow' @@ -1217,13 +1214,12 @@ class Article { global $wgOut, $wgUser, $wgRequest, $wgRedirectSources; $rdfrom = $wgRequest->getVal( 'rdfrom' ); - $sk = $wgUser->getSkin(); if ( isset( $this->mRedirectedFrom ) ) { // This is an internally redirected page view. // We'll need a backlink to the source page for navigation. if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) { - $redir = $sk->link( + $redir = $wgUser->getSkin()->link( $this->mRedirectedFrom, null, array(), @@ -1251,7 +1247,7 @@ class Article { // This is an externally redirected view, from some other wiki. // If it was reported from a trusted site, supply a backlink. if ( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) { - $redir = $sk->makeExternalLink( $rdfrom, $rdfrom ); + $redir = $wgUser->getSkin()->makeExternalLink( $rdfrom, $rdfrom ); $s = wfMsgExt( 'redirectedfrom', array( 'parseinline', 'replaceafter' ), $redir ); $wgOut->setSubtitle( $s ); @@ -1295,6 +1291,9 @@ class Article { if ( $wgUseTrackbacks ) { $this->addTrackbacks(); } + + wfRunHooks( 'ArticleViewFooter', array( $this ) ); + } /** @@ -1388,7 +1387,7 @@ class Article { wfMsgNoTrans( 'missingarticle-rev', $oldid ) ); } elseif ( $this->mTitle->getNamespace() === NS_MEDIAWIKI ) { // Use the default message text - $text = $this->getContent(); + $text = $this->mTitle->getDefaultMessageText(); } else { $createErrors = $this->mTitle->getUserPermissionsErrors( 'create', $wgUser ); $editErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser ); @@ -1562,13 +1561,12 @@ class Article { $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png'; $alt = $wgContLang->isRTL() ? '←' : '→'; // Automatically append redirect=no to each link, since most of them are redirect pages themselves. - // FIXME: where this happens? foreach ( $target as $rt ) { $link .= Html::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) ); if ( $forceKnown ) { - $link .= $sk->linkKnown( $rt, htmlspecialchars( $rt->getFullText() ) ); + $link .= $sk->linkKnown( $rt, htmlspecialchars( $rt->getFullText(), array(), array( 'redirect' => 'no' ) ) ); } else { - $link .= $sk->link( $rt, htmlspecialchars( $rt->getFullText() ) ); + $link .= $sk->link( $rt, htmlspecialchars( $rt->getFullText() ), array(), array( 'redirect' => 'no' ) ); } } @@ -1709,15 +1707,13 @@ class Article { } if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { - global $wgMessageCache; - if ( $this->getID() == 0 ) { $text = false; } else { $text = $this->getRawText(); } - $wgMessageCache->replace( $this->mTitle->getDBkey(), $text ); + MessageCache::singleton()->replace( $this->mTitle->getDBkey(), $text ); } } @@ -1754,7 +1750,7 @@ class Article { if ( $affected ) { $newid = $dbw->insertId(); - $this->mTitle->resetArticleId( $newid ); + $this->mTitle->resetArticleID( $newid ); } wfProfileOut( __METHOD__ ); @@ -1766,7 +1762,7 @@ class Article { * * @param $dbw DatabaseBase: object * @param $revision Revision: For ID number, and text used to set - length and redirect status fields + length and redirect status fields * @param $lastRevision Integer: 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 @@ -1832,25 +1828,25 @@ class Article { // Delete if changing from redirect to non-redirect $isRedirect = !is_null( $redirectTitle ); - if ( $isRedirect || is_null( $lastRevIsRedirect ) || $lastRevIsRedirect !== $isRedirect ) { - wfProfileIn( __METHOD__ ); - if ( $isRedirect ) { - $this->insertRedirectEntry( $redirectTitle ); - } else { - // This is not a redirect, remove row from redirect table - $where = array( 'rd_from' => $this->getId() ); - $dbw->delete( 'redirect', $where, __METHOD__ ); - } + if ( !$isRedirect && !is_null( $lastRevIsRedirect ) && $lastRevIsRedirect === $isRedirect ) { + return true; + } - if ( $this->getTitle()->getNamespace() == NS_FILE ) { - RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() ); - } - wfProfileOut( __METHOD__ ); + wfProfileIn( __METHOD__ ); + if ( $isRedirect ) { + $this->insertRedirectEntry( $redirectTitle ); + } else { + // This is not a redirect, remove row from redirect table + $where = array( 'rd_from' => $this->getId() ); + $dbw->delete( 'redirect', $where, __METHOD__ ); + } - return ( $dbw->affectedRows() != 0 ); + if ( $this->getTitle()->getNamespace() == NS_FILE ) { + RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() ); } + wfProfileOut( __METHOD__ ); - return true; + return ( $dbw->affectedRows() != 0 ); } /** @@ -1914,6 +1910,7 @@ class Article { if ( !$rev ) { wfDebug( "Article::replaceSection asked for bogus section (page: " . $this->getId() . "; section: $section; edittime: $edittime)\n" ); + wfProfileOut( __METHOD__ ); return null; } @@ -1937,76 +1934,6 @@ class Article { return $text; } - /** - * This function is not deprecated until somebody fixes the core not to use - * it. Nevertheless, use Article::doEdit() instead. - * @deprecated @since 1.7 - */ - function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC = false, $comment = false, $bot = false ) { - $flags = EDIT_NEW | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY | - ( $isminor ? EDIT_MINOR : 0 ) | - ( $suppressRC ? EDIT_SUPPRESS_RC : 0 ) | - ( $bot ? EDIT_FORCE_BOT : 0 ); - - # If this is a comment, add the summary as headline - if ( $comment && $summary != "" ) { - $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $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 @since 1.7 use Article::doEdit() - */ - function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) { - $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY | - ( $minor ? EDIT_MINOR : 0 ) | - ( $forceBot ? EDIT_FORCE_BOT : 0 ); - - $status = $this->doEdit( $text, $summary, $flags ); - - if ( !$status->isOK() ) { - return false; - } - - $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(); - } - } - - $extraQuery = ''; // Give extensions a chance to modify URL query on update - wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraQuery ) ); - - $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraQuery ); - return true; - } - /** * Check flags and add EDIT_NEW or EDIT_UPDATE to them as needed. * @param $flags Int @@ -2096,12 +2023,12 @@ class Article { $flags & EDIT_MINOR, null, null, &$flags, &$status ) ) ) { wfDebug( __METHOD__ . ": ArticleSave hook aborted save!\n" ); - wfProfileOut( __METHOD__ ); if ( $status->isOK() ) { $status->fatal( 'edit-hook-aborted' ); } + wfProfileOut( __METHOD__ ); return $status; } @@ -2268,6 +2195,8 @@ class Article { $revisionId = $revision->insertOn( $dbw ); $this->mTitle->resetArticleID( $newid ); + # Update the LinkCache. Resetting the Title ArticleID means it will rely on having that already cached (FIXME?) + LinkCache::singleton()->addGoodLinkObj( $newid, $this->mTitle, strlen( $text ), (bool)Title::newFromRedirect( $text ), $revisionId ); # Update the page record with revision data $this->updateRevisionOn( $dbw, $revision, 0 ); @@ -2427,6 +2356,9 @@ class Article { /** * Add this page to $wgUser's watchlist + * + * This is safe to be called multiple times + * * @return bool true on successful watch operation */ public function doWatch() { @@ -2610,9 +2542,9 @@ class Article { $protect_description = ''; foreach ( $limit as $action => $restrictions ) { if ( !isset( $expiry[$action] ) ) - $expiry[$action] = Block::infinity(); + $expiry[$action] = $dbw->getInfinity(); - $encodedExpiry[$action] = Block::encodeExpiry( $expiry[$action], $dbw ); + $encodedExpiry[$action] = $dbw->encodeExpiry( $expiry[$action] ); if ( $restrictions != '' ) { $protect_description .= "[$action=$restrictions] ("; if ( $encodedExpiry[$action] != 'infinity' ) { @@ -2910,7 +2842,10 @@ class Article { //FIXME: lego $wgOut->addHTML( '' . wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) . - wfMsgHtml( 'word-separator' ) . $skin->historyLink() . + wfMsgHtml( 'word-separator' ) . $skin->link( $this->mTitle, + wfMsgHtml( 'history' ), + array( 'rel' => 'archives' ), + array( 'action' => 'history' ) ) . '' ); @@ -3450,7 +3385,7 @@ class Article { $flags |= EDIT_MINOR; } - if ( $bot && ( $wgUser->isAllowed( 'markbotedits' ) || $wgUser->isAllowed( 'bot' ) ) ) { + if ( $bot && ( $wgUser->isAllowedAny( 'markbotedits', 'bot' ) ) ) { $flags |= EDIT_FORCE_BOT; } @@ -3591,11 +3526,18 @@ class Article { global $wgParser; + if( $user === null ) { + global $wgUser; + $user = $wgUser; + } + $popts = ParserOptions::newFromUser( $user ); + wfRunHooks( 'ArticlePrepareTextForEdit', array( $this, $popts ) ); + $edit = (object)array(); $edit->revid = $revid; $edit->newText = $text; - $edit->pst = $this->preSaveTransform( $text, $user ); - $edit->popts = $this->getParserOptions( true ); + $edit->pst = $this->preSaveTransform( $text, $user, $popts ); + $edit->popts = $this->getParserOptions(); $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid ); $edit->oldText = $this->getRawText(); @@ -3620,7 +3562,7 @@ class Article { * @param $user User object: User doing the edit */ public function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true, User $user = null ) { - global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgEnableParserCache; + global $wgDeferredUpdateList, $wgUser, $wgEnableParserCache; wfProfileIn( __METHOD__ ); @@ -3698,7 +3640,7 @@ class Article { } if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { - $wgMessageCache->replace( $shortTitle, $text ); + MessageCache::singleton()->replace( $shortTitle, $text ); } wfProfileOut( __METHOD__ ); @@ -3871,10 +3813,12 @@ class Article { * @param $text String article contents * @param $user User object: user doing the edit, $wgUser will be used if * null is given + * @param $popts ParserOptions object: parser options, default options for + * the user loaded if null given * @return string article contents with altered wikitext markup (signatures * converted, {{subst:}}, templates, etc.) */ - public function preSaveTransform( $text, User $user = null ) { + public function preSaveTransform( $text, User $user = null, ParserOptions $popts = null ) { global $wgParser; if ( $user === null ) { @@ -3882,7 +3826,11 @@ class Article { $user = $wgUser; } - return $wgParser->preSaveTransform( $text, $this->mTitle, $user, ParserOptions::newFromUser( $user ) ); + if ( $popts === null ) { + $popts = ParserOptions::newFromUser( $user ); + } + + return $wgParser->preSaveTransform( $text, $this->mTitle, $user, $popts ); } /* Caching functions */ @@ -4033,8 +3981,6 @@ class Article { * Clears caches when article is deleted */ public static function onArticleDelete( $title ) { - global $wgMessageCache; - # Update existence markers on article/talk tabs... if ( $title->isTalkPage() ) { $other = $title->getSubjectPage(); @@ -4053,7 +3999,7 @@ class Article { # Messages if ( $title->getNamespace() == NS_MEDIAWIKI ) { - $wgMessageCache->replace( $title->getDBkey(), false ); + MessageCache::singleton()->replace( $title->getDBkey(), false ); } # Images @@ -4128,7 +4074,7 @@ class Article { if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { // This doesn't quite make sense; the user is asking for // information about the _page_, not the message... -- RC - $wgOut->addHTML( htmlspecialchars( wfMsgWeirdKey( $this->mTitle->getText() ) ) ); + $wgOut->addHTML( htmlspecialchars( $this->mTitle->getDefaultMessageText() ) ); } else { $msg = $wgUser->isLoggedIn() ? 'noarticletext' @@ -4376,23 +4322,15 @@ class Article { /** * Get parser options suitable for rendering the primary article wikitext - * @param $canonical boolean Determines that the generated must not depend on user preferences (see bug 14404) * @return mixed ParserOptions object or boolean false */ - public function getParserOptions( $canonical = false ) { - global $wgUser, $wgLanguageCode; - - if ( !$this->mParserOptions || $canonical ) { - $user = !$canonical ? $wgUser : new User; - $parserOptions = new ParserOptions( $user ); - $parserOptions->setTidy( true ); - $parserOptions->enableLimitReport(); - - if ( $canonical ) { - $parserOptions->setUserLang( $wgLanguageCode ); # Must be set explicitely - return $parserOptions; - } - $this->mParserOptions = $parserOptions; + public function getParserOptions() { + global $wgUser; + + if ( !$this->mParserOptions ) { + $this->mParserOptions = new ParserOptions( $wgUser ); + $this->mParserOptions->setTidy( true ); + $this->mParserOptions->enableLimitReport(); } // Clone to allow modifications of the return value without affecting @@ -4522,7 +4460,7 @@ class Article { * @since 1.16 (r52326) for LiquidThreads * * @param $oldid mixed integer Revision ID or null - * @return ParserOutput + * @return ParserOutput or false if the given revsion ID is not found */ public function getParserOutput( $oldid = null ) { global $wgEnableParserCache, $wgUser; @@ -4539,19 +4477,25 @@ class Article { wfIncrStats( 'pcache_miss_stub' ); } - $parserOutput = false; if ( $useParserCache ) { $parserOutput = ParserCache::singleton()->get( $this, $this->getParserOptions() ); + if ( $parserOutput !== false ) { + return $parserOutput; + } } - if ( $parserOutput === false ) { - // Cache miss; parse and output it. - $rev = Revision::newFromTitle( $this->getTitle(), $oldid ); - - return $this->getOutputFromWikitext( $rev->getText(), $useParserCache ); + // Cache miss; parse and output it. + if ( $oldid === null ) { + $text = $this->getRawText(); } else { - return $parserOutput; + $rev = Revision::newFromTitle( $this->getTitle(), $oldid ); + if ( $rev === null ) { + return false; + } + $text = $rev->getText(); } + + return $this->getOutputFromWikitext( $text, $useParserCache ); } }