mTitle =& $title; $this->mOldId = $oldId; $this->clear(); } /** * Tell the page view functions that this view was redirected * from another page on the wiki. * @param $from Title object. */ function setRedirectedFrom( $from ) { $this->mRedirectedFrom = $from; } /** * If this page is a redirect, get its target * * The target will be fetched from the redirect table if possible. * If this page doesn't have an entry there, call insertRedirect() * @return mixed Title object, or null if this page is not a redirect */ public function getRedirectTarget() { if(!$this->mTitle || !$this->mTitle->isRedirect()) return null; if(!is_null($this->mRedirectTarget)) return $this->mRedirectTarget; # Query the redirect table $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('redirect', array('rd_namespace', 'rd_title'), array('rd_from' => $this->getID()), __METHOD__ ); $row = $dbr->fetchObject($res); if($row) return $this->mRedirectTarget = Title::makeTitle($row->rd_namespace, $row->rd_title); # This page doesn't have an entry in the redirect table return $this->mRedirectTarget = $this->insertRedirect(); } /** * Insert an entry for this page into the redirect table. * * Don't call this function directly unless you know what you're doing. * @return Title object */ public function insertRedirect() { $retval = Title::newFromRedirect($this->getContent()); if(!$retval) return null; $dbw = wfGetDB(DB_MASTER); $dbw->replace('redirect', array('rd_from'), array( 'rd_from' => $this->getID(), 'rd_namespace' => $retval->getNamespace(), 'rd_title' => $retval->getDBKey() ), __METHOD__); return $retval; } /** * Get the Title object this page redirects to * * @return mixed false, Title of in-wiki target, or string with URL */ public function followRedirect() { $text = $this->getContent(); return self::followRedirectText( $text ); } /** * Get the Title object this text redirects to * * @return mixed false, Title of in-wiki target, or string with URL */ public function followRedirectText( $text ) { $rt = Title::newFromRedirect( $text ); # process if title object is valid and not special:userlogout if( $rt ) { if( $rt->getInterwiki() != '' ) { if( $rt->isLocal() ) { // Offsite wikis need an HTTP redirect. // // This can be hard to reverse and may produce loops, // so they may be disabled in the site configuration. $source = $this->mTitle->getFullURL( 'redirect=no' ); return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) ); } } else { if( $rt->getNamespace() == NS_SPECIAL ) { // Gotta handle redirects to special pages differently: // Fill the HTTP response "Location" header and ignore // the rest of the page we're on. // // This can be hard to reverse, so they may be disabled. if( $rt->isSpecial( 'Userlogout' ) ) { // rolleyes } else { return $rt->getFullURL(); } } return $rt; } } // No or invalid redirect return false; } /** * get the title object of the article */ function getTitle() { return $this->mTitle; } /** * Clear the object * @private */ function clear() { $this->mDataLoaded = false; $this->mContentLoaded = false; $this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded $this->mRedirectedFrom = null; # Title object if set $this->mRedirectTarget = null; # Title object if set $this->mUserText = $this->mTimestamp = $this->mComment = ''; $this->mGoodAdjustment = $this->mTotalAdjustment = 0; $this->mTouched = '19700101000000'; $this->mForUpdate = false; $this->mIsRedirect = false; $this->mRevIdFetched = 0; $this->mRedirectUrl = false; $this->mLatest = false; $this->mPreparedEdit = false; } /** * Note that getContent/loadContent do not follow redirects anymore. * If you need to fetch redirectable content easily, try * the shortcut in Article::followContent() * FIXME * @todo There are still side-effects in this! * In general, you should use the Revision class, not Article, * to fetch text for purposes other than page views. * * @return Return the text of this revision */ function getContent() { global $wgUser, $wgOut, $wgMessageCache; wfProfileIn( __METHOD__ ); if ( 0 == $this->getID() ) { wfProfileOut( __METHOD__ ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { $wgMessageCache->loadAllMessages(); $ret = wfMsgWeirdKey ( $this->mTitle->getText() ) ; } else { $ret = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' ); } return "
and don't parse $m = array(); preg_match( '!\.(css|js)$!u', $this->mTitle->getText(), $m ); $wgOut->addHtml( "\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(); } if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { global $wgMessageCache; if ( $this->getID() == 0 ) { $text = false; } else { $text = $this->getContent(); } $wgMessageCache->replace( $this->mTitle->getDBkey(), $text ); } $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 * @return int The newly created page_id key * @private */ function insertOn( $dbw ) { 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' => '', '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. * @param bool $lastRevIsRedirect If given, will optimize adding and * removing rows in redirect table. * @return bool true on success, false on failure * @private */ function updateRevisionOn( &$dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null ) { wfProfileIn( __METHOD__ ); $text = $revision->getText(); $rt = Title::newFromRedirect( $text ); $conditions = array( 'page_id' => $this->getId() ); if( !is_null( $lastRevision ) ) { # An extra check against threads stepping on each other $conditions['page_latest'] = $lastRevision; } $dbw->update( 'page', array( /* SET */ 'page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp(), 'page_is_new' => ($lastRevision === 0) ? 1 : 0, 'page_is_redirect' => $rt !== NULL ? 1 : 0, 'page_len' => strlen( $text ), ), $conditions, __METHOD__ ); $result = $dbw->affectedRows() != 0; if ($result) { $this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect ); } wfProfileOut( __METHOD__ ); return $result; } /** * Add row to the redirect table if this is a redirect, remove otherwise. * * @param Database $dbw * @param $redirectTitle a title object pointing to the redirect target, * or NULL if this is not a redirect * @param bool $lastRevIsRedirect If given, will optimize adding and * removing rows in redirect table. * @return bool true on success, false on failure * @private */ function updateRedirectOn( &$dbw, $redirectTitle, $lastRevIsRedirect = null ) { // Always update redirects (target link might have changed) // Update/Insert if we don't know if the last revision was a redirect or not // Delete if changing from redirect to non-redirect $isRedirect = !is_null($redirectTitle); if ($isRedirect || is_null($lastRevIsRedirect) || $lastRevIsRedirect !== $isRedirect) { wfProfileIn( __METHOD__ ); if ($isRedirect) { // This title is a redirect, Add/Update row in the redirect table $set = array( /* SET */ 'rd_namespace' => $redirectTitle->getNamespace(), 'rd_title' => $redirectTitle->getDBkey(), 'rd_from' => $this->getId(), ); $dbw->replace( 'redirect', array( 'rd_from' ), $set, __METHOD__ ); } else { // This is not a redirect, remove row from redirect table $where = array( 'rd_from' => $this->getId() ); $dbw->delete( 'redirect', $where, __METHOD__); } if( $this->getTitle()->getNamespace() == NS_IMAGE ) RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() ); wfProfileOut( __METHOD__ ); return ( $dbw->affectedRows() != 0 ); } return true; } /** * 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', 'page_is_redirect' ), 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; $lastRevIsRedirect = (bool)$row->page_is_redirect; } else { # No or missing previous revision; mark the page as new $prev = 0; $lastRevIsRedirect = null; } $ret = $this->updateRevisionOn( $dbw, $revision, $prev, $lastRevIsRedirect ); 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' ) { # Inserting a new section $subject = $summary ? wfMsgForContent('newsectionheaderdefaultlevel',$summary) . "\n\n" : ''; $text = strlen( trim( $oldtext ) ) > 0 ? "{$oldtext}\n\n{$subject}{$text}" : "{$subject}{$text}"; } else { # Replacing an existing section; roll out the big guns 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, $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 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 ); $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(); } } $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 $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 * EDIT_AUTOSUMMARY * Fill in blank summaries with generated text where possible * * 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. * @param $baseRevId, the revision ID this edit was based off, if any * * @return bool success */ function doEdit( $text, $summary, $flags = 0, $baseRevId = false ) { global $wgUser, $wgDBtransactions, $wgUseAutomaticEditSummaries; 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 = $flags & EDIT_FORCE_BOT; $oldtext = $this->getContent(); $oldsize = strlen( $oldtext ); # Provide autosummaries if one is not provided and autosummaries are enabled. if( $wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY && $summary == '' ) { $summary = $this->getAutosummary( $oldtext, $text, $flags ); } $editInfo = $this->prepareTextForEdit( $text ); $text = $editInfo->pst; $newsize = strlen( $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 ); } $lastRevision = 0; $revisionId = 0; $changed = ( strcmp( $text, $oldtext ) != 0 ); if ( $changed ) { $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, 'parent_id' => $lastRevision ) ); $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 { wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId ) ); # 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 if( $GLOBALS['wgUseRCPatrol'] && $wgUser->isAllowed( 'autopatrol' ) ) { RecentChange::markPatrolled( $rcid ); PatrolLog::record( $rcid, true ); } } $wgUser->incEditCount(); $dbw->commit(); } } else { $revision = null; // 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. $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 ); wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, false) ); 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 if( ($GLOBALS['wgUseRCPatrol'] || $GLOBALS['wgUseNPPatrol']) && $wgUser->isAllowed( 'autopatrol' ) ) { RecentChange::markPatrolled( $rcid ); PatrolLog::record( $rcid, true ); } } $wgUser->incEditCount(); $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, $revision ) ); } if ( $good && !( $flags & EDIT_DEFER_UPDATES ) ) { wfDoUpdates(); } if ( $good ) { wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text, $summary, $flags & EDIT_MINOR, null, null, &$flags, $revision ) ); } 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 "#" * @param string $extraQuery, extra query params */ function doRedirect( $noRedir = false, $sectionAnchor = '', $extraQuery = '' ) { global $wgOut; if ( $noRedir ) { $query = 'redirect=no'; if( $extraQuery ) $query .= "&$query"; } else { $query = $extraQuery; } $wgOut->redirect( $this->mTitle->getFullURL( $query ) . $sectionAnchor ); } /** * Mark this particular edit/page as patrolled */ function markpatrolled() { global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUseNPPatrol, $wgUser; $wgOut->setRobotPolicy( 'noindex,nofollow' ); # Check patrol config options if ( !($wgUseNPPatrol || $wgUseRCPatrol)) { $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' ); return; } # If we haven't been given an rc_id value, we can't do anything $rcid = (int) $wgRequest->getVal('rcid'); $rc = $rcid ? RecentChange::newFromId($rcid) : null; if ( is_null ( $rc ) ) { $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' ); return; } if ( !$wgUseRCPatrol && $rc->getAttribute( 'rc_type' ) != RC_NEW) { // Only new pages can be patrolled if the general patrolling is off....??? // @fixme -- is this necessary? Shouldn't we only bother controlling the // front end here? $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' ); return; } # Check permissions $permission_errors = $this->mTitle->getUserPermissionsErrors( 'patrol', $wgUser ); if (count($permission_errors)>0) { $wgOut->showPermissionsErrorPage( $permission_errors ); return; } # Handle the 'MarkPatrolled' hook if( !wfRunHooks( 'MarkPatrolled', array( $rcid, &$wgUser, false ) ) ) { return; } #It would be nice to see where the user had actually come from, but for now just guess $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges'; $return = Title::makeTitle( NS_SPECIAL, $returnto ); # If it's left up to us, check that the user is allowed to patrol this edit # If the user has the "autopatrol" right, then we'll assume there are no # other conditions stopping them doing so if( !$wgUser->isAllowed( 'autopatrol' ) ) { $rc = RecentChange::newFromId( $rcid ); # Graceful error handling, as we've done before here... # (If the recent change doesn't exist, then it doesn't matter whether # the user is allowed to patrol it or not; nothing is going to happen if( is_object( $rc ) && $wgUser->getName() == $rc->getAttribute( 'rc_user_text' ) ) { # The user made this edit, and can't patrol it # Tell them so, and then back off $wgOut->setPageTitle( wfMsg( 'markedaspatrollederror' ) ); $wgOut->addWikiMsg( 'markedaspatrollederror-noautopatrol' ); $wgOut->returnToMain( false, $return ); return; } } # Check that the revision isn't patrolled already # Prevents duplicate log entries if( !$rc->getAttribute( 'rc_patrolled' ) ) { # Mark the edit as patrolled RecentChange::markPatrolled( $rcid ); PatrolLog::record( $rcid ); wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) ); } # Inform the user $wgOut->setPageTitle( wfMsg( 'markedaspatrolled' ) ); $wgOut->addWikiMsg( 'markedaspatrolledtext' ); $wgOut->returnToMain( false, $return ); } /** * User-interface handler for the "watch" action */ function watch() { global $wgUser, $wgOut; if ( $wgUser->isAnon() ) { $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' ); return; } if ( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } if( $this->doWatch() ) { $wgOut->setPagetitle( wfMsg( 'addedwatch' ) ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); $wgOut->addWikiMsg( 'addedwatchtext', $this->mTitle->getPrefixedText() ); } $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() ); } /** * Add this page to $wgUser's watchlist * @return bool true on successful watch operation */ function doWatch() { global $wgUser; if( $wgUser->isAnon() ) { return false; } if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) { $wgUser->addWatch( $this->mTitle ); return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this)); } return false; } /** * User interface handler for the "unwatch" action. */ function unwatch() { global $wgUser, $wgOut; if ( $wgUser->isAnon() ) { $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' ); return; } if ( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } if( $this->doUnwatch() ) { $wgOut->setPagetitle( wfMsg( 'removedwatch' ) ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); $wgOut->addWikiMsg( 'removedwatchtext', $this->mTitle->getPrefixedText() ); } $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() ); } /** * Stop watching a page * @return bool true on successful unwatch */ function doUnwatch() { global $wgUser; if( $wgUser->isAnon() ) { return false; } if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) { $wgUser->removeWatch( $this->mTitle ); return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this)); } return false; } /** * action=protect handler */ function protect() { $form = new ProtectionForm( $this ); $form->execute(); } /** * action=unprotect handler (alias) */ function unprotect() { $this->protect(); } /** * Update the article's restriction field, and leave a log entry. * * @param array $limit set of restriction keys * @param string $reason * @return bool true on success */ function updateRestrictions( $limit = array(), $reason = '', $cascade = 0, $expiry = null ) { global $wgUser, $wgRestrictionTypes, $wgContLang; $id = $this->mTitle->getArticleID(); if( array() != $this->mTitle->getUserPermissionsErrors( 'protect', $wgUser ) || wfReadOnly() || $id == 0 ) { return false; } if (!$cascade) { $cascade = false; } // Take this opportunity to purge out expired restrictions Title::purgeExpiredRestrictions(); # FIXME: Same limitations as described in ProtectionForm.php (line 37); # we expect a single selection, but the schema allows otherwise. $current = array(); foreach( $wgRestrictionTypes as $action ) $current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) ); $current = Article::flattenRestrictions( $current ); $updated = Article::flattenRestrictions( $limit ); $changed = ( $current != $updated ); $changed = $changed || ($updated && $this->mTitle->areRestrictionsCascading() != $cascade); $changed = $changed || ($updated && $this->mTitle->mRestrictionsExpiry != $expiry); $protect = ( $updated != '' ); # If nothing's changed, do nothing if( $changed ) { global $wgGroupPermissions; if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) { $dbw = wfGetDB( DB_MASTER ); $encodedExpiry = Block::encodeExpiry($expiry, $dbw ); $expiry_description = ''; if ( $encodedExpiry != 'infinity' ) { $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry, false, false ) ).')'; } # Prepare a null revision to be added to the history $modified = $current != '' && $protect; if ( $protect ) { $comment_type = $modified ? 'modifiedarticleprotection' : 'protectedarticle'; } else { $comment_type = 'unprotectedarticle'; } $comment = $wgContLang->ucfirst( wfMsgForContent( $comment_type, $this->mTitle->getPrefixedText() ) ); # Only restrictions with the 'protect' right can cascade... # Otherwise, people who cannot normally protect can "protect" pages via transclusion foreach( $limit as $action => $restriction ) { # FIXME: can $restriction be an array or what? (same as fixme above) if( $restriction != 'protect' && $restriction != 'sysop' ) { $cascade = false; break; } } $cascade_description = ''; if ($cascade) { $cascade_description = ' ['.wfMsg('protect-summary-cascade').']'; } if( $reason ) $comment .= ": $reason"; if( $protect ) $comment .= " [$updated]"; if ( $expiry_description && $protect ) $comment .= "$expiry_description"; if ( $cascade ) $comment .= "$cascade_description"; # Update restrictions table foreach( $limit as $action => $restrictions ) { if ($restrictions != '' ) { $dbw->replace( 'page_restrictions', array(array('pr_page', 'pr_type')), array( 'pr_page' => $id, 'pr_type' => $action , 'pr_level' => $restrictions, 'pr_cascade' => $cascade ? 1 : 0 , 'pr_expiry' => $encodedExpiry ), __METHOD__ ); } else { $dbw->delete( 'page_restrictions', array( 'pr_page' => $id, 'pr_type' => $action ), __METHOD__ ); } } # Insert a null revision $nullRevision = Revision::newNullRevision( $dbw, $id, $comment, true ); $nullRevId = $nullRevision->insertOn( $dbw ); # Update page record $dbw->update( 'page', array( /* SET */ 'page_touched' => $dbw->timestamp(), 'page_restrictions' => '', 'page_latest' => $nullRevId ), array( /* WHERE */ 'page_id' => $id ), 'Article::protect' ); wfRunHooks( 'NewRevisionFromEditComplete', array($this, $nullRevision, false) ); wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) ); # Update the protection log $log = new LogPage( 'protect' ); if( $protect ) { $log->addEntry( $modified ? 'modify' : 'protect', $this->mTitle, trim( $reason . " [$updated]$cascade_description$expiry_description" ) ); } else { $log->addEntry( 'unprotect', $this->mTitle, $reason ); } } # End hook } # End "changed" check return true; } /** * Take an array of page restrictions and flatten it to a string * suitable for insertion into the page_restrictions field. * @param array $limit * @return string * @private */ function flattenRestrictions( $limit ) { if( !is_array( $limit ) ) { throw new MWException( 'Article::flattenRestrictions given non-array restriction set' ); } $bits = array(); ksort( $limit ); foreach( $limit as $action => $restrictions ) { if( $restrictions != '' ) { $bits[] = "$action=$restrictions"; } } return implode( ':', $bits ); } /** * Auto-generates a deletion reason * @param bool &$hasHistory Whether the page has a history */ public function generateReason(&$hasHistory) { global $wgContLang; $dbw = wfGetDB(DB_MASTER); // Get the last revision $rev = Revision::newFromTitle($this->mTitle); if(is_null($rev)) return false; // Get the article's contents $contents = $rev->getText(); $blank = false; // If the page is blank, use the text from the previous revision, // which can only be blank if there's a move/import/protect dummy revision involved if($contents == '') { $prev = $rev->getPrevious(); if($prev) { $contents = $prev->getText(); $blank = true; } } // Find out if there was only one contributor // Only scan the last 20 revisions $limit = 20; $res = $dbw->select('revision', 'rev_user_text', array('rev_page' => $this->getID()), __METHOD__, array('LIMIT' => $limit)); if($res === false) // This page has no revisions, which is very weird return false; if($res->numRows() > 1) $hasHistory = true; else $hasHistory = false; $row = $dbw->fetchObject($res); $onlyAuthor = $row->rev_user_text; // Try to find a second contributor while( $row = $dbw->fetchObject($res) ) { if($row->rev_user_text != $onlyAuthor) { $onlyAuthor = false; break; } } $dbw->freeResult($res); // Generate the summary with a '$1' placeholder if($blank) { // The current revision is blank and the one before is also // blank. It's just not our lucky day $reason = wfMsgForContent('exbeforeblank', '$1'); } else { if($onlyAuthor) $reason = wfMsgForContent('excontentauthor', '$1', $onlyAuthor); else $reason = wfMsgForContent('excontent', '$1'); } // Replace newlines with spaces to prevent uglyness $contents = preg_replace("/[\n\r]/", ' ', $contents); // Calculate the maximum amount of chars to get // Max content length = max comment length - length of the comment (excl. $1) - '...' $maxLength = 255 - (strlen($reason) - 2) - 3; $contents = $wgContLang->truncate($contents, $maxLength, '...'); // Remove possible unfinished links $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents ); // Now replace the '$1' placeholder $reason = str_replace( '$1', $contents, $reason ); return $reason; } /* * UI entry point for page deletion */ function delete() { global $wgUser, $wgOut, $wgRequest; $confirm = $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ); $this->DeleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' ); $this->DeleteReason = $wgRequest->getText( 'wpReason' ); $reason = $this->DeleteReasonList; if ( $reason != 'other' && $this->DeleteReason != '') { // Entry from drop down menu + additional comment $reason .= ': ' . $this->DeleteReason; } elseif ( $reason == 'other' ) { $reason = $this->DeleteReason; } # Flag to hide all contents of the archived revisions $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed('suppressrevision'); # This code desperately needs to be totally rewritten # Read-only check... if ( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } # Check permissions $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser ); if (count($permission_errors)>0) { $wgOut->showPermissionsErrorPage( $permission_errors ); return; } $wgOut->setPagetitle( wfMsg( 'delete-confirm', $this->mTitle->getPrefixedText() ) ); # Better double-check that it hasn't been deleted yet! $dbw = wfGetDB( DB_MASTER ); $conds = $this->mTitle->pageCond(); $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ ); if ( $latest === false ) { $wgOut->showFatalError( wfMsg( 'cannotdelete' ) ); return; } # Hack for big sites $bigHistory = $this->isBigDeletion(); if( $bigHistory && !$this->mTitle->userCan( 'bigdelete' ) ) { global $wgLang, $wgDeleteRevisionsLimit; $wgOut->wrapWikiMsg( "\n" ); $wgOut->addHtml( htmlspecialchars( $this->mContent ) ); $wgOut->addHtml( "\n\n" ); } } else if ( $rt = Title::newFromRedirect( $text ) ) { # Don't append the subtitle if this was an old revision $this->viewRedirect( $rt, !$wasRedirected && $this->isCurrent() ); $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser)); $wgOut->addParserOutputNoText( $parseout ); } else if ( $pcache ) { # Display content and save to parser cache $this->outputWikiText( $text ); } else { # Display content, don't attempt to save to parser cache # Don't show section-edit links on old revisions... this way lies madness. if( !$this->isCurrent() ) { $oldEditSectionSetting = $wgOut->parserOptions()->setEditSection( false ); } # Display content and don't save to parser cache # With timing hack -- TS 2006-07-26 $time = -wfTime(); $this->outputWikiText( $text, false ); $time += wfTime(); # Timing hack if ( $time > 3 ) { wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time, $this->mTitle->getPrefixedDBkey())); } if( !$this->isCurrent() ) { $wgOut->parserOptions()->setEditSection( $oldEditSectionSetting ); } } } /* title may have been set from the cache */ $t = $wgOut->getPageTitle(); if( empty( $t ) ) { $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); } # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page if( $ns == NS_USER_TALK && IP::isValid( $this->mTitle->getText() ) ) { $wgOut->addWikiMsg('anontalkpagetext'); } # If we have been passed an &rcid= parameter, we want to give the user a # chance to mark this new article as patrolled. if( !is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) && $this->mTitle->exists() ) { $wgOut->addHTML( "" . wfMsgHtml( 'markaspatrolledlink', $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" ) ) . '' ); } # Trackbacks if ($wgUseTrackbacks) $this->addTrackbacks(); $this->viewUpdates(); wfProfileOut( __METHOD__ ); } /* * Should the parser cache be used? */ protected function useParserCache( $oldid ) { global $wgUser, $wgEnableParserCache; return $wgEnableParserCache && intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 && $this->exists() && empty( $oldid ) && !$this->mTitle->isCssOrJsPage() && !$this->mTitle->isCssJsSubpage(); } protected function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) { global $wgParser, $wgOut, $wgContLang, $wgStylePath, $wgUser; # Display redirect $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr'; $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png'; if( $appendSubtitle ) { $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) ); } $sk = $wgUser->getSkin(); if ( $forceKnown ) $link = $sk->makeKnownLinkObj( $target, htmlspecialchars( $target->getFullText() ) ); else $link = $sk->makeLinkObj( $target, htmlspecialchars( $target->getFullText() ) ); $wgOut->addHTML( '' . ''.$link.'' ); } function addTrackbacks() { global $wgOut, $wgUser; $dbr = wfGetDB(DB_SLAVE); $tbs = $dbr->select( /* FROM */ 'trackbacks', /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'), /* WHERE */ array('tb_page' => $this->getID()) ); if (!$dbr->numrows($tbs)) return; $tbtext = ""; while ($o = $dbr->fetchObject($tbs)) { $rmvtxt = ""; if ($wgUser->isAllowed( 'trackback' )) { $delurl = $this->mTitle->getFullURL("action=deletetrackback&tbid=" . $o->tb_id . "&token=" . urlencode( $wgUser->editToken() ) ); $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) ); } $tbtext .= "\n"; $tbtext .= wfMsg(strlen($o->tb_ex) ? 'trackbackexcerpt' : 'trackback', $o->tb_title, $o->tb_url, $o->tb_ex, $o->tb_name, $rmvtxt); } $wgOut->addWikiMsg( 'trackbackbox', $tbtext ); } function deletetrackback() { global $wgUser, $wgRequest, $wgOut, $wgTitle; if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) { $wgOut->addWikiMsg( 'sessionfailure' ); return; } $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser ); if (count($permission_errors)>0) { $wgOut->showPermissionsErrorPage( $permission_errors ); return; } $db = wfGetDB(DB_MASTER); $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid'))); $wgTitle->invalidateCache(); $wgOut->addWikiMsg('trackbackdeleteok'); } function render() { global $wgOut; $wgOut->setArticleBodyOnly(true); $this->view(); } /** * Handle action=purge */ function purge() { global $wgUser, $wgRequest, $wgOut; if ( $wgUser->isAllowed( 'purge' ) || $wgRequest->wasPosted() ) { if( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) { $this->doPurge(); } } else { $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) ); $action = htmlspecialchars( $_SERVER['REQUEST_URI'] ); $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) ); $msg = str_replace( '$1', "
' . $link . '
'; } $wgOut->addHTML( $form ); $this->showLogExtract( $wgOut ); } /** * Show relevant lines from the deletion log */ function showLogExtract( $out ) { $out->addHtml( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) ); LogEventsList::showLogExtract( $out, 'delete', $this->mTitle->getPrefixedText() ); } /** * Perform a deletion and output success or failure messages */ function doDelete( $reason, $suppress = false ) { global $wgOut, $wgUser; wfDebug( __METHOD__."\n" ); $id = $this->getId(); $error = ''; if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason, &$error))) { if ( $this->doDeleteArticle( $reason, $suppress ) ) { $deleted = $this->mTitle->getPrefixedText(); $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]'; $wgOut->addWikiMsg( 'deletedtext', $deleted, $loglink ); $wgOut->returnToMain( false ); wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason, $id)); } else { if ($error = '') $wgOut->showFatalError( wfMsg( 'cannotdelete' ) ); else $wgOut->showFatalError( $error ); } } } /** * Back-end article deletion * Deletes the article with database consistency, writes logs, purges caches * Returns success */ function doDeleteArticle( $reason, $suppress = false ) { global $wgUseSquid, $wgDeferredUpdateList; global $wgUseTrackbacks; wfDebug( __METHOD__."\n" ); $dbw = wfGetDB( DB_MASTER ); $ns = $this->mTitle->getNamespace(); $t = $this->mTitle->getDBkey(); $id = $this->mTitle->getArticleID(); if ( $t == '' || $id == 0 ) { return false; } $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 ); array_push( $wgDeferredUpdateList, $u ); // Bitfields to further suppress the content if ( $suppress ) { $bitfield = 0; // This should be 15... $bitfield |= Revision::DELETED_TEXT; $bitfield |= Revision::DELETED_COMMENT; $bitfield |= Revision::DELETED_USER; $bitfield |= Revision::DELETED_RESTRICTED; } else { $bitfield = 'rev_deleted'; } $dbw->begin(); // For now, shunt the revision data into the archive table. // Text is *not* removed from the text table; bulk storage // is left intact to avoid breaking block-compression or // immutable storage schemes. // // For backwards compatibility, note that some older archive // table entries will have ar_text and ar_flags fields still. // // In the future, we may keep revisions and mark them with // the rev_deleted field, which is reserved for this purpose. $dbw->insertSelect( 'archive', array( 'page', 'revision' ), array( 'ar_namespace' => 'page_namespace', 'ar_title' => 'page_title', 'ar_comment' => 'rev_comment', 'ar_user' => 'rev_user', 'ar_user_text' => 'rev_user_text', 'ar_timestamp' => 'rev_timestamp', 'ar_minor_edit' => 'rev_minor_edit', 'ar_rev_id' => 'rev_id', 'ar_text_id' => 'rev_text_id', 'ar_text' => '\'\'', // Be explicit to appease 'ar_flags' => '\'\'', // MySQL's "strict mode"... 'ar_len' => 'rev_len', 'ar_page_id' => 'page_id', 'ar_deleted' => $bitfield ), array( 'page_id' => $id, 'page_id = rev_page' ), __METHOD__ ); # Delete restrictions for it $dbw->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__ ); # Fix category table counts $cats = array(); $res = $dbw->select( 'categorylinks', 'cl_to', array( 'cl_from' => $id ), __METHOD__ ); foreach( $res as $row ) { $cats []= $row->cl_to; } $this->updateCategoryCounts( array(), $cats ); # Now that it's safely backed up, delete it $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__); $ok = ( $dbw->affectedRows() > 0 ); // getArticleId() uses slave, could be laggy if( !$ok ) { $dbw->rollback(); return false; } # If using cascading deletes, we can skip some explicit deletes if ( !$dbw->cascadingDeletes() ) { $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ ); if ($wgUseTrackbacks) $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__ ); # Delete outgoing links $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) ); $dbw->delete( 'imagelinks', array( 'il_from' => $id ) ); $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) ); $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) ); $dbw->delete( 'externallinks', array( 'el_from' => $id ) ); $dbw->delete( 'langlinks', array( 'll_from' => $id ) ); $dbw->delete( 'redirect', array( 'rd_from' => $id ) ); } # If using cleanup triggers, we can skip some manual deletes if ( !$dbw->cleanupTriggers() ) { # Clean up recentchanges entries... $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t, 'rc_type != '.RC_LOG ), __METHOD__ ); } $dbw->commit(); # Clear caches Article::onArticleDelete( $this->mTitle ); # Clear the cached article id so the interface doesn't act like we exist $this->mTitle->resetArticleID( 0 ); $this->mTitle->mArticleID = 0; # Log the deletion, if the page was suppressed, log it at Oversight instead $logtype = $suppress ? 'suppress' : 'delete'; $log = new LogPage( $logtype ); # Make sure logging got through $log->addEntry( 'delete', $this->mTitle, $reason, array() ); return true; } /** * Roll back the most recent consecutive set of edits to a page * from the same user; fails if there are no eligible edits to * roll back to, e.g. user is the sole contributor. This function * performs permissions checks on $wgUser, then calls commitRollback() * to do the dirty work * * @param string $fromP - Name of the user whose edits to rollback. * @param string $summary - Custom summary. Set to default summary if empty. * @param string $token - Rollback token. * @param bool $bot - If true, mark all reverted edits as bot. * * @param array $resultDetails contains result-specific array of additional values * 'alreadyrolled' : 'current' (rev) * success : 'summary' (str), 'current' (rev), 'target' (rev) * * @return array of errors, each error formatted as * array(messagekey, param1, param2, ...). * On success, the array is empty. This array can also be passed to * OutputPage::showPermissionsErrorPage(). */ public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails ) { global $wgUser; $resultDetails = null; # Check permissions $errors = array_merge( $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser ), $this->mTitle->getUserPermissionsErrors( 'rollback', $wgUser ) ); if( !$wgUser->matchEditToken( $token, array( $this->mTitle->getPrefixedText(), $fromP ) ) ) $errors[] = array( 'sessionfailure' ); if ( $wgUser->pingLimiter('rollback') || $wgUser->pingLimiter() ) { $errors[] = array( 'actionthrottledtext' ); } # If there were errors, bail out now if(!empty($errors)) return $errors; return $this->commitRollback($fromP, $summary, $bot, $resultDetails); } /** * Backend implementation of doRollback(), please refer there for parameter * and return value documentation * * NOTE: This function does NOT check ANY permissions, it just commits the * rollback to the DB Therefore, you should only call this function direct- * ly if you want to use custom permissions checks. If you don't, use * doRollback() instead. */ public function commitRollback($fromP, $summary, $bot, &$resultDetails) { global $wgUseRCPatrol, $wgUser, $wgLang; $dbw = wfGetDB( DB_MASTER ); if( wfReadOnly() ) { return array( array( 'readonlytext' ) ); } # Get the last editor $current = Revision::newFromTitle( $this->mTitle ); if( is_null( $current ) ) { # Something wrong... no page? return array(array('notanarticle')); } $from = str_replace( '_', ' ', $fromP ); if( $from != $current->getUserText() ) { $resultDetails = array( 'current' => $current ); return array(array('alreadyrolled', htmlspecialchars($this->mTitle->getPrefixedText()), htmlspecialchars($fromP), htmlspecialchars($current->getUserText()) )); } # Get the last edit not by this guy $user = intval( $current->getUser() ); $user_text = $dbw->addQuotes( $current->getUserText() ); $s = $dbw->selectRow( 'revision', array( 'rev_id', 'rev_timestamp', 'rev_deleted' ), array( 'rev_page' => $current->getPage(), "rev_user <> {$user} OR rev_user_text <> {$user_text}" ), __METHOD__, array( 'USE INDEX' => 'page_timestamp', 'ORDER BY' => 'rev_timestamp DESC' ) ); if( $s === false ) { # No one else ever edited this page return array(array('cantrollback')); } else if( $s->rev_deleted & REVISION::DELETED_TEXT || $s->rev_deleted & REVISION::DELETED_USER ) { # Only admins can see this text return array(array('notvisiblerev')); } $set = array(); if ( $bot && $wgUser->isAllowed('markbotedits') ) { # Mark all reverted edits as bot $set['rc_bot'] = 1; } if ( $wgUseRCPatrol ) { # Mark all reverted edits as patrolled $set['rc_patrolled'] = 1; } if ( $set ) { $dbw->update( 'recentchanges', $set, array( /* WHERE */ 'rc_cur_id' => $current->getPage(), 'rc_user_text' => $current->getUserText(), "rc_timestamp > '{$s->rev_timestamp}'", ), __METHOD__ ); } # Generate the edit summary if necessary $target = Revision::newFromId( $s->rev_id ); if( empty( $summary ) ){ $summary = wfMsgForContent( 'revertpage' ); } # Allow the custom summary to use the same args as the default message $args = array( $target->getUserText(), $from, $s->rev_id, $wgLang->timeanddate(wfTimestamp(TS_MW, $s->rev_timestamp), true), $current->getId(), $wgLang->timeanddate($current->getTimestamp()) ); $summary = wfMsgReplaceArgs( $summary, $args ); # Save $flags = EDIT_UPDATE; if ($wgUser->isAllowed('minoredit')) $flags |= EDIT_MINOR; if( $bot && ($wgUser->isAllowed('markbotedits') || $wgUser->isAllowed('bot')) ) $flags |= EDIT_FORCE_BOT; $this->doEdit( $target->getText(), $summary, $flags, $target->getId() ); wfRunHooks( 'ArticleRollbackComplete', array( $this, $wgUser, $target ) ); $resultDetails = array( 'summary' => $summary, 'current' => $current, 'target' => $target, ); return array(); } /** * User interface for rollback operations */ function rollback() { global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol; $details = null; $result = $this->doRollback( $wgRequest->getVal( 'from' ), $wgRequest->getText( 'summary' ), $wgRequest->getVal( 'token' ), $wgRequest->getBool( 'bot' ), $details ); if( in_array( array( 'blocked' ), $result ) ) { $wgOut->blockedPage(); return; } if( in_array( array( 'actionthrottledtext' ), $result ) ) { $wgOut->rateLimited(); return; } if( isset( $result[0][0] ) && ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' ) ){ $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) ); $errArray = $result[0]; $errMsg = array_shift( $errArray ); $wgOut->addWikiMsgArray( $errMsg, $errArray ); if( isset( $details['current'] ) ){ $current = $details['current']; if( $current->getComment() != '' ) { $wgOut->addWikiMsgArray( 'editcomment', array( $wgUser->getSkin()->formatComment( $current->getComment() ) ), array( 'replaceafter' ) ); } } return; } # Display permissions errors before read-only message -- there's no # point in misleading the user into thinking the inability to rollback # is only temporary. if( !empty($result) && $result !== array( array('readonlytext') ) ) { # array_diff is completely broken for arrays of arrays, sigh. Re- # move any 'readonlytext' error manually. $out = array(); foreach( $result as $error ) { if( $error != array( 'readonlytext' ) ) { $out []= $error; } } $wgOut->showPermissionsErrorPage( $out ); return; } if( $result == array( array('readonlytext') ) ) { $wgOut->readOnlyPage(); return; } $current = $details['current']; $target = $details['target']; $wgOut->setPageTitle( wfMsg( 'actioncomplete' ) ); $wgOut->setRobotPolicy( 'noindex,nofollow' ); $old = $wgUser->getSkin()->userLink( $current->getUser(), $current->getUserText() ) . $wgUser->getSkin()->userToolLinks( $current->getUser(), $current->getUserText() ); $new = $wgUser->getSkin()->userLink( $target->getUser(), $target->getUserText() ) . $wgUser->getSkin()->userToolLinks( $target->getUser(), $target->getUserText() ); $wgOut->addHtml( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) ); $wgOut->returnToMain( false, $this->mTitle ); if( !$wgRequest->getBool( 'hidediff', false ) ) { $de = new DifferenceEngine( $this->mTitle, $current->getId(), 'next', false, true ); $de->showDiff( '', '' ); } } /** * Do standard deferred updates after page view * @private */ function viewUpdates() { global $wgDeferredUpdateList, $wgUser; if ( 0 != $this->getID() ) { # Don't update page view counters on views from bot users (bug 14044) global $wgDisableCounters; if( !$wgDisableCounters && !$wgUser->isAllowed( 'bot' ) ) { Article::incViewCount( $this->getID() ); $u = new SiteStatsUpdate( 1, 0, 0 ); array_push( $wgDeferredUpdateList, $u ); } } # Update newtalk / watchlist notification status $wgUser->clearNotification( $this->mTitle ); } /** * Prepare text which is about to be saved. * Returns a stdclass with source, pst and output members */ function prepareTextForEdit( $text, $revid=null ) { if ( $this->mPreparedEdit && $this->mPreparedEdit->newText == $text && $this->mPreparedEdit->revid == $revid) { // Already prepared return $this->mPreparedEdit; } global $wgParser; $edit = (object)array(); $edit->revid = $revid; $edit->newText = $text; $edit->pst = $this->preSaveTransform( $text ); $options = new ParserOptions; $options->setTidy( true ); $options->enableLimitReport(); $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $options, true, true, $revid ); $edit->oldText = $this->getContent(); $this->mPreparedEdit = $edit; return $edit; } /** * Do standard deferred updates after page edit. * Update links tables, site stats, search index and message cache. * Every 100th edit, prune the recent changes table. * * @private * @param $text New text of the article * @param $summary Edit summary * @param $minoredit Minor edit * @param $timestamp_of_pagechange Timestamp associated with the page change * @param $newid rev_id value of the new revision * @param $changed Whether or not the content actually changed */ function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true ) { global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser, $wgEnableParserCache; wfProfileIn( __METHOD__ ); # Parse the text # Be careful not to double-PST: $text is usually already PST-ed once if ( !$this->mPreparedEdit || $this->mPreparedEdit->output->getFlag( 'vary-revision' ) ) { wfDebug( __METHOD__ . ": No prepared edit or vary-revision is set...\n" ); $editInfo = $this->prepareTextForEdit( $text, $newid ); } else { wfDebug( __METHOD__ . ": No vary-revision, using prepared edit...\n" ); $editInfo = $this->mPreparedEdit; } # Save it to the parser cache if ( $wgEnableParserCache ) { $parserCache = ParserCache::singleton(); $parserCache->save( $editInfo->output, $this, $wgUser ); } # Update the links tables $u = new LinksUpdate( $this->mTitle, $editInfo->output ); $u->doUpdate(); if( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) { if ( 0 == mt_rand( 0, 99 ) ) { // Flush old entries from the `recentchanges` table; we do this on // random requests so as to avoid an increase in writes for no good reason 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 ( 0 == $id ) { wfProfileOut( __METHOD__ ); return; } $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment, $this->mTotalAdjustment ); array_push( $wgDeferredUpdateList, $u ); $u = new SearchUpdate( $id, $title, $text ); array_push( $wgDeferredUpdateList, $u ); # If this is another user's talk page, update newtalk # Don't do this if $changed = false otherwise some idiot can null-edit a # load of user talk pages and piss people off, nor if it's a minor edit # by a properly-flagged bot. if( $this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getTitleKey() && $changed && !($minoredit && $wgUser->isAllowed('nominornewtalk') ) ) { if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) { $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 ); } } } if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { $wgMessageCache->replace( $shortTitle, $text ); } wfProfileOut( __METHOD__ ); } /** * Perform article updates on a special page creation. * * @param Revision $rev * * @todo This is a shitty interface function. Kill it and replace the * other shitty functions like editUpdates and such so it's not needed * anymore. */ function createUpdates( $rev ) { $this->mGoodAdjustment = $this->isCountable( $rev->getText() ); $this->mTotalAdjustment = 1; $this->editUpdates( $rev->getText(), $rev->getComment(), $rev->isMinor(), wfTimestamp(), $rev->getId(), true ); } /** * Generate the navigation links when browsing through an article revisions * It shows the information as: * Revision as of \