Localisation updates German
[mediawiki.git] / includes / Article.php
blob6b141b3f3271e5d83636c18bf0d9200189dcda6d
1 <?php
2 /**
3 * File for articles
4 */
6 /**
7 * Class representing a MediaWiki article and history.
9 * See design.txt for an overview.
10 * Note: edit user interface and cache support functions have been
11 * moved to separate EditPage and HTMLFileCache classes.
14 class Article {
15 /**@{{
16 * @private
18 var $mComment; //!<
19 var $mContent; //!<
20 var $mContentLoaded; //!<
21 var $mCounter; //!<
22 var $mForUpdate; //!<
23 var $mGoodAdjustment; //!<
24 var $mLatest; //!<
25 var $mMinorEdit; //!<
26 var $mOldId; //!<
27 var $mRedirectedFrom; //!<
28 var $mRedirectUrl; //!<
29 var $mRevIdFetched; //!<
30 var $mRevision; //!<
31 var $mTimestamp; //!<
32 var $mTitle; //!<
33 var $mTotalAdjustment; //!<
34 var $mTouched; //!<
35 var $mUser; //!<
36 var $mUserText; //!<
37 var $mRedirectTarget; //!<
38 /**@}}*/
40 /**
41 * Constructor and clear the article
42 * @param $title Reference to a Title object.
43 * @param $oldId Integer revision ID, null to fetch from request, zero for current
45 function __construct( Title $title, $oldId = null ) {
46 $this->mTitle =& $title;
47 $this->mOldId = $oldId;
48 $this->clear();
51 /**
52 * Tell the page view functions that this view was redirected
53 * from another page on the wiki.
54 * @param $from Title object.
56 function setRedirectedFrom( $from ) {
57 $this->mRedirectedFrom = $from;
60 /**
61 * If this page is a redirect, get its target
63 * The target will be fetched from the redirect table if possible.
64 * If this page doesn't have an entry there, call insertRedirect()
65 * @return mixed Title object, or null if this page is not a redirect
67 public function getRedirectTarget() {
68 if(!$this->mTitle || !$this->mTitle->isRedirect())
69 return null;
70 if(!is_null($this->mRedirectTarget))
71 return $this->mRedirectTarget;
73 # Query the redirect table
74 $dbr = wfGetDB(DB_SLAVE);
75 $res = $dbr->select('redirect',
76 array('rd_namespace', 'rd_title'),
77 array('rd_from' => $this->getID()),
78 __METHOD__
80 $row = $dbr->fetchObject($res);
81 if($row)
82 return $this->mRedirectTarget = Title::makeTitle($row->rd_namespace, $row->rd_title);
84 # This page doesn't have an entry in the redirect table
85 return $this->mRedirectTarget = $this->insertRedirect();
88 /**
89 * Insert an entry for this page into the redirect table.
91 * Don't call this function directly unless you know what you're doing.
92 * @return Title object
94 public function insertRedirect() {
95 $retval = Title::newFromRedirect($this->getContent());
96 if(!$retval)
97 return null;
98 $dbw = wfGetDB(DB_MASTER);
99 $dbw->replace('redirect', array('rd_from'), array(
100 'rd_from' => $this->getID(),
101 'rd_namespace' => $retval->getNamespace(),
102 'rd_title' => $retval->getDBKey()
103 ), __METHOD__);
104 return $retval;
108 * Get the Title object this page redirects to
110 * @return mixed false, Title of in-wiki target, or string with URL
112 function followRedirect() {
113 $text = $this->getContent();
114 $rt = Title::newFromRedirect( $text );
116 # process if title object is valid and not special:userlogout
117 if( $rt ) {
118 if( $rt->getInterwiki() != '' ) {
119 if( $rt->isLocal() ) {
120 // Offsite wikis need an HTTP redirect.
122 // This can be hard to reverse and may produce loops,
123 // so they may be disabled in the site configuration.
125 $source = $this->mTitle->getFullURL( 'redirect=no' );
126 return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
128 } else {
129 if( $rt->getNamespace() == NS_SPECIAL ) {
130 // Gotta handle redirects to special pages differently:
131 // Fill the HTTP response "Location" header and ignore
132 // the rest of the page we're on.
134 // This can be hard to reverse, so they may be disabled.
136 if( $rt->isSpecial( 'Userlogout' ) ) {
137 // rolleyes
138 } else {
139 return $rt->getFullURL();
142 return $rt;
146 // No or invalid redirect
147 return false;
151 * get the title object of the article
153 function getTitle() {
154 return $this->mTitle;
158 * Clear the object
159 * @private
161 function clear() {
162 $this->mDataLoaded = false;
163 $this->mContentLoaded = false;
165 $this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded
166 $this->mRedirectedFrom = null; # Title object if set
167 $this->mRedirectTarget = null; # Title object if set
168 $this->mUserText =
169 $this->mTimestamp = $this->mComment = '';
170 $this->mGoodAdjustment = $this->mTotalAdjustment = 0;
171 $this->mTouched = '19700101000000';
172 $this->mForUpdate = false;
173 $this->mIsRedirect = false;
174 $this->mRevIdFetched = 0;
175 $this->mRedirectUrl = false;
176 $this->mLatest = false;
177 $this->mPreparedEdit = false;
181 * Note that getContent/loadContent do not follow redirects anymore.
182 * If you need to fetch redirectable content easily, try
183 * the shortcut in Article::followContent()
184 * FIXME
185 * @todo There are still side-effects in this!
186 * In general, you should use the Revision class, not Article,
187 * to fetch text for purposes other than page views.
189 * @return Return the text of this revision
191 function getContent() {
192 global $wgUser, $wgOut, $wgMessageCache;
194 wfProfileIn( __METHOD__ );
196 if ( 0 == $this->getID() ) {
197 wfProfileOut( __METHOD__ );
198 $wgOut->setRobotpolicy( 'noindex,nofollow' );
200 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
201 $wgMessageCache->loadAllMessages();
202 $ret = wfMsgWeirdKey ( $this->mTitle->getText() ) ;
203 } else {
204 $ret = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );
207 return "<div class='noarticletext'>\n$ret\n</div>";
208 } else {
209 $this->loadContent();
210 wfProfileOut( __METHOD__ );
211 return $this->mContent;
216 * This function returns the text of a section, specified by a number ($section).
217 * A section is text under a heading like == Heading == or \<h1\>Heading\</h1\>, or
218 * the first section before any such heading (section 0).
220 * If a section contains subsections, these are also returned.
222 * @param $text String: text to look in
223 * @param $section Integer: section number
224 * @return string text of the requested section
225 * @deprecated
227 function getSection($text,$section) {
228 global $wgParser;
229 return $wgParser->getSection( $text, $section );
233 * @return int The oldid of the article that is to be shown, 0 for the
234 * current revision
236 function getOldID() {
237 if ( is_null( $this->mOldId ) ) {
238 $this->mOldId = $this->getOldIDFromRequest();
240 return $this->mOldId;
244 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
246 * @return int The old id for the request
248 function getOldIDFromRequest() {
249 global $wgRequest;
250 $this->mRedirectUrl = false;
251 $oldid = $wgRequest->getVal( 'oldid' );
252 if ( isset( $oldid ) ) {
253 $oldid = intval( $oldid );
254 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
255 $nextid = $this->mTitle->getNextRevisionID( $oldid );
256 if ( $nextid ) {
257 $oldid = $nextid;
258 } else {
259 $this->mRedirectUrl = $this->mTitle->getFullURL( 'redirect=no' );
261 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
262 $previd = $this->mTitle->getPreviousRevisionID( $oldid );
263 if ( $previd ) {
264 $oldid = $previd;
265 } else {
266 # TODO
269 # unused:
270 # $lastid = $oldid;
273 if ( !$oldid ) {
274 $oldid = 0;
276 return $oldid;
280 * Load the revision (including text) into this object
282 function loadContent() {
283 if ( $this->mContentLoaded ) return;
285 # Query variables :P
286 $oldid = $this->getOldID();
288 # Pre-fill content with error message so that if something
289 # fails we'll have something telling us what we intended.
290 $this->mOldId = $oldid;
291 $this->fetchContent( $oldid );
296 * Fetch a page record with the given conditions
297 * @param Database $dbr
298 * @param array $conditions
299 * @private
301 function pageData( $dbr, $conditions ) {
302 $fields = array(
303 'page_id',
304 'page_namespace',
305 'page_title',
306 'page_restrictions',
307 'page_counter',
308 'page_is_redirect',
309 'page_is_new',
310 'page_random',
311 'page_touched',
312 'page_latest',
313 'page_len',
315 wfRunHooks( 'ArticlePageDataBefore', array( &$this, &$fields ) );
316 $row = $dbr->selectRow(
317 'page',
318 $fields,
319 $conditions,
320 __METHOD__
322 wfRunHooks( 'ArticlePageDataAfter', array( &$this, &$row ) );
323 return $row ;
327 * @param Database $dbr
328 * @param Title $title
330 function pageDataFromTitle( $dbr, $title ) {
331 return $this->pageData( $dbr, array(
332 'page_namespace' => $title->getNamespace(),
333 'page_title' => $title->getDBkey() ) );
337 * @param Database $dbr
338 * @param int $id
340 function pageDataFromId( $dbr, $id ) {
341 return $this->pageData( $dbr, array( 'page_id' => $id ) );
345 * Set the general counter, title etc data loaded from
346 * some source.
348 * @param object $data
349 * @private
351 function loadPageData( $data = 'fromdb' ) {
352 if ( $data === 'fromdb' ) {
353 $dbr = $this->getDB();
354 $data = $this->pageDataFromId( $dbr, $this->getId() );
357 $lc = LinkCache::singleton();
358 if ( $data ) {
359 $lc->addGoodLinkObj( $data->page_id, $this->mTitle, $data->page_len, $data->page_is_redirect );
361 $this->mTitle->mArticleID = $data->page_id;
363 # Old-fashioned restrictions.
364 $this->mTitle->loadRestrictions( $data->page_restrictions );
366 $this->mCounter = $data->page_counter;
367 $this->mTouched = wfTimestamp( TS_MW, $data->page_touched );
368 $this->mIsRedirect = $data->page_is_redirect;
369 $this->mLatest = $data->page_latest;
370 } else {
371 if ( is_object( $this->mTitle ) ) {
372 $lc->addBadLinkObj( $this->mTitle );
374 $this->mTitle->mArticleID = 0;
377 $this->mDataLoaded = true;
381 * Get text of an article from database
382 * Does *NOT* follow redirects.
383 * @param int $oldid 0 for whatever the latest revision is
384 * @return string
386 function fetchContent( $oldid = 0 ) {
387 if ( $this->mContentLoaded ) {
388 return $this->mContent;
391 $dbr = $this->getDB();
393 # Pre-fill content with error message so that if something
394 # fails we'll have something telling us what we intended.
395 $t = $this->mTitle->getPrefixedText();
396 if( $oldid ) {
397 $t .= ' ' . wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid );
399 $this->mContent = wfMsg( 'missingarticle', $t ) ;
401 if( $oldid ) {
402 $revision = Revision::newFromId( $oldid );
403 if( is_null( $revision ) ) {
404 wfDebug( __METHOD__." failed to retrieve specified revision, id $oldid\n" );
405 return false;
407 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
408 if( !$data ) {
409 wfDebug( __METHOD__." failed to get page data linked to revision id $oldid\n" );
410 return false;
412 $this->mTitle = Title::makeTitle( $data->page_namespace, $data->page_title );
413 $this->loadPageData( $data );
414 } else {
415 if( !$this->mDataLoaded ) {
416 $data = $this->pageDataFromTitle( $dbr, $this->mTitle );
417 if( !$data ) {
418 wfDebug( __METHOD__." failed to find page data for title " . $this->mTitle->getPrefixedText() . "\n" );
419 return false;
421 $this->loadPageData( $data );
423 $revision = Revision::newFromId( $this->mLatest );
424 if( is_null( $revision ) ) {
425 wfDebug( __METHOD__." failed to retrieve current page, rev_id {$data->page_latest}\n" );
426 return false;
430 // FIXME: Horrible, horrible! This content-loading interface just plain sucks.
431 // We should instead work with the Revision object when we need it...
432 $this->mContent = $revision->revText(); // Loads if user is allowed
434 $this->mUser = $revision->getUser();
435 $this->mUserText = $revision->getUserText();
436 $this->mComment = $revision->getComment();
437 $this->mTimestamp = wfTimestamp( TS_MW, $revision->getTimestamp() );
439 $this->mRevIdFetched = $revision->getID();
440 $this->mContentLoaded = true;
441 $this->mRevision =& $revision;
443 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) ) ;
445 return $this->mContent;
449 * Read/write accessor to select FOR UPDATE
451 * @param $x Mixed: FIXME
453 function forUpdate( $x = NULL ) {
454 return wfSetVar( $this->mForUpdate, $x );
458 * Get the database which should be used for reads
460 * @return Database
462 function getDB() {
463 return wfGetDB( DB_MASTER );
467 * Get options for all SELECT statements
469 * @param $options Array: an optional options array which'll be appended to
470 * the default
471 * @return Array: options
473 function getSelectOptions( $options = '' ) {
474 if ( $this->mForUpdate ) {
475 if ( is_array( $options ) ) {
476 $options[] = 'FOR UPDATE';
477 } else {
478 $options = 'FOR UPDATE';
481 return $options;
485 * @return int Page ID
487 function getID() {
488 if( $this->mTitle ) {
489 return $this->mTitle->getArticleID();
490 } else {
491 return 0;
496 * @return bool Whether or not the page exists in the database
498 function exists() {
499 return $this->getId() != 0;
503 * @return int The view count for the page
505 function getCount() {
506 if ( -1 == $this->mCounter ) {
507 $id = $this->getID();
508 if ( $id == 0 ) {
509 $this->mCounter = 0;
510 } else {
511 $dbr = wfGetDB( DB_SLAVE );
512 $this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
513 'Article::getCount', $this->getSelectOptions() );
516 return $this->mCounter;
520 * Determine whether a page would be suitable for being counted as an
521 * article in the site_stats table based on the title & its content
523 * @param $text String: text to analyze
524 * @return bool
526 function isCountable( $text ) {
527 global $wgUseCommaCount;
529 $token = $wgUseCommaCount ? ',' : '[[';
530 return
531 $this->mTitle->isContentPage()
532 && !$this->isRedirect( $text )
533 && in_string( $token, $text );
537 * Tests if the article text represents a redirect
539 * @param $text String: FIXME
540 * @return bool
542 function isRedirect( $text = false ) {
543 if ( $text === false ) {
544 $this->loadContent();
545 $titleObj = Title::newFromRedirect( $this->fetchContent() );
546 } else {
547 $titleObj = Title::newFromRedirect( $text );
549 return $titleObj !== NULL;
553 * Returns true if the currently-referenced revision is the current edit
554 * to this page (and it exists).
555 * @return bool
557 function isCurrent() {
558 # If no oldid, this is the current version.
559 if ($this->getOldID() == 0)
560 return true;
562 return $this->exists() &&
563 isset( $this->mRevision ) &&
564 $this->mRevision->isCurrent();
568 * Loads everything except the text
569 * This isn't necessary for all uses, so it's only done if needed.
570 * @private
572 function loadLastEdit() {
573 if ( -1 != $this->mUser )
574 return;
576 # New or non-existent articles have no user information
577 $id = $this->getID();
578 if ( 0 == $id ) return;
580 $this->mLastRevision = Revision::loadFromPageId( $this->getDB(), $id );
581 if( !is_null( $this->mLastRevision ) ) {
582 $this->mUser = $this->mLastRevision->getUser();
583 $this->mUserText = $this->mLastRevision->getUserText();
584 $this->mTimestamp = $this->mLastRevision->getTimestamp();
585 $this->mComment = $this->mLastRevision->getComment();
586 $this->mMinorEdit = $this->mLastRevision->isMinor();
587 $this->mRevIdFetched = $this->mLastRevision->getID();
591 function getTimestamp() {
592 // Check if the field has been filled by ParserCache::get()
593 if ( !$this->mTimestamp ) {
594 $this->loadLastEdit();
596 return wfTimestamp(TS_MW, $this->mTimestamp);
599 function getUser() {
600 $this->loadLastEdit();
601 return $this->mUser;
604 function getUserText() {
605 $this->loadLastEdit();
606 return $this->mUserText;
609 function getComment() {
610 $this->loadLastEdit();
611 return $this->mComment;
614 function getMinorEdit() {
615 $this->loadLastEdit();
616 return $this->mMinorEdit;
619 function getRevIdFetched() {
620 $this->loadLastEdit();
621 return $this->mRevIdFetched;
625 * @todo Document, fixme $offset never used.
626 * @param $limit Integer: default 0.
627 * @param $offset Integer: default 0.
629 function getContributors($limit = 0, $offset = 0) {
630 # XXX: this is expensive; cache this info somewhere.
632 $contribs = array();
633 $dbr = wfGetDB( DB_SLAVE );
634 $revTable = $dbr->tableName( 'revision' );
635 $userTable = $dbr->tableName( 'user' );
636 $user = $this->getUser();
637 $pageId = $this->getId();
639 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
640 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
641 WHERE rev_page = $pageId
642 AND rev_user != $user
643 GROUP BY rev_user, rev_user_text, user_real_name
644 ORDER BY timestamp DESC";
646 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
647 $sql .= ' '. $this->getSelectOptions();
649 $res = $dbr->query($sql, __METHOD__);
651 while ( $line = $dbr->fetchObject( $res ) ) {
652 $contribs[] = array($line->rev_user, $line->rev_user_text, $line->user_real_name);
655 $dbr->freeResult($res);
656 return $contribs;
660 * This is the default action of the script: just view the page of
661 * the given title.
663 function view() {
664 global $wgUser, $wgOut, $wgRequest, $wgContLang;
665 global $wgEnableParserCache, $wgStylePath, $wgParser;
666 global $wgUseTrackbacks, $wgNamespaceRobotPolicies, $wgArticleRobotPolicies;
667 global $wgDefaultRobotPolicy;
668 $sk = $wgUser->getSkin();
670 wfProfileIn( __METHOD__ );
672 $parserCache = ParserCache::singleton();
673 $ns = $this->mTitle->getNamespace(); # shortcut
675 # Get variables from query string
676 $oldid = $this->getOldID();
678 # getOldID may want us to redirect somewhere else
679 if ( $this->mRedirectUrl ) {
680 $wgOut->redirect( $this->mRedirectUrl );
681 wfProfileOut( __METHOD__ );
682 return;
685 $diff = $wgRequest->getVal( 'diff' );
686 $rcid = $wgRequest->getVal( 'rcid' );
687 $rdfrom = $wgRequest->getVal( 'rdfrom' );
688 $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
689 $purge = $wgRequest->getVal( 'action' ) == 'purge';
691 $wgOut->setArticleFlag( true );
693 # Discourage indexing of printable versions, but encourage following
694 if( $wgOut->isPrintable() ) {
695 $policy = 'noindex,follow';
696 } elseif ( isset( $wgArticleRobotPolicies[$this->mTitle->getPrefixedText()] ) ) {
697 $policy = $wgArticleRobotPolicies[$this->mTitle->getPrefixedText()];
698 } elseif( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
699 # Honour customised robot policies for this namespace
700 $policy = $wgNamespaceRobotPolicies[$ns];
701 } else {
702 $policy = $wgDefaultRobotPolicy;
704 $wgOut->setRobotPolicy( $policy );
706 # If we got diff and oldid in the query, we want to see a
707 # diff page instead of the article.
709 if ( !is_null( $diff ) ) {
710 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
712 $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge );
713 // DifferenceEngine directly fetched the revision:
714 $this->mRevIdFetched = $de->mNewid;
715 $de->showDiffPage( $diffOnly );
717 // Needed to get the page's current revision
718 $this->loadPageData();
719 if( $diff == 0 || $diff == $this->mLatest ) {
720 # Run view updates for current revision only
721 $this->viewUpdates();
723 wfProfileOut( __METHOD__ );
724 return;
727 if ( empty( $oldid ) && $this->checkTouched() ) {
728 $wgOut->setETag($parserCache->getETag($this, $wgUser));
730 if( $wgOut->checkLastModified( $this->mTouched ) ){
731 wfProfileOut( __METHOD__ );
732 return;
733 } else if ( $this->tryFileCache() ) {
734 # tell wgOut that output is taken care of
735 $wgOut->disable();
736 $this->viewUpdates();
737 wfProfileOut( __METHOD__ );
738 return;
742 # Should the parser cache be used?
743 $pcache = $wgEnableParserCache
744 && intval( $wgUser->getOption( 'stubthreshold' ) ) == 0
745 && $this->exists()
746 && empty( $oldid )
747 && !$this->mTitle->isCssOrJsPage()
748 && !$this->mTitle->isCssJsSubpage();
749 wfDebug( 'Article::view using parser cache: ' . ($pcache ? 'yes' : 'no' ) . "\n" );
750 if ( $wgUser->getOption( 'stubthreshold' ) ) {
751 wfIncrStats( 'pcache_miss_stub' );
754 $wasRedirected = false;
755 if ( isset( $this->mRedirectedFrom ) ) {
756 // This is an internally redirected page view.
757 // We'll need a backlink to the source page for navigation.
758 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
759 $sk = $wgUser->getSkin();
760 $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom, '', 'redirect=no' );
761 $s = wfMsg( 'redirectedfrom', $redir );
762 $wgOut->setSubtitle( $s );
764 // Set the fragment if one was specified in the redirect
765 if ( strval( $this->mTitle->getFragment() ) != '' ) {
766 $fragment = Xml::escapeJsString( $this->mTitle->getFragmentForURL() );
767 $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
769 $wasRedirected = true;
771 } elseif ( !empty( $rdfrom ) ) {
772 // This is an externally redirected view, from some other wiki.
773 // If it was reported from a trusted site, supply a backlink.
774 global $wgRedirectSources;
775 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
776 $sk = $wgUser->getSkin();
777 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
778 $s = wfMsg( 'redirectedfrom', $redir );
779 $wgOut->setSubtitle( $s );
780 $wasRedirected = true;
784 $outputDone = false;
785 wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$pcache ) );
786 if ( $pcache ) {
787 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
788 // Ensure that UI elements requiring revision ID have
789 // the correct version information.
790 $wgOut->setRevisionId( $this->mLatest );
791 $outputDone = true;
794 if ( !$outputDone ) {
795 $text = $this->getContent();
796 if ( $text === false ) {
797 # Failed to load, replace text with error message
798 $t = $this->mTitle->getPrefixedText();
799 if( $oldid ) {
800 $t .= ' ' . wfMsgExt( 'missingarticle-rev', array( 'escape' ), $oldid );
801 $text = wfMsg( 'missingarticle', $t );
802 } else {
803 $text = wfMsg( 'noarticletext' );
807 # Another whitelist check in case oldid is altering the title
808 if ( !$this->mTitle->userCanRead() ) {
809 $wgOut->loginToUse();
810 $wgOut->output();
811 wfProfileOut( __METHOD__ );
812 exit;
815 # We're looking at an old revision
817 if ( !empty( $oldid ) ) {
818 $wgOut->setRobotpolicy( 'noindex,nofollow' );
819 if( is_null( $this->mRevision ) ) {
820 // FIXME: This would be a nice place to load the 'no such page' text.
821 } else {
822 $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
823 if( $this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
824 if( !$this->mRevision->userCan( Revision::DELETED_TEXT ) ) {
825 $wgOut->addWikiMsg( 'rev-deleted-text-permission' );
826 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
827 wfProfileOut( __METHOD__ );
828 return;
829 } else {
830 $wgOut->addWikiMsg( 'rev-deleted-text-view' );
831 // and we are allowed to see...
838 if( !$outputDone ) {
839 $wgOut->setRevisionId( $this->getRevIdFetched() );
841 // Pages containing custom CSS or JavaScript get special treatment
842 if( $this->mTitle->isCssOrJsPage() || $this->mTitle->isCssJsSubpage() ) {
843 $wgOut->addHtml( wfMsgExt( 'clearyourcache', 'parse' ) );
845 // Give hooks a chance to customise the output
846 if( wfRunHooks( 'ShowRawCssJs', array( $this->mContent, $this->mTitle, $wgOut ) ) ) {
847 // Wrap the whole lot in a <pre> and don't parse
848 $m = array();
849 preg_match( '!\.(css|js)$!u', $this->mTitle->getText(), $m );
850 $wgOut->addHtml( "<pre class=\"mw-code mw-{$m[1]}\" dir=\"ltr\">\n" );
851 $wgOut->addHtml( htmlspecialchars( $this->mContent ) );
852 $wgOut->addHtml( "\n</pre>\n" );
857 elseif ( $rt = Title::newFromRedirect( $text ) ) {
858 # Display redirect
859 $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
860 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
861 # Don't overwrite the subtitle if this was an old revision
862 if( !$wasRedirected && $this->isCurrent() ) {
863 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
865 $link = $sk->makeLinkObj( $rt, htmlspecialchars( $rt->getFullText() ) );
867 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT " />' .
868 '<span class="redirectText">'.$link.'</span>' );
870 $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser));
871 $wgOut->addParserOutputNoText( $parseout );
872 } else if ( $pcache ) {
873 # Display content and save to parser cache
874 $this->outputWikiText( $text );
875 } else {
876 # Display content, don't attempt to save to parser cache
877 # Don't show section-edit links on old revisions... this way lies madness.
878 if( !$this->isCurrent() ) {
879 $oldEditSectionSetting = $wgOut->parserOptions()->setEditSection( false );
881 # Display content and don't save to parser cache
882 # With timing hack -- TS 2006-07-26
883 $time = -wfTime();
884 $this->outputWikiText( $text, false );
885 $time += wfTime();
887 # Timing hack
888 if ( $time > 3 ) {
889 wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
890 $this->mTitle->getPrefixedDBkey()));
893 if( !$this->isCurrent() ) {
894 $wgOut->parserOptions()->setEditSection( $oldEditSectionSetting );
899 /* title may have been set from the cache */
900 $t = $wgOut->getPageTitle();
901 if( empty( $t ) ) {
902 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
905 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
906 if( $ns == NS_USER_TALK &&
907 IP::isValid( $this->mTitle->getText() ) ) {
908 $wgOut->addWikiMsg('anontalkpagetext');
911 # If we have been passed an &rcid= parameter, we want to give the user a
912 # chance to mark this new article as patrolled.
913 if( !is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) && $this->mTitle->exists() ) {
914 $wgOut->addHTML(
915 "<div class='patrollink'>" .
916 wfMsgHtml( 'markaspatrolledlink',
917 $sk->makeKnownLinkObj( $this->mTitle, wfMsgHtml('markaspatrolledtext'),
918 "action=markpatrolled&rcid=$rcid" )
920 '</div>'
924 # Trackbacks
925 if ($wgUseTrackbacks)
926 $this->addTrackbacks();
928 $this->viewUpdates();
929 wfProfileOut( __METHOD__ );
932 function addTrackbacks() {
933 global $wgOut, $wgUser;
935 $dbr = wfGetDB(DB_SLAVE);
936 $tbs = $dbr->select(
937 /* FROM */ 'trackbacks',
938 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
939 /* WHERE */ array('tb_page' => $this->getID())
942 if (!$dbr->numrows($tbs))
943 return;
945 $tbtext = "";
946 while ($o = $dbr->fetchObject($tbs)) {
947 $rmvtxt = "";
948 if ($wgUser->isAllowed( 'trackback' )) {
949 $delurl = $this->mTitle->getFullURL("action=deletetrackback&tbid="
950 . $o->tb_id . "&token=" . urlencode( $wgUser->editToken() ) );
951 $rmvtxt = wfMsg( 'trackbackremove', htmlspecialchars( $delurl ) );
953 $tbtext .= "\n";
954 $tbtext .= wfMsg(strlen($o->tb_ex) ? 'trackbackexcerpt' : 'trackback',
955 $o->tb_title,
956 $o->tb_url,
957 $o->tb_ex,
958 $o->tb_name,
959 $rmvtxt);
961 $wgOut->addWikiMsg( 'trackbackbox', $tbtext );
964 function deletetrackback() {
965 global $wgUser, $wgRequest, $wgOut, $wgTitle;
967 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
968 $wgOut->addWikiMsg( 'sessionfailure' );
969 return;
972 $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser );
974 if (count($permission_errors)>0)
976 $wgOut->showPermissionsErrorPage( $permission_errors );
977 return;
980 $db = wfGetDB(DB_MASTER);
981 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
982 $wgTitle->invalidateCache();
983 $wgOut->addWikiMsg('trackbackdeleteok');
986 function render() {
987 global $wgOut;
989 $wgOut->setArticleBodyOnly(true);
990 $this->view();
994 * Handle action=purge
996 function purge() {
997 global $wgUser, $wgRequest, $wgOut;
999 if ( $wgUser->isAllowed( 'purge' ) || $wgRequest->wasPosted() ) {
1000 if( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
1001 $this->doPurge();
1003 } else {
1004 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
1005 $action = htmlspecialchars( $_SERVER['REQUEST_URI'] );
1006 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
1007 $msg = str_replace( '$1',
1008 "<form method=\"post\" action=\"$action\">\n" .
1009 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
1010 "</form>\n", $msg );
1012 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
1013 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1014 $wgOut->addHTML( $msg );
1019 * Perform the actions of a page purging
1021 function doPurge() {
1022 global $wgUseSquid;
1023 // Invalidate the cache
1024 $this->mTitle->invalidateCache();
1026 if ( $wgUseSquid ) {
1027 // Commit the transaction before the purge is sent
1028 $dbw = wfGetDB( DB_MASTER );
1029 $dbw->immediateCommit();
1031 // Send purge
1032 $update = SquidUpdate::newSimplePurge( $this->mTitle );
1033 $update->doUpdate();
1035 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1036 global $wgMessageCache;
1037 if ( $this->getID() == 0 ) {
1038 $text = false;
1039 } else {
1040 $text = $this->getContent();
1042 $wgMessageCache->replace( $this->mTitle->getDBkey(), $text );
1044 $this->view();
1048 * Insert a new empty page record for this article.
1049 * This *must* be followed up by creating a revision
1050 * and running $this->updateToLatest( $rev_id );
1051 * or else the record will be left in a funky state.
1052 * Best if all done inside a transaction.
1054 * @param Database $dbw
1055 * @return int The newly created page_id key
1056 * @private
1058 function insertOn( $dbw ) {
1059 wfProfileIn( __METHOD__ );
1061 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
1062 $dbw->insert( 'page', array(
1063 'page_id' => $page_id,
1064 'page_namespace' => $this->mTitle->getNamespace(),
1065 'page_title' => $this->mTitle->getDBkey(),
1066 'page_counter' => 0,
1067 'page_restrictions' => '',
1068 'page_is_redirect' => 0, # Will set this shortly...
1069 'page_is_new' => 1,
1070 'page_random' => wfRandom(),
1071 'page_touched' => $dbw->timestamp(),
1072 'page_latest' => 0, # Fill this in shortly...
1073 'page_len' => 0, # Fill this in shortly...
1074 ), __METHOD__ );
1075 $newid = $dbw->insertId();
1077 $this->mTitle->resetArticleId( $newid );
1079 wfProfileOut( __METHOD__ );
1080 return $newid;
1084 * Update the page record to point to a newly saved revision.
1086 * @param Database $dbw
1087 * @param Revision $revision For ID number, and text used to set
1088 length and redirect status fields
1089 * @param int $lastRevision If given, will not overwrite the page field
1090 * when different from the currently set value.
1091 * Giving 0 indicates the new page flag should
1092 * be set on.
1093 * @param bool $lastRevIsRedirect If given, will optimize adding and
1094 * removing rows in redirect table.
1095 * @return bool true on success, false on failure
1096 * @private
1098 function updateRevisionOn( &$dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null ) {
1099 wfProfileIn( __METHOD__ );
1101 $text = $revision->getText();
1102 $rt = Title::newFromRedirect( $text );
1104 $conditions = array( 'page_id' => $this->getId() );
1105 if( !is_null( $lastRevision ) ) {
1106 # An extra check against threads stepping on each other
1107 $conditions['page_latest'] = $lastRevision;
1110 $dbw->update( 'page',
1111 array( /* SET */
1112 'page_latest' => $revision->getId(),
1113 'page_touched' => $dbw->timestamp(),
1114 'page_is_new' => ($lastRevision === 0) ? 1 : 0,
1115 'page_is_redirect' => $rt !== NULL ? 1 : 0,
1116 'page_len' => strlen( $text ),
1118 $conditions,
1119 __METHOD__ );
1121 $result = $dbw->affectedRows() != 0;
1123 if ($result) {
1124 $this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect );
1127 wfProfileOut( __METHOD__ );
1128 return $result;
1132 * Add row to the redirect table if this is a redirect, remove otherwise.
1134 * @param Database $dbw
1135 * @param $redirectTitle a title object pointing to the redirect target,
1136 * or NULL if this is not a redirect
1137 * @param bool $lastRevIsRedirect If given, will optimize adding and
1138 * removing rows in redirect table.
1139 * @return bool true on success, false on failure
1140 * @private
1142 function updateRedirectOn( &$dbw, $redirectTitle, $lastRevIsRedirect = null ) {
1144 // Always update redirects (target link might have changed)
1145 // Update/Insert if we don't know if the last revision was a redirect or not
1146 // Delete if changing from redirect to non-redirect
1147 $isRedirect = !is_null($redirectTitle);
1148 if ($isRedirect || is_null($lastRevIsRedirect) || $lastRevIsRedirect !== $isRedirect) {
1150 wfProfileIn( __METHOD__ );
1152 if ($isRedirect) {
1154 // This title is a redirect, Add/Update row in the redirect table
1155 $set = array( /* SET */
1156 'rd_namespace' => $redirectTitle->getNamespace(),
1157 'rd_title' => $redirectTitle->getDBkey(),
1158 'rd_from' => $this->getId(),
1161 $dbw->replace( 'redirect', array( 'rd_from' ), $set, __METHOD__ );
1162 } else {
1163 // This is not a redirect, remove row from redirect table
1164 $where = array( 'rd_from' => $this->getId() );
1165 $dbw->delete( 'redirect', $where, __METHOD__);
1168 if( $this->getTitle()->getNamespace() == NS_IMAGE )
1169 RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() );
1170 wfProfileOut( __METHOD__ );
1171 return ( $dbw->affectedRows() != 0 );
1174 return true;
1178 * If the given revision is newer than the currently set page_latest,
1179 * update the page record. Otherwise, do nothing.
1181 * @param Database $dbw
1182 * @param Revision $revision
1184 function updateIfNewerOn( &$dbw, $revision ) {
1185 wfProfileIn( __METHOD__ );
1187 $row = $dbw->selectRow(
1188 array( 'revision', 'page' ),
1189 array( 'rev_id', 'rev_timestamp', 'page_is_redirect' ),
1190 array(
1191 'page_id' => $this->getId(),
1192 'page_latest=rev_id' ),
1193 __METHOD__ );
1194 if( $row ) {
1195 if( wfTimestamp(TS_MW, $row->rev_timestamp) >= $revision->getTimestamp() ) {
1196 wfProfileOut( __METHOD__ );
1197 return false;
1199 $prev = $row->rev_id;
1200 $lastRevIsRedirect = (bool)$row->page_is_redirect;
1201 } else {
1202 # No or missing previous revision; mark the page as new
1203 $prev = 0;
1204 $lastRevIsRedirect = null;
1207 $ret = $this->updateRevisionOn( $dbw, $revision, $prev, $lastRevIsRedirect );
1208 wfProfileOut( __METHOD__ );
1209 return $ret;
1213 * @return string Complete article text, or null if error
1215 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1216 wfProfileIn( __METHOD__ );
1218 if( $section == '' ) {
1219 // Whole-page edit; let the text through unmolested.
1220 } else {
1221 if( is_null( $edittime ) ) {
1222 $rev = Revision::newFromTitle( $this->mTitle );
1223 } else {
1224 $dbw = wfGetDB( DB_MASTER );
1225 $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
1227 if( is_null( $rev ) ) {
1228 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1229 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1230 return null;
1232 $oldtext = $rev->getText();
1234 if( $section == 'new' ) {
1235 # Inserting a new section
1236 $subject = $summary ? wfMsgForContent('newsectionheaderdefaultlevel',$summary) . "\n\n" : '';
1237 $text = strlen( trim( $oldtext ) ) > 0
1238 ? "{$oldtext}\n\n{$subject}{$text}"
1239 : "{$subject}{$text}";
1240 } else {
1241 # Replacing an existing section; roll out the big guns
1242 global $wgParser;
1243 $text = $wgParser->replaceSection( $oldtext, $section, $text );
1248 wfProfileOut( __METHOD__ );
1249 return $text;
1253 * @deprecated use Article::doEdit()
1255 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false, $bot=false ) {
1256 $flags = EDIT_NEW | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
1257 ( $isminor ? EDIT_MINOR : 0 ) |
1258 ( $suppressRC ? EDIT_SUPPRESS_RC : 0 ) |
1259 ( $bot ? EDIT_FORCE_BOT : 0 );
1261 # If this is a comment, add the summary as headline
1262 if ( $comment && $summary != "" ) {
1263 $text = wfMsgForContent('newsectionheaderdefaultlevel',$summary) . "\n\n".$text;
1266 $this->doEdit( $text, $summary, $flags );
1268 $dbw = wfGetDB( DB_MASTER );
1269 if ($watchthis) {
1270 if (!$this->mTitle->userIsWatching()) {
1271 $dbw->begin();
1272 $this->doWatch();
1273 $dbw->commit();
1275 } else {
1276 if ( $this->mTitle->userIsWatching() ) {
1277 $dbw->begin();
1278 $this->doUnwatch();
1279 $dbw->commit();
1282 $this->doRedirect( $this->isRedirect( $text ) );
1286 * @deprecated use Article::doEdit()
1288 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1289 $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
1290 ( $minor ? EDIT_MINOR : 0 ) |
1291 ( $forceBot ? EDIT_FORCE_BOT : 0 );
1293 $good = $this->doEdit( $text, $summary, $flags );
1294 if ( $good ) {
1295 $dbw = wfGetDB( DB_MASTER );
1296 if ($watchthis) {
1297 if (!$this->mTitle->userIsWatching()) {
1298 $dbw->begin();
1299 $this->doWatch();
1300 $dbw->commit();
1302 } else {
1303 if ( $this->mTitle->userIsWatching() ) {
1304 $dbw->begin();
1305 $this->doUnwatch();
1306 $dbw->commit();
1310 $extraq = ''; // Give extensions a chance to modify URL query on update
1311 wfRunHooks( 'ArticleUpdateBeforeRedirect', array( $this, &$sectionanchor, &$extraq ) );
1313 $this->doRedirect( $this->isRedirect( $text ), $sectionanchor, $extraq );
1315 return $good;
1319 * Article::doEdit()
1321 * Change an existing article or create a new article. Updates RC and all necessary caches,
1322 * optionally via the deferred update array.
1324 * $wgUser must be set before calling this function.
1326 * @param string $text New text
1327 * @param string $summary Edit summary
1328 * @param integer $flags bitfield:
1329 * EDIT_NEW
1330 * Article is known or assumed to be non-existent, create a new one
1331 * EDIT_UPDATE
1332 * Article is known or assumed to be pre-existing, update it
1333 * EDIT_MINOR
1334 * Mark this edit minor, if the user is allowed to do so
1335 * EDIT_SUPPRESS_RC
1336 * Do not log the change in recentchanges
1337 * EDIT_FORCE_BOT
1338 * Mark the edit a "bot" edit regardless of user rights
1339 * EDIT_DEFER_UPDATES
1340 * Defer some of the updates until the end of index.php
1341 * EDIT_AUTOSUMMARY
1342 * Fill in blank summaries with generated text where possible
1344 * If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the article will be detected.
1345 * If EDIT_UPDATE is specified and the article doesn't exist, the function will return false. If
1346 * EDIT_NEW is specified and the article does exist, a duplicate key error will cause an exception
1347 * to be thrown from the Database. These two conditions are also possible with auto-detection due
1348 * to MediaWiki's performance-optimised locking strategy.
1350 * @return bool success
1352 function doEdit( $text, $summary, $flags = 0 ) {
1353 global $wgUser, $wgDBtransactions;
1355 wfProfileIn( __METHOD__ );
1356 $good = true;
1358 if ( !($flags & EDIT_NEW) && !($flags & EDIT_UPDATE) ) {
1359 $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
1360 if ( $aid ) {
1361 $flags |= EDIT_UPDATE;
1362 } else {
1363 $flags |= EDIT_NEW;
1367 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1368 &$summary, $flags & EDIT_MINOR,
1369 null, null, &$flags ) ) )
1371 wfDebug( __METHOD__ . ": ArticleSave hook aborted save!\n" );
1372 wfProfileOut( __METHOD__ );
1373 return false;
1376 # Silently ignore EDIT_MINOR if not allowed
1377 $isminor = ( $flags & EDIT_MINOR ) && $wgUser->isAllowed('minoredit');
1378 $bot = $flags & EDIT_FORCE_BOT;
1380 $oldtext = $this->getContent();
1381 $oldsize = strlen( $oldtext );
1383 # Provide autosummaries if one is not provided.
1384 if ($flags & EDIT_AUTOSUMMARY && $summary == '')
1385 $summary = $this->getAutosummary( $oldtext, $text, $flags );
1387 $editInfo = $this->prepareTextForEdit( $text );
1388 $text = $editInfo->pst;
1389 $newsize = strlen( $text );
1391 $dbw = wfGetDB( DB_MASTER );
1392 $now = wfTimestampNow();
1394 if ( $flags & EDIT_UPDATE ) {
1395 # Update article, but only if changed.
1397 # Make sure the revision is either completely inserted or not inserted at all
1398 if( !$wgDBtransactions ) {
1399 $userAbort = ignore_user_abort( true );
1402 $lastRevision = 0;
1403 $revisionId = 0;
1405 $changed = ( strcmp( $text, $oldtext ) != 0 );
1407 if ( $changed ) {
1408 $this->mGoodAdjustment = (int)$this->isCountable( $text )
1409 - (int)$this->isCountable( $oldtext );
1410 $this->mTotalAdjustment = 0;
1412 $lastRevision = $dbw->selectField(
1413 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1415 if ( !$lastRevision ) {
1416 # Article gone missing
1417 wfDebug( __METHOD__.": EDIT_UPDATE specified but article doesn't exist\n" );
1418 wfProfileOut( __METHOD__ );
1419 return false;
1422 $revision = new Revision( array(
1423 'page' => $this->getId(),
1424 'comment' => $summary,
1425 'minor_edit' => $isminor,
1426 'text' => $text,
1427 'parent_id' => $lastRevision
1428 ) );
1430 $dbw->begin();
1431 $revisionId = $revision->insertOn( $dbw );
1433 # Update page
1434 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1436 if( !$ok ) {
1437 /* Belated edit conflict! Run away!! */
1438 $good = false;
1439 $dbw->rollback();
1440 } else {
1441 # Update recentchanges
1442 if( !( $flags & EDIT_SUPPRESS_RC ) ) {
1443 $rcid = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary,
1444 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1445 $revisionId );
1447 # Mark as patrolled if the user can do so
1448 if( $GLOBALS['wgUseRCPatrol'] && $wgUser->isAllowed( 'autopatrol' ) ) {
1449 RecentChange::markPatrolled( $rcid );
1450 PatrolLog::record( $rcid, true );
1453 $wgUser->incEditCount();
1454 $dbw->commit();
1456 } else {
1457 $revision = null;
1458 // Keep the same revision ID, but do some updates on it
1459 $revisionId = $this->getRevIdFetched();
1460 // Update page_touched, this is usually implicit in the page update
1461 // Other cache updates are done in onArticleEdit()
1462 $this->mTitle->invalidateCache();
1465 if( !$wgDBtransactions ) {
1466 ignore_user_abort( $userAbort );
1469 if ( $good ) {
1470 # Invalidate cache of this article and all pages using this article
1471 # as a template. Partly deferred.
1472 Article::onArticleEdit( $this->mTitle );
1474 # Update links tables, site stats, etc.
1475 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
1477 } else {
1478 # Create new article
1480 # Set statistics members
1481 # We work out if it's countable after PST to avoid counter drift
1482 # when articles are created with {{subst:}}
1483 $this->mGoodAdjustment = (int)$this->isCountable( $text );
1484 $this->mTotalAdjustment = 1;
1486 $dbw->begin();
1488 # Add the page record; stake our claim on this title!
1489 # This will fail with a database query exception if the article already exists
1490 $newid = $this->insertOn( $dbw );
1492 # Save the revision text...
1493 $revision = new Revision( array(
1494 'page' => $newid,
1495 'comment' => $summary,
1496 'minor_edit' => $isminor,
1497 'text' => $text
1498 ) );
1499 $revisionId = $revision->insertOn( $dbw );
1501 $this->mTitle->resetArticleID( $newid );
1503 # Update the page record with revision data
1504 $this->updateRevisionOn( $dbw, $revision, 0 );
1506 if( !( $flags & EDIT_SUPPRESS_RC ) ) {
1507 $rcid = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary, $bot,
1508 '', strlen( $text ), $revisionId );
1509 # Mark as patrolled if the user can
1510 if( ($GLOBALS['wgUseRCPatrol'] || $GLOBALS['wgUseNPPatrol']) && $wgUser->isAllowed( 'autopatrol' ) ) {
1511 RecentChange::markPatrolled( $rcid );
1512 PatrolLog::record( $rcid, true );
1515 $wgUser->incEditCount();
1516 $dbw->commit();
1518 # Update links, etc.
1519 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true );
1521 # Clear caches
1522 Article::onArticleCreate( $this->mTitle );
1524 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text, $summary,
1525 $flags & EDIT_MINOR, null, null, &$flags, $revision ) );
1528 if ( $good && !( $flags & EDIT_DEFER_UPDATES ) ) {
1529 wfDoUpdates();
1532 if ( $good ) {
1533 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text, $summary,
1534 $flags & EDIT_MINOR, null, null, &$flags, $revision ) );
1537 wfProfileOut( __METHOD__ );
1538 return $good;
1542 * @deprecated wrapper for doRedirect
1544 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1545 $this->doRedirect( $this->isRedirect( $text ), $sectionanchor );
1549 * Output a redirect back to the article.
1550 * This is typically used after an edit.
1552 * @param boolean $noRedir Add redirect=no
1553 * @param string $sectionAnchor section to redirect to, including "#"
1554 * @param string $extraq, extra query params
1556 function doRedirect( $noRedir = false, $sectionAnchor = '', $extraq = '' ) {
1557 global $wgOut;
1558 if ( $noRedir ) {
1559 $query = 'redirect=no';
1560 if( $extraq )
1561 $query .= "&$query";
1562 } else {
1563 $query = $extraq;
1565 $wgOut->redirect( $this->mTitle->getFullURL( $query ) . $sectionAnchor );
1569 * Mark this particular edit/page as patrolled
1571 function markpatrolled() {
1572 global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUseNPPatrol, $wgUser;
1573 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1575 # Check patrol config options
1577 if ( !($wgUseNPPatrol || $wgUseRCPatrol)) {
1578 $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1579 return;
1582 # If we haven't been given an rc_id value, we can't do anything
1583 $rcid = (int) $wgRequest->getVal('rcid');
1584 $rc = $rcid ? RecentChange::newFromId($rcid) : null;
1585 if ( is_null ( $rc ) )
1587 $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1588 return;
1591 if ( !$wgUseRCPatrol && $rc->getAttribute( 'rc_type' ) != RC_NEW) {
1592 // Only new pages can be patrolled if the general patrolling is off....???
1593 // @fixme -- is this necessary? Shouldn't we only bother controlling the
1594 // front end here?
1595 $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1596 return;
1599 # Check permissions
1600 $permission_errors = $this->mTitle->getUserPermissionsErrors( 'patrol', $wgUser );
1602 if (count($permission_errors)>0)
1604 $wgOut->showPermissionsErrorPage( $permission_errors );
1605 return;
1608 # Handle the 'MarkPatrolled' hook
1609 if( !wfRunHooks( 'MarkPatrolled', array( $rcid, &$wgUser, false ) ) ) {
1610 return;
1613 #It would be nice to see where the user had actually come from, but for now just guess
1614 $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
1615 $return = Title::makeTitle( NS_SPECIAL, $returnto );
1617 # If it's left up to us, check that the user is allowed to patrol this edit
1618 # If the user has the "autopatrol" right, then we'll assume there are no
1619 # other conditions stopping them doing so
1620 if( !$wgUser->isAllowed( 'autopatrol' ) ) {
1621 $rc = RecentChange::newFromId( $rcid );
1622 # Graceful error handling, as we've done before here...
1623 # (If the recent change doesn't exist, then it doesn't matter whether
1624 # the user is allowed to patrol it or not; nothing is going to happen
1625 if( is_object( $rc ) && $wgUser->getName() == $rc->getAttribute( 'rc_user_text' ) ) {
1626 # The user made this edit, and can't patrol it
1627 # Tell them so, and then back off
1628 $wgOut->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
1629 $wgOut->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
1630 $wgOut->returnToMain( false, $return );
1631 return;
1635 # Check that the revision isn't patrolled already
1636 # Prevents duplicate log entries
1637 if( !$rc->getAttribute( 'rc_patrolled' ) ) {
1638 # Mark the edit as patrolled
1639 RecentChange::markPatrolled( $rcid );
1640 PatrolLog::record( $rcid );
1641 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
1644 # Inform the user
1645 $wgOut->setPageTitle( wfMsg( 'markedaspatrolled' ) );
1646 $wgOut->addWikiMsg( 'markedaspatrolledtext' );
1647 $wgOut->returnToMain( false, $return );
1651 * User-interface handler for the "watch" action
1654 function watch() {
1656 global $wgUser, $wgOut;
1658 if ( $wgUser->isAnon() ) {
1659 $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
1660 return;
1662 if ( wfReadOnly() ) {
1663 $wgOut->readOnlyPage();
1664 return;
1667 if( $this->doWatch() ) {
1668 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1669 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1671 $wgOut->addWikiMsg( 'addedwatchtext', $this->mTitle->getPrefixedText() );
1674 $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
1678 * Add this page to $wgUser's watchlist
1679 * @return bool true on successful watch operation
1681 function doWatch() {
1682 global $wgUser;
1683 if( $wgUser->isAnon() ) {
1684 return false;
1687 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1688 $wgUser->addWatch( $this->mTitle );
1690 return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1693 return false;
1697 * User interface handler for the "unwatch" action.
1699 function unwatch() {
1701 global $wgUser, $wgOut;
1703 if ( $wgUser->isAnon() ) {
1704 $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
1705 return;
1707 if ( wfReadOnly() ) {
1708 $wgOut->readOnlyPage();
1709 return;
1712 if( $this->doUnwatch() ) {
1713 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1714 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1716 $wgOut->addWikiMsg( 'removedwatchtext', $this->mTitle->getPrefixedText() );
1719 $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
1723 * Stop watching a page
1724 * @return bool true on successful unwatch
1726 function doUnwatch() {
1727 global $wgUser;
1728 if( $wgUser->isAnon() ) {
1729 return false;
1732 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1733 $wgUser->removeWatch( $this->mTitle );
1735 return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1738 return false;
1742 * action=protect handler
1744 function protect() {
1745 $form = new ProtectionForm( $this );
1746 $form->execute();
1750 * action=unprotect handler (alias)
1752 function unprotect() {
1753 $this->protect();
1757 * Update the article's restriction field, and leave a log entry.
1759 * @param array $limit set of restriction keys
1760 * @param string $reason
1761 * @return bool true on success
1763 function updateRestrictions( $limit = array(), $reason = '', $cascade = 0, $expiry = null ) {
1764 global $wgUser, $wgRestrictionTypes, $wgContLang;
1766 $id = $this->mTitle->getArticleID();
1767 if( array() != $this->mTitle->getUserPermissionsErrors( 'protect', $wgUser ) || wfReadOnly() || $id == 0 ) {
1768 return false;
1771 if (!$cascade) {
1772 $cascade = false;
1775 // Take this opportunity to purge out expired restrictions
1776 Title::purgeExpiredRestrictions();
1778 # FIXME: Same limitations as described in ProtectionForm.php (line 37);
1779 # we expect a single selection, but the schema allows otherwise.
1780 $current = array();
1781 foreach( $wgRestrictionTypes as $action )
1782 $current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
1784 $current = Article::flattenRestrictions( $current );
1785 $updated = Article::flattenRestrictions( $limit );
1787 $changed = ( $current != $updated );
1788 $changed = $changed || ($updated && $this->mTitle->areRestrictionsCascading() != $cascade);
1789 $changed = $changed || ($updated && $this->mTitle->mRestrictionsExpiry != $expiry);
1790 $protect = ( $updated != '' );
1792 # If nothing's changed, do nothing
1793 if( $changed ) {
1794 global $wgGroupPermissions;
1795 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {
1797 $dbw = wfGetDB( DB_MASTER );
1799 $encodedExpiry = Block::encodeExpiry($expiry, $dbw );
1801 $expiry_description = '';
1802 if ( $encodedExpiry != 'infinity' ) {
1803 $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry, false, false ) ).')';
1806 # Prepare a null revision to be added to the history
1807 $modified = $current != '' && $protect;
1808 if ( $protect ) {
1809 $comment_type = $modified ? 'modifiedarticleprotection' : 'protectedarticle';
1810 } else {
1811 $comment_type = 'unprotectedarticle';
1813 $comment = $wgContLang->ucfirst( wfMsgForContent( $comment_type, $this->mTitle->getPrefixedText() ) );
1815 foreach( $limit as $action => $restrictions ) {
1816 # Check if the group level required to edit also can protect pages
1817 # Otherwise, people who cannot normally protect can "protect" pages via transclusion
1818 $cascade = ( $cascade && isset($wgGroupPermissions[$restrictions]['protect']) &&
1819 $wgGroupPermissions[$restrictions]['protect'] );
1822 $cascade_description = '';
1823 if ($cascade) {
1824 $cascade_description = ' ['.wfMsg('protect-summary-cascade').']';
1827 if( $reason )
1828 $comment .= ": $reason";
1829 if( $protect )
1830 $comment .= " [$updated]";
1831 if ( $expiry_description && $protect )
1832 $comment .= "$expiry_description";
1833 if ( $cascade )
1834 $comment .= "$cascade_description";
1836 # Update restrictions table
1837 foreach( $limit as $action => $restrictions ) {
1838 if ($restrictions != '' ) {
1839 $dbw->replace( 'page_restrictions', array(array('pr_page', 'pr_type')),
1840 array( 'pr_page' => $id, 'pr_type' => $action
1841 , 'pr_level' => $restrictions, 'pr_cascade' => $cascade ? 1 : 0
1842 , 'pr_expiry' => $encodedExpiry ), __METHOD__ );
1843 } else {
1844 $dbw->delete( 'page_restrictions', array( 'pr_page' => $id,
1845 'pr_type' => $action ), __METHOD__ );
1849 # Insert a null revision
1850 $nullRevision = Revision::newNullRevision( $dbw, $id, $comment, true );
1851 $nullRevId = $nullRevision->insertOn( $dbw );
1853 # Update page record
1854 $dbw->update( 'page',
1855 array( /* SET */
1856 'page_touched' => $dbw->timestamp(),
1857 'page_restrictions' => '',
1858 'page_latest' => $nullRevId
1859 ), array( /* WHERE */
1860 'page_id' => $id
1861 ), 'Article::protect'
1863 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) );
1865 # Update the protection log
1866 $log = new LogPage( 'protect' );
1867 if( $protect ) {
1868 $log->addEntry( $modified ? 'modify' : 'protect', $this->mTitle, trim( $reason . " [$updated]$cascade_description$expiry_description" ) );
1869 } else {
1870 $log->addEntry( 'unprotect', $this->mTitle, $reason );
1873 } # End hook
1874 } # End "changed" check
1876 return true;
1880 * Take an array of page restrictions and flatten it to a string
1881 * suitable for insertion into the page_restrictions field.
1882 * @param array $limit
1883 * @return string
1884 * @private
1886 function flattenRestrictions( $limit ) {
1887 if( !is_array( $limit ) ) {
1888 throw new MWException( 'Article::flattenRestrictions given non-array restriction set' );
1890 $bits = array();
1891 ksort( $limit );
1892 foreach( $limit as $action => $restrictions ) {
1893 if( $restrictions != '' ) {
1894 $bits[] = "$action=$restrictions";
1897 return implode( ':', $bits );
1901 * Auto-generates a deletion reason
1902 * @param bool &$hasHistory Whether the page has a history
1904 public function generateReason(&$hasHistory)
1906 global $wgContLang;
1907 $dbw = wfGetDB(DB_MASTER);
1908 // Get the last revision
1909 $rev = Revision::newFromTitle($this->mTitle);
1910 if(is_null($rev))
1911 return false;
1912 // Get the article's contents
1913 $contents = $rev->getText();
1914 $blank = false;
1915 // If the page is blank, use the text from the previous revision,
1916 // which can only be blank if there's a move/import/protect dummy revision involved
1917 if($contents == '')
1919 $prev = $rev->getPrevious();
1920 if($prev)
1922 $contents = $prev->getText();
1923 $blank = true;
1927 // Find out if there was only one contributor
1928 // Only scan the last 20 revisions
1929 $limit = 20;
1930 $res = $dbw->select('revision', 'rev_user_text', array('rev_page' => $this->getID()), __METHOD__,
1931 array('LIMIT' => $limit));
1932 if($res === false)
1933 // This page has no revisions, which is very weird
1934 return false;
1935 if($res->numRows() > 1)
1936 $hasHistory = true;
1937 else
1938 $hasHistory = false;
1939 $row = $dbw->fetchObject($res);
1940 $onlyAuthor = $row->rev_user_text;
1941 // Try to find a second contributor
1942 while( $row = $dbw->fetchObject($res) ) {
1943 if($row->rev_user_text != $onlyAuthor) {
1944 $onlyAuthor = false;
1945 break;
1948 $dbw->freeResult($res);
1950 // Generate the summary with a '$1' placeholder
1951 if($blank) {
1952 // The current revision is blank and the one before is also
1953 // blank. It's just not our lucky day
1954 $reason = wfMsgForContent('exbeforeblank', '$1');
1955 } else {
1956 if($onlyAuthor)
1957 $reason = wfMsgForContent('excontentauthor', '$1', $onlyAuthor);
1958 else
1959 $reason = wfMsgForContent('excontent', '$1');
1962 // Replace newlines with spaces to prevent uglyness
1963 $contents = preg_replace("/[\n\r]/", ' ', $contents);
1964 // Calculate the maximum amount of chars to get
1965 // Max content length = max comment length - length of the comment (excl. $1) - '...'
1966 $maxLength = 255 - (strlen($reason) - 2) - 3;
1967 $contents = $wgContLang->truncate($contents, $maxLength, '...');
1968 // Remove possible unfinished links
1969 $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
1970 // Now replace the '$1' placeholder
1971 $reason = str_replace( '$1', $contents, $reason );
1972 return $reason;
1977 * UI entry point for page deletion
1979 function delete() {
1980 global $wgUser, $wgOut, $wgRequest;
1982 $confirm = $wgRequest->wasPosted() &&
1983 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1985 $this->DeleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
1986 $this->DeleteReason = $wgRequest->getText( 'wpReason' );
1988 $reason = $this->DeleteReasonList;
1990 if ( $reason != 'other' && $this->DeleteReason != '') {
1991 // Entry from drop down menu + additional comment
1992 $reason .= ': ' . $this->DeleteReason;
1993 } elseif ( $reason == 'other' ) {
1994 $reason = $this->DeleteReason;
1996 # Flag to hide all contents of the archived revisions
1997 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $wgUser->isAllowed('hiderevision');
1999 # This code desperately needs to be totally rewritten
2001 # Read-only check...
2002 if ( wfReadOnly() ) {
2003 $wgOut->readOnlyPage();
2004 return;
2007 # Check permissions
2008 $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser );
2010 if (count($permission_errors)>0) {
2011 $wgOut->showPermissionsErrorPage( $permission_errors );
2012 return;
2015 $wgOut->setPagetitle( wfMsg( 'delete-confirm', $this->mTitle->getPrefixedText() ) );
2017 # Better double-check that it hasn't been deleted yet!
2018 $dbw = wfGetDB( DB_MASTER );
2019 $conds = $this->mTitle->pageCond();
2020 $latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ );
2021 if ( $latest === false ) {
2022 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
2023 return;
2026 # Hack for big sites
2027 $bigHistory = $this->isBigDeletion();
2028 if( $bigHistory && !$this->mTitle->userCan( 'bigdelete' ) ) {
2029 global $wgLang, $wgDeleteRevisionsLimit;
2030 $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>\n",
2031 array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
2032 return;
2035 if( $confirm ) {
2036 $this->doDelete( $reason, $suppress );
2037 if( $wgRequest->getCheck( 'wpWatch' ) ) {
2038 $this->doWatch();
2039 } elseif( $this->mTitle->userIsWatching() ) {
2040 $this->doUnwatch();
2042 return;
2045 // Generate deletion reason
2046 $hasHistory = false;
2047 if ( !$reason ) $reason = $this->generateReason($hasHistory);
2049 // If the page has a history, insert a warning
2050 if( $hasHistory && !$confirm ) {
2051 $skin=$wgUser->getSkin();
2052 $wgOut->addHTML( '<strong>' . wfMsg( 'historywarning' ) . ' ' . $skin->historyLink() . '</strong>' );
2053 if( $bigHistory ) {
2054 global $wgLang, $wgDeleteRevisionsLimit;
2055 $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>\n",
2056 array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
2060 return $this->confirmDelete( '', $reason );
2064 * @return bool whether or not the page surpasses $wgDeleteRevisionsLimit revisions
2066 function isBigDeletion() {
2067 global $wgDeleteRevisionsLimit;
2068 if( $wgDeleteRevisionsLimit ) {
2069 $revCount = $this->estimateRevisionCount();
2070 return $revCount > $wgDeleteRevisionsLimit;
2072 return false;
2076 * @return int approximate revision count
2078 function estimateRevisionCount() {
2079 $dbr = wfGetDB();
2080 // For an exact count...
2081 //return $dbr->selectField( 'revision', 'COUNT(*)',
2082 // array( 'rev_page' => $this->getId() ), __METHOD__ );
2083 return $dbr->estimateRowCount( 'revision', '*',
2084 array( 'rev_page' => $this->getId() ), __METHOD__ );
2088 * Get the last N authors
2089 * @param int $num Number of revisions to get
2090 * @param string $revLatest The latest rev_id, selected from the master (optional)
2091 * @return array Array of authors, duplicates not removed
2093 function getLastNAuthors( $num, $revLatest = 0 ) {
2094 wfProfileIn( __METHOD__ );
2096 // First try the slave
2097 // If that doesn't have the latest revision, try the master
2098 $continue = 2;
2099 $db = wfGetDB( DB_SLAVE );
2100 do {
2101 $res = $db->select( array( 'page', 'revision' ),
2102 array( 'rev_id', 'rev_user_text' ),
2103 array(
2104 'page_namespace' => $this->mTitle->getNamespace(),
2105 'page_title' => $this->mTitle->getDBkey(),
2106 'rev_page = page_id'
2107 ), __METHOD__, $this->getSelectOptions( array(
2108 'ORDER BY' => 'rev_timestamp DESC',
2109 'LIMIT' => $num
2112 if ( !$res ) {
2113 wfProfileOut( __METHOD__ );
2114 return array();
2116 $row = $db->fetchObject( $res );
2117 if ( $continue == 2 && $revLatest && $row->rev_id != $revLatest ) {
2118 $db = wfGetDB( DB_MASTER );
2119 $continue--;
2120 } else {
2121 $continue = 0;
2123 } while ( $continue );
2125 $authors = array( $row->rev_user_text );
2126 while ( $row = $db->fetchObject( $res ) ) {
2127 $authors[] = $row->rev_user_text;
2129 wfProfileOut( __METHOD__ );
2130 return $authors;
2134 * Output deletion confirmation dialog
2135 * @param $par string FIXME: do we need this parameter? One Call from Article::delete with '' only.
2136 * @param $reason string Prefilled reason
2138 function confirmDelete( $par, $reason ) {
2139 global $wgOut, $wgUser, $wgContLang;
2140 $align = $wgContLang->isRtl() ? 'left' : 'right';
2142 wfDebug( "Article::confirmDelete\n" );
2144 $wgOut->setSubtitle( wfMsg( 'delete-backlink', $wgUser->getSkin()->makeKnownLinkObj( $this->mTitle ) ) );
2145 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2146 $wgOut->addWikiMsg( 'confirmdeletetext' );
2148 if( $wgUser->isAllowed( 'hiderevision' ) ) {
2149 $suppress = "<tr id=\"wpDeleteSuppressRow\" name=\"wpDeleteSuppressRow\"><td></td><td>";
2150 $suppress .= Xml::checkLabel( wfMsg( 'revdelete-suppress' ), 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '2' ) );
2151 $suppress .= "</td></tr>";
2152 } else {
2153 $suppress = '';
2156 $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->mTitle->getLocalURL( 'action=delete' . $par ), 'id' => 'deleteconfirm' ) ) .
2157 Xml::openElement( 'fieldset', array( 'id' => 'mw-delete-table' ) ) .
2158 Xml::element( 'legend', null, wfMsg( 'delete-legend' ) ) .
2159 Xml::openElement( 'table' ) .
2160 "<tr id=\"wpDeleteReasonListRow\">
2161 <td align='$align'>" .
2162 Xml::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
2163 "</td>
2164 <td>" .
2165 Xml::listDropDown( 'wpDeleteReasonList',
2166 wfMsgForContent( 'deletereason-dropdown' ),
2167 wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
2168 "</td>
2169 </tr>
2170 <tr id=\"wpDeleteReasonRow\">
2171 <td align='$align'>" .
2172 Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
2173 "</td>
2174 <td>" .
2175 Xml::input( 'wpReason', 60, $reason, array( 'type' => 'text', 'maxlength' => '255', 'tabindex' => '2', 'id' => 'wpReason' ) ) .
2176 "</td>
2177 </tr>
2178 <tr>
2179 <td></td>
2180 <td>" .
2181 Xml::checkLabel( wfMsg( 'watchthis' ), 'wpWatch', 'wpWatch', $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching(), array( 'tabindex' => '3' ) ) .
2182 "</td>
2183 </tr>
2184 $suppress
2185 <tr>
2186 <td></td>
2187 <td>" .
2188 Xml::submitButton( wfMsg( 'deletepage' ), array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '4' ) ) .
2189 "</td>
2190 </tr>" .
2191 Xml::closeElement( 'table' ) .
2192 Xml::closeElement( 'fieldset' ) .
2193 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
2194 Xml::closeElement( 'form' );
2196 if ( $wgUser->isAllowed( 'editinterface' ) ) {
2197 $skin = $wgUser->getSkin();
2198 $link = $skin->makeLink ( 'MediaWiki:Deletereason-dropdown', wfMsgHtml( 'delete-edit-reasonlist' ) );
2199 $form .= '<p class="mw-delete-editreasons">' . $link . '</p>';
2202 $wgOut->addHTML( $form );
2203 $this->showLogExtract( $wgOut );
2208 * Show relevant lines from the deletion log
2210 function showLogExtract( $out ) {
2211 $out->addHtml( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) );
2212 LogEventsList::showLogExtract( $out, 'delete', $this->mTitle->getPrefixedText() );
2217 * Perform a deletion and output success or failure messages
2219 function doDelete( $reason, $suppress = false ) {
2220 global $wgOut, $wgUser;
2221 wfDebug( __METHOD__."\n" );
2223 $id = $this->getId();
2225 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
2226 if ( $this->doDeleteArticle( $reason, $suppress ) ) {
2227 $deleted = $this->mTitle->getPrefixedText();
2229 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2230 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2232 $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
2234 $wgOut->addWikiMsg( 'deletedtext', $deleted, $loglink );
2235 $wgOut->returnToMain( false );
2236 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason, $id));
2237 } else {
2238 $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
2244 * Back-end article deletion
2245 * Deletes the article with database consistency, writes logs, purges caches
2246 * Returns success
2248 function doDeleteArticle( $reason, $suppress = false ) {
2249 global $wgUseSquid, $wgDeferredUpdateList;
2250 global $wgUseTrackbacks;
2252 wfDebug( __METHOD__."\n" );
2254 $dbw = wfGetDB( DB_MASTER );
2255 $ns = $this->mTitle->getNamespace();
2256 $t = $this->mTitle->getDBkey();
2257 $id = $this->mTitle->getArticleID();
2259 if ( $t == '' || $id == 0 ) {
2260 return false;
2263 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
2264 array_push( $wgDeferredUpdateList, $u );
2266 // Bitfields to further suppress the content
2267 if ( $suppress ) {
2268 $bitfield = 0;
2269 // This should be 15...
2270 $bitfield |= Revision::DELETED_TEXT;
2271 $bitfield |= Revision::DELETED_COMMENT;
2272 $bitfield |= Revision::DELETED_USER;
2273 $bitfield |= Revision::DELETED_RESTRICTED;
2274 } else {
2275 $bitfield = 'rev_deleted';
2278 $dbw->begin();
2279 // For now, shunt the revision data into the archive table.
2280 // Text is *not* removed from the text table; bulk storage
2281 // is left intact to avoid breaking block-compression or
2282 // immutable storage schemes.
2284 // For backwards compatibility, note that some older archive
2285 // table entries will have ar_text and ar_flags fields still.
2287 // In the future, we may keep revisions and mark them with
2288 // the rev_deleted field, which is reserved for this purpose.
2289 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
2290 array(
2291 'ar_namespace' => 'page_namespace',
2292 'ar_title' => 'page_title',
2293 'ar_comment' => 'rev_comment',
2294 'ar_user' => 'rev_user',
2295 'ar_user_text' => 'rev_user_text',
2296 'ar_timestamp' => 'rev_timestamp',
2297 'ar_minor_edit' => 'rev_minor_edit',
2298 'ar_rev_id' => 'rev_id',
2299 'ar_text_id' => 'rev_text_id',
2300 'ar_text' => '\'\'', // Be explicit to appease
2301 'ar_flags' => '\'\'', // MySQL's "strict mode"...
2302 'ar_len' => 'rev_len',
2303 'ar_page_id' => 'page_id',
2304 'ar_deleted' => $bitfield
2305 ), array(
2306 'page_id' => $id,
2307 'page_id = rev_page'
2308 ), __METHOD__
2311 # Delete restrictions for it
2312 $dbw->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__ );
2314 # Fix category table counts
2315 $cats = array();
2316 $res = $dbw->select( 'categorylinks', 'cl_to',
2317 array( 'cl_from' => $id ), __METHOD__ );
2318 foreach( $res as $row ) {
2319 $cats []= $row->cl_to;
2321 $this->updateCategoryCounts( array(), $cats );
2323 # Now that it's safely backed up, delete it
2324 $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__);
2325 $ok = ( $dbw->affectedRows() > 0 ); // getArticleId() uses slave, could be laggy
2326 if( !$ok ) {
2327 $dbw->rollback();
2328 return false;
2331 # If using cascading deletes, we can skip some explicit deletes
2332 if ( !$dbw->cascadingDeletes() ) {
2333 $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ );
2335 if ($wgUseTrackbacks)
2336 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__ );
2338 # Delete outgoing links
2339 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
2340 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
2341 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
2342 $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
2343 $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
2344 $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
2345 $dbw->delete( 'redirect', array( 'rd_from' => $id ) );
2348 # If using cleanup triggers, we can skip some manual deletes
2349 if ( !$dbw->cleanupTriggers() ) {
2351 # Clean up recentchanges entries...
2352 $dbw->delete( 'recentchanges',
2353 array( 'rc_namespace' => $ns, 'rc_title' => $t, 'rc_type != '.RC_LOG ),
2354 __METHOD__ );
2356 $dbw->commit();
2358 # Clear caches
2359 Article::onArticleDelete( $this->mTitle );
2361 # Clear the cached article id so the interface doesn't act like we exist
2362 $this->mTitle->resetArticleID( 0 );
2363 $this->mTitle->mArticleID = 0;
2365 # Log the deletion, if the page was suppressed, log it at Oversight instead
2366 $logtype = $suppress ? 'suppress' : 'delete';
2367 $log = new LogPage( $logtype );
2369 # Make sure logging got through
2370 $log->addEntry( 'delete', $this->mTitle, $reason, array() );
2372 return true;
2376 * Roll back the most recent consecutive set of edits to a page
2377 * from the same user; fails if there are no eligible edits to
2378 * roll back to, e.g. user is the sole contributor. This function
2379 * performs permissions checks on $wgUser, then calls commitRollback()
2380 * to do the dirty work
2382 * @param string $fromP - Name of the user whose edits to rollback.
2383 * @param string $summary - Custom summary. Set to default summary if empty.
2384 * @param string $token - Rollback token.
2385 * @param bool $bot - If true, mark all reverted edits as bot.
2387 * @param array $resultDetails contains result-specific array of additional values
2388 * 'alreadyrolled' : 'current' (rev)
2389 * success : 'summary' (str), 'current' (rev), 'target' (rev)
2391 * @return array of errors, each error formatted as
2392 * array(messagekey, param1, param2, ...).
2393 * On success, the array is empty. This array can also be passed to
2394 * OutputPage::showPermissionsErrorPage().
2396 public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails ) {
2397 global $wgUser;
2398 $resultDetails = null;
2400 # Check permissions
2401 $errors = array_merge( $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser ),
2402 $this->mTitle->getUserPermissionsErrors( 'rollback', $wgUser ) );
2403 if( !$wgUser->matchEditToken( $token, array( $this->mTitle->getPrefixedText(), $fromP ) ) )
2404 $errors[] = array( 'sessionfailure' );
2406 if ( $wgUser->pingLimiter('rollback') || $wgUser->pingLimiter() ) {
2407 $errors[] = array( 'actionthrottledtext' );
2409 # If there were errors, bail out now
2410 if(!empty($errors))
2411 return $errors;
2413 return $this->commitRollback($fromP, $summary, $bot, $resultDetails);
2417 * Backend implementation of doRollback(), please refer there for parameter
2418 * and return value documentation
2420 * NOTE: This function does NOT check ANY permissions, it just commits the
2421 * rollback to the DB Therefore, you should only call this function direct-
2422 * ly if you want to use custom permissions checks. If you don't, use
2423 * doRollback() instead.
2425 public function commitRollback($fromP, $summary, $bot, &$resultDetails) {
2426 global $wgUseRCPatrol, $wgUser;
2427 $dbw = wfGetDB( DB_MASTER );
2429 if( wfReadOnly() ) {
2430 return array( array( 'readonlytext' ) );
2433 # Get the last editor
2434 $current = Revision::newFromTitle( $this->mTitle );
2435 if( is_null( $current ) ) {
2436 # Something wrong... no page?
2437 return array(array('notanarticle'));
2440 $from = str_replace( '_', ' ', $fromP );
2441 if( $from != $current->getUserText() ) {
2442 $resultDetails = array( 'current' => $current );
2443 return array(array('alreadyrolled',
2444 htmlspecialchars($this->mTitle->getPrefixedText()),
2445 htmlspecialchars($fromP),
2446 htmlspecialchars($current->getUserText())
2450 # Get the last edit not by this guy
2451 $user = intval( $current->getUser() );
2452 $user_text = $dbw->addQuotes( $current->getUserText() );
2453 $s = $dbw->selectRow( 'revision',
2454 array( 'rev_id', 'rev_timestamp', 'rev_deleted' ),
2455 array( 'rev_page' => $current->getPage(),
2456 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2457 ), __METHOD__,
2458 array( 'USE INDEX' => 'page_timestamp',
2459 'ORDER BY' => 'rev_timestamp DESC' )
2461 if( $s === false ) {
2462 # No one else ever edited this page
2463 return array(array('cantrollback'));
2464 } else if( $s->rev_deleted & REVISION::DELETED_TEXT || $s->rev_deleted & REVISION::DELETED_USER ) {
2465 # Only admins can see this text
2466 return array(array('notvisiblerev'));
2469 $set = array();
2470 if ( $bot && $wgUser->isAllowed('markbotedits') ) {
2471 # Mark all reverted edits as bot
2472 $set['rc_bot'] = 1;
2474 if ( $wgUseRCPatrol ) {
2475 # Mark all reverted edits as patrolled
2476 $set['rc_patrolled'] = 1;
2479 if ( $set ) {
2480 $dbw->update( 'recentchanges', $set,
2481 array( /* WHERE */
2482 'rc_cur_id' => $current->getPage(),
2483 'rc_user_text' => $current->getUserText(),
2484 "rc_timestamp > '{$s->rev_timestamp}'",
2485 ), __METHOD__
2489 # Generate the edit summary if necessary
2490 $target = Revision::newFromId( $s->rev_id );
2491 if( empty( $summary ) )
2493 global $wgLang;
2494 $summary = wfMsgForContent( 'revertpage',
2495 $target->getUserText(), $from,
2496 $s->rev_id, $wgLang->timeanddate(wfTimestamp(TS_MW, $s->rev_timestamp), true),
2497 $current->getId(), $wgLang->timeanddate($current->getTimestamp())
2501 # Save
2502 $flags = EDIT_UPDATE;
2504 if ($wgUser->isAllowed('minoredit'))
2505 $flags |= EDIT_MINOR;
2507 if( $bot && ($wgUser->isAllowed('markbotedits') || $wgUser->isAllowed('bot')) )
2508 $flags |= EDIT_FORCE_BOT;
2509 $this->doEdit( $target->getText(), $summary, $flags );
2511 wfRunHooks( 'ArticleRollbackComplete', array( $this, $wgUser, $target ) );
2513 $resultDetails = array(
2514 'summary' => $summary,
2515 'current' => $current,
2516 'target' => $target,
2518 return array();
2522 * User interface for rollback operations
2524 function rollback() {
2525 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
2526 $details = null;
2528 $result = $this->doRollback(
2529 $wgRequest->getVal( 'from' ),
2530 $wgRequest->getText( 'summary' ),
2531 $wgRequest->getVal( 'token' ),
2532 $wgRequest->getBool( 'bot' ),
2533 $details
2536 if( in_array( array( 'blocked' ), $result ) ) {
2537 $wgOut->blockedPage();
2538 return;
2540 if( in_array( array( 'actionthrottledtext' ), $result ) ) {
2541 $wgOut->rateLimited();
2542 return;
2544 if( isset( $result[0][0] ) && ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' ) ){
2545 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2546 $errArray = $result[0];
2547 $errMsg = array_shift( $errArray );
2548 $wgOut->addWikiMsgArray( $errMsg, $errArray );
2549 if( isset( $details['current'] ) ){
2550 $current = $details['current'];
2551 if( $current->getComment() != '' ) {
2552 $wgOut->addWikiMsgArray( 'editcomment', array( $wgUser->getSkin()->formatComment( $current->getComment() ) ), array( 'replaceafter' ) );
2555 return;
2557 # Display permissions errors before read-only message -- there's no
2558 # point in misleading the user into thinking the inability to rollback
2559 # is only temporary.
2560 if( !empty($result) && $result !== array( array('readonlytext') ) ) {
2561 # array_diff is completely broken for arrays of arrays, sigh. Re-
2562 # move any 'readonlytext' error manually.
2563 $out = array();
2564 foreach( $result as $error ) {
2565 if( $error != array( 'readonlytext' ) ) {
2566 $out []= $error;
2569 $wgOut->showPermissionsErrorPage( $out );
2570 return;
2572 if( $result == array( array('readonlytext') ) ) {
2573 $wgOut->readOnlyPage();
2574 return;
2577 $current = $details['current'];
2578 $target = $details['target'];
2579 $wgOut->setPageTitle( wfMsg( 'actioncomplete' ) );
2580 $wgOut->setRobotPolicy( 'noindex,nofollow' );
2581 $old = $wgUser->getSkin()->userLink( $current->getUser(), $current->getUserText() )
2582 . $wgUser->getSkin()->userToolLinks( $current->getUser(), $current->getUserText() );
2583 $new = $wgUser->getSkin()->userLink( $target->getUser(), $target->getUserText() )
2584 . $wgUser->getSkin()->userToolLinks( $target->getUser(), $target->getUserText() );
2585 $wgOut->addHtml( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
2586 $wgOut->returnToMain( false, $this->mTitle );
2591 * Do standard deferred updates after page view
2592 * @private
2594 function viewUpdates() {
2595 global $wgDeferredUpdateList;
2597 if ( 0 != $this->getID() ) {
2598 global $wgDisableCounters;
2599 if( !$wgDisableCounters ) {
2600 Article::incViewCount( $this->getID() );
2601 $u = new SiteStatsUpdate( 1, 0, 0 );
2602 array_push( $wgDeferredUpdateList, $u );
2606 # Update newtalk / watchlist notification status
2607 global $wgUser;
2608 $wgUser->clearNotification( $this->mTitle );
2612 * Prepare text which is about to be saved.
2613 * Returns a stdclass with source, pst and output members
2615 function prepareTextForEdit( $text, $revid=null ) {
2616 if ( $this->mPreparedEdit && $this->mPreparedEdit->newText == $text && $this->mPreparedEdit->revid == $revid) {
2617 // Already prepared
2618 return $this->mPreparedEdit;
2620 global $wgParser;
2621 $edit = (object)array();
2622 $edit->revid = $revid;
2623 $edit->newText = $text;
2624 $edit->pst = $this->preSaveTransform( $text );
2625 $options = new ParserOptions;
2626 $options->setTidy( true );
2627 $options->enableLimitReport();
2628 $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $options, true, true, $revid );
2629 $edit->oldText = $this->getContent();
2630 $this->mPreparedEdit = $edit;
2631 return $edit;
2635 * Do standard deferred updates after page edit.
2636 * Update links tables, site stats, search index and message cache.
2637 * Every 100th edit, prune the recent changes table.
2639 * @private
2640 * @param $text New text of the article
2641 * @param $summary Edit summary
2642 * @param $minoredit Minor edit
2643 * @param $timestamp_of_pagechange Timestamp associated with the page change
2644 * @param $newid rev_id value of the new revision
2645 * @param $changed Whether or not the content actually changed
2647 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true ) {
2648 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser, $wgEnableParserCache;
2650 wfProfileIn( __METHOD__ );
2652 # Parse the text
2653 # Be careful not to double-PST: $text is usually already PST-ed once
2654 if ( !$this->mPreparedEdit || $this->mPreparedEdit->output->getFlag( 'vary-revision' ) ) {
2655 wfDebug( __METHOD__ . ": No prepared edit or vary-revision is set...\n" );
2656 $editInfo = $this->prepareTextForEdit( $text, $newid );
2657 } else {
2658 wfDebug( __METHOD__ . ": No vary-revision, using prepared edit...\n" );
2659 $editInfo = $this->mPreparedEdit;
2662 # Save it to the parser cache
2663 if ( $wgEnableParserCache ) {
2664 $parserCache = ParserCache::singleton();
2665 $parserCache->save( $editInfo->output, $this, $wgUser );
2668 # Update the links tables
2669 $u = new LinksUpdate( $this->mTitle, $editInfo->output );
2670 $u->doUpdate();
2672 if( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2673 if ( 0 == mt_rand( 0, 99 ) ) {
2674 // Flush old entries from the `recentchanges` table; we do this on
2675 // random requests so as to avoid an increase in writes for no good reason
2676 global $wgRCMaxAge;
2677 $dbw = wfGetDB( DB_MASTER );
2678 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2679 $recentchanges = $dbw->tableName( 'recentchanges' );
2680 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2681 $dbw->query( $sql );
2685 $id = $this->getID();
2686 $title = $this->mTitle->getPrefixedDBkey();
2687 $shortTitle = $this->mTitle->getDBkey();
2689 if ( 0 == $id ) {
2690 wfProfileOut( __METHOD__ );
2691 return;
2694 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment, $this->mTotalAdjustment );
2695 array_push( $wgDeferredUpdateList, $u );
2696 $u = new SearchUpdate( $id, $title, $text );
2697 array_push( $wgDeferredUpdateList, $u );
2699 # If this is another user's talk page, update newtalk
2700 # Don't do this if $changed = false otherwise some idiot can null-edit a
2701 # load of user talk pages and piss people off, nor if it's a minor edit
2702 # by a properly-flagged bot.
2703 if( $this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getTitleKey() && $changed
2704 && !($minoredit && $wgUser->isAllowed('nominornewtalk') ) ) {
2705 if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
2706 $other = User::newFromName( $shortTitle );
2707 if( is_null( $other ) && User::isIP( $shortTitle ) ) {
2708 // An anonymous user
2709 $other = new User();
2710 $other->setName( $shortTitle );
2712 if( $other ) {
2713 $other->setNewtalk( true );
2718 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
2719 $wgMessageCache->replace( $shortTitle, $text );
2722 wfProfileOut( __METHOD__ );
2726 * Perform article updates on a special page creation.
2728 * @param Revision $rev
2730 * @todo This is a shitty interface function. Kill it and replace the
2731 * other shitty functions like editUpdates and such so it's not needed
2732 * anymore.
2734 function createUpdates( $rev ) {
2735 $this->mGoodAdjustment = $this->isCountable( $rev->getText() );
2736 $this->mTotalAdjustment = 1;
2737 $this->editUpdates( $rev->getText(), $rev->getComment(),
2738 $rev->isMinor(), wfTimestamp(), $rev->getId(), true );
2742 * Generate the navigation links when browsing through an article revisions
2743 * It shows the information as:
2744 * Revision as of \<date\>; view current revision
2745 * \<- Previous version | Next Version -\>
2747 * @private
2748 * @param string $oldid Revision ID of this article revision
2750 function setOldSubtitle( $oldid=0 ) {
2751 global $wgLang, $wgOut, $wgUser;
2753 if ( !wfRunHooks( 'DisplayOldSubtitle', array(&$this, &$oldid) ) ) {
2754 return;
2757 $revision = Revision::newFromId( $oldid );
2759 $current = ( $oldid == $this->mLatest );
2760 $td = $wgLang->timeanddate( $this->mTimestamp, true );
2761 $sk = $wgUser->getSkin();
2762 $lnk = $current
2763 ? wfMsg( 'currentrevisionlink' )
2764 : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'currentrevisionlink' ) );
2765 $curdiff = $current
2766 ? wfMsg( 'diff' )
2767 : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'diff' ), 'diff=cur&oldid='.$oldid );
2768 $prev = $this->mTitle->getPreviousRevisionID( $oldid ) ;
2769 $prevlink = $prev
2770 ? $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
2771 : wfMsg( 'previousrevision' );
2772 $prevdiff = $prev
2773 ? $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'diff' ), 'diff=prev&oldid='.$oldid )
2774 : wfMsg( 'diff' );
2775 $nextlink = $current
2776 ? wfMsg( 'nextrevision' )
2777 : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2778 $nextdiff = $current
2779 ? wfMsg( 'diff' )
2780 : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'diff' ), 'diff=next&oldid='.$oldid );
2782 $cdel='';
2783 if( $wgUser->isAllowed( 'deleterevision' ) ) {
2784 $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
2785 if( $revision->isCurrent() ) {
2786 // We don't handle top deleted edits too well
2787 $cdel = wfMsgHtml('rev-delundel');
2788 } else if( !$revision->userCan( Revision::DELETED_RESTRICTED ) ) {
2789 // If revision was hidden from sysops
2790 $cdel = wfMsgHtml('rev-delundel');
2791 } else {
2792 $cdel = $sk->makeKnownLinkObj( $revdel,
2793 wfMsgHtml('rev-delundel'),
2794 'target=' . urlencode( $this->mTitle->getPrefixedDbkey() ) .
2795 '&oldid=' . urlencode( $oldid ) );
2796 // Bolden oversighted content
2797 if( $revision->isDeleted( Revision::DELETED_RESTRICTED ) )
2798 $cdel = "<strong>$cdel</strong>";
2800 $cdel = "(<small>$cdel</small>) ";
2802 # Show user links if allowed to see them. Normally they
2803 # are hidden regardless, but since we can already see the text here...
2804 $userlinks = $sk->revUserTools( $revision, false );
2806 $m = wfMsg( 'revision-info-current' );
2807 $infomsg = $current && !wfEmptyMsg( 'revision-info-current', $m ) && $m != '-'
2808 ? 'revision-info-current'
2809 : 'revision-info';
2811 $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" . wfMsg( $infomsg, $td, $userlinks ) . "</div>\n" .
2813 "\n\t\t\t\t<div id=\"mw-revision-nav\">" . $cdel . wfMsg( 'revision-nav', $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
2814 $wgOut->setSubtitle( $r );
2818 * This function is called right before saving the wikitext,
2819 * so we can do things like signatures and links-in-context.
2821 * @param string $text
2823 function preSaveTransform( $text ) {
2824 global $wgParser, $wgUser;
2825 return $wgParser->preSaveTransform( $text, $this->mTitle, $wgUser, ParserOptions::newFromUser( $wgUser ) );
2828 /* Caching functions */
2831 * checkLastModified returns true if it has taken care of all
2832 * output to the client that is necessary for this request.
2833 * (that is, it has sent a cached version of the page)
2835 function tryFileCache() {
2836 static $called = false;
2837 if( $called ) {
2838 wfDebug( "Article::tryFileCache(): called twice!?\n" );
2839 return;
2841 $called = true;
2842 if($this->isFileCacheable()) {
2843 $touched = $this->mTouched;
2844 $cache = new HTMLFileCache( $this->mTitle );
2845 if($cache->isFileCacheGood( $touched )) {
2846 wfDebug( "Article::tryFileCache(): about to load file\n" );
2847 $cache->loadFromFileCache();
2848 return true;
2849 } else {
2850 wfDebug( "Article::tryFileCache(): starting buffer\n" );
2851 ob_start( array(&$cache, 'saveToFileCache' ) );
2853 } else {
2854 wfDebug( "Article::tryFileCache(): not cacheable\n" );
2859 * Check if the page can be cached
2860 * @return bool
2862 function isFileCacheable() {
2863 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest, $wgLang, $wgContLang;
2864 $action = $wgRequest->getVal( 'action' );
2865 $oldid = $wgRequest->getVal( 'oldid' );
2866 $diff = $wgRequest->getVal( 'diff' );
2867 $redirect = $wgRequest->getVal( 'redirect' );
2868 $printable = $wgRequest->getVal( 'printable' );
2869 $page = $wgRequest->getVal( 'page' );
2871 //check for non-standard user language; this covers uselang,
2872 //and extensions for auto-detecting user language.
2873 $ulang = $wgLang->getCode();
2874 $clang = $wgContLang->getCode();
2876 $cacheable = $wgUseFileCache
2877 && (!$wgShowIPinHeader)
2878 && ($this->getID() != 0)
2879 && ($wgUser->isAnon())
2880 && (!$wgUser->getNewtalk())
2881 && ($this->mTitle->getNamespace() != NS_SPECIAL )
2882 && (empty( $action ) || $action == 'view')
2883 && (!isset($oldid))
2884 && (!isset($diff))
2885 && (!isset($redirect))
2886 && (!isset($printable))
2887 && !isset($page)
2888 && (!$this->mRedirectedFrom)
2889 && ($ulang === $clang);
2891 if ( $cacheable ) {
2892 //extension may have reason to disable file caching on some pages.
2893 $cacheable = wfRunHooks( 'IsFileCacheable', array( $this ) );
2896 return $cacheable;
2900 * Loads page_touched and returns a value indicating if it should be used
2903 function checkTouched() {
2904 if( !$this->mDataLoaded ) {
2905 $this->loadPageData();
2907 return !$this->mIsRedirect;
2911 * Get the page_touched field
2913 function getTouched() {
2914 # Ensure that page data has been loaded
2915 if( !$this->mDataLoaded ) {
2916 $this->loadPageData();
2918 return $this->mTouched;
2922 * Get the page_latest field
2924 function getLatest() {
2925 if ( !$this->mDataLoaded ) {
2926 $this->loadPageData();
2928 return $this->mLatest;
2932 * Edit an article without doing all that other stuff
2933 * The article must already exist; link tables etc
2934 * are not updated, caches are not flushed.
2936 * @param string $text text submitted
2937 * @param string $comment comment submitted
2938 * @param bool $minor whereas it's a minor modification
2940 function quickEdit( $text, $comment = '', $minor = 0 ) {
2941 wfProfileIn( __METHOD__ );
2943 $dbw = wfGetDB( DB_MASTER );
2944 $dbw->begin();
2945 $revision = new Revision( array(
2946 'page' => $this->getId(),
2947 'text' => $text,
2948 'comment' => $comment,
2949 'minor_edit' => $minor ? 1 : 0,
2950 ) );
2951 $revision->insertOn( $dbw );
2952 $this->updateRevisionOn( $dbw, $revision );
2953 $dbw->commit();
2955 wfProfileOut( __METHOD__ );
2959 * Used to increment the view counter
2961 * @static
2962 * @param integer $id article id
2964 function incViewCount( $id ) {
2965 $id = intval( $id );
2966 global $wgHitcounterUpdateFreq, $wgDBtype;
2968 $dbw = wfGetDB( DB_MASTER );
2969 $pageTable = $dbw->tableName( 'page' );
2970 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2971 $acchitsTable = $dbw->tableName( 'acchits' );
2973 if( $wgHitcounterUpdateFreq <= 1 ) {
2974 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2975 return;
2978 # Not important enough to warrant an error page in case of failure
2979 $oldignore = $dbw->ignoreErrors( true );
2981 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2983 $checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 );
2984 if( (rand() % $checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2985 # Most of the time (or on SQL errors), skip row count check
2986 $dbw->ignoreErrors( $oldignore );
2987 return;
2990 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2991 $row = $dbw->fetchObject( $res );
2992 $rown = intval( $row->n );
2993 if( $rown >= $wgHitcounterUpdateFreq ){
2994 wfProfileIn( 'Article::incViewCount-collect' );
2995 $old_user_abort = ignore_user_abort( true );
2997 if ($wgDBtype == 'mysql')
2998 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2999 $tabletype = $wgDBtype == 'mysql' ? "ENGINE=HEAP " : '';
3000 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype AS ".
3001 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
3002 'GROUP BY hc_id');
3003 $dbw->query("DELETE FROM $hitcounterTable");
3004 if ($wgDBtype == 'mysql') {
3005 $dbw->query('UNLOCK TABLES');
3006 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
3007 'WHERE page_id = hc_id');
3009 else {
3010 $dbw->query("UPDATE $pageTable SET page_counter=page_counter + hc_n ".
3011 "FROM $acchitsTable WHERE page_id = hc_id");
3013 $dbw->query("DROP TABLE $acchitsTable");
3015 ignore_user_abort( $old_user_abort );
3016 wfProfileOut( 'Article::incViewCount-collect' );
3018 $dbw->ignoreErrors( $oldignore );
3021 /**#@+
3022 * The onArticle*() functions are supposed to be a kind of hooks
3023 * which should be called whenever any of the specified actions
3024 * are done.
3026 * This is a good place to put code to clear caches, for instance.
3028 * This is called on page move and undelete, as well as edit
3029 * @static
3030 * @param $title_obj a title object
3033 static function onArticleCreate($title) {
3034 # The talk page isn't in the regular link tables, so we need to update manually:
3035 if ( $title->isTalkPage() ) {
3036 $other = $title->getSubjectPage();
3037 } else {
3038 $other = $title->getTalkPage();
3040 $other->invalidateCache();
3041 $other->purgeSquid();
3043 $title->touchLinks();
3044 $title->purgeSquid();
3045 $title->deleteTitleProtection();
3048 static function onArticleDelete( $title ) {
3049 global $wgUseFileCache, $wgMessageCache;
3051 // Update existence markers on article/talk tabs...
3052 if( $title->isTalkPage() ) {
3053 $other = $title->getSubjectPage();
3054 } else {
3055 $other = $title->getTalkPage();
3057 $other->invalidateCache();
3058 $other->purgeSquid();
3060 $title->touchLinks();
3061 $title->purgeSquid();
3063 # File cache
3064 if ( $wgUseFileCache ) {
3065 $cm = new HTMLFileCache( $title );
3066 @unlink( $cm->fileCacheName() );
3069 if( $title->getNamespace() == NS_MEDIAWIKI) {
3070 $wgMessageCache->replace( $title->getDBkey(), false );
3072 if( $title->getNamespace() == NS_IMAGE ) {
3073 $update = new HTMLCacheUpdate( $title, 'imagelinks' );
3074 $update->doUpdate();
3079 * Purge caches on page update etc
3081 static function onArticleEdit( $title ) {
3082 global $wgDeferredUpdateList, $wgUseFileCache;
3084 // Invalidate caches of articles which include this page
3085 $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'templatelinks' );
3087 // Invalidate the caches of all pages which redirect here
3088 $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'redirect' );
3090 # Purge squid for this page only
3091 $title->purgeSquid();
3093 # Clear file cache
3094 if ( $wgUseFileCache ) {
3095 $cm = new HTMLFileCache( $title );
3096 @unlink( $cm->fileCacheName() );
3100 /**#@-*/
3103 * Overriden by ImagePage class, only present here to avoid a fatal error
3104 * Called for ?action=revert
3106 public function revert(){
3107 global $wgOut;
3108 $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
3112 * Info about this page
3113 * Called for ?action=info when $wgAllowPageInfo is on.
3115 * @public
3117 function info() {
3118 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
3120 if ( !$wgAllowPageInfo ) {
3121 $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
3122 return;
3125 $page = $this->mTitle->getSubjectPage();
3127 $wgOut->setPagetitle( $page->getPrefixedText() );
3128 $wgOut->setPageTitleActionText( wfMsg( 'info_short' ) );
3129 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ) );
3131 if( !$this->mTitle->exists() ) {
3132 $wgOut->addHtml( '<div class="noarticletext">' );
3133 if( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
3134 // This doesn't quite make sense; the user is asking for
3135 // information about the _page_, not the message... -- RC
3136 $wgOut->addHtml( htmlspecialchars( wfMsgWeirdKey( $this->mTitle->getText() ) ) );
3137 } else {
3138 $msg = $wgUser->isLoggedIn()
3139 ? 'noarticletext'
3140 : 'noarticletextanon';
3141 $wgOut->addHtml( wfMsgExt( $msg, 'parse' ) );
3143 $wgOut->addHtml( '</div>' );
3144 } else {
3145 $dbr = wfGetDB( DB_SLAVE );
3146 $wl_clause = array(
3147 'wl_title' => $page->getDBkey(),
3148 'wl_namespace' => $page->getNamespace() );
3149 $numwatchers = $dbr->selectField(
3150 'watchlist',
3151 'COUNT(*)',
3152 $wl_clause,
3153 __METHOD__,
3154 $this->getSelectOptions() );
3156 $pageInfo = $this->pageCountInfo( $page );
3157 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
3159 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
3160 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
3161 if( $talkInfo ) {
3162 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
3164 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
3165 if( $talkInfo ) {
3166 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
3168 $wgOut->addHTML( '</ul>' );
3174 * Return the total number of edits and number of unique editors
3175 * on a given page. If page does not exist, returns false.
3177 * @param Title $title
3178 * @return array
3179 * @private
3181 function pageCountInfo( $title ) {
3182 $id = $title->getArticleId();
3183 if( $id == 0 ) {
3184 return false;
3187 $dbr = wfGetDB( DB_SLAVE );
3189 $rev_clause = array( 'rev_page' => $id );
3191 $edits = $dbr->selectField(
3192 'revision',
3193 'COUNT(rev_page)',
3194 $rev_clause,
3195 __METHOD__,
3196 $this->getSelectOptions() );
3198 $authors = $dbr->selectField(
3199 'revision',
3200 'COUNT(DISTINCT rev_user_text)',
3201 $rev_clause,
3202 __METHOD__,
3203 $this->getSelectOptions() );
3205 return array( 'edits' => $edits, 'authors' => $authors );
3209 * Return a list of templates used by this article.
3210 * Uses the templatelinks table
3212 * @return array Array of Title objects
3214 function getUsedTemplates() {
3215 $result = array();
3216 $id = $this->mTitle->getArticleID();
3217 if( $id == 0 ) {
3218 return array();
3221 $dbr = wfGetDB( DB_SLAVE );
3222 $res = $dbr->select( array( 'templatelinks' ),
3223 array( 'tl_namespace', 'tl_title' ),
3224 array( 'tl_from' => $id ),
3225 'Article:getUsedTemplates' );
3226 if ( false !== $res ) {
3227 if ( $dbr->numRows( $res ) ) {
3228 while ( $row = $dbr->fetchObject( $res ) ) {
3229 $result[] = Title::makeTitle( $row->tl_namespace, $row->tl_title );
3233 $dbr->freeResult( $res );
3234 return $result;
3238 * Returns a list of hidden categories this page is a member of.
3239 * Uses the page_props and categorylinks tables.
3241 * @return array Array of Title objects
3243 function getHiddenCategories() {
3244 $result = array();
3245 $id = $this->mTitle->getArticleID();
3246 if( $id == 0 ) {
3247 return array();
3250 $dbr = wfGetDB( DB_SLAVE );
3251 $res = $dbr->select( array( 'categorylinks', 'page_props', 'page' ),
3252 array( 'cl_to' ),
3253 array( 'cl_from' => $id, 'pp_page=page_id', 'pp_propname' => 'hiddencat',
3254 'page_namespace' => NS_CATEGORY, 'page_title=cl_to'),
3255 'Article:getHiddenCategories' );
3256 if ( false !== $res ) {
3257 if ( $dbr->numRows( $res ) ) {
3258 while ( $row = $dbr->fetchObject( $res ) ) {
3259 $result[] = Title::makeTitle( NS_CATEGORY, $row->cl_to );
3263 $dbr->freeResult( $res );
3264 return $result;
3268 * Return an auto-generated summary if the text provided is a redirect.
3270 * @param string $text The wikitext to check
3271 * @return string '' or an appropriate summary
3273 public static function getRedirectAutosummary( $text ) {
3274 $rt = Title::newFromRedirect( $text );
3275 if( is_object( $rt ) )
3276 return wfMsgForContent( 'autoredircomment', $rt->getFullText() );
3277 else
3278 return '';
3282 * Return an auto-generated summary if the new text is much shorter than
3283 * the old text.
3285 * @param string $oldtext The previous text of the page
3286 * @param string $text The submitted text of the page
3287 * @return string An appropriate autosummary, or an empty string.
3289 public static function getBlankingAutosummary( $oldtext, $text ) {
3290 if ($oldtext!='' && $text=='') {
3291 return wfMsgForContent('autosumm-blank');
3292 } elseif (strlen($oldtext) > 10 * strlen($text) && strlen($text) < 500) {
3293 #Removing more than 90% of the article
3294 global $wgContLang;
3295 $truncatedtext = $wgContLang->truncate($text, max(0, 200 - strlen(wfMsgForContent('autosumm-replace'))), '...');
3296 return wfMsgForContent('autosumm-replace', $truncatedtext);
3297 } else {
3298 return '';
3303 * Return an applicable autosummary if one exists for the given edit.
3304 * @param string $oldtext The previous text of the page.
3305 * @param string $newtext The submitted text of the page.
3306 * @param bitmask $flags A bitmask of flags submitted for the edit.
3307 * @return string An appropriate autosummary, or an empty string.
3309 public static function getAutosummary( $oldtext, $newtext, $flags ) {
3311 # This code is UGLY UGLY UGLY.
3312 # Somebody PLEASE come up with a more elegant way to do it.
3314 #Redirect autosummaries
3315 $summary = self::getRedirectAutosummary( $newtext );
3317 if ($summary)
3318 return $summary;
3320 #Blanking autosummaries
3321 if (!($flags & EDIT_NEW))
3322 $summary = self::getBlankingAutosummary( $oldtext, $newtext );
3324 if ($summary)
3325 return $summary;
3327 #New page autosummaries
3328 if ($flags & EDIT_NEW && strlen($newtext)) {
3329 #If they're making a new article, give its text, truncated, in the summary.
3330 global $wgContLang;
3331 $truncatedtext = $wgContLang->truncate(
3332 str_replace("\n", ' ', $newtext),
3333 max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new') ) ),
3334 '...' );
3335 $summary = wfMsgForContent( 'autosumm-new', $truncatedtext );
3338 if ($summary)
3339 return $summary;
3341 return $summary;
3345 * Add the primary page-view wikitext to the output buffer
3346 * Saves the text into the parser cache if possible.
3347 * Updates templatelinks if it is out of date.
3349 * @param string $text
3350 * @param bool $cache
3352 public function outputWikiText( $text, $cache = true ) {
3353 global $wgParser, $wgUser, $wgOut, $wgEnableParserCache;
3355 $popts = $wgOut->parserOptions();
3356 $popts->setTidy(true);
3357 $popts->enableLimitReport();
3358 $parserOutput = $wgParser->parse( $text, $this->mTitle,
3359 $popts, true, true, $this->getRevIdFetched() );
3360 $popts->setTidy(false);
3361 $popts->enableLimitReport( false );
3362 if ( $wgEnableParserCache && $cache && $this && $parserOutput->getCacheTime() != -1 ) {
3363 $parserCache = ParserCache::singleton();
3364 $parserCache->save( $parserOutput, $this, $wgUser );
3367 if ( !wfReadOnly() && $this->mTitle->areRestrictionsCascading() ) {
3368 // templatelinks table may have become out of sync,
3369 // especially if using variable-based transclusions.
3370 // For paranoia, check if things have changed and if
3371 // so apply updates to the database. This will ensure
3372 // that cascaded protections apply as soon as the changes
3373 // are visible.
3375 # Get templates from templatelinks
3376 $id = $this->mTitle->getArticleID();
3378 $tlTemplates = array();
3380 $dbr = wfGetDB( DB_SLAVE );
3381 $res = $dbr->select( array( 'templatelinks' ),
3382 array( 'tl_namespace', 'tl_title' ),
3383 array( 'tl_from' => $id ),
3384 'Article:getUsedTemplates' );
3386 global $wgContLang;
3388 if ( false !== $res ) {
3389 if ( $dbr->numRows( $res ) ) {
3390 while ( $row = $dbr->fetchObject( $res ) ) {
3391 $tlTemplates[] = $wgContLang->getNsText( $row->tl_namespace ) . ':' . $row->tl_title ;
3396 # Get templates from parser output.
3397 $poTemplates_allns = $parserOutput->getTemplates();
3399 $poTemplates = array ();
3400 foreach ( $poTemplates_allns as $ns_templates ) {
3401 $poTemplates = array_merge( $poTemplates, $ns_templates );
3404 # Get the diff
3405 $templates_diff = array_diff( $poTemplates, $tlTemplates );
3407 if ( count( $templates_diff ) > 0 ) {
3408 # Whee, link updates time.
3409 $u = new LinksUpdate( $this->mTitle, $parserOutput );
3411 $dbw = wfGetDb( DB_MASTER );
3412 $dbw->begin();
3414 $u->doUpdate();
3416 $dbw->commit();
3420 $wgOut->addParserOutput( $parserOutput );
3424 * Update all the appropriate counts in the category table, given that
3425 * we've added the categories $added and deleted the categories $deleted.
3427 * @param $added array The names of categories that were added
3428 * @param $deleted array The names of categories that were deleted
3429 * @return null
3431 public function updateCategoryCounts( $added, $deleted ) {
3432 $ns = $this->mTitle->getNamespace();
3433 $dbw = wfGetDB( DB_MASTER );
3435 # First make sure the rows exist. If one of the "deleted" ones didn't
3436 # exist, we might legitimately not create it, but it's simpler to just
3437 # create it and then give it a negative value, since the value is bogus
3438 # anyway.
3440 # Sometimes I wish we had INSERT ... ON DUPLICATE KEY UPDATE.
3441 $insertCats = array_merge( $added, $deleted );
3442 if( !$insertCats ) {
3443 # Okay, nothing to do
3444 return;
3446 $insertRows = array();
3447 foreach( $insertCats as $cat ) {
3448 $insertRows[] = array( 'cat_title' => $cat );
3450 $dbw->insert( 'category', $insertRows, __METHOD__, 'IGNORE' );
3452 $addFields = array( 'cat_pages = cat_pages + 1' );
3453 $removeFields = array( 'cat_pages = cat_pages - 1' );
3454 if( $ns == NS_CATEGORY ) {
3455 $addFields[] = 'cat_subcats = cat_subcats + 1';
3456 $removeFields[] = 'cat_subcats = cat_subcats - 1';
3457 } elseif( $ns == NS_IMAGE ) {
3458 $addFields[] = 'cat_files = cat_files + 1';
3459 $removeFields[] = 'cat_files = cat_files - 1';
3462 if ( $added ) {
3463 $dbw->update(
3464 'category',
3465 $addFields,
3466 array( 'cat_title' => $added ),
3467 __METHOD__
3470 if ( $deleted ) {
3471 $dbw->update(
3472 'category',
3473 $removeFields,
3474 array( 'cat_title' => $deleted ),
3475 __METHOD__