3 * Abstract class for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
8 * Class representing a MediaWiki article and history.
10 * Some fields are public only for backwards-compatibility. Use accessors.
11 * In the past, this class was part of Article.php and everything was public.
13 * @internal documentation reviewed 15 Mar 2010
15 class WikiPage
extends Page
{
20 public $mTitle = null;
25 public $mCounter = -1; // !< Integer (-1 means "not loaded")
26 public $mDataLoaded = false; // !< Boolean
27 public $mIsRedirect = false; // !< Boolean
28 public $mLatest = false; // !< Boolean
29 public $mPreparedEdit = false; // !< Array
30 public $mRedirectTarget = null; // !< Title object
31 public $mLastRevision = null; // !< Revision object
32 public $mTimestamp = ''; // !< String
33 public $mTouched = '19700101000000'; // !< String
38 * @var ParserOptions: ParserOptions object for $wgUser articles
40 public $mParserOptions;
43 * Constructor and clear the article
44 * @param $title Title Reference to a Title object.
46 public function __construct( Title
$title ) {
47 $this->mTitle
= $title;
51 * Constructor from a page id
53 * Always override this for all subclasses (until we use PHP with LSB)
55 * @param $id Int article ID to load
57 public static function newFromID( $id ) {
58 $t = Title
::newFromID( $id );
59 # @todo FIXME: Doesn't inherit right
60 return $t == null ?
null : new self( $t );
61 # return $t == null ? null : new static( $t ); // PHP 5.3
65 * Returns overrides for action handlers.
66 * Classes listed here will be used instead of the default one when
67 * (and only when) $wgActions[$action] === true. This allows subclasses
68 * to override the default behavior.
72 public function getActionOverrides() {
77 * If this page is a redirect, get its target
79 * The target will be fetched from the redirect table if possible.
80 * If this page doesn't have an entry there, call insertRedirect()
81 * @return Title|mixed object, or null if this page is not a redirect
83 public function getRedirectTarget() {
84 if ( !$this->mTitle
->isRedirect() ) {
88 if ( $this->mRedirectTarget
!== null ) {
89 return $this->mRedirectTarget
;
92 # Query the redirect table
93 $dbr = wfGetDB( DB_SLAVE
);
94 $row = $dbr->selectRow( 'redirect',
95 array( 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ),
96 array( 'rd_from' => $this->getId() ),
100 // rd_fragment and rd_interwiki were added later, populate them if empty
101 if ( $row && !is_null( $row->rd_fragment
) && !is_null( $row->rd_interwiki
) ) {
102 return $this->mRedirectTarget
= Title
::makeTitle(
103 $row->rd_namespace
, $row->rd_title
,
104 $row->rd_fragment
, $row->rd_interwiki
);
107 # This page doesn't have an entry in the redirect table
108 return $this->mRedirectTarget
= $this->insertRedirect();
112 * Insert an entry for this page into the redirect table.
114 * Don't call this function directly unless you know what you're doing.
115 * @return Title object or null if not a redirect
117 public function insertRedirect() {
118 // recurse through to only get the final target
119 $retval = Title
::newFromRedirectRecurse( $this->getRawText() );
123 $this->insertRedirectEntry( $retval );
128 * Insert or update the redirect table entry for this page to indicate
129 * it redirects to $rt .
130 * @param $rt Title redirect target
132 public function insertRedirectEntry( $rt ) {
133 $dbw = wfGetDB( DB_MASTER
);
134 $dbw->replace( 'redirect', array( 'rd_from' ),
136 'rd_from' => $this->getId(),
137 'rd_namespace' => $rt->getNamespace(),
138 'rd_title' => $rt->getDBkey(),
139 'rd_fragment' => $rt->getFragment(),
140 'rd_interwiki' => $rt->getInterwiki(),
147 * Get the Title object or URL this page redirects to
149 * @return mixed false, Title of in-wiki target, or string with URL
151 public function followRedirect() {
152 return $this->getRedirectURL( $this->getRedirectTarget() );
156 * Get the Title object or URL to use for a redirect. We use Title
157 * objects for same-wiki, non-special redirects and URLs for everything
159 * @param $rt Title Redirect target
160 * @return mixed false, Title object of local target, or string with URL
162 public function getRedirectURL( $rt ) {
164 if ( $rt->getInterwiki() != '' ) {
165 if ( $rt->isLocal() ) {
166 // Offsite wikis need an HTTP redirect.
168 // This can be hard to reverse and may produce loops,
169 // so they may be disabled in the site configuration.
170 $source = $this->mTitle
->getFullURL( 'redirect=no' );
171 return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
174 if ( $rt->getNamespace() == NS_SPECIAL
) {
175 // Gotta handle redirects to special pages differently:
176 // Fill the HTTP response "Location" header and ignore
177 // the rest of the page we're on.
179 // This can be hard to reverse, so they may be disabled.
180 if ( $rt->isSpecial( 'Userlogout' ) ) {
183 return $rt->getFullURL();
191 // No or invalid redirect
196 * Get the title object of the article
197 * @return Title object of this page
199 public function getTitle() {
200 return $this->mTitle
;
206 public function clear() {
207 $this->mDataLoaded
= false;
209 $this->mCounter
= -1; # Not loaded
210 $this->mRedirectTarget
= null; # Title object if set
211 $this->mLastRevision
= null; # Latest revision
212 $this->mTimestamp
= '';
213 $this->mTouched
= '19700101000000';
214 $this->mIsRedirect
= false;
215 $this->mLatest
= false;
216 $this->mPreparedEdit
= false;
220 * Get the text that needs to be saved in order to undo all revisions
221 * between $undo and $undoafter. Revisions must belong to the same page,
222 * must exist and must not be deleted
223 * @param $undo Revision
224 * @param $undoafter Revision Must be an earlier revision than $undo
225 * @return mixed string on success, false on failure
227 public function getUndoText( Revision
$undo, Revision
$undoafter = null ) {
228 $cur_text = $this->getRawText();
229 if ( $cur_text === false ) {
230 return false; // no page
232 $undo_text = $undo->getText();
233 $undoafter_text = $undoafter->getText();
235 if ( $cur_text == $undo_text ) {
236 # No use doing a merge if it's just a straight revert.
237 return $undoafter_text;
242 if ( !wfMerge( $undo_text, $undoafter_text, $cur_text, $undone_text ) ) {
250 * Return the list of revision fields that should be selected to create
253 public static function selectFields() {
270 * Fetch a page record with the given conditions
271 * @param $dbr DatabaseBase object
272 * @param $conditions Array
273 * @return mixed Database result resource, or false on failure
275 protected function pageData( $dbr, $conditions ) {
276 $fields = self
::selectFields();
278 wfRunHooks( 'ArticlePageDataBefore', array( &$this, &$fields ) );
280 $row = $dbr->selectRow( 'page', $fields, $conditions, __METHOD__
);
282 wfRunHooks( 'ArticlePageDataAfter', array( &$this, &$row ) );
288 * Fetch a page record matching the Title object's namespace and title
289 * using a sanitized title string
291 * @param $dbr DatabaseBase object
292 * @param $title Title object
293 * @return mixed Database result resource, or false on failure
295 public function pageDataFromTitle( $dbr, $title ) {
296 return $this->pageData( $dbr, array(
297 'page_namespace' => $title->getNamespace(),
298 'page_title' => $title->getDBkey() ) );
302 * Fetch a page record matching the requested ID
304 * @param $dbr DatabaseBase
306 * @return mixed Database result resource, or false on failure
308 public function pageDataFromId( $dbr, $id ) {
309 return $this->pageData( $dbr, array( 'page_id' => $id ) );
313 * Set the general counter, title etc data loaded from
316 * @param $data Object|String $res->fetchObject() object or the string "fromdb" to reload
318 public function loadPageData( $data = 'fromdb' ) {
319 if ( $data === 'fromdb' ) {
320 $dbr = wfGetDB( DB_SLAVE
);
321 $data = $this->pageDataFromTitle( $dbr, $this->mTitle
);
324 $lc = LinkCache
::singleton();
327 $lc->addGoodLinkObj( $data->page_id
, $this->mTitle
, $data->page_len
, $data->page_is_redirect
, $data->page_latest
);
329 $this->mTitle
->loadFromRow( $data );
331 # Old-fashioned restrictions
332 $this->mTitle
->loadRestrictions( $data->page_restrictions
);
334 $this->mCounter
= intval( $data->page_counter
);
335 $this->mTouched
= wfTimestamp( TS_MW
, $data->page_touched
);
336 $this->mIsRedirect
= intval( $data->page_is_redirect
);
337 $this->mLatest
= intval( $data->page_latest
);
339 $lc->addBadLinkObj( $this->mTitle
);
341 $this->mTitle
->loadFromRow( false );
344 $this->mDataLoaded
= true;
348 * @return int Page ID
350 public function getId() {
351 return $this->mTitle
->getArticleID();
355 * @return bool Whether or not the page exists in the database
357 public function exists() {
358 return $this->getId() > 0;
362 * Check if this page is something we're going to be showing
363 * some sort of sensible content for. If we return false, page
364 * views (plain action=view) will return an HTTP 404 response,
365 * so spiders and robots can know they're following a bad link.
369 public function hasViewableContent() {
370 return $this->exists() ||
$this->mTitle
->isAlwaysKnown();
374 * @return int The view count for the page
376 public function getCount() {
377 if ( -1 == $this->mCounter
) {
378 $id = $this->getId();
383 $dbr = wfGetDB( DB_SLAVE
);
384 $this->mCounter
= $dbr->selectField( 'page',
386 array( 'page_id' => $id ),
392 return $this->mCounter
;
396 * Determine whether a page would be suitable for being counted as an
397 * article in the site_stats table based on the title & its content
399 * @param $editInfo Object or false: object returned by prepareTextForEdit(),
400 * if false, the current database state will be used
403 public function isCountable( $editInfo = false ) {
404 global $wgArticleCountMethod;
406 if ( !$this->mTitle
->isContentPage() ) {
410 $text = $editInfo ?
$editInfo->pst
: false;
412 if ( $this->isRedirect( $text ) ) {
416 switch ( $wgArticleCountMethod ) {
420 if ( $text === false ) {
421 $text = $this->getRawText();
423 return strpos( $text, ',' ) !== false;
426 // ParserOutput::getLinks() is a 2D array of page links, so
427 // to be really correct we would need to recurse in the array
428 // but the main array should only have items in it if there are
430 return (bool)count( $editInfo->output
->getLinks() );
432 return (bool)wfGetDB( DB_SLAVE
)->selectField( 'pagelinks', 1,
433 array( 'pl_from' => $this->getId() ), __METHOD__
);
439 * Tests if the article text represents a redirect
441 * @param $text mixed string containing article contents, or boolean
444 public function isRedirect( $text = false ) {
445 if ( $text === false ) {
446 if ( !$this->mDataLoaded
) {
447 $this->loadPageData();
450 return (bool)$this->mIsRedirect
;
452 return Title
::newFromRedirect( $text ) !== null;
457 * Loads everything except the text
458 * This isn't necessary for all uses, so it's only done if needed.
460 protected function loadLastEdit() {
461 if ( $this->mLastRevision
!== null ) {
462 return; // already loaded
465 $latest = $this->getLatest();
467 return; // page doesn't exist or is missing page_latest info
470 $revision = Revision
::newFromPageId( $this->getId(), $latest );
471 if ( $revision ) { // sanity
472 $this->setLastEdit( $revision );
477 * Set the latest revision
479 protected function setLastEdit( Revision
$revision ) {
480 $this->mLastRevision
= $revision;
481 $this->mTimestamp
= $revision->getTimestamp();
485 * Get the latest revision
486 * @return Revision|null
488 public function getRevision() {
489 $this->loadLastEdit();
490 if ( $this->mLastRevision
) {
491 return $this->mLastRevision
;
497 * Get the text of the current revision. No side-effects...
499 * @param $audience Integer: one of:
500 * Revision::FOR_PUBLIC to be displayed to all users
501 * Revision::FOR_THIS_USER to be displayed to $wgUser
502 * Revision::RAW get the text regardless of permissions
503 * @return String|false The text of the current revision
505 public function getText( $audience = Revision
::FOR_PUBLIC
) {
506 $this->loadLastEdit();
507 if ( $this->mLastRevision
) {
508 return $this->mLastRevision
->getText( $audience );
514 * Get the text of the current revision. No side-effects...
516 * @return String|false The text of the current revision
518 public function getRawText() {
519 $this->loadLastEdit();
520 if ( $this->mLastRevision
) {
521 return $this->mLastRevision
->getRawText();
527 * @return string MW timestamp of last article revision
529 public function getTimestamp() {
530 // Check if the field has been filled by ParserCache::get()
531 if ( !$this->mTimestamp
) {
532 $this->loadLastEdit();
534 return wfTimestamp( TS_MW
, $this->mTimestamp
);
538 * Set the page timestamp (use only to avoid DB queries)
539 * @param $ts string MW timestamp of last article revision
542 public function setTimestamp( $ts ) {
543 $this->mTimestamp
= wfTimestamp( TS_MW
, $ts );
547 * @param $audience Integer: one of:
548 * Revision::FOR_PUBLIC to be displayed to all users
549 * Revision::FOR_THIS_USER to be displayed to $wgUser
550 * Revision::RAW get the text regardless of permissions
551 * @return int user ID for the user that made the last article revision
553 public function getUser( $audience = Revision
::FOR_PUBLIC
) {
554 $this->loadLastEdit();
555 if ( $this->mLastRevision
) {
556 return $this->mLastRevision
->getUser( $audience );
563 * @param $audience Integer: one of:
564 * Revision::FOR_PUBLIC to be displayed to all users
565 * Revision::FOR_THIS_USER to be displayed to $wgUser
566 * Revision::RAW get the text regardless of permissions
567 * @return string username of the user that made the last article revision
569 public function getUserText( $audience = Revision
::FOR_PUBLIC
) {
570 $this->loadLastEdit();
571 if ( $this->mLastRevision
) {
572 return $this->mLastRevision
->getUserText( $audience );
579 * @param $audience Integer: one of:
580 * Revision::FOR_PUBLIC to be displayed to all users
581 * Revision::FOR_THIS_USER to be displayed to $wgUser
582 * Revision::RAW get the text regardless of permissions
583 * @return string Comment stored for the last article revision
585 public function getComment( $audience = Revision
::FOR_PUBLIC
) {
586 $this->loadLastEdit();
587 if ( $this->mLastRevision
) {
588 return $this->mLastRevision
->getComment( $audience );
595 * Returns true if last revision was marked as "minor edit"
597 * @return boolean Minor edit indicator for the last article revision.
599 public function getMinorEdit() {
600 $this->loadLastEdit();
601 if ( $this->mLastRevision
) {
602 return $this->mLastRevision
->isMinor();
609 * Get a list of users who have edited this article, not including the user who made
610 * the most recent revision, which you can get from $article->getUser() if you want it
611 * @return UserArrayFromResult
613 public function getContributors() {
614 # @todo FIXME: This is expensive; cache this info somewhere.
616 $dbr = wfGetDB( DB_SLAVE
);
618 if ( $dbr->implicitGroupby() ) {
619 $realNameField = 'user_real_name';
621 $realNameField = 'FIRST(user_real_name) AS user_real_name';
624 $tables = array( 'revision', 'user' );
627 'rev_user as user_id',
628 'rev_user_text AS user_name',
630 'MAX(rev_timestamp) AS timestamp',
633 $conds = array( 'rev_page' => $this->getId() );
635 // The user who made the top revision gets credited as "this page was last edited by
636 // John, based on contributions by Tom, Dick and Harry", so don't include them twice.
637 $user = $this->getUser();
639 $conds[] = "rev_user != $user";
641 $conds[] = "rev_user_text != {$dbr->addQuotes( $this->getUserText() )}";
644 $conds[] = "{$dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER )} = 0"; // username hidden?
647 'user' => array( 'LEFT JOIN', 'rev_user = user_id' ),
651 'GROUP BY' => array( 'rev_user', 'rev_user_text' ),
652 'ORDER BY' => 'timestamp DESC',
655 $res = $dbr->select( $tables, $fields, $conds, __METHOD__
, $options, $jconds );
656 return new UserArrayFromResult( $res );
660 * Should the parser cache be used?
662 * @param $user User The relevant user
665 public function isParserCacheUsed( User
$user, $oldid ) {
666 global $wgEnableParserCache;
668 return $wgEnableParserCache
669 && $user->getStubThreshold() == 0
672 && !$this->mTitle
->isCssOrJsPage()
673 && !$this->mTitle
->isCssJsSubpage();
677 * Perform the actions of a page purging
679 public function doPurge() {
682 if( !wfRunHooks( 'ArticlePurge', array( &$this ) ) ){
686 // Invalidate the cache
687 $this->mTitle
->invalidateCache();
691 // Commit the transaction before the purge is sent
692 $dbw = wfGetDB( DB_MASTER
);
696 $update = SquidUpdate
::newSimplePurge( $this->mTitle
);
700 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
701 if ( $this->getId() == 0 ) {
704 $text = $this->getRawText();
707 MessageCache
::singleton()->replace( $this->mTitle
->getDBkey(), $text );
712 * Insert a new empty page record for this article.
713 * This *must* be followed up by creating a revision
714 * and running $this->updateRevisionOn( ... );
715 * or else the record will be left in a funky state.
716 * Best if all done inside a transaction.
718 * @param $dbw DatabaseBase
719 * @return int The newly created page_id key, or false if the title already existed
722 public function insertOn( $dbw ) {
723 wfProfileIn( __METHOD__
);
725 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
726 $dbw->insert( 'page', array(
727 'page_id' => $page_id,
728 'page_namespace' => $this->mTitle
->getNamespace(),
729 'page_title' => $this->mTitle
->getDBkey(),
731 'page_restrictions' => '',
732 'page_is_redirect' => 0, # Will set this shortly...
734 'page_random' => wfRandom(),
735 'page_touched' => $dbw->timestamp(),
736 'page_latest' => 0, # Fill this in shortly...
737 'page_len' => 0, # Fill this in shortly...
738 ), __METHOD__
, 'IGNORE' );
740 $affected = $dbw->affectedRows();
743 $newid = $dbw->insertId();
744 $this->mTitle
->resetArticleID( $newid );
746 wfProfileOut( __METHOD__
);
748 return $affected ?
$newid : false;
752 * Update the page record to point to a newly saved revision.
754 * @param $dbw DatabaseBase: object
755 * @param $revision Revision: For ID number, and text used to set
756 length and redirect status fields
757 * @param $lastRevision Integer: if given, will not overwrite the page field
758 * when different from the currently set value.
759 * Giving 0 indicates the new page flag should be set
761 * @param $lastRevIsRedirect Boolean: if given, will optimize adding and
762 * removing rows in redirect table.
763 * @return bool true on success, false on failure
766 public function updateRevisionOn( $dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null ) {
767 wfProfileIn( __METHOD__
);
769 $text = $revision->getText();
770 $rt = Title
::newFromRedirectRecurse( $text );
772 $conditions = array( 'page_id' => $this->getId() );
774 if ( !is_null( $lastRevision ) ) {
775 # An extra check against threads stepping on each other
776 $conditions['page_latest'] = $lastRevision;
779 $dbw->update( 'page',
781 'page_latest' => $revision->getId(),
782 'page_touched' => $dbw->timestamp(),
783 'page_is_new' => ( $lastRevision === 0 ) ?
1 : 0,
784 'page_is_redirect' => $rt !== null ?
1 : 0,
785 'page_len' => strlen( $text ),
790 $result = $dbw->affectedRows() != 0;
792 $this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect );
795 wfProfileOut( __METHOD__
);
800 * Add row to the redirect table if this is a redirect, remove otherwise.
802 * @param $dbw DatabaseBase
803 * @param $redirectTitle Title object pointing to the redirect target,
804 * or NULL if this is not a redirect
805 * @param $lastRevIsRedirect If given, will optimize adding and
806 * removing rows in redirect table.
807 * @return bool true on success, false on failure
810 public function updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect = null ) {
811 // Always update redirects (target link might have changed)
812 // Update/Insert if we don't know if the last revision was a redirect or not
813 // Delete if changing from redirect to non-redirect
814 $isRedirect = !is_null( $redirectTitle );
816 if ( !$isRedirect && !is_null( $lastRevIsRedirect ) && $lastRevIsRedirect === $isRedirect ) {
820 wfProfileIn( __METHOD__
);
822 $this->insertRedirectEntry( $redirectTitle );
824 // This is not a redirect, remove row from redirect table
825 $where = array( 'rd_from' => $this->getId() );
826 $dbw->delete( 'redirect', $where, __METHOD__
);
829 if ( $this->getTitle()->getNamespace() == NS_FILE
) {
830 RepoGroup
::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() );
832 wfProfileOut( __METHOD__
);
834 return ( $dbw->affectedRows() != 0 );
838 * If the given revision is newer than the currently set page_latest,
839 * update the page record. Otherwise, do nothing.
841 * @param $dbw Database object
842 * @param $revision Revision object
845 public function updateIfNewerOn( $dbw, $revision ) {
846 wfProfileIn( __METHOD__
);
848 $row = $dbw->selectRow(
849 array( 'revision', 'page' ),
850 array( 'rev_id', 'rev_timestamp', 'page_is_redirect' ),
852 'page_id' => $this->getId(),
853 'page_latest=rev_id' ),
857 if ( wfTimestamp( TS_MW
, $row->rev_timestamp
) >= $revision->getTimestamp() ) {
858 wfProfileOut( __METHOD__
);
861 $prev = $row->rev_id
;
862 $lastRevIsRedirect = (bool)$row->page_is_redirect
;
864 # No or missing previous revision; mark the page as new
866 $lastRevIsRedirect = null;
869 $ret = $this->updateRevisionOn( $dbw, $revision, $prev, $lastRevIsRedirect );
871 wfProfileOut( __METHOD__
);
876 * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...)
877 * @param $text String: new text of the section
878 * @param $summary String: new section's subject, only if $section is 'new'
879 * @param $edittime String: revision timestamp or null to use the current revision
880 * @return string Complete article text, or null if error
882 public function replaceSection( $section, $text, $summary = '', $edittime = null ) {
883 wfProfileIn( __METHOD__
);
885 if ( strval( $section ) == '' ) {
886 // Whole-page edit; let the whole text through
888 if ( is_null( $edittime ) ) {
889 $rev = Revision
::newFromTitle( $this->mTitle
);
891 $dbw = wfGetDB( DB_MASTER
);
892 $rev = Revision
::loadFromTimestamp( $dbw, $this->mTitle
, $edittime );
896 wfDebug( "WikiPage::replaceSection asked for bogus section (page: " .
897 $this->getId() . "; section: $section; edittime: $edittime)\n" );
898 wfProfileOut( __METHOD__
);
902 $oldtext = $rev->getText();
904 if ( $section == 'new' ) {
905 # Inserting a new section
906 $subject = $summary ?
wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" : '';
907 $text = strlen( trim( $oldtext ) ) > 0
908 ?
"{$oldtext}\n\n{$subject}{$text}"
909 : "{$subject}{$text}";
911 # Replacing an existing section; roll out the big guns
914 $text = $wgParser->replaceSection( $oldtext, $section, $text );
918 wfProfileOut( __METHOD__
);
923 * Check flags and add EDIT_NEW or EDIT_UPDATE to them as needed.
925 * @return Int updated $flags
927 function checkFlags( $flags ) {
928 if ( !( $flags & EDIT_NEW
) && !( $flags & EDIT_UPDATE
) ) {
929 if ( $this->mTitle
->getArticleID() ) {
930 $flags |
= EDIT_UPDATE
;
940 * Change an existing article or create a new article. Updates RC and all necessary caches,
941 * optionally via the deferred update array.
943 * @param $text String: new text
944 * @param $summary String: edit summary
945 * @param $flags Integer bitfield:
947 * Article is known or assumed to be non-existent, create a new one
949 * Article is known or assumed to be pre-existing, update it
951 * Mark this edit minor, if the user is allowed to do so
953 * Do not log the change in recentchanges
955 * Mark the edit a "bot" edit regardless of user rights
957 * Defer some of the updates until the end of index.php
959 * Fill in blank summaries with generated text where possible
961 * If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the article will be detected.
962 * If EDIT_UPDATE is specified and the article doesn't exist, the function will an
963 * edit-gone-missing error. If EDIT_NEW is specified and the article does exist, an
964 * edit-already-exists error will be returned. These two conditions are also possible with
965 * auto-detection due to MediaWiki's performance-optimised locking strategy.
967 * @param $baseRevId the revision ID this edit was based off, if any
968 * @param $user User the user doing the edit
970 * @return Status object. Possible errors:
971 * edit-hook-aborted: The ArticleSave hook aborted the edit but didn't set the fatal flag of $status
972 * edit-gone-missing: In update mode, but the article didn't exist
973 * edit-conflict: In update mode, the article changed unexpectedly
974 * edit-no-change: Warning that the text was the same as before
975 * edit-already-exists: In creation mode, but the article already exists
977 * Extensions may define additional errors.
979 * $return->value will contain an associative array with members as follows:
980 * new: Boolean indicating if the function attempted to create a new article
981 * revision: The revision object for the inserted revision, or null
983 * Compatibility note: this function previously returned a boolean value indicating success/failure
985 public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) {
986 global $wgUser, $wgDBtransactions, $wgUseAutomaticEditSummaries;
988 # Low-level sanity check
989 if ( $this->mTitle
->getText() === '' ) {
990 throw new MWException( 'Something is trying to edit an article with an empty title' );
993 wfProfileIn( __METHOD__
);
995 $user = is_null( $user ) ?
$wgUser : $user;
996 $status = Status
::newGood( array() );
998 # Load $this->mTitle->getArticleID() and $this->mLatest if it's not already
999 $this->loadPageData();
1001 $flags = $this->checkFlags( $flags );
1003 if ( !wfRunHooks( 'ArticleSave', array( &$this, &$user, &$text, &$summary,
1004 $flags & EDIT_MINOR
, null, null, &$flags, &$status ) ) )
1006 wfDebug( __METHOD__
. ": ArticleSave hook aborted save!\n" );
1008 if ( $status->isOK() ) {
1009 $status->fatal( 'edit-hook-aborted' );
1012 wfProfileOut( __METHOD__
);
1016 # Silently ignore EDIT_MINOR if not allowed
1017 $isminor = ( $flags & EDIT_MINOR
) && $user->isAllowed( 'minoredit' );
1018 $bot = $flags & EDIT_FORCE_BOT
;
1020 $oldtext = $this->getRawText(); // current revision
1021 $oldsize = strlen( $oldtext );
1022 $oldcountable = $this->isCountable();
1024 # Provide autosummaries if one is not provided and autosummaries are enabled.
1025 if ( $wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY
&& $summary == '' ) {
1026 $summary = $this->getAutosummary( $oldtext, $text, $flags );
1029 $editInfo = $this->prepareTextForEdit( $text, null, $user );
1030 $text = $editInfo->pst
;
1031 $newsize = strlen( $text );
1033 $dbw = wfGetDB( DB_MASTER
);
1034 $now = wfTimestampNow();
1035 $this->mTimestamp
= $now;
1037 if ( $flags & EDIT_UPDATE
) {
1038 # Update article, but only if changed.
1039 $status->value
['new'] = false;
1041 # Make sure the revision is either completely inserted or not inserted at all
1042 if ( !$wgDBtransactions ) {
1043 $userAbort = ignore_user_abort( true );
1046 $revision = new Revision( array(
1047 'page' => $this->getId(),
1048 'comment' => $summary,
1049 'minor_edit' => $isminor,
1051 'parent_id' => $this->mLatest
,
1052 'user' => $user->getId(),
1053 'user_text' => $user->getName(),
1057 $changed = ( strcmp( $text, $oldtext ) != 0 );
1060 if ( !$this->mLatest
) {
1061 # Article gone missing
1062 wfDebug( __METHOD__
. ": EDIT_UPDATE specified but article doesn't exist\n" );
1063 $status->fatal( 'edit-gone-missing' );
1065 wfProfileOut( __METHOD__
);
1070 $revisionId = $revision->insertOn( $dbw );
1074 # Note that we use $this->mLatest instead of fetching a value from the master DB
1075 # during the course of this function. This makes sure that EditPage can detect
1076 # edit conflicts reliably, either by $ok here, or by $article->getTimestamp()
1077 # before this function is called. A previous function used a separate query, this
1078 # creates a window where concurrent edits can cause an ignored edit conflict.
1079 $ok = $this->updateRevisionOn( $dbw, $revision, $this->mLatest
);
1082 /* Belated edit conflict! Run away!! */
1083 $status->fatal( 'edit-conflict' );
1085 # Delete the invalid revision if the DB is not transactional
1086 if ( !$wgDBtransactions ) {
1087 $dbw->delete( 'revision', array( 'rev_id' => $revisionId ), __METHOD__
);
1093 global $wgUseRCPatrol;
1094 wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
1095 # Update recentchanges
1096 if ( !( $flags & EDIT_SUPPRESS_RC
) ) {
1097 # Mark as patrolled if the user can do so
1098 $patrolled = $wgUseRCPatrol && !count(
1099 $this->mTitle
->getUserPermissionsErrors( 'autopatrol', $user ) );
1100 # Add RC row to the DB
1101 $rc = RecentChange
::notifyEdit( $now, $this->mTitle
, $isminor, $user, $summary,
1102 $this->mLatest
, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1103 $revisionId, $patrolled
1106 # Log auto-patrolled edits
1108 PatrolLog
::record( $rc, true );
1111 $user->incEditCount();
1116 if ( !$wgDBtransactions ) {
1117 ignore_user_abort( $userAbort );
1120 // Now that ignore_user_abort is restored, we can respond to fatal errors
1121 if ( !$status->isOK() ) {
1122 wfProfileOut( __METHOD__
);
1126 # Update links tables, site stats, etc.
1127 $this->doEditUpdates( $revision, $user, array( 'changed' => $changed,
1128 'oldcountable' => $oldcountable ) );
1131 $status->warning( 'edit-no-change' );
1133 // Keep the same revision ID, but do some updates on it
1134 $revisionId = $this->getLatest();
1135 // Update page_touched, this is usually implicit in the page update
1136 // Other cache updates are done in onArticleEdit()
1137 $this->mTitle
->invalidateCache();
1140 # Create new article
1141 $status->value
['new'] = true;
1145 # Add the page record; stake our claim on this title!
1146 # This will return false if the article already exists
1147 $newid = $this->insertOn( $dbw );
1149 if ( $newid === false ) {
1151 $status->fatal( 'edit-already-exists' );
1153 wfProfileOut( __METHOD__
);
1157 # Save the revision text...
1158 $revision = new Revision( array(
1160 'comment' => $summary,
1161 'minor_edit' => $isminor,
1163 'user' => $user->getId(),
1164 'user_text' => $user->getName(),
1167 $revisionId = $revision->insertOn( $dbw );
1169 $this->mTitle
->resetArticleID( $newid );
1170 # Update the LinkCache. Resetting the Title ArticleID means it will rely on having that already cached
1172 LinkCache
::singleton()->addGoodLinkObj( $newid, $this->mTitle
, strlen( $text ), (bool)Title
::newFromRedirect( $text ), $revisionId );
1174 # Update the page record with revision data
1175 $this->updateRevisionOn( $dbw, $revision, 0 );
1177 wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
1179 # Update recentchanges
1180 if ( !( $flags & EDIT_SUPPRESS_RC
) ) {
1181 global $wgUseRCPatrol, $wgUseNPPatrol;
1183 # Mark as patrolled if the user can do so
1184 $patrolled = ( $wgUseRCPatrol ||
$wgUseNPPatrol ) && !count(
1185 $this->mTitle
->getUserPermissionsErrors( 'autopatrol', $user ) );
1186 # Add RC row to the DB
1187 $rc = RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $user, $summary, $bot,
1188 '', strlen( $text ), $revisionId, $patrolled );
1190 # Log auto-patrolled edits
1192 PatrolLog
::record( $rc, true );
1195 $user->incEditCount();
1198 # Update links, etc.
1199 $this->doEditUpdates( $revision, $user, array( 'created' => true ) );
1201 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$user, $text, $summary,
1202 $flags & EDIT_MINOR
, null, null, &$flags, $revision ) );
1205 # Do updates right now unless deferral was requested
1206 if ( !( $flags & EDIT_DEFER_UPDATES
) ) {
1210 // Return the new revision (or null) to the caller
1211 $status->value
['revision'] = $revision;
1213 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$user, $text, $summary,
1214 $flags & EDIT_MINOR
, null, null, &$flags, $revision, &$status, $baseRevId ) );
1216 # Promote user to any groups they meet the criteria for
1217 $user->addAutopromoteOnceGroups( 'onEdit' );
1219 wfProfileOut( __METHOD__
);
1224 * Update the article's restriction field, and leave a log entry.
1226 * @param $limit Array: set of restriction keys
1227 * @param $reason String
1228 * @param &$cascade Integer. Set to false if cascading protection isn't allowed.
1229 * @param $expiry Array: per restriction type expiration
1230 * @param $user User The user updating the restrictions
1231 * @return bool true on success
1233 public function updateRestrictions(
1234 $limit = array(), $reason = '', &$cascade = 0, $expiry = array(), User
$user = null
1236 global $wgUser, $wgContLang;
1237 $user = is_null( $user ) ?
$wgUser : $user;
1239 $restrictionTypes = $this->mTitle
->getRestrictionTypes();
1241 $id = $this->mTitle
->getArticleID();
1244 wfDebug( "updateRestrictions failed: article id $id <= 0\n" );
1248 if ( wfReadOnly() ) {
1249 wfDebug( "updateRestrictions failed: read-only\n" );
1253 if ( count( $this->mTitle
->getUserPermissionsErrors( 'protect', $user ) ) ) {
1254 wfDebug( "updateRestrictions failed: insufficient permissions\n" );
1262 // Take this opportunity to purge out expired restrictions
1263 Title
::purgeExpiredRestrictions();
1265 # @todo FIXME: Same limitations as described in ProtectionForm.php (line 37);
1266 # we expect a single selection, but the schema allows otherwise.
1268 $updated = self
::flattenRestrictions( $limit );
1271 foreach ( $restrictionTypes as $action ) {
1272 if ( isset( $expiry[$action] ) ) {
1273 # Get current restrictions on $action
1274 $aLimits = $this->mTitle
->getRestrictions( $action );
1275 $current[$action] = implode( '', $aLimits );
1276 # Are any actual restrictions being dealt with here?
1277 $aRChanged = count( $aLimits ) ||
!empty( $limit[$action] );
1279 # If something changed, we need to log it. Checking $aRChanged
1280 # assures that "unprotecting" a page that is not protected does
1281 # not log just because the expiry was "changed".
1283 $this->mTitle
->getRestrictionExpiry( $action ) != $expiry[$action] )
1290 $current = self
::flattenRestrictions( $current );
1292 $changed = ( $changed ||
$current != $updated );
1293 $changed = $changed ||
( $updated && $this->mTitle
->areRestrictionsCascading() != $cascade );
1294 $protect = ( $updated != '' );
1296 # If nothing's changed, do nothing
1298 if ( wfRunHooks( 'ArticleProtect', array( &$this, &$user, $limit, $reason ) ) ) {
1299 $dbw = wfGetDB( DB_MASTER
);
1301 # Prepare a null revision to be added to the history
1302 $modified = $current != '' && $protect;
1305 $comment_type = $modified ?
'modifiedarticleprotection' : 'protectedarticle';
1307 $comment_type = 'unprotectedarticle';
1310 $comment = $wgContLang->ucfirst( wfMsgForContent( $comment_type, $this->mTitle
->getPrefixedText() ) );
1312 # Only restrictions with the 'protect' right can cascade...
1313 # Otherwise, people who cannot normally protect can "protect" pages via transclusion
1314 $editrestriction = isset( $limit['edit'] ) ?
array( $limit['edit'] ) : $this->mTitle
->getRestrictions( 'edit' );
1316 # The schema allows multiple restrictions
1317 if ( !in_array( 'protect', $editrestriction ) && !in_array( 'sysop', $editrestriction ) ) {
1321 $cascade_description = '';
1324 $cascade_description = ' [' . wfMsgForContent( 'protect-summary-cascade' ) . ']';
1328 $comment .= ": $reason";
1331 $editComment = $comment;
1332 $encodedExpiry = array();
1333 $protect_description = '';
1334 foreach ( $limit as $action => $restrictions ) {
1335 if ( !isset( $expiry[$action] ) )
1336 $expiry[$action] = $dbw->getInfinity();
1338 $encodedExpiry[$action] = $dbw->encodeExpiry( $expiry[$action] );
1339 if ( $restrictions != '' ) {
1340 $protect_description .= "[$action=$restrictions] (";
1341 if ( $encodedExpiry[$action] != 'infinity' ) {
1342 $protect_description .= wfMsgForContent( 'protect-expiring',
1343 $wgContLang->timeanddate( $expiry[$action], false, false ) ,
1344 $wgContLang->date( $expiry[$action], false, false ) ,
1345 $wgContLang->time( $expiry[$action], false, false ) );
1347 $protect_description .= wfMsgForContent( 'protect-expiry-indefinite' );
1350 $protect_description .= ') ';
1353 $protect_description = trim( $protect_description );
1355 if ( $protect_description && $protect ) {
1356 $editComment .= " ($protect_description)";
1360 $editComment .= "$cascade_description";
1363 # Update restrictions table
1364 foreach ( $limit as $action => $restrictions ) {
1365 if ( $restrictions != '' ) {
1366 $dbw->replace( 'page_restrictions', array( array( 'pr_page', 'pr_type' ) ),
1367 array( 'pr_page' => $id,
1368 'pr_type' => $action,
1369 'pr_level' => $restrictions,
1370 'pr_cascade' => ( $cascade && $action == 'edit' ) ?
1 : 0,
1371 'pr_expiry' => $encodedExpiry[$action]
1376 $dbw->delete( 'page_restrictions', array( 'pr_page' => $id,
1377 'pr_type' => $action ), __METHOD__
);
1381 # Insert a null revision
1382 $nullRevision = Revision
::newNullRevision( $dbw, $id, $editComment, true );
1383 $nullRevId = $nullRevision->insertOn( $dbw );
1385 $latest = $this->getLatest();
1386 # Update page record
1387 $dbw->update( 'page',
1389 'page_touched' => $dbw->timestamp(),
1390 'page_restrictions' => '',
1391 'page_latest' => $nullRevId
1392 ), array( /* WHERE */
1397 wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $nullRevision, $latest, $user ) );
1398 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$user, $limit, $reason ) );
1400 # Update the protection log
1401 $log = new LogPage( 'protect' );
1403 $params = array( $protect_description, $cascade ?
'cascade' : '' );
1404 $log->addEntry( $modified ?
'modify' : 'protect', $this->mTitle
, trim( $reason ), $params );
1406 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1409 } # End "changed" check
1415 * Take an array of page restrictions and flatten it to a string
1416 * suitable for insertion into the page_restrictions field.
1417 * @param $limit Array
1420 protected static function flattenRestrictions( $limit ) {
1421 if ( !is_array( $limit ) ) {
1422 throw new MWException( 'WikiPage::flattenRestrictions given non-array restriction set' );
1428 foreach ( $limit as $action => $restrictions ) {
1429 if ( $restrictions != '' ) {
1430 $bits[] = "$action=$restrictions";
1434 return implode( ':', $bits );
1438 * @return bool whether or not the page surpasses $wgDeleteRevisionsLimit revisions
1440 public function isBigDeletion() {
1441 global $wgDeleteRevisionsLimit;
1443 if ( $wgDeleteRevisionsLimit ) {
1444 $revCount = $this->estimateRevisionCount();
1446 return $revCount > $wgDeleteRevisionsLimit;
1453 * @return int approximate revision count
1455 public function estimateRevisionCount() {
1456 $dbr = wfGetDB( DB_SLAVE
);
1458 // For an exact count...
1459 // return $dbr->selectField( 'revision', 'COUNT(*)',
1460 // array( 'rev_page' => $this->getId() ), __METHOD__ );
1461 return $dbr->estimateRowCount( 'revision', '*',
1462 array( 'rev_page' => $this->getId() ), __METHOD__
);
1466 * Get the last N authors
1467 * @param $num Integer: number of revisions to get
1468 * @param $revLatest String: the latest rev_id, selected from the master (optional)
1469 * @return array Array of authors, duplicates not removed
1471 public function getLastNAuthors( $num, $revLatest = 0 ) {
1472 wfProfileIn( __METHOD__
);
1473 // First try the slave
1474 // If that doesn't have the latest revision, try the master
1476 $db = wfGetDB( DB_SLAVE
);
1479 $res = $db->select( array( 'page', 'revision' ),
1480 array( 'rev_id', 'rev_user_text' ),
1482 'page_namespace' => $this->mTitle
->getNamespace(),
1483 'page_title' => $this->mTitle
->getDBkey(),
1484 'rev_page = page_id'
1487 'ORDER BY' => 'rev_timestamp DESC',
1493 wfProfileOut( __METHOD__
);
1497 $row = $db->fetchObject( $res );
1499 if ( $continue == 2 && $revLatest && $row->rev_id
!= $revLatest ) {
1500 $db = wfGetDB( DB_MASTER
);
1505 } while ( $continue );
1507 $authors = array( $row->rev_user_text
);
1509 foreach ( $res as $row ) {
1510 $authors[] = $row->rev_user_text
;
1513 wfProfileOut( __METHOD__
);
1518 * Back-end article deletion
1519 * Deletes the article with database consistency, writes logs, purges caches
1521 * @param $reason string delete reason for deletion log
1522 * @param suppress bitfield
1523 * Revision::DELETED_TEXT
1524 * Revision::DELETED_COMMENT
1525 * Revision::DELETED_USER
1526 * Revision::DELETED_RESTRICTED
1527 * @param $id int article ID
1528 * @param $commit boolean defaults to true, triggers transaction end
1529 * @param &$errors Array of errors to append to
1530 * @param $user User The relevant user
1531 * @return boolean true if successful
1533 public function doDeleteArticle(
1534 $reason, $suppress = false, $id = 0, $commit = true, &$error = '', User
$user = null
1536 global $wgDeferredUpdateList, $wgUseTrackbacks, $wgUser;
1537 $user = is_null( $user ) ?
$wgUser : $user;
1539 wfDebug( __METHOD__
. "\n" );
1541 if ( ! wfRunHooks( 'ArticleDelete', array( &$this, &$user, &$reason, &$error ) ) ) {
1544 $dbw = wfGetDB( DB_MASTER
);
1545 $t = $this->mTitle
->getDBkey();
1546 $id = $id ?
$id : $this->mTitle
->getArticleID( Title
::GAID_FOR_UPDATE
);
1548 if ( $t === '' ||
$id == 0 ) {
1552 $u = new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 );
1553 array_push( $wgDeferredUpdateList, $u );
1555 // Bitfields to further suppress the content
1558 // This should be 15...
1559 $bitfield |
= Revision
::DELETED_TEXT
;
1560 $bitfield |
= Revision
::DELETED_COMMENT
;
1561 $bitfield |
= Revision
::DELETED_USER
;
1562 $bitfield |
= Revision
::DELETED_RESTRICTED
;
1564 $bitfield = 'rev_deleted';
1568 // For now, shunt the revision data into the archive table.
1569 // Text is *not* removed from the text table; bulk storage
1570 // is left intact to avoid breaking block-compression or
1571 // immutable storage schemes.
1573 // For backwards compatibility, note that some older archive
1574 // table entries will have ar_text and ar_flags fields still.
1576 // In the future, we may keep revisions and mark them with
1577 // the rev_deleted field, which is reserved for this purpose.
1578 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
1580 'ar_namespace' => 'page_namespace',
1581 'ar_title' => 'page_title',
1582 'ar_comment' => 'rev_comment',
1583 'ar_user' => 'rev_user',
1584 'ar_user_text' => 'rev_user_text',
1585 'ar_timestamp' => 'rev_timestamp',
1586 'ar_minor_edit' => 'rev_minor_edit',
1587 'ar_rev_id' => 'rev_id',
1588 'ar_text_id' => 'rev_text_id',
1589 'ar_text' => '\'\'', // Be explicit to appease
1590 'ar_flags' => '\'\'', // MySQL's "strict mode"...
1591 'ar_len' => 'rev_len',
1592 'ar_page_id' => 'page_id',
1593 'ar_deleted' => $bitfield
1596 'page_id = rev_page'
1600 # Delete restrictions for it
1601 $dbw->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__
);
1603 # Now that it's safely backed up, delete it
1604 $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__
);
1605 $ok = ( $dbw->affectedRows() > 0 ); // getArticleId() uses slave, could be laggy
1612 # Fix category table counts
1614 $res = $dbw->select( 'categorylinks', 'cl_to', array( 'cl_from' => $id ), __METHOD__
);
1616 foreach ( $res as $row ) {
1617 $cats [] = $row->cl_to
;
1620 $this->updateCategoryCounts( array(), $cats );
1622 # If using cascading deletes, we can skip some explicit deletes
1623 if ( !$dbw->cascadingDeletes() ) {
1624 $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__
);
1626 if ( $wgUseTrackbacks )
1627 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__
);
1629 # Delete outgoing links
1630 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
1631 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1632 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1633 $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
1634 $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
1635 $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
1636 $dbw->delete( 'iwlinks', array( 'iwl_from' => $id ) );
1637 $dbw->delete( 'redirect', array( 'rd_from' => $id ) );
1640 # If using cleanup triggers, we can skip some manual deletes
1641 if ( !$dbw->cleanupTriggers() ) {
1642 # Clean up recentchanges entries...
1643 $dbw->delete( 'recentchanges',
1644 array( 'rc_type != ' . RC_LOG
,
1645 'rc_namespace' => $this->mTitle
->getNamespace(),
1646 'rc_title' => $this->mTitle
->getDBkey() ),
1648 $dbw->delete( 'recentchanges',
1649 array( 'rc_type != ' . RC_LOG
, 'rc_cur_id' => $id ),
1654 self
::onArticleDelete( $this->mTitle
);
1656 # Clear the cached article id so the interface doesn't act like we exist
1657 $this->mTitle
->resetArticleID( 0 );
1659 # Log the deletion, if the page was suppressed, log it at Oversight instead
1660 $logtype = $suppress ?
'suppress' : 'delete';
1661 $log = new LogPage( $logtype );
1663 # Make sure logging got through
1664 $log->addEntry( 'delete', $this->mTitle
, $reason, array() );
1670 wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id ) );
1675 * Roll back the most recent consecutive set of edits to a page
1676 * from the same user; fails if there are no eligible edits to
1677 * roll back to, e.g. user is the sole contributor. This function
1678 * performs permissions checks on $user, then calls commitRollback()
1679 * to do the dirty work
1681 * @param $fromP String: Name of the user whose edits to rollback.
1682 * @param $summary String: Custom summary. Set to default summary if empty.
1683 * @param $token String: Rollback token.
1684 * @param $bot Boolean: If true, mark all reverted edits as bot.
1686 * @param $resultDetails Array: contains result-specific array of additional values
1687 * 'alreadyrolled' : 'current' (rev)
1688 * success : 'summary' (str), 'current' (rev), 'target' (rev)
1690 * @param $user User The user performing the rollback
1691 * @return array of errors, each error formatted as
1692 * array(messagekey, param1, param2, ...).
1693 * On success, the array is empty. This array can also be passed to
1694 * OutputPage::showPermissionsErrorPage().
1696 public function doRollback(
1697 $fromP, $summary, $token, $bot, &$resultDetails, User
$user
1699 $resultDetails = null;
1702 $editErrors = $this->mTitle
->getUserPermissionsErrors( 'edit', $user );
1703 $rollbackErrors = $this->mTitle
->getUserPermissionsErrors( 'rollback', $user );
1704 $errors = array_merge( $editErrors, wfArrayDiff2( $rollbackErrors, $editErrors ) );
1706 if ( !$user->matchEditToken( $token, array( $this->mTitle
->getPrefixedText(), $fromP ) ) ) {
1707 $errors[] = array( 'sessionfailure' );
1710 if ( $user->pingLimiter( 'rollback' ) ||
$user->pingLimiter() ) {
1711 $errors[] = array( 'actionthrottledtext' );
1714 # If there were errors, bail out now
1715 if ( !empty( $errors ) ) {
1719 return $this->commitRollback( $fromP, $summary, $bot, $resultDetails, $user );
1723 * Backend implementation of doRollback(), please refer there for parameter
1724 * and return value documentation
1726 * NOTE: This function does NOT check ANY permissions, it just commits the
1727 * rollback to the DB Therefore, you should only call this function direct-
1728 * ly if you want to use custom permissions checks. If you don't, use
1729 * doRollback() instead.
1730 * @param $fromP String: Name of the user whose edits to rollback.
1731 * @param $summary String: Custom summary. Set to default summary if empty.
1732 * @param $bot Boolean: If true, mark all reverted edits as bot.
1734 * @param $resultDetails Array: contains result-specific array of additional values
1735 * @param $guser User The user performing the rollback
1737 public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User
$guser ) {
1738 global $wgUseRCPatrol, $wgContLang;
1740 $dbw = wfGetDB( DB_MASTER
);
1742 if ( wfReadOnly() ) {
1743 return array( array( 'readonlytext' ) );
1746 # Get the last editor
1747 $current = Revision
::newFromTitle( $this->mTitle
);
1748 if ( is_null( $current ) ) {
1749 # Something wrong... no page?
1750 return array( array( 'notanarticle' ) );
1753 $from = str_replace( '_', ' ', $fromP );
1754 # User name given should match up with the top revision.
1755 # If the user was deleted then $from should be empty.
1756 if ( $from != $current->getUserText() ) {
1757 $resultDetails = array( 'current' => $current );
1758 return array( array( 'alreadyrolled',
1759 htmlspecialchars( $this->mTitle
->getPrefixedText() ),
1760 htmlspecialchars( $fromP ),
1761 htmlspecialchars( $current->getUserText() )
1765 # Get the last edit not by this guy...
1766 # Note: these may not be public values
1767 $user = intval( $current->getRawUser() );
1768 $user_text = $dbw->addQuotes( $current->getRawUserText() );
1769 $s = $dbw->selectRow( 'revision',
1770 array( 'rev_id', 'rev_timestamp', 'rev_deleted' ),
1771 array( 'rev_page' => $current->getPage(),
1772 "rev_user != {$user} OR rev_user_text != {$user_text}"
1774 array( 'USE INDEX' => 'page_timestamp',
1775 'ORDER BY' => 'rev_timestamp DESC' )
1777 if ( $s === false ) {
1778 # No one else ever edited this page
1779 return array( array( 'cantrollback' ) );
1780 } elseif ( $s->rev_deleted
& Revision
::DELETED_TEXT ||
$s->rev_deleted
& Revision
::DELETED_USER
) {
1781 # Only admins can see this text
1782 return array( array( 'notvisiblerev' ) );
1786 if ( $bot && $guser->isAllowed( 'markbotedits' ) ) {
1787 # Mark all reverted edits as bot
1791 if ( $wgUseRCPatrol ) {
1792 # Mark all reverted edits as patrolled
1793 $set['rc_patrolled'] = 1;
1796 if ( count( $set ) ) {
1797 $dbw->update( 'recentchanges', $set,
1799 'rc_cur_id' => $current->getPage(),
1800 'rc_user_text' => $current->getUserText(),
1801 "rc_timestamp > '{$s->rev_timestamp}'",
1806 # Generate the edit summary if necessary
1807 $target = Revision
::newFromId( $s->rev_id
);
1808 if ( empty( $summary ) ) {
1809 if ( $from == '' ) { // no public user name
1810 $summary = wfMsgForContent( 'revertpage-nouser' );
1812 $summary = wfMsgForContent( 'revertpage' );
1816 # Allow the custom summary to use the same args as the default message
1818 $target->getUserText(), $from, $s->rev_id
,
1819 $wgContLang->timeanddate( wfTimestamp( TS_MW
, $s->rev_timestamp
) ),
1820 $current->getId(), $wgContLang->timeanddate( $current->getTimestamp() )
1822 $summary = wfMsgReplaceArgs( $summary, $args );
1825 $flags = EDIT_UPDATE
;
1827 if ( $guser->isAllowed( 'minoredit' ) ) {
1828 $flags |
= EDIT_MINOR
;
1831 if ( $bot && ( $guser->isAllowedAny( 'markbotedits', 'bot' ) ) ) {
1832 $flags |
= EDIT_FORCE_BOT
;
1835 # Actually store the edit
1836 $status = $this->doEdit( $target->getText(), $summary, $flags, $target->getId() );
1837 if ( !empty( $status->value
['revision'] ) ) {
1838 $revId = $status->value
['revision']->getId();
1843 wfRunHooks( 'ArticleRollbackComplete', array( $this, $guser, $target, $current ) );
1845 $resultDetails = array(
1846 'summary' => $summary,
1847 'current' => $current,
1848 'target' => $target,
1856 * Do standard deferred updates after page view
1857 * @param $user User The relevant user
1859 public function doViewUpdates( User
$user ) {
1860 global $wgDeferredUpdateList, $wgDisableCounters;
1861 if ( wfReadOnly() ) {
1865 # Don't update page view counters on views from bot users (bug 14044)
1866 if ( !$wgDisableCounters && !$user->isAllowed( 'bot' ) && $this->getId() ) {
1867 $wgDeferredUpdateList[] = new ViewCountUpdate( $this->getId() );
1868 $wgDeferredUpdateList[] = new SiteStatsUpdate( 1, 0, 0 );
1871 # Update newtalk / watchlist notification status
1872 $user->clearNotification( $this->mTitle
);
1876 * Prepare text which is about to be saved.
1877 * Returns a stdclass with source, pst and output members
1879 public function prepareTextForEdit( $text, $revid = null, User
$user = null ) {
1880 global $wgParser, $wgUser;
1881 $user = is_null( $user ) ?
$wgUser : $user;
1882 // @TODO fixme: check $user->getId() here???
1883 if ( $this->mPreparedEdit
1884 && $this->mPreparedEdit
->newText
== $text
1885 && $this->mPreparedEdit
->revid
== $revid
1888 return $this->mPreparedEdit
;
1891 $popts = ParserOptions
::newFromUser( $user );
1892 wfRunHooks( 'ArticlePrepareTextForEdit', array( $this, $popts ) );
1894 $edit = (object)array();
1895 $edit->revid
= $revid;
1896 $edit->newText
= $text;
1897 $edit->pst
= $this->preSaveTransform( $text, $user, $popts );
1898 $edit->popts
= $this->getParserOptions( true );
1899 $edit->output
= $wgParser->parse( $edit->pst
, $this->mTitle
, $edit->popts
, true, true, $revid );
1900 $edit->oldText
= $this->getRawText();
1902 $this->mPreparedEdit
= $edit;
1908 * Do standard deferred updates after page edit.
1909 * Update links tables, site stats, search index and message cache.
1910 * Purges pages that include this page if the text was changed here.
1911 * Every 100th edit, prune the recent changes table.
1914 * @param $revision Revision object
1915 * @param $user User object that did the revision
1916 * @param $options Array of options, following indexes are used:
1917 * - changed: boolean, whether the revision changed the content (default true)
1918 * - created: boolean, whether the revision created the page (default false)
1919 * - oldcountable: boolean or null (default null):
1920 * - boolean: whether the page was counted as an article before that
1921 * revision, only used in changed is true and created is false
1922 * - null: don't change the article count
1924 public function doEditUpdates( Revision
$revision, User
$user, array $options = array() ) {
1925 global $wgDeferredUpdateList, $wgEnableParserCache;
1927 wfProfileIn( __METHOD__
);
1929 $options +
= array( 'changed' => true, 'created' => false, 'oldcountable' => null );
1930 $text = $revision->getText();
1933 # Be careful not to double-PST: $text is usually already PST-ed once
1934 if ( !$this->mPreparedEdit ||
$this->mPreparedEdit
->output
->getFlag( 'vary-revision' ) ) {
1935 wfDebug( __METHOD__
. ": No prepared edit or vary-revision is set...\n" );
1936 $editInfo = $this->prepareTextForEdit( $text, $revision->getId(), $user );
1938 wfDebug( __METHOD__
. ": No vary-revision, using prepared edit...\n" );
1939 $editInfo = $this->mPreparedEdit
;
1942 # Save it to the parser cache
1943 if ( $wgEnableParserCache ) {
1944 $parserCache = ParserCache
::singleton();
1945 $parserCache->save( $editInfo->output
, $this, $editInfo->popts
);
1948 # Update the links tables
1949 $u = new LinksUpdate( $this->mTitle
, $editInfo->output
);
1952 wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
1954 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
1955 if ( 0 == mt_rand( 0, 99 ) ) {
1956 // Flush old entries from the `recentchanges` table; we do this on
1957 // random requests so as to avoid an increase in writes for no good reason
1960 $dbw = wfGetDB( DB_MASTER
);
1961 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
1964 array( "rc_timestamp < '$cutoff'" ),
1970 $id = $this->getId();
1971 $title = $this->mTitle
->getPrefixedDBkey();
1972 $shortTitle = $this->mTitle
->getDBkey();
1975 wfProfileOut( __METHOD__
);
1979 if ( !$options['changed'] ) {
1982 } elseif ( $options['created'] ) {
1983 $good = (int)$this->isCountable( $editInfo );
1985 } elseif ( $options['oldcountable'] !== null ) {
1986 $good = (int)$this->isCountable( $editInfo ) - (int)$options['oldcountable'];
1993 $wgDeferredUpdateList[] = new SiteStatsUpdate( 0, 1, $good, $total );
1994 $wgDeferredUpdateList[] = new SearchUpdate( $id, $title, $text );
1996 # If this is another user's talk page, update newtalk.
1997 # Don't do this if $options['changed'] = false (null-edits) nor if
1998 # it's a minor edit and the user doesn't want notifications for those.
1999 if ( $options['changed']
2000 && $this->mTitle
->getNamespace() == NS_USER_TALK
2001 && $shortTitle != $user->getTitleKey()
2002 && !( $revision->isMinor() && $user->isAllowed( 'nominornewtalk' ) )
2004 if ( wfRunHooks( 'ArticleEditUpdateNewTalk', array( &$this ) ) ) {
2005 $other = User
::newFromName( $shortTitle, false );
2007 wfDebug( __METHOD__
. ": invalid username\n" );
2008 } elseif ( User
::isIP( $shortTitle ) ) {
2009 // An anonymous user
2010 $other->setNewtalk( true );
2011 } elseif ( $other->isLoggedIn() ) {
2012 $other->setNewtalk( true );
2014 wfDebug( __METHOD__
. ": don't need to notify a nonexistent user\n" );
2019 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
2020 MessageCache
::singleton()->replace( $shortTitle, $text );
2023 if( $options['created'] ) {
2024 self
::onArticleCreate( $this->mTitle
);
2026 self
::onArticleEdit( $this->mTitle
);
2029 wfProfileOut( __METHOD__
);
2033 * Perform article updates on a special page creation.
2035 * @param $rev Revision object
2037 * @todo This is a shitty interface function. Kill it and replace the
2038 * other shitty functions like doEditUpdates and such so it's not needed
2040 * @deprecated since 1.19, use doEditUpdates()
2042 public function createUpdates( $rev ) {
2044 $this->doEditUpdates( $rev, $wgUser, array( 'created' => true ) );
2048 * This function is called right before saving the wikitext,
2049 * so we can do things like signatures and links-in-context.
2051 * @param $text String article contents
2052 * @param $user User object: user doing the edit
2053 * @param $popts ParserOptions object: parser options, default options for
2054 * the user loaded if null given
2055 * @return string article contents with altered wikitext markup (signatures
2056 * converted, {{subst:}}, templates, etc.)
2058 public function preSaveTransform( $text, User
$user = null, ParserOptions
$popts = null ) {
2059 global $wgParser, $wgUser;
2060 $user = is_null( $user ) ?
$wgUser : $user;
2062 if ( $popts === null ) {
2063 $popts = ParserOptions
::newFromUser( $user );
2066 return $wgParser->preSaveTransform( $text, $this->mTitle
, $user, $popts );
2070 * Loads page_touched and returns a value indicating if it should be used
2071 * @return boolean true if not a redirect
2073 public function checkTouched() {
2074 if ( !$this->mDataLoaded
) {
2075 $this->loadPageData();
2077 return !$this->mIsRedirect
;
2081 * Get the page_touched field
2082 * @return string containing GMT timestamp
2084 public function getTouched() {
2085 if ( !$this->mDataLoaded
) {
2086 $this->loadPageData();
2088 return $this->mTouched
;
2092 * Get the page_latest field
2093 * @return integer rev_id of current revision
2095 public function getLatest() {
2096 if ( !$this->mDataLoaded
) {
2097 $this->loadPageData();
2099 return (int)$this->mLatest
;
2103 * Edit an article without doing all that other stuff
2104 * The article must already exist; link tables etc
2105 * are not updated, caches are not flushed.
2107 * @param $text String: text submitted
2108 * @param $user User The relevant user
2109 * @param $comment String: comment submitted
2110 * @param $minor Boolean: whereas it's a minor modification
2112 public function doQuickEdit( $text, User
$user, $comment = '', $minor = 0 ) {
2113 wfProfileIn( __METHOD__
);
2115 $dbw = wfGetDB( DB_MASTER
);
2116 $revision = new Revision( array(
2117 'page' => $this->getId(),
2119 'comment' => $comment,
2120 'minor_edit' => $minor ?
1 : 0,
2122 $revision->insertOn( $dbw );
2123 $this->updateRevisionOn( $dbw, $revision );
2125 wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
2127 wfProfileOut( __METHOD__
);
2131 * The onArticle*() functions are supposed to be a kind of hooks
2132 * which should be called whenever any of the specified actions
2135 * This is a good place to put code to clear caches, for instance.
2137 * This is called on page move and undelete, as well as edit
2139 * @param $title Title object
2141 public static function onArticleCreate( $title ) {
2142 # Update existence markers on article/talk tabs...
2143 if ( $title->isTalkPage() ) {
2144 $other = $title->getSubjectPage();
2146 $other = $title->getTalkPage();
2149 $other->invalidateCache();
2150 $other->purgeSquid();
2152 $title->touchLinks();
2153 $title->purgeSquid();
2154 $title->deleteTitleProtection();
2158 * Clears caches when article is deleted
2160 * @param $title Title
2162 public static function onArticleDelete( $title ) {
2163 # Update existence markers on article/talk tabs...
2164 if ( $title->isTalkPage() ) {
2165 $other = $title->getSubjectPage();
2167 $other = $title->getTalkPage();
2170 $other->invalidateCache();
2171 $other->purgeSquid();
2173 $title->touchLinks();
2174 $title->purgeSquid();
2177 HTMLFileCache
::clearFileCache( $title );
2180 if ( $title->getNamespace() == NS_MEDIAWIKI
) {
2181 MessageCache
::singleton()->replace( $title->getDBkey(), false );
2185 if ( $title->getNamespace() == NS_FILE
) {
2186 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
2187 $update->doUpdate();
2191 if ( $title->getNamespace() == NS_USER_TALK
) {
2192 $user = User
::newFromName( $title->getText(), false );
2193 $user->setNewtalk( false );
2197 RepoGroup
::singleton()->getLocalRepo()->invalidateImageRedirect( $title );
2201 * Purge caches on page update etc
2203 * @param $title Title object
2204 * @todo: verify that $title is always a Title object (and never false or null), add Title hint to parameter $title
2206 public static function onArticleEdit( $title ) {
2207 global $wgDeferredUpdateList;
2209 // Invalidate caches of articles which include this page
2210 $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'templatelinks' );
2212 // Invalidate the caches of all pages which redirect here
2213 $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'redirect' );
2215 # Purge squid for this page only
2216 $title->purgeSquid();
2218 # Clear file cache for this page only
2219 HTMLFileCache
::clearFileCache( $title );
2225 * Return a list of templates used by this article.
2226 * Uses the templatelinks table
2228 * @return Array of Title objects
2230 public function getUsedTemplates() {
2232 $id = $this->mTitle
->getArticleID();
2238 $dbr = wfGetDB( DB_SLAVE
);
2239 $res = $dbr->select( array( 'templatelinks' ),
2240 array( 'tl_namespace', 'tl_title' ),
2241 array( 'tl_from' => $id ),
2244 if ( $res !== false ) {
2245 foreach ( $res as $row ) {
2246 $result[] = Title
::makeTitle( $row->tl_namespace
, $row->tl_title
);
2254 * Returns a list of hidden categories this page is a member of.
2255 * Uses the page_props and categorylinks tables.
2257 * @return Array of Title objects
2259 public function getHiddenCategories() {
2261 $id = $this->mTitle
->getArticleID();
2267 $dbr = wfGetDB( DB_SLAVE
);
2268 $res = $dbr->select( array( 'categorylinks', 'page_props', 'page' ),
2270 array( 'cl_from' => $id, 'pp_page=page_id', 'pp_propname' => 'hiddencat',
2271 'page_namespace' => NS_CATEGORY
, 'page_title=cl_to' ),
2274 if ( $res !== false ) {
2275 foreach ( $res as $row ) {
2276 $result[] = Title
::makeTitle( NS_CATEGORY
, $row->cl_to
);
2284 * Return an applicable autosummary if one exists for the given edit.
2285 * @param $oldtext String: the previous text of the page.
2286 * @param $newtext String: The submitted text of the page.
2287 * @param $flags Int bitmask: a bitmask of flags submitted for the edit.
2288 * @return string An appropriate autosummary, or an empty string.
2290 public static function getAutosummary( $oldtext, $newtext, $flags ) {
2293 # Decide what kind of autosummary is needed.
2295 # Redirect autosummaries
2296 $ot = Title
::newFromRedirect( $oldtext );
2297 $rt = Title
::newFromRedirect( $newtext );
2299 if ( is_object( $rt ) && ( !is_object( $ot ) ||
!$rt->equals( $ot ) ||
$ot->getFragment() != $rt->getFragment() ) ) {
2300 $truncatedtext = $wgContLang->truncate(
2301 str_replace( "\n", ' ', $newtext ),
2303 - strlen( wfMsgForContent( 'autoredircomment' ) )
2304 - strlen( $rt->getFullText() )
2306 return wfMsgForContent( 'autoredircomment', $rt->getFullText(), $truncatedtext );
2309 # New page autosummaries
2310 if ( $flags & EDIT_NEW
&& strlen( $newtext ) ) {
2311 # If they're making a new article, give its text, truncated, in the summary.
2313 $truncatedtext = $wgContLang->truncate(
2314 str_replace( "\n", ' ', $newtext ),
2315 max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new' ) ) ) );
2317 return wfMsgForContent( 'autosumm-new', $truncatedtext );
2320 # Blanking autosummaries
2321 if ( $oldtext != '' && $newtext == '' ) {
2322 return wfMsgForContent( 'autosumm-blank' );
2323 } elseif ( strlen( $oldtext ) > 10 * strlen( $newtext ) && strlen( $newtext ) < 500 ) {
2324 # Removing more than 90% of the article
2326 $truncatedtext = $wgContLang->truncate(
2328 max( 0, 200 - strlen( wfMsgForContent( 'autosumm-replace' ) ) ) );
2330 return wfMsgForContent( 'autosumm-replace', $truncatedtext );
2333 # If we reach this point, there's no applicable autosummary for our case, so our
2334 # autosummary is empty.
2339 * Get parser options suitable for rendering the primary article wikitext
2340 * @param $canonical boolean Determines that the generated options must not depend on user preferences (see bug 14404)
2341 * @return mixed ParserOptions object or boolean false
2343 public function getParserOptions( $canonical = false ) {
2344 global $wgUser, $wgLanguageCode;
2346 if ( !$this->mParserOptions ||
$canonical ) {
2347 $user = !$canonical ?
$wgUser : new User
;
2348 $parserOptions = new ParserOptions( $user );
2349 $parserOptions->setTidy( true );
2350 $parserOptions->enableLimitReport();
2353 $parserOptions->setUserLang( $wgLanguageCode ); # Must be set explicitely
2354 return $parserOptions;
2356 $this->mParserOptions
= $parserOptions;
2358 // Clone to allow modifications of the return value without affecting cache
2359 return clone $this->mParserOptions
;
2363 * Get parser options suitable for rendering the primary article wikitext
2365 * @return ParserOptions
2367 public function makeParserOptions( User
$user ) {
2368 $options = ParserOptions
::newFromUser( $user );
2369 $options->enableLimitReport(); // show inclusion/loop reports
2370 $options->setTidy( true ); // fix bad HTML
2375 * Update all the appropriate counts in the category table, given that
2376 * we've added the categories $added and deleted the categories $deleted.
2378 * @param $added array The names of categories that were added
2379 * @param $deleted array The names of categories that were deleted
2381 public function updateCategoryCounts( $added, $deleted ) {
2382 $ns = $this->mTitle
->getNamespace();
2383 $dbw = wfGetDB( DB_MASTER
);
2385 # First make sure the rows exist. If one of the "deleted" ones didn't
2386 # exist, we might legitimately not create it, but it's simpler to just
2387 # create it and then give it a negative value, since the value is bogus
2390 # Sometimes I wish we had INSERT ... ON DUPLICATE KEY UPDATE.
2391 $insertCats = array_merge( $added, $deleted );
2392 if ( !$insertCats ) {
2393 # Okay, nothing to do
2397 $insertRows = array();
2399 foreach ( $insertCats as $cat ) {
2400 $insertRows[] = array(
2401 'cat_id' => $dbw->nextSequenceValue( 'category_cat_id_seq' ),
2405 $dbw->insert( 'category', $insertRows, __METHOD__
, 'IGNORE' );
2407 $addFields = array( 'cat_pages = cat_pages + 1' );
2408 $removeFields = array( 'cat_pages = cat_pages - 1' );
2410 if ( $ns == NS_CATEGORY
) {
2411 $addFields[] = 'cat_subcats = cat_subcats + 1';
2412 $removeFields[] = 'cat_subcats = cat_subcats - 1';
2413 } elseif ( $ns == NS_FILE
) {
2414 $addFields[] = 'cat_files = cat_files + 1';
2415 $removeFields[] = 'cat_files = cat_files - 1';
2422 array( 'cat_title' => $added ),
2431 array( 'cat_title' => $deleted ),
2438 * Updates cascading protections
2440 * @param $parserOutput ParserOutput object for the current version
2442 public function doCascadeProtectionUpdates( ParserOutput
$parserOutput ) {
2443 if ( wfReadOnly() ||
!$this->mTitle
->areRestrictionsCascading() ) {
2447 // templatelinks table may have become out of sync,
2448 // especially if using variable-based transclusions.
2449 // For paranoia, check if things have changed and if
2450 // so apply updates to the database. This will ensure
2451 // that cascaded protections apply as soon as the changes
2454 # Get templates from templatelinks
2455 $id = $this->mTitle
->getArticleID();
2457 $tlTemplates = array();
2459 $dbr = wfGetDB( DB_SLAVE
);
2460 $res = $dbr->select( array( 'templatelinks' ),
2461 array( 'tl_namespace', 'tl_title' ),
2462 array( 'tl_from' => $id ),
2466 foreach ( $res as $row ) {
2467 $tlTemplates["{$row->tl_namespace}:{$row->tl_title}"] = true;
2470 # Get templates from parser output.
2471 $poTemplates = array();
2472 foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
2473 foreach ( $templates as $dbk => $id ) {
2474 $poTemplates["$ns:$dbk"] = true;
2479 $templates_diff = array_diff_key( $poTemplates, $tlTemplates );
2481 if ( count( $templates_diff ) > 0 ) {
2482 # Whee, link updates time.
2483 $u = new LinksUpdate( $this->mTitle
, $parserOutput, false );
2489 * @deprecated since 1.19
2491 public function quickEdit( $text, $comment = '', $minor = 0 ) {
2493 return $this->doQuickEdit( $text, $wgUser, $comment, $minor );
2497 * @deprecated since 1.19
2499 public function viewUpdates() {
2501 return $this->doViewUpdates( $wgUser );
2505 * @deprecated since 1.19
2507 public function useParserCache( $oldid ) {
2509 return $this->isParserCacheUsed( $wgUser, $oldid );