MediaWiki REL1_29
WikiPage.php
Go to the documentation of this file.
1<?php
23use \MediaWiki\Logger\LoggerFactory;
24use \MediaWiki\MediaWikiServices;
29
36class WikiPage implements Page, IDBAccessObject {
37 // Constants for $mDataLoadedFrom and related
38
42 public $mTitle = null;
43
47 public $mDataLoaded = false; // !< Boolean
48 public $mIsRedirect = false; // !< Boolean
49 public $mLatest = false; // !< Integer (false means "not loaded")
53 public $mPreparedEdit = false;
54
58 protected $mId = null;
59
64
68 protected $mRedirectTarget = null;
69
73 protected $mLastRevision = null;
74
78 protected $mTimestamp = '';
79
83 protected $mTouched = '19700101000000';
84
88 protected $mLinksUpdated = '19700101000000';
89
91 const PURGE_CDN_CACHE = 1;
94 const PURGE_ALL = 7;
95
100 public function __construct( Title $title ) {
101 $this->mTitle = $title;
102 }
103
108 public function __clone() {
109 $this->mTitle = clone $this->mTitle;
110 }
111
120 public static function factory( Title $title ) {
121 $ns = $title->getNamespace();
122
123 if ( $ns == NS_MEDIA ) {
124 throw new MWException( "NS_MEDIA is a virtual namespace; use NS_FILE." );
125 } elseif ( $ns < 0 ) {
126 throw new MWException( "Invalid or virtual namespace $ns given." );
127 }
128
129 $page = null;
130 if ( !Hooks::run( 'WikiPageFactory', [ $title, &$page ] ) ) {
131 return $page;
132 }
133
134 switch ( $ns ) {
135 case NS_FILE:
136 $page = new WikiFilePage( $title );
137 break;
138 case NS_CATEGORY:
140 break;
141 default:
142 $page = new WikiPage( $title );
143 }
144
145 return $page;
146 }
147
158 public static function newFromID( $id, $from = 'fromdb' ) {
159 // page ids are never 0 or negative, see T63166
160 if ( $id < 1 ) {
161 return null;
162 }
163
164 $from = self::convertSelectType( $from );
165 $db = wfGetDB( $from === self::READ_LATEST ? DB_MASTER : DB_REPLICA );
166 $row = $db->selectRow(
167 'page', self::selectFields(), [ 'page_id' => $id ], __METHOD__ );
168 if ( !$row ) {
169 return null;
170 }
171 return self::newFromRow( $row, $from );
172 }
173
185 public static function newFromRow( $row, $from = 'fromdb' ) {
186 $page = self::factory( Title::newFromRow( $row ) );
187 $page->loadFromRow( $row, $from );
188 return $page;
189 }
190
197 private static function convertSelectType( $type ) {
198 switch ( $type ) {
199 case 'fromdb':
200 return self::READ_NORMAL;
201 case 'fromdbmaster':
202 return self::READ_LATEST;
203 case 'forupdate':
204 return self::READ_LOCKING;
205 default:
206 // It may already be an integer or whatever else
207 return $type;
208 }
209 }
210
216 public function getActionOverrides() {
217 return $this->getContentHandler()->getActionOverrides();
218 }
219
229 public function getContentHandler() {
231 }
232
237 public function getTitle() {
238 return $this->mTitle;
239 }
240
245 public function clear() {
246 $this->mDataLoaded = false;
247 $this->mDataLoadedFrom = self::READ_NONE;
248
249 $this->clearCacheFields();
250 }
251
256 protected function clearCacheFields() {
257 $this->mId = null;
258 $this->mRedirectTarget = null; // Title object if set
259 $this->mLastRevision = null; // Latest revision
260 $this->mTouched = '19700101000000';
261 $this->mLinksUpdated = '19700101000000';
262 $this->mTimestamp = '';
263 $this->mIsRedirect = false;
264 $this->mLatest = false;
265 // T59026: do not clear mPreparedEdit since prepareTextForEdit() already checks
266 // the requested rev ID and content against the cached one for equality. For most
267 // content types, the output should not change during the lifetime of this cache.
268 // Clearing it can cause extra parses on edit for no reason.
269 }
270
276 public function clearPreparedEdit() {
277 $this->mPreparedEdit = false;
278 }
279
286 public static function selectFields() {
288
289 $fields = [
290 'page_id',
291 'page_namespace',
292 'page_title',
293 'page_restrictions',
294 'page_is_redirect',
295 'page_is_new',
296 'page_random',
297 'page_touched',
298 'page_links_updated',
299 'page_latest',
300 'page_len',
301 ];
302
304 $fields[] = 'page_content_model';
305 }
306
307 if ( $wgPageLanguageUseDB ) {
308 $fields[] = 'page_lang';
309 }
310
311 return $fields;
312 }
313
321 protected function pageData( $dbr, $conditions, $options = [] ) {
322 $fields = self::selectFields();
323
324 // Avoid PHP 7.1 warning of passing $this by reference
325 $wikiPage = $this;
326
327 Hooks::run( 'ArticlePageDataBefore', [ &$wikiPage, &$fields ] );
328
329 $row = $dbr->selectRow( 'page', $fields, $conditions, __METHOD__, $options );
330
331 Hooks::run( 'ArticlePageDataAfter', [ &$wikiPage, &$row ] );
332
333 return $row;
334 }
335
345 public function pageDataFromTitle( $dbr, $title, $options = [] ) {
346 return $this->pageData( $dbr, [
347 'page_namespace' => $title->getNamespace(),
348 'page_title' => $title->getDBkey() ], $options );
349 }
350
359 public function pageDataFromId( $dbr, $id, $options = [] ) {
360 return $this->pageData( $dbr, [ 'page_id' => $id ], $options );
361 }
362
375 public function loadPageData( $from = 'fromdb' ) {
376 $from = self::convertSelectType( $from );
377 if ( is_int( $from ) && $from <= $this->mDataLoadedFrom ) {
378 // We already have the data from the correct location, no need to load it twice.
379 return;
380 }
381
382 if ( is_int( $from ) ) {
383 list( $index, $opts ) = DBAccessObjectUtils::getDBOptions( $from );
384 $data = $this->pageDataFromTitle( wfGetDB( $index ), $this->mTitle, $opts );
385
386 if ( !$data
387 && $index == DB_REPLICA
388 && wfGetLB()->getServerCount() > 1
389 && wfGetLB()->hasOrMadeRecentMasterChanges()
390 ) {
391 $from = self::READ_LATEST;
392 list( $index, $opts ) = DBAccessObjectUtils::getDBOptions( $from );
393 $data = $this->pageDataFromTitle( wfGetDB( $index ), $this->mTitle, $opts );
394 }
395 } else {
396 // No idea from where the caller got this data, assume replica DB.
397 $data = $from;
398 $from = self::READ_NORMAL;
399 }
400
401 $this->loadFromRow( $data, $from );
402 }
403
415 public function loadFromRow( $data, $from ) {
416 $lc = LinkCache::singleton();
417 $lc->clearLink( $this->mTitle );
418
419 if ( $data ) {
420 $lc->addGoodLinkObjFromRow( $this->mTitle, $data );
421
422 $this->mTitle->loadFromRow( $data );
423
424 // Old-fashioned restrictions
425 $this->mTitle->loadRestrictions( $data->page_restrictions );
426
427 $this->mId = intval( $data->page_id );
428 $this->mTouched = wfTimestamp( TS_MW, $data->page_touched );
429 $this->mLinksUpdated = wfTimestampOrNull( TS_MW, $data->page_links_updated );
430 $this->mIsRedirect = intval( $data->page_is_redirect );
431 $this->mLatest = intval( $data->page_latest );
432 // T39225: $latest may no longer match the cached latest Revision object.
433 // Double-check the ID of any cached latest Revision object for consistency.
434 if ( $this->mLastRevision && $this->mLastRevision->getId() != $this->mLatest ) {
435 $this->mLastRevision = null;
436 $this->mTimestamp = '';
437 }
438 } else {
439 $lc->addBadLinkObj( $this->mTitle );
440
441 $this->mTitle->loadFromRow( false );
442
443 $this->clearCacheFields();
444
445 $this->mId = 0;
446 }
447
448 $this->mDataLoaded = true;
449 $this->mDataLoadedFrom = self::convertSelectType( $from );
450 }
451
455 public function getId() {
456 if ( !$this->mDataLoaded ) {
457 $this->loadPageData();
458 }
459 return $this->mId;
460 }
461
465 public function exists() {
466 if ( !$this->mDataLoaded ) {
467 $this->loadPageData();
468 }
469 return $this->mId > 0;
470 }
471
480 public function hasViewableContent() {
481 return $this->mTitle->isKnown();
482 }
483
489 public function isRedirect() {
490 if ( !$this->mDataLoaded ) {
491 $this->loadPageData();
492 }
493
494 return (bool)$this->mIsRedirect;
495 }
496
507 public function getContentModel() {
508 if ( $this->exists() ) {
509 $cache = ObjectCache::getMainWANInstance();
510
511 return $cache->getWithSetCallback(
512 $cache->makeKey( 'page', 'content-model', $this->getLatest() ),
513 $cache::TTL_MONTH,
514 function () {
515 $rev = $this->getRevision();
516 if ( $rev ) {
517 // Look at the revision's actual content model
518 return $rev->getContentModel();
519 } else {
520 $title = $this->mTitle->getPrefixedDBkey();
521 wfWarn( "Page $title exists but has no (visible) revisions!" );
522 return $this->mTitle->getContentModel();
523 }
524 }
525 );
526 }
527
528 // use the default model for this page
529 return $this->mTitle->getContentModel();
530 }
531
536 public function checkTouched() {
537 if ( !$this->mDataLoaded ) {
538 $this->loadPageData();
539 }
540 return ( $this->mId && !$this->mIsRedirect );
541 }
542
547 public function getTouched() {
548 if ( !$this->mDataLoaded ) {
549 $this->loadPageData();
550 }
551 return $this->mTouched;
552 }
553
558 public function getLinksTimestamp() {
559 if ( !$this->mDataLoaded ) {
560 $this->loadPageData();
561 }
563 }
564
569 public function getLatest() {
570 if ( !$this->mDataLoaded ) {
571 $this->loadPageData();
572 }
573 return (int)$this->mLatest;
574 }
575
580 public function getOldestRevision() {
581 // Try using the replica DB first, then try the master
582 $rev = $this->mTitle->getFirstRevision();
583 if ( !$rev ) {
584 $rev = $this->mTitle->getFirstRevision( Title::GAID_FOR_UPDATE );
585 }
586 return $rev;
587 }
588
593 protected function loadLastEdit() {
594 if ( $this->mLastRevision !== null ) {
595 return; // already loaded
596 }
597
598 $latest = $this->getLatest();
599 if ( !$latest ) {
600 return; // page doesn't exist or is missing page_latest info
601 }
602
603 if ( $this->mDataLoadedFrom == self::READ_LOCKING ) {
604 // T39225: if session S1 loads the page row FOR UPDATE, the result always
605 // includes the latest changes committed. This is true even within REPEATABLE-READ
606 // transactions, where S1 normally only sees changes committed before the first S1
607 // SELECT. Thus we need S1 to also gets the revision row FOR UPDATE; otherwise, it
608 // may not find it since a page row UPDATE and revision row INSERT by S2 may have
609 // happened after the first S1 SELECT.
610 // https://dev.mysql.com/doc/refman/5.0/en/set-transaction.html#isolevel_repeatable-read
612 $revision = Revision::newFromPageId( $this->getId(), $latest, $flags );
613 } elseif ( $this->mDataLoadedFrom == self::READ_LATEST ) {
614 // Bug T93976: if page_latest was loaded from the master, fetch the
615 // revision from there as well, as it may not exist yet on a replica DB.
616 // Also, this keeps the queries in the same REPEATABLE-READ snapshot.
617 $flags = Revision::READ_LATEST;
618 $revision = Revision::newFromPageId( $this->getId(), $latest, $flags );
619 } else {
621 $revision = Revision::newKnownCurrent( $dbr, $this->getId(), $latest );
622 }
623
624 if ( $revision ) { // sanity
625 $this->setLastEdit( $revision );
626 }
627 }
628
633 protected function setLastEdit( Revision $revision ) {
634 $this->mLastRevision = $revision;
635 $this->mTimestamp = $revision->getTimestamp();
636 }
637
642 public function getRevision() {
643 $this->loadLastEdit();
644 if ( $this->mLastRevision ) {
646 }
647 return null;
648 }
649
663 public function getContent( $audience = Revision::FOR_PUBLIC, User $user = null ) {
664 $this->loadLastEdit();
665 if ( $this->mLastRevision ) {
666 return $this->mLastRevision->getContent( $audience, $user );
667 }
668 return null;
669 }
670
674 public function getTimestamp() {
675 // Check if the field has been filled by WikiPage::setTimestamp()
676 if ( !$this->mTimestamp ) {
677 $this->loadLastEdit();
678 }
679
680 return wfTimestamp( TS_MW, $this->mTimestamp );
681 }
682
688 public function setTimestamp( $ts ) {
689 $this->mTimestamp = wfTimestamp( TS_MW, $ts );
690 }
691
701 public function getUser( $audience = Revision::FOR_PUBLIC, User $user = null ) {
702 $this->loadLastEdit();
703 if ( $this->mLastRevision ) {
704 return $this->mLastRevision->getUser( $audience, $user );
705 } else {
706 return -1;
707 }
708 }
709
720 public function getCreator( $audience = Revision::FOR_PUBLIC, User $user = null ) {
721 $revision = $this->getOldestRevision();
722 if ( $revision ) {
723 $userName = $revision->getUserText( $audience, $user );
724 return User::newFromName( $userName, false );
725 } else {
726 return null;
727 }
728 }
729
739 public function getUserText( $audience = Revision::FOR_PUBLIC, User $user = null ) {
740 $this->loadLastEdit();
741 if ( $this->mLastRevision ) {
742 return $this->mLastRevision->getUserText( $audience, $user );
743 } else {
744 return '';
745 }
746 }
747
757 public function getComment( $audience = Revision::FOR_PUBLIC, User $user = null ) {
758 $this->loadLastEdit();
759 if ( $this->mLastRevision ) {
760 return $this->mLastRevision->getComment( $audience, $user );
761 } else {
762 return '';
763 }
764 }
765
771 public function getMinorEdit() {
772 $this->loadLastEdit();
773 if ( $this->mLastRevision ) {
774 return $this->mLastRevision->isMinor();
775 } else {
776 return false;
777 }
778 }
779
788 public function isCountable( $editInfo = false ) {
790
791 if ( !$this->mTitle->isContentPage() ) {
792 return false;
793 }
794
795 if ( $editInfo ) {
796 $content = $editInfo->pstContent;
797 } else {
798 $content = $this->getContent();
799 }
800
801 if ( !$content || $content->isRedirect() ) {
802 return false;
803 }
804
805 $hasLinks = null;
806
807 if ( $wgArticleCountMethod === 'link' ) {
808 // nasty special case to avoid re-parsing to detect links
809
810 if ( $editInfo ) {
811 // ParserOutput::getLinks() is a 2D array of page links, so
812 // to be really correct we would need to recurse in the array
813 // but the main array should only have items in it if there are
814 // links.
815 $hasLinks = (bool)count( $editInfo->output->getLinks() );
816 } else {
817 $hasLinks = (bool)wfGetDB( DB_REPLICA )->selectField( 'pagelinks', 1,
818 [ 'pl_from' => $this->getId() ], __METHOD__ );
819 }
820 }
821
822 return $content->isCountable( $hasLinks );
823 }
824
832 public function getRedirectTarget() {
833 if ( !$this->mTitle->isRedirect() ) {
834 return null;
835 }
836
837 if ( $this->mRedirectTarget !== null ) {
839 }
840
841 // Query the redirect table
843 $row = $dbr->selectRow( 'redirect',
844 [ 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ],
845 [ 'rd_from' => $this->getId() ],
846 __METHOD__
847 );
848
849 // rd_fragment and rd_interwiki were added later, populate them if empty
850 if ( $row && !is_null( $row->rd_fragment ) && !is_null( $row->rd_interwiki ) ) {
851 $this->mRedirectTarget = Title::makeTitle(
852 $row->rd_namespace, $row->rd_title,
853 $row->rd_fragment, $row->rd_interwiki
854 );
856 }
857
858 // This page doesn't have an entry in the redirect table
859 $this->mRedirectTarget = $this->insertRedirect();
861 }
862
871 public function insertRedirect() {
872 $content = $this->getContent();
873 $retval = $content ? $content->getUltimateRedirectTarget() : null;
874 if ( !$retval ) {
875 return null;
876 }
877
878 // Update the DB post-send if the page has not cached since now
879 $that = $this;
880 $latest = $this->getLatest();
881 DeferredUpdates::addCallableUpdate(
882 function () use ( $that, $retval, $latest ) {
883 $that->insertRedirectEntry( $retval, $latest );
884 },
885 DeferredUpdates::POSTSEND,
887 );
888
889 return $retval;
890 }
891
897 public function insertRedirectEntry( Title $rt, $oldLatest = null ) {
898 $dbw = wfGetDB( DB_MASTER );
899 $dbw->startAtomic( __METHOD__ );
900
901 if ( !$oldLatest || $oldLatest == $this->lockAndGetLatest() ) {
902 $dbw->upsert(
903 'redirect',
904 [
905 'rd_from' => $this->getId(),
906 'rd_namespace' => $rt->getNamespace(),
907 'rd_title' => $rt->getDBkey(),
908 'rd_fragment' => $rt->getFragment(),
909 'rd_interwiki' => $rt->getInterwiki(),
910 ],
911 [ 'rd_from' ],
912 [
913 'rd_namespace' => $rt->getNamespace(),
914 'rd_title' => $rt->getDBkey(),
915 'rd_fragment' => $rt->getFragment(),
916 'rd_interwiki' => $rt->getInterwiki(),
917 ],
918 __METHOD__
919 );
920 }
921
922 $dbw->endAtomic( __METHOD__ );
923 }
924
930 public function followRedirect() {
931 return $this->getRedirectURL( $this->getRedirectTarget() );
932 }
933
941 public function getRedirectURL( $rt ) {
942 if ( !$rt ) {
943 return false;
944 }
945
946 if ( $rt->isExternal() ) {
947 if ( $rt->isLocal() ) {
948 // Offsite wikis need an HTTP redirect.
949 // This can be hard to reverse and may produce loops,
950 // so they may be disabled in the site configuration.
951 $source = $this->mTitle->getFullURL( 'redirect=no' );
952 return $rt->getFullURL( [ 'rdfrom' => $source ] );
953 } else {
954 // External pages without "local" bit set are not valid
955 // redirect targets
956 return false;
957 }
958 }
959
960 if ( $rt->isSpecialPage() ) {
961 // Gotta handle redirects to special pages differently:
962 // Fill the HTTP response "Location" header and ignore the rest of the page we're on.
963 // Some pages are not valid targets.
964 if ( $rt->isValidRedirectTarget() ) {
965 return $rt->getFullURL();
966 } else {
967 return false;
968 }
969 }
970
971 return $rt;
972 }
973
979 public function getContributors() {
980 // @todo FIXME: This is expensive; cache this info somewhere.
981
983
984 if ( $dbr->implicitGroupby() ) {
985 $realNameField = 'user_real_name';
986 } else {
987 $realNameField = 'MIN(user_real_name) AS user_real_name';
988 }
989
990 $tables = [ 'revision', 'user' ];
991
992 $fields = [
993 'user_id' => 'rev_user',
994 'user_name' => 'rev_user_text',
995 $realNameField,
996 'timestamp' => 'MAX(rev_timestamp)',
997 ];
998
999 $conds = [ 'rev_page' => $this->getId() ];
1000
1001 // The user who made the top revision gets credited as "this page was last edited by
1002 // John, based on contributions by Tom, Dick and Harry", so don't include them twice.
1003 $user = $this->getUser();
1004 if ( $user ) {
1005 $conds[] = "rev_user != $user";
1006 } else {
1007 $conds[] = "rev_user_text != {$dbr->addQuotes( $this->getUserText() )}";
1008 }
1009
1010 // Username hidden?
1011 $conds[] = "{$dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER )} = 0";
1012
1013 $jconds = [
1014 'user' => [ 'LEFT JOIN', 'rev_user = user_id' ],
1015 ];
1016
1017 $options = [
1018 'GROUP BY' => [ 'rev_user', 'rev_user_text' ],
1019 'ORDER BY' => 'timestamp DESC',
1020 ];
1021
1022 $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $jconds );
1023 return new UserArrayFromResult( $res );
1024 }
1025
1033 public function shouldCheckParserCache( ParserOptions $parserOptions, $oldId ) {
1034 return $parserOptions->getStubThreshold() == 0
1035 && $this->exists()
1036 && ( $oldId === null || $oldId === 0 || $oldId === $this->getLatest() )
1037 && $this->getContentHandler()->isParserCacheSupported();
1038 }
1039
1053 public function getParserOutput(
1054 ParserOptions $parserOptions, $oldid = null, $forceParse = false
1055 ) {
1056 $useParserCache =
1057 ( !$forceParse ) && $this->shouldCheckParserCache( $parserOptions, $oldid );
1058 wfDebug( __METHOD__ .
1059 ': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
1060 if ( $parserOptions->getStubThreshold() ) {
1061 wfIncrStats( 'pcache.miss.stub' );
1062 }
1063
1064 if ( $useParserCache ) {
1065 $parserOutput = ParserCache::singleton()->get( $this, $parserOptions );
1066 if ( $parserOutput !== false ) {
1067 return $parserOutput;
1068 }
1069 }
1070
1071 if ( $oldid === null || $oldid === 0 ) {
1072 $oldid = $this->getLatest();
1073 }
1074
1075 $pool = new PoolWorkArticleView( $this, $parserOptions, $oldid, $useParserCache );
1076 $pool->execute();
1077
1078 return $pool->getParserOutput();
1079 }
1080
1086 public function doViewUpdates( User $user, $oldid = 0 ) {
1087 if ( wfReadOnly() ) {
1088 return;
1089 }
1090
1091 Hooks::run( 'PageViewUpdates', [ $this, $user ] );
1092 // Update newtalk / watchlist notification status
1093 try {
1094 $user->clearNotification( $this->mTitle, $oldid );
1095 } catch ( DBError $e ) {
1096 // Avoid outage if the master is not reachable
1097 MWExceptionHandler::logException( $e );
1098 }
1099 }
1100
1107 public function doPurge() {
1108 // Avoid PHP 7.1 warning of passing $this by reference
1109 $wikiPage = $this;
1110
1111 if ( !Hooks::run( 'ArticlePurge', [ &$wikiPage ] ) ) {
1112 return false;
1113 }
1114
1115 $this->mTitle->invalidateCache();
1116
1117 // Clear file cache
1119 // Send purge after above page_touched update was committed
1120 DeferredUpdates::addUpdate(
1121 new CdnCacheUpdate( $this->mTitle->getCdnUrls() ),
1122 DeferredUpdates::PRESEND
1123 );
1124
1125 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1126 $messageCache = MessageCache::singleton();
1127 $messageCache->updateMessageOverride( $this->mTitle, $this->getContent() );
1128 }
1129
1130 return true;
1131 }
1132
1140 public function getLastPurgeTimestamp() {
1141 wfDeprecated( __METHOD__, '1.29' );
1142 return false;
1143 }
1144
1159 public function insertOn( $dbw, $pageId = null ) {
1160 $pageIdForInsert = $pageId ?: $dbw->nextSequenceValue( 'page_page_id_seq' );
1161 $dbw->insert(
1162 'page',
1163 [
1164 'page_id' => $pageIdForInsert,
1165 'page_namespace' => $this->mTitle->getNamespace(),
1166 'page_title' => $this->mTitle->getDBkey(),
1167 'page_restrictions' => '',
1168 'page_is_redirect' => 0, // Will set this shortly...
1169 'page_is_new' => 1,
1170 'page_random' => wfRandom(),
1171 'page_touched' => $dbw->timestamp(),
1172 'page_latest' => 0, // Fill this in shortly...
1173 'page_len' => 0, // Fill this in shortly...
1174 ],
1175 __METHOD__,
1176 'IGNORE'
1177 );
1178
1179 if ( $dbw->affectedRows() > 0 ) {
1180 $newid = $pageId ?: $dbw->insertId();
1181 $this->mId = $newid;
1182 $this->mTitle->resetArticleID( $newid );
1183
1184 return $newid;
1185 } else {
1186 return false; // nothing changed
1187 }
1188 }
1189
1203 public function updateRevisionOn( $dbw, $revision, $lastRevision = null,
1204 $lastRevIsRedirect = null
1205 ) {
1207
1208 // Assertion to try to catch T92046
1209 if ( (int)$revision->getId() === 0 ) {
1210 throw new InvalidArgumentException(
1211 __METHOD__ . ': Revision has ID ' . var_export( $revision->getId(), 1 )
1212 );
1213 }
1214
1215 $content = $revision->getContent();
1216 $len = $content ? $content->getSize() : 0;
1217 $rt = $content ? $content->getUltimateRedirectTarget() : null;
1218
1219 $conditions = [ 'page_id' => $this->getId() ];
1220
1221 if ( !is_null( $lastRevision ) ) {
1222 // An extra check against threads stepping on each other
1223 $conditions['page_latest'] = $lastRevision;
1224 }
1225
1226 $row = [ /* SET */
1227 'page_latest' => $revision->getId(),
1228 'page_touched' => $dbw->timestamp( $revision->getTimestamp() ),
1229 'page_is_new' => ( $lastRevision === 0 ) ? 1 : 0,
1230 'page_is_redirect' => $rt !== null ? 1 : 0,
1231 'page_len' => $len,
1232 ];
1233
1234 if ( $wgContentHandlerUseDB ) {
1235 $row['page_content_model'] = $revision->getContentModel();
1236 }
1237
1238 $dbw->update( 'page',
1239 $row,
1240 $conditions,
1241 __METHOD__ );
1242
1243 $result = $dbw->affectedRows() > 0;
1244 if ( $result ) {
1245 $this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect );
1246 $this->setLastEdit( $revision );
1247 $this->mLatest = $revision->getId();
1248 $this->mIsRedirect = (bool)$rt;
1249 // Update the LinkCache.
1250 LinkCache::singleton()->addGoodLinkObj(
1251 $this->getId(),
1252 $this->mTitle,
1253 $len,
1254 $this->mIsRedirect,
1255 $this->mLatest,
1256 $revision->getContentModel()
1257 );
1258 }
1259
1260 return $result;
1261 }
1262
1274 public function updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect = null ) {
1275 // Always update redirects (target link might have changed)
1276 // Update/Insert if we don't know if the last revision was a redirect or not
1277 // Delete if changing from redirect to non-redirect
1278 $isRedirect = !is_null( $redirectTitle );
1279
1280 if ( !$isRedirect && $lastRevIsRedirect === false ) {
1281 return true;
1282 }
1283
1284 if ( $isRedirect ) {
1285 $this->insertRedirectEntry( $redirectTitle );
1286 } else {
1287 // This is not a redirect, remove row from redirect table
1288 $where = [ 'rd_from' => $this->getId() ];
1289 $dbw->delete( 'redirect', $where, __METHOD__ );
1290 }
1291
1292 if ( $this->getTitle()->getNamespace() == NS_FILE ) {
1293 RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() );
1294 }
1295
1296 return ( $dbw->affectedRows() != 0 );
1297 }
1298
1309 public function updateIfNewerOn( $dbw, $revision ) {
1310
1311 $row = $dbw->selectRow(
1312 [ 'revision', 'page' ],
1313 [ 'rev_id', 'rev_timestamp', 'page_is_redirect' ],
1314 [
1315 'page_id' => $this->getId(),
1316 'page_latest=rev_id' ],
1317 __METHOD__ );
1318
1319 if ( $row ) {
1320 if ( wfTimestamp( TS_MW, $row->rev_timestamp ) >= $revision->getTimestamp() ) {
1321 return false;
1322 }
1323 $prev = $row->rev_id;
1324 $lastRevIsRedirect = (bool)$row->page_is_redirect;
1325 } else {
1326 // No or missing previous revision; mark the page as new
1327 $prev = 0;
1328 $lastRevIsRedirect = null;
1329 }
1330
1331 $ret = $this->updateRevisionOn( $dbw, $revision, $prev, $lastRevIsRedirect );
1332
1333 return $ret;
1334 }
1335
1346 public function getUndoContent( Revision $undo, Revision $undoafter = null ) {
1347 $handler = $undo->getContentHandler();
1348 return $handler->getUndoContent( $this->getRevision(), $undo, $undoafter );
1349 }
1350
1361 public function supportsSections() {
1362 return $this->getContentHandler()->supportsSections();
1363 }
1364
1379 public function replaceSectionContent(
1380 $sectionId, Content $sectionContent, $sectionTitle = '', $edittime = null
1381 ) {
1382
1383 $baseRevId = null;
1384 if ( $edittime && $sectionId !== 'new' ) {
1385 $dbr = wfGetDB( DB_REPLICA );
1386 $rev = Revision::loadFromTimestamp( $dbr, $this->mTitle, $edittime );
1387 // Try the master if this thread may have just added it.
1388 // This could be abstracted into a Revision method, but we don't want
1389 // to encourage loading of revisions by timestamp.
1390 if ( !$rev
1391 && wfGetLB()->getServerCount() > 1
1392 && wfGetLB()->hasOrMadeRecentMasterChanges()
1393 ) {
1394 $dbw = wfGetDB( DB_MASTER );
1395 $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
1396 }
1397 if ( $rev ) {
1398 $baseRevId = $rev->getId();
1399 }
1400 }
1401
1402 return $this->replaceSectionAtRev( $sectionId, $sectionContent, $sectionTitle, $baseRevId );
1403 }
1404
1418 public function replaceSectionAtRev( $sectionId, Content $sectionContent,
1419 $sectionTitle = '', $baseRevId = null
1420 ) {
1421
1422 if ( strval( $sectionId ) === '' ) {
1423 // Whole-page edit; let the whole text through
1424 $newContent = $sectionContent;
1425 } else {
1426 if ( !$this->supportsSections() ) {
1427 throw new MWException( "sections not supported for content model " .
1428 $this->getContentHandler()->getModelID() );
1429 }
1430
1431 // T32711: always use current version when adding a new section
1432 if ( is_null( $baseRevId ) || $sectionId === 'new' ) {
1433 $oldContent = $this->getContent();
1434 } else {
1435 $rev = Revision::newFromId( $baseRevId );
1436 if ( !$rev ) {
1437 wfDebug( __METHOD__ . " asked for bogus section (page: " .
1438 $this->getId() . "; section: $sectionId)\n" );
1439 return null;
1440 }
1441
1442 $oldContent = $rev->getContent();
1443 }
1444
1445 if ( !$oldContent ) {
1446 wfDebug( __METHOD__ . ": no page text\n" );
1447 return null;
1448 }
1449
1450 $newContent = $oldContent->replaceSection( $sectionId, $sectionContent, $sectionTitle );
1451 }
1452
1453 return $newContent;
1454 }
1455
1461 public function checkFlags( $flags ) {
1462 if ( !( $flags & EDIT_NEW ) && !( $flags & EDIT_UPDATE ) ) {
1463 if ( $this->exists() ) {
1465 } else {
1466 $flags |= EDIT_NEW;
1467 }
1468 }
1469
1470 return $flags;
1471 }
1472
1531 public function doEditContent(
1532 Content $content, $summary, $flags = 0, $baseRevId = false,
1533 User $user = null, $serialFormat = null, $tags = [], $undidRevId = 0
1534 ) {
1536
1537 // Old default parameter for $tags was null
1538 if ( $tags === null ) {
1539 $tags = [];
1540 }
1541
1542 // Low-level sanity check
1543 if ( $this->mTitle->getText() === '' ) {
1544 throw new MWException( 'Something is trying to edit an article with an empty title' );
1545 }
1546 // Make sure the given content type is allowed for this page
1547 if ( !$content->getContentHandler()->canBeUsedOn( $this->mTitle ) ) {
1548 return Status::newFatal( 'content-not-allowed-here',
1550 $this->mTitle->getPrefixedText()
1551 );
1552 }
1553
1554 // Load the data from the master database if needed.
1555 // The caller may already loaded it from the master or even loaded it using
1556 // SELECT FOR UPDATE, so do not override that using clear().
1557 $this->loadPageData( 'fromdbmaster' );
1558
1559 $user = $user ?: $wgUser;
1560 $flags = $this->checkFlags( $flags );
1561
1562 // Avoid PHP 7.1 warning of passing $this by reference
1563 $wikiPage = $this;
1564
1565 // Trigger pre-save hook (using provided edit summary)
1566 $hookStatus = Status::newGood( [] );
1567 $hook_args = [ &$wikiPage, &$user, &$content, &$summary,
1568 $flags & EDIT_MINOR, null, null, &$flags, &$hookStatus ];
1569 // Check if the hook rejected the attempted save
1570 if ( !Hooks::run( 'PageContentSave', $hook_args ) ) {
1571 if ( $hookStatus->isOK() ) {
1572 // Hook returned false but didn't call fatal(); use generic message
1573 $hookStatus->fatal( 'edit-hook-aborted' );
1574 }
1575
1576 return $hookStatus;
1577 }
1578
1579 $old_revision = $this->getRevision(); // current revision
1580 $old_content = $this->getContent( Revision::RAW ); // current revision's content
1581
1582 if ( $old_content && $old_content->getModel() !== $content->getModel() ) {
1583 $tags[] = 'mw-contentmodelchange';
1584 }
1585
1586 // Provide autosummaries if one is not provided and autosummaries are enabled
1587 if ( $wgUseAutomaticEditSummaries && ( $flags & EDIT_AUTOSUMMARY ) && $summary == '' ) {
1588 $handler = $content->getContentHandler();
1589 $summary = $handler->getAutosummary( $old_content, $content, $flags );
1590 }
1591
1592 // Avoid statsd noise and wasted cycles check the edit stash (T136678)
1593 if ( ( $flags & EDIT_INTERNAL ) || ( $flags & EDIT_FORCE_BOT ) ) {
1594 $useCache = false;
1595 } else {
1596 $useCache = true;
1597 }
1598
1599 // Get the pre-save transform content and final parser output
1600 $editInfo = $this->prepareContentForEdit( $content, null, $user, $serialFormat, $useCache );
1601 $pstContent = $editInfo->pstContent; // Content object
1602 $meta = [
1603 'bot' => ( $flags & EDIT_FORCE_BOT ),
1604 'minor' => ( $flags & EDIT_MINOR ) && $user->isAllowed( 'minoredit' ),
1605 'serialized' => $editInfo->pst,
1606 'serialFormat' => $serialFormat,
1607 'baseRevId' => $baseRevId,
1608 'oldRevision' => $old_revision,
1609 'oldContent' => $old_content,
1610 'oldId' => $this->getLatest(),
1611 'oldIsRedirect' => $this->isRedirect(),
1612 'oldCountable' => $this->isCountable(),
1613 'tags' => ( $tags !== null ) ? (array)$tags : [],
1614 'undidRevId' => $undidRevId
1615 ];
1616
1617 // Actually create the revision and create/update the page
1618 if ( $flags & EDIT_UPDATE ) {
1619 $status = $this->doModify( $pstContent, $flags, $user, $summary, $meta );
1620 } else {
1621 $status = $this->doCreate( $pstContent, $flags, $user, $summary, $meta );
1622 }
1623
1624 // Promote user to any groups they meet the criteria for
1625 DeferredUpdates::addCallableUpdate( function () use ( $user ) {
1626 $user->addAutopromoteOnceGroups( 'onEdit' );
1627 $user->addAutopromoteOnceGroups( 'onView' ); // b/c
1628 } );
1629
1630 return $status;
1631 }
1632
1645 private function doModify(
1646 Content $content, $flags, User $user, $summary, array $meta
1647 ) {
1649
1650 // Update article, but only if changed.
1651 $status = Status::newGood( [ 'new' => false, 'revision' => null ] );
1652
1653 // Convenience variables
1654 $now = wfTimestampNow();
1655 $oldid = $meta['oldId'];
1657 $oldContent = $meta['oldContent'];
1658 $newsize = $content->getSize();
1659
1660 if ( !$oldid ) {
1661 // Article gone missing
1662 $status->fatal( 'edit-gone-missing' );
1663
1664 return $status;
1665 } elseif ( !$oldContent ) {
1666 // Sanity check for T39225
1667 throw new MWException( "Could not find text for current revision {$oldid}." );
1668 }
1669
1670 // @TODO: pass content object?!
1671 $revision = new Revision( [
1672 'page' => $this->getId(),
1673 'title' => $this->mTitle, // for determining the default content model
1674 'comment' => $summary,
1675 'minor_edit' => $meta['minor'],
1676 'text' => $meta['serialized'],
1677 'len' => $newsize,
1678 'parent_id' => $oldid,
1679 'user' => $user->getId(),
1680 'user_text' => $user->getName(),
1681 'timestamp' => $now,
1682 'content_model' => $content->getModel(),
1683 'content_format' => $meta['serialFormat'],
1684 ] );
1685
1686 $changed = !$content->equals( $oldContent );
1687
1688 $dbw = wfGetDB( DB_MASTER );
1689
1690 if ( $changed ) {
1691 $prepStatus = $content->prepareSave( $this, $flags, $oldid, $user );
1692 $status->merge( $prepStatus );
1693 if ( !$status->isOK() ) {
1694 return $status;
1695 }
1696
1697 $dbw->startAtomic( __METHOD__ );
1698 // Get the latest page_latest value while locking it.
1699 // Do a CAS style check to see if it's the same as when this method
1700 // started. If it changed then bail out before touching the DB.
1701 $latestNow = $this->lockAndGetLatest();
1702 if ( $latestNow != $oldid ) {
1703 $dbw->endAtomic( __METHOD__ );
1704 // Page updated or deleted in the mean time
1705 $status->fatal( 'edit-conflict' );
1706
1707 return $status;
1708 }
1709
1710 // At this point we are now comitted to returning an OK
1711 // status unless some DB query error or other exception comes up.
1712 // This way callers don't have to call rollback() if $status is bad
1713 // unless they actually try to catch exceptions (which is rare).
1714
1715 // Save the revision text
1716 $revisionId = $revision->insertOn( $dbw );
1717 // Update page_latest and friends to reflect the new revision
1718 if ( !$this->updateRevisionOn( $dbw, $revision, null, $meta['oldIsRedirect'] ) ) {
1719 throw new MWException( "Failed to update page row to use new revision." );
1720 }
1721
1722 Hooks::run( 'NewRevisionFromEditComplete',
1723 [ $this, $revision, $meta['baseRevId'], $user ] );
1724
1725 // Update recentchanges
1726 if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
1727 // Mark as patrolled if the user can do so
1728 $patrolled = $wgUseRCPatrol && !count(
1729 $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
1730 // Add RC row to the DB
1732 $now,
1733 $this->mTitle,
1734 $revision->isMinor(),
1735 $user,
1736 $summary,
1737 $oldid,
1738 $this->getTimestamp(),
1739 $meta['bot'],
1740 '',
1741 $oldContent ? $oldContent->getSize() : 0,
1742 $newsize,
1743 $revisionId,
1744 $patrolled,
1745 $meta['tags']
1746 );
1747 }
1748
1749 $user->incEditCount();
1750
1751 $dbw->endAtomic( __METHOD__ );
1752 $this->mTimestamp = $now;
1753 } else {
1754 // T34948: revision ID must be set to page {{REVISIONID}} and
1755 // related variables correctly. Likewise for {{REVISIONUSER}} (T135261).
1756 $revision->setId( $this->getLatest() );
1757 $revision->setUserIdAndName(
1758 $this->getUser( Revision::RAW ),
1759 $this->getUserText( Revision::RAW )
1760 );
1761 }
1762
1763 if ( $changed ) {
1764 // Return the new revision to the caller
1765 $status->value['revision'] = $revision;
1766 } else {
1767 $status->warning( 'edit-no-change' );
1768 // Update page_touched as updateRevisionOn() was not called.
1769 // Other cache updates are managed in onArticleEdit() via doEditUpdates().
1770 $this->mTitle->invalidateCache( $now );
1771 }
1772
1773 // Do secondary updates once the main changes have been committed...
1774 DeferredUpdates::addUpdate(
1776 $dbw,
1777 __METHOD__,
1778 function () use (
1779 $revision, &$user, $content, $summary, &$flags,
1780 $changed, $meta, &$status
1781 ) {
1782 // Update links tables, site stats, etc.
1783 $this->doEditUpdates(
1784 $revision,
1785 $user,
1786 [
1787 'changed' => $changed,
1788 'oldcountable' => $meta['oldCountable'],
1789 'oldrevision' => $meta['oldRevision']
1790 ]
1791 );
1792 // Avoid PHP 7.1 warning of passing $this by reference
1793 $wikiPage = $this;
1794 // Trigger post-save hook
1795 $params = [ &$wikiPage, &$user, $content, $summary, $flags & EDIT_MINOR,
1796 null, null, &$flags, $revision, &$status, $meta['baseRevId'],
1797 $meta['undidRevId'] ];
1798 Hooks::run( 'PageContentSaveComplete', $params );
1799 }
1800 ),
1801 DeferredUpdates::PRESEND
1802 );
1803
1804 return $status;
1805 }
1806
1819 private function doCreate(
1820 Content $content, $flags, User $user, $summary, array $meta
1821 ) {
1823
1824 $status = Status::newGood( [ 'new' => true, 'revision' => null ] );
1825
1826 $now = wfTimestampNow();
1827 $newsize = $content->getSize();
1828 $prepStatus = $content->prepareSave( $this, $flags, $meta['oldId'], $user );
1829 $status->merge( $prepStatus );
1830 if ( !$status->isOK() ) {
1831 return $status;
1832 }
1833
1834 $dbw = wfGetDB( DB_MASTER );
1835 $dbw->startAtomic( __METHOD__ );
1836
1837 // Add the page record unless one already exists for the title
1838 $newid = $this->insertOn( $dbw );
1839 if ( $newid === false ) {
1840 $dbw->endAtomic( __METHOD__ ); // nothing inserted
1841 $status->fatal( 'edit-already-exists' );
1842
1843 return $status; // nothing done
1844 }
1845
1846 // At this point we are now comitted to returning an OK
1847 // status unless some DB query error or other exception comes up.
1848 // This way callers don't have to call rollback() if $status is bad
1849 // unless they actually try to catch exceptions (which is rare).
1850
1851 // @TODO: pass content object?!
1852 $revision = new Revision( [
1853 'page' => $newid,
1854 'title' => $this->mTitle, // for determining the default content model
1855 'comment' => $summary,
1856 'minor_edit' => $meta['minor'],
1857 'text' => $meta['serialized'],
1858 'len' => $newsize,
1859 'user' => $user->getId(),
1860 'user_text' => $user->getName(),
1861 'timestamp' => $now,
1862 'content_model' => $content->getModel(),
1863 'content_format' => $meta['serialFormat'],
1864 ] );
1865
1866 // Save the revision text...
1867 $revisionId = $revision->insertOn( $dbw );
1868 // Update the page record with revision data
1869 if ( !$this->updateRevisionOn( $dbw, $revision, 0 ) ) {
1870 throw new MWException( "Failed to update page row to use new revision." );
1871 }
1872
1873 Hooks::run( 'NewRevisionFromEditComplete', [ $this, $revision, false, $user ] );
1874
1875 // Update recentchanges
1876 if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
1877 // Mark as patrolled if the user can do so
1878 $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) &&
1879 !count( $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
1880 // Add RC row to the DB
1882 $now,
1883 $this->mTitle,
1884 $revision->isMinor(),
1885 $user,
1886 $summary,
1887 $meta['bot'],
1888 '',
1889 $newsize,
1890 $revisionId,
1891 $patrolled,
1892 $meta['tags']
1893 );
1894 }
1895
1896 $user->incEditCount();
1897
1898 $dbw->endAtomic( __METHOD__ );
1899 $this->mTimestamp = $now;
1900
1901 // Return the new revision to the caller
1902 $status->value['revision'] = $revision;
1903
1904 // Do secondary updates once the main changes have been committed...
1905 DeferredUpdates::addUpdate(
1907 $dbw,
1908 __METHOD__,
1909 function () use (
1910 $revision, &$user, $content, $summary, &$flags, $meta, &$status
1911 ) {
1912 // Update links, etc.
1913 $this->doEditUpdates( $revision, $user, [ 'created' => true ] );
1914 // Avoid PHP 7.1 warning of passing $this by reference
1915 $wikiPage = $this;
1916 // Trigger post-create hook
1917 $params = [ &$wikiPage, &$user, $content, $summary,
1918 $flags & EDIT_MINOR, null, null, &$flags, $revision ];
1919 Hooks::run( 'PageContentInsertComplete', $params );
1920 // Trigger post-save hook
1921 $params = array_merge( $params, [ &$status, $meta['baseRevId'] ] );
1922 Hooks::run( 'PageContentSaveComplete', $params );
1923 }
1924 ),
1925 DeferredUpdates::PRESEND
1926 );
1927
1928 return $status;
1929 }
1930
1945 public function makeParserOptions( $context ) {
1946 $options = $this->getContentHandler()->makeParserOptions( $context );
1947
1948 if ( $this->getTitle()->isConversionTable() ) {
1949 // @todo ConversionTable should become a separate content model, so
1950 // we don't need special cases like this one.
1951 $options->disableContentConversion();
1952 }
1953
1954 return $options;
1955 }
1956
1972 public function prepareContentForEdit(
1973 Content $content, $revision = null, User $user = null,
1974 $serialFormat = null, $useCache = true
1975 ) {
1977
1978 if ( is_object( $revision ) ) {
1979 $revid = $revision->getId();
1980 } else {
1981 $revid = $revision;
1982 // This code path is deprecated, and nothing is known to
1983 // use it, so performance here shouldn't be a worry.
1984 if ( $revid !== null ) {
1985 $revision = Revision::newFromId( $revid, Revision::READ_LATEST );
1986 } else {
1987 $revision = null;
1988 }
1989 }
1990
1991 $user = is_null( $user ) ? $wgUser : $user;
1992 // XXX: check $user->getId() here???
1993
1994 // Use a sane default for $serialFormat, see T59026
1995 if ( $serialFormat === null ) {
1996 $serialFormat = $content->getContentHandler()->getDefaultFormat();
1997 }
1998
1999 if ( $this->mPreparedEdit
2000 && isset( $this->mPreparedEdit->newContent )
2001 && $this->mPreparedEdit->newContent->equals( $content )
2002 && $this->mPreparedEdit->revid == $revid
2003 && $this->mPreparedEdit->format == $serialFormat
2004 // XXX: also check $user here?
2005 ) {
2006 // Already prepared
2007 return $this->mPreparedEdit;
2008 }
2009
2010 // The edit may have already been prepared via api.php?action=stashedit
2011 $cachedEdit = $useCache && $wgAjaxEditStash
2012 ? ApiStashEdit::checkCache( $this->getTitle(), $content, $user )
2013 : false;
2014
2016 Hooks::run( 'ArticlePrepareTextForEdit', [ $this, $popts ] );
2017
2018 $edit = (object)[];
2019 if ( $cachedEdit ) {
2020 $edit->timestamp = $cachedEdit->timestamp;
2021 } else {
2022 $edit->timestamp = wfTimestampNow();
2023 }
2024 // @note: $cachedEdit is safely not used if the rev ID was referenced in the text
2025 $edit->revid = $revid;
2026
2027 if ( $cachedEdit ) {
2028 $edit->pstContent = $cachedEdit->pstContent;
2029 } else {
2030 $edit->pstContent = $content
2031 ? $content->preSaveTransform( $this->mTitle, $user, $popts )
2032 : null;
2033 }
2034
2035 $edit->format = $serialFormat;
2036 $edit->popts = $this->makeParserOptions( 'canonical' );
2037 if ( $cachedEdit ) {
2038 $edit->output = $cachedEdit->output;
2039 } else {
2040 if ( $revision ) {
2041 // We get here if vary-revision is set. This means that this page references
2042 // itself (such as via self-transclusion). In this case, we need to make sure
2043 // that any such self-references refer to the newly-saved revision, and not
2044 // to the previous one, which could otherwise happen due to replica DB lag.
2045 $oldCallback = $edit->popts->getCurrentRevisionCallback();
2046 $edit->popts->setCurrentRevisionCallback(
2047 function ( Title $title, $parser = false ) use ( $revision, &$oldCallback ) {
2048 if ( $title->equals( $revision->getTitle() ) ) {
2049 return $revision;
2050 } else {
2051 return call_user_func( $oldCallback, $title, $parser );
2052 }
2053 }
2054 );
2055 } else {
2056 // Try to avoid a second parse if {{REVISIONID}} is used
2057 $dbIndex = ( $this->mDataLoadedFrom & self::READ_LATEST ) === self::READ_LATEST
2058 ? DB_MASTER // use the best possible guess
2059 : DB_REPLICA; // T154554
2060
2061 $edit->popts->setSpeculativeRevIdCallback( function () use ( $dbIndex ) {
2062 return 1 + (int)wfGetDB( $dbIndex )->selectField(
2063 'revision',
2064 'MAX(rev_id)',
2065 [],
2066 __METHOD__
2067 );
2068 } );
2069 }
2070 $edit->output = $edit->pstContent
2071 ? $edit->pstContent->getParserOutput( $this->mTitle, $revid, $edit->popts )
2072 : null;
2073 }
2074
2075 $edit->newContent = $content;
2076 $edit->oldContent = $this->getContent( Revision::RAW );
2077
2078 // NOTE: B/C for hooks! don't use these fields!
2079 $edit->newText = $edit->newContent
2080 ? ContentHandler::getContentText( $edit->newContent )
2081 : '';
2082 $edit->oldText = $edit->oldContent
2083 ? ContentHandler::getContentText( $edit->oldContent )
2084 : '';
2085 $edit->pst = $edit->pstContent ? $edit->pstContent->serialize( $serialFormat ) : '';
2086
2087 if ( $edit->output ) {
2088 $edit->output->setCacheTime( wfTimestampNow() );
2089 }
2090
2091 // Process cache the result
2092 $this->mPreparedEdit = $edit;
2093
2094 return $edit;
2095 }
2096
2118 public function doEditUpdates( Revision $revision, User $user, array $options = [] ) {
2120
2121 $options += [
2122 'changed' => true,
2123 'created' => false,
2124 'moved' => false,
2125 'restored' => false,
2126 'oldrevision' => null,
2127 'oldcountable' => null
2128 ];
2129 $content = $revision->getContent();
2130
2131 $logger = LoggerFactory::getInstance( 'SaveParse' );
2132
2133 // See if the parser output before $revision was inserted is still valid
2134 $editInfo = false;
2135 if ( !$this->mPreparedEdit ) {
2136 $logger->debug( __METHOD__ . ": No prepared edit...\n" );
2137 } elseif ( $this->mPreparedEdit->output->getFlag( 'vary-revision' ) ) {
2138 $logger->info( __METHOD__ . ": Prepared edit has vary-revision...\n" );
2139 } elseif ( $this->mPreparedEdit->output->getFlag( 'vary-revision-id' )
2140 && $this->mPreparedEdit->output->getSpeculativeRevIdUsed() !== $revision->getId()
2141 ) {
2142 $logger->info( __METHOD__ . ": Prepared edit has vary-revision-id with wrong ID...\n" );
2143 } elseif ( $this->mPreparedEdit->output->getFlag( 'vary-user' ) && !$options['changed'] ) {
2144 $logger->info( __METHOD__ . ": Prepared edit has vary-user and is null...\n" );
2145 } else {
2146 wfDebug( __METHOD__ . ": Using prepared edit...\n" );
2147 $editInfo = $this->mPreparedEdit;
2148 }
2149
2150 if ( !$editInfo ) {
2151 // Parse the text again if needed. Be careful not to do pre-save transform twice:
2152 // $text is usually already pre-save transformed once. Avoid using the edit stash
2153 // as any prepared content from there or in doEditContent() was already rejected.
2154 $editInfo = $this->prepareContentForEdit( $content, $revision, $user, null, false );
2155 }
2156
2157 // Save it to the parser cache.
2158 // Make sure the cache time matches page_touched to avoid double parsing.
2159 ParserCache::singleton()->save(
2160 $editInfo->output, $this, $editInfo->popts,
2161 $revision->getTimestamp(), $editInfo->revid
2162 );
2163
2164 // Update the links tables and other secondary data
2165 if ( $content ) {
2166 $recursive = $options['changed']; // T52785
2167 $updates = $content->getSecondaryDataUpdates(
2168 $this->getTitle(), null, $recursive, $editInfo->output
2169 );
2170 foreach ( $updates as $update ) {
2171 if ( $update instanceof LinksUpdate ) {
2172 $update->setRevision( $revision );
2173 $update->setTriggeringUser( $user );
2174 }
2175 DeferredUpdates::addUpdate( $update );
2176 }
2178 && $this->getContentHandler()->supportsCategories() === true
2179 && ( $options['changed'] || $options['created'] )
2180 && !$options['restored']
2181 ) {
2182 // Note: jobs are pushed after deferred updates, so the job should be able to see
2183 // the recent change entry (also done via deferred updates) and carry over any
2184 // bot/deletion/IP flags, ect.
2186 $this->getTitle(),
2187 [
2188 'pageId' => $this->getId(),
2189 'revTimestamp' => $revision->getTimestamp()
2190 ]
2191 ) );
2192 }
2193 }
2194
2195 // Avoid PHP 7.1 warning of passing $this by reference
2196 $wikiPage = $this;
2197
2198 Hooks::run( 'ArticleEditUpdates', [ &$wikiPage, &$editInfo, $options['changed'] ] );
2199
2200 if ( Hooks::run( 'ArticleEditUpdatesDeleteFromRecentchanges', [ &$wikiPage ] ) ) {
2201 // Flush old entries from the `recentchanges` table
2202 if ( mt_rand( 0, 9 ) == 0 ) {
2204 }
2205 }
2206
2207 if ( !$this->exists() ) {
2208 return;
2209 }
2210
2211 $id = $this->getId();
2212 $title = $this->mTitle->getPrefixedDBkey();
2213 $shortTitle = $this->mTitle->getDBkey();
2214
2215 if ( $options['oldcountable'] === 'no-change' ||
2216 ( !$options['changed'] && !$options['moved'] )
2217 ) {
2218 $good = 0;
2219 } elseif ( $options['created'] ) {
2220 $good = (int)$this->isCountable( $editInfo );
2221 } elseif ( $options['oldcountable'] !== null ) {
2222 $good = (int)$this->isCountable( $editInfo ) - (int)$options['oldcountable'];
2223 } else {
2224 $good = 0;
2225 }
2226 $edits = $options['changed'] ? 1 : 0;
2227 $total = $options['created'] ? 1 : 0;
2228
2229 DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, $edits, $good, $total ) );
2230 DeferredUpdates::addUpdate( new SearchUpdate( $id, $title, $content ) );
2231
2232 // If this is another user's talk page, update newtalk.
2233 // Don't do this if $options['changed'] = false (null-edits) nor if
2234 // it's a minor edit and the user doesn't want notifications for those.
2235 if ( $options['changed']
2236 && $this->mTitle->getNamespace() == NS_USER_TALK
2237 && $shortTitle != $user->getTitleKey()
2238 && !( $revision->isMinor() && $user->isAllowed( 'nominornewtalk' ) )
2239 ) {
2240 $recipient = User::newFromName( $shortTitle, false );
2241 if ( !$recipient ) {
2242 wfDebug( __METHOD__ . ": invalid username\n" );
2243 } else {
2244 // Avoid PHP 7.1 warning of passing $this by reference
2245 $wikiPage = $this;
2246
2247 // Allow extensions to prevent user notification
2248 // when a new message is added to their talk page
2249 if ( Hooks::run( 'ArticleEditUpdateNewTalk', [ &$wikiPage, $recipient ] ) ) {
2250 if ( User::isIP( $shortTitle ) ) {
2251 // An anonymous user
2252 $recipient->setNewtalk( true, $revision );
2253 } elseif ( $recipient->isLoggedIn() ) {
2254 $recipient->setNewtalk( true, $revision );
2255 } else {
2256 wfDebug( __METHOD__ . ": don't need to notify a nonexistent user\n" );
2257 }
2258 }
2259 }
2260 }
2261
2262 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
2263 MessageCache::singleton()->updateMessageOverride( $this->mTitle, $content );
2264 }
2265
2266 if ( $options['created'] ) {
2267 self::onArticleCreate( $this->mTitle );
2268 } elseif ( $options['changed'] ) { // T52785
2269 self::onArticleEdit( $this->mTitle, $revision );
2270 }
2271
2273 $this->mTitle, $options['oldrevision'], $revision, wfWikiID()
2274 );
2275 }
2276
2291 public function doUpdateRestrictions( array $limit, array $expiry,
2292 &$cascade, $reason, User $user, $tags = null
2293 ) {
2295
2296 if ( wfReadOnly() ) {
2297 return Status::newFatal( 'readonlytext', wfReadOnlyReason() );
2298 }
2299
2300 $this->loadPageData( 'fromdbmaster' );
2301 $restrictionTypes = $this->mTitle->getRestrictionTypes();
2302 $id = $this->getId();
2303
2304 if ( !$cascade ) {
2305 $cascade = false;
2306 }
2307
2308 // Take this opportunity to purge out expired restrictions
2309 Title::purgeExpiredRestrictions();
2310
2311 // @todo FIXME: Same limitations as described in ProtectionForm.php (line 37);
2312 // we expect a single selection, but the schema allows otherwise.
2313 $isProtected = false;
2314 $protect = false;
2315 $changed = false;
2316
2317 $dbw = wfGetDB( DB_MASTER );
2318
2319 foreach ( $restrictionTypes as $action ) {
2320 if ( !isset( $expiry[$action] ) || $expiry[$action] === $dbw->getInfinity() ) {
2321 $expiry[$action] = 'infinity';
2322 }
2323 if ( !isset( $limit[$action] ) ) {
2324 $limit[$action] = '';
2325 } elseif ( $limit[$action] != '' ) {
2326 $protect = true;
2327 }
2328
2329 // Get current restrictions on $action
2330 $current = implode( '', $this->mTitle->getRestrictions( $action ) );
2331 if ( $current != '' ) {
2332 $isProtected = true;
2333 }
2334
2335 if ( $limit[$action] != $current ) {
2336 $changed = true;
2337 } elseif ( $limit[$action] != '' ) {
2338 // Only check expiry change if the action is actually being
2339 // protected, since expiry does nothing on an not-protected
2340 // action.
2341 if ( $this->mTitle->getRestrictionExpiry( $action ) != $expiry[$action] ) {
2342 $changed = true;
2343 }
2344 }
2345 }
2346
2347 if ( !$changed && $protect && $this->mTitle->areRestrictionsCascading() != $cascade ) {
2348 $changed = true;
2349 }
2350
2351 // If nothing has changed, do nothing
2352 if ( !$changed ) {
2353 return Status::newGood();
2354 }
2355
2356 if ( !$protect ) { // No protection at all means unprotection
2357 $revCommentMsg = 'unprotectedarticle-comment';
2358 $logAction = 'unprotect';
2359 } elseif ( $isProtected ) {
2360 $revCommentMsg = 'modifiedarticleprotection-comment';
2361 $logAction = 'modify';
2362 } else {
2363 $revCommentMsg = 'protectedarticle-comment';
2364 $logAction = 'protect';
2365 }
2366
2367 // Truncate for whole multibyte characters
2368 $reason = $wgContLang->truncate( $reason, 255 );
2369
2370 $logRelationsValues = [];
2371 $logRelationsField = null;
2372 $logParamsDetails = [];
2373
2374 // Null revision (used for change tag insertion)
2375 $nullRevision = null;
2376
2377 if ( $id ) { // Protection of existing page
2378 // Avoid PHP 7.1 warning of passing $this by reference
2379 $wikiPage = $this;
2380
2381 if ( !Hooks::run( 'ArticleProtect', [ &$wikiPage, &$user, $limit, $reason ] ) ) {
2382 return Status::newGood();
2383 }
2384
2385 // Only certain restrictions can cascade...
2386 $editrestriction = isset( $limit['edit'] )
2387 ? [ $limit['edit'] ]
2388 : $this->mTitle->getRestrictions( 'edit' );
2389 foreach ( array_keys( $editrestriction, 'sysop' ) as $key ) {
2390 $editrestriction[$key] = 'editprotected'; // backwards compatibility
2391 }
2392 foreach ( array_keys( $editrestriction, 'autoconfirmed' ) as $key ) {
2393 $editrestriction[$key] = 'editsemiprotected'; // backwards compatibility
2394 }
2395
2396 $cascadingRestrictionLevels = $wgCascadingRestrictionLevels;
2397 foreach ( array_keys( $cascadingRestrictionLevels, 'sysop' ) as $key ) {
2398 $cascadingRestrictionLevels[$key] = 'editprotected'; // backwards compatibility
2399 }
2400 foreach ( array_keys( $cascadingRestrictionLevels, 'autoconfirmed' ) as $key ) {
2401 $cascadingRestrictionLevels[$key] = 'editsemiprotected'; // backwards compatibility
2402 }
2403
2404 // The schema allows multiple restrictions
2405 if ( !array_intersect( $editrestriction, $cascadingRestrictionLevels ) ) {
2406 $cascade = false;
2407 }
2408
2409 // insert null revision to identify the page protection change as edit summary
2410 $latest = $this->getLatest();
2411 $nullRevision = $this->insertProtectNullRevision(
2412 $revCommentMsg,
2413 $limit,
2414 $expiry,
2415 $cascade,
2416 $reason,
2417 $user
2418 );
2419
2420 if ( $nullRevision === null ) {
2421 return Status::newFatal( 'no-null-revision', $this->mTitle->getPrefixedText() );
2422 }
2423
2424 $logRelationsField = 'pr_id';
2425
2426 // Update restrictions table
2427 foreach ( $limit as $action => $restrictions ) {
2428 $dbw->delete(
2429 'page_restrictions',
2430 [
2431 'pr_page' => $id,
2432 'pr_type' => $action
2433 ],
2434 __METHOD__
2435 );
2436 if ( $restrictions != '' ) {
2437 $cascadeValue = ( $cascade && $action == 'edit' ) ? 1 : 0;
2438 $dbw->insert(
2439 'page_restrictions',
2440 [
2441 'pr_id' => $dbw->nextSequenceValue( 'page_restrictions_pr_id_seq' ),
2442 'pr_page' => $id,
2443 'pr_type' => $action,
2444 'pr_level' => $restrictions,
2445 'pr_cascade' => $cascadeValue,
2446 'pr_expiry' => $dbw->encodeExpiry( $expiry[$action] )
2447 ],
2448 __METHOD__
2449 );
2450 $logRelationsValues[] = $dbw->insertId();
2451 $logParamsDetails[] = [
2452 'type' => $action,
2453 'level' => $restrictions,
2454 'expiry' => $expiry[$action],
2455 'cascade' => (bool)$cascadeValue,
2456 ];
2457 }
2458 }
2459
2460 // Clear out legacy restriction fields
2461 $dbw->update(
2462 'page',
2463 [ 'page_restrictions' => '' ],
2464 [ 'page_id' => $id ],
2465 __METHOD__
2466 );
2467
2468 // Avoid PHP 7.1 warning of passing $this by reference
2469 $wikiPage = $this;
2470
2471 Hooks::run( 'NewRevisionFromEditComplete',
2472 [ $this, $nullRevision, $latest, $user ] );
2473 Hooks::run( 'ArticleProtectComplete', [ &$wikiPage, &$user, $limit, $reason ] );
2474 } else { // Protection of non-existing page (also known as "title protection")
2475 // Cascade protection is meaningless in this case
2476 $cascade = false;
2477
2478 if ( $limit['create'] != '' ) {
2479 $dbw->replace( 'protected_titles',
2480 [ [ 'pt_namespace', 'pt_title' ] ],
2481 [
2482 'pt_namespace' => $this->mTitle->getNamespace(),
2483 'pt_title' => $this->mTitle->getDBkey(),
2484 'pt_create_perm' => $limit['create'],
2485 'pt_timestamp' => $dbw->timestamp(),
2486 'pt_expiry' => $dbw->encodeExpiry( $expiry['create'] ),
2487 'pt_user' => $user->getId(),
2488 'pt_reason' => $reason,
2489 ], __METHOD__
2490 );
2491 $logParamsDetails[] = [
2492 'type' => 'create',
2493 'level' => $limit['create'],
2494 'expiry' => $expiry['create'],
2495 ];
2496 } else {
2497 $dbw->delete( 'protected_titles',
2498 [
2499 'pt_namespace' => $this->mTitle->getNamespace(),
2500 'pt_title' => $this->mTitle->getDBkey()
2501 ], __METHOD__
2502 );
2503 }
2504 }
2505
2506 $this->mTitle->flushRestrictions();
2507 InfoAction::invalidateCache( $this->mTitle );
2508
2509 if ( $logAction == 'unprotect' ) {
2510 $params = [];
2511 } else {
2512 $protectDescriptionLog = $this->protectDescriptionLog( $limit, $expiry );
2513 $params = [
2514 '4::description' => $protectDescriptionLog, // parameter for IRC
2515 '5:bool:cascade' => $cascade,
2516 'details' => $logParamsDetails, // parameter for localize and api
2517 ];
2518 }
2519
2520 // Update the protection log
2521 $logEntry = new ManualLogEntry( 'protect', $logAction );
2522 $logEntry->setTarget( $this->mTitle );
2523 $logEntry->setComment( $reason );
2524 $logEntry->setPerformer( $user );
2525 $logEntry->setParameters( $params );
2526 if ( !is_null( $nullRevision ) ) {
2527 $logEntry->setAssociatedRevId( $nullRevision->getId() );
2528 }
2529 $logEntry->setTags( $tags );
2530 if ( $logRelationsField !== null && count( $logRelationsValues ) ) {
2531 $logEntry->setRelations( [ $logRelationsField => $logRelationsValues ] );
2532 }
2533 $logId = $logEntry->insert();
2534 $logEntry->publish( $logId );
2535
2536 return Status::newGood( $logId );
2537 }
2538
2550 public function insertProtectNullRevision( $revCommentMsg, array $limit,
2551 array $expiry, $cascade, $reason, $user = null
2552 ) {
2553 $dbw = wfGetDB( DB_MASTER );
2554
2555 // Prepare a null revision to be added to the history
2556 $editComment = wfMessage(
2557 $revCommentMsg,
2558 $this->mTitle->getPrefixedText(),
2559 $user ? $user->getName() : ''
2560 )->inContentLanguage()->text();
2561 if ( $reason ) {
2562 $editComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason;
2563 }
2564 $protectDescription = $this->protectDescription( $limit, $expiry );
2565 if ( $protectDescription ) {
2566 $editComment .= wfMessage( 'word-separator' )->inContentLanguage()->text();
2567 $editComment .= wfMessage( 'parentheses' )->params( $protectDescription )
2568 ->inContentLanguage()->text();
2569 }
2570 if ( $cascade ) {
2571 $editComment .= wfMessage( 'word-separator' )->inContentLanguage()->text();
2572 $editComment .= wfMessage( 'brackets' )->params(
2573 wfMessage( 'protect-summary-cascade' )->inContentLanguage()->text()
2574 )->inContentLanguage()->text();
2575 }
2576
2577 $nullRev = Revision::newNullRevision( $dbw, $this->getId(), $editComment, true, $user );
2578 if ( $nullRev ) {
2579 $nullRev->insertOn( $dbw );
2580
2581 // Update page record and touch page
2582 $oldLatest = $nullRev->getParentId();
2583 $this->updateRevisionOn( $dbw, $nullRev, $oldLatest );
2584 }
2585
2586 return $nullRev;
2587 }
2588
2593 protected function formatExpiry( $expiry ) {
2595
2596 if ( $expiry != 'infinity' ) {
2597 return wfMessage(
2598 'protect-expiring',
2599 $wgContLang->timeanddate( $expiry, false, false ),
2600 $wgContLang->date( $expiry, false, false ),
2601 $wgContLang->time( $expiry, false, false )
2602 )->inContentLanguage()->text();
2603 } else {
2604 return wfMessage( 'protect-expiry-indefinite' )
2605 ->inContentLanguage()->text();
2606 }
2607 }
2608
2616 public function protectDescription( array $limit, array $expiry ) {
2617 $protectDescription = '';
2618
2619 foreach ( array_filter( $limit ) as $action => $restrictions ) {
2620 # $action is one of $wgRestrictionTypes = [ 'create', 'edit', 'move', 'upload' ].
2621 # All possible message keys are listed here for easier grepping:
2622 # * restriction-create
2623 # * restriction-edit
2624 # * restriction-move
2625 # * restriction-upload
2626 $actionText = wfMessage( 'restriction-' . $action )->inContentLanguage()->text();
2627 # $restrictions is one of $wgRestrictionLevels = [ '', 'autoconfirmed', 'sysop' ],
2628 # with '' filtered out. All possible message keys are listed below:
2629 # * protect-level-autoconfirmed
2630 # * protect-level-sysop
2631 $restrictionsText = wfMessage( 'protect-level-' . $restrictions )
2632 ->inContentLanguage()->text();
2633
2634 $expiryText = $this->formatExpiry( $expiry[$action] );
2635
2636 if ( $protectDescription !== '' ) {
2637 $protectDescription .= wfMessage( 'word-separator' )->inContentLanguage()->text();
2638 }
2639 $protectDescription .= wfMessage( 'protect-summary-desc' )
2640 ->params( $actionText, $restrictionsText, $expiryText )
2641 ->inContentLanguage()->text();
2642 }
2643
2644 return $protectDescription;
2645 }
2646
2658 public function protectDescriptionLog( array $limit, array $expiry ) {
2660
2661 $protectDescriptionLog = '';
2662
2663 foreach ( array_filter( $limit ) as $action => $restrictions ) {
2664 $expiryText = $this->formatExpiry( $expiry[$action] );
2665 $protectDescriptionLog .= $wgContLang->getDirMark() .
2666 "[$action=$restrictions] ($expiryText)";
2667 }
2668
2669 return trim( $protectDescriptionLog );
2670 }
2671
2681 protected static function flattenRestrictions( $limit ) {
2682 if ( !is_array( $limit ) ) {
2683 throw new MWException( __METHOD__ . ' given non-array restriction set' );
2684 }
2685
2686 $bits = [];
2687 ksort( $limit );
2688
2689 foreach ( array_filter( $limit ) as $action => $restrictions ) {
2690 $bits[] = "$action=$restrictions";
2691 }
2692
2693 return implode( ':', $bits );
2694 }
2695
2712 public function doDeleteArticle(
2713 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User $user = null
2714 ) {
2715 $status = $this->doDeleteArticleReal( $reason, $suppress, $u1, $u2, $error, $user );
2716 return $status->isGood();
2717 }
2718
2737 public function doDeleteArticleReal(
2738 $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User $user = null,
2739 $tags = [], $logsubtype = 'delete'
2740 ) {
2742
2743 wfDebug( __METHOD__ . "\n" );
2744
2745 $status = Status::newGood();
2746
2747 if ( $this->mTitle->getDBkey() === '' ) {
2748 $status->error( 'cannotdelete',
2749 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) );
2750 return $status;
2751 }
2752
2753 // Avoid PHP 7.1 warning of passing $this by reference
2754 $wikiPage = $this;
2755
2756 $user = is_null( $user ) ? $wgUser : $user;
2757 if ( !Hooks::run( 'ArticleDelete',
2758 [ &$wikiPage, &$user, &$reason, &$error, &$status, $suppress ]
2759 ) ) {
2760 if ( $status->isOK() ) {
2761 // Hook aborted but didn't set a fatal status
2762 $status->fatal( 'delete-hook-aborted' );
2763 }
2764 return $status;
2765 }
2766
2767 $dbw = wfGetDB( DB_MASTER );
2768 $dbw->startAtomic( __METHOD__ );
2769
2770 $this->loadPageData( self::READ_LATEST );
2771 $id = $this->getId();
2772 // T98706: lock the page from various other updates but avoid using
2773 // WikiPage::READ_LOCKING as that will carry over the FOR UPDATE to
2774 // the revisions queries (which also JOIN on user). Only lock the page
2775 // row and CAS check on page_latest to see if the trx snapshot matches.
2776 $lockedLatest = $this->lockAndGetLatest();
2777 if ( $id == 0 || $this->getLatest() != $lockedLatest ) {
2778 $dbw->endAtomic( __METHOD__ );
2779 // Page not there or trx snapshot is stale
2780 $status->error( 'cannotdelete',
2781 wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) );
2782 return $status;
2783 }
2784
2785 // Given the lock above, we can be confident in the title and page ID values
2786 $namespace = $this->getTitle()->getNamespace();
2787 $dbKey = $this->getTitle()->getDBkey();
2788
2789 // At this point we are now comitted to returning an OK
2790 // status unless some DB query error or other exception comes up.
2791 // This way callers don't have to call rollback() if $status is bad
2792 // unless they actually try to catch exceptions (which is rare).
2793
2794 // we need to remember the old content so we can use it to generate all deletion updates.
2795 $revision = $this->getRevision();
2796 try {
2797 $content = $this->getContent( Revision::RAW );
2798 } catch ( Exception $ex ) {
2799 wfLogWarning( __METHOD__ . ': failed to load content during deletion! '
2800 . $ex->getMessage() );
2801
2802 $content = null;
2803 }
2804
2805 $fields = Revision::selectFields();
2806 $bitfield = false;
2807
2808 // Bitfields to further suppress the content
2809 if ( $suppress ) {
2810 $bitfield = Revision::SUPPRESSED_ALL;
2811 $fields = array_diff( $fields, [ 'rev_deleted' ] );
2812 }
2813
2814 // For now, shunt the revision data into the archive table.
2815 // Text is *not* removed from the text table; bulk storage
2816 // is left intact to avoid breaking block-compression or
2817 // immutable storage schemes.
2818 // In the future, we may keep revisions and mark them with
2819 // the rev_deleted field, which is reserved for this purpose.
2820
2821 // Get all of the page revisions
2822 $res = $dbw->select(
2823 'revision',
2824 $fields,
2825 [ 'rev_page' => $id ],
2826 __METHOD__,
2827 'FOR UPDATE'
2828 );
2829 // Build their equivalent archive rows
2830 $rowsInsert = [];
2831 foreach ( $res as $row ) {
2832 $rowInsert = [
2833 'ar_namespace' => $namespace,
2834 'ar_title' => $dbKey,
2835 'ar_comment' => $row->rev_comment,
2836 'ar_user' => $row->rev_user,
2837 'ar_user_text' => $row->rev_user_text,
2838 'ar_timestamp' => $row->rev_timestamp,
2839 'ar_minor_edit' => $row->rev_minor_edit,
2840 'ar_rev_id' => $row->rev_id,
2841 'ar_parent_id' => $row->rev_parent_id,
2842 'ar_text_id' => $row->rev_text_id,
2843 'ar_text' => '',
2844 'ar_flags' => '',
2845 'ar_len' => $row->rev_len,
2846 'ar_page_id' => $id,
2847 'ar_deleted' => $suppress ? $bitfield : $row->rev_deleted,
2848 'ar_sha1' => $row->rev_sha1,
2849 ];
2850 if ( $wgContentHandlerUseDB ) {
2851 $rowInsert['ar_content_model'] = $row->rev_content_model;
2852 $rowInsert['ar_content_format'] = $row->rev_content_format;
2853 }
2854 $rowsInsert[] = $rowInsert;
2855 }
2856 // Copy them into the archive table
2857 $dbw->insert( 'archive', $rowsInsert, __METHOD__ );
2858 // Save this so we can pass it to the ArticleDeleteComplete hook.
2859 $archivedRevisionCount = $dbw->affectedRows();
2860
2861 // Clone the title and wikiPage, so we have the information we need when
2862 // we log and run the ArticleDeleteComplete hook.
2863 $logTitle = clone $this->mTitle;
2864 $wikiPageBeforeDelete = clone $this;
2865
2866 // Now that it's safely backed up, delete it
2867 $dbw->delete( 'page', [ 'page_id' => $id ], __METHOD__ );
2868 $dbw->delete( 'revision', [ 'rev_page' => $id ], __METHOD__ );
2869
2870 // Log the deletion, if the page was suppressed, put it in the suppression log instead
2871 $logtype = $suppress ? 'suppress' : 'delete';
2872
2873 $logEntry = new ManualLogEntry( $logtype, $logsubtype );
2874 $logEntry->setPerformer( $user );
2875 $logEntry->setTarget( $logTitle );
2876 $logEntry->setComment( $reason );
2877 $logEntry->setTags( $tags );
2878 $logid = $logEntry->insert();
2879
2880 $dbw->onTransactionPreCommitOrIdle(
2881 function () use ( $dbw, $logEntry, $logid ) {
2882 // T58776: avoid deadlocks (especially from FileDeleteForm)
2883 $logEntry->publish( $logid );
2884 },
2885 __METHOD__
2886 );
2887
2888 $dbw->endAtomic( __METHOD__ );
2889
2890 $this->doDeleteUpdates( $id, $content, $revision );
2891
2892 Hooks::run( 'ArticleDeleteComplete', [
2893 &$wikiPageBeforeDelete,
2894 &$user,
2895 $reason,
2896 $id,
2897 $content,
2898 $logEntry,
2899 $archivedRevisionCount
2900 ] );
2901 $status->value = $logid;
2902
2903 // Show log excerpt on 404 pages rather than just a link
2904 $cache = ObjectCache::getMainStashInstance();
2905 $key = wfMemcKey( 'page-recent-delete', md5( $logTitle->getPrefixedText() ) );
2906 $cache->set( $key, 1, $cache::TTL_DAY );
2907
2908 return $status;
2909 }
2910
2917 public function lockAndGetLatest() {
2918 return (int)wfGetDB( DB_MASTER )->selectField(
2919 'page',
2920 'page_latest',
2921 [
2922 'page_id' => $this->getId(),
2923 // Typically page_id is enough, but some code might try to do
2924 // updates assuming the title is the same, so verify that
2925 'page_namespace' => $this->getTitle()->getNamespace(),
2926 'page_title' => $this->getTitle()->getDBkey()
2927 ],
2928 __METHOD__,
2929 [ 'FOR UPDATE' ]
2930 );
2931 }
2932
2942 public function doDeleteUpdates( $id, Content $content = null, Revision $revision = null ) {
2943 try {
2944 $countable = $this->isCountable();
2945 } catch ( Exception $ex ) {
2946 // fallback for deleting broken pages for which we cannot load the content for
2947 // some reason. Note that doDeleteArticleReal() already logged this problem.
2948 $countable = false;
2949 }
2950
2951 // Update site status
2952 DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 1, - (int)$countable, -1 ) );
2953
2954 // Delete pagelinks, update secondary indexes, etc
2955 $updates = $this->getDeletionUpdates( $content );
2956 foreach ( $updates as $update ) {
2957 DeferredUpdates::addUpdate( $update );
2958 }
2959
2960 // Reparse any pages transcluding this page
2961 LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks' );
2962
2963 // Reparse any pages including this image
2964 if ( $this->mTitle->getNamespace() == NS_FILE ) {
2965 LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'imagelinks' );
2966 }
2967
2968 // Clear caches
2969 WikiPage::onArticleDelete( $this->mTitle );
2971 $this->mTitle, $revision, null, wfWikiID()
2972 );
2973
2974 // Reset this object and the Title object
2975 $this->loadFromRow( false, self::READ_LATEST );
2976
2977 // Search engine
2978 DeferredUpdates::addUpdate( new SearchUpdate( $id, $this->mTitle ) );
2979 }
2980
3010 public function doRollback(
3011 $fromP, $summary, $token, $bot, &$resultDetails, User $user, $tags = null
3012 ) {
3013 $resultDetails = null;
3014
3015 // Check permissions
3016 $editErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $user );
3017 $rollbackErrors = $this->mTitle->getUserPermissionsErrors( 'rollback', $user );
3018 $errors = array_merge( $editErrors, wfArrayDiff2( $rollbackErrors, $editErrors ) );
3019
3020 if ( !$user->matchEditToken( $token, 'rollback' ) ) {
3021 $errors[] = [ 'sessionfailure' ];
3022 }
3023
3024 if ( $user->pingLimiter( 'rollback' ) || $user->pingLimiter() ) {
3025 $errors[] = [ 'actionthrottledtext' ];
3026 }
3027
3028 // If there were errors, bail out now
3029 if ( !empty( $errors ) ) {
3030 return $errors;
3031 }
3032
3033 return $this->commitRollback( $fromP, $summary, $bot, $resultDetails, $user, $tags );
3034 }
3035
3056 public function commitRollback( $fromP, $summary, $bot,
3057 &$resultDetails, User $guser, $tags = null
3058 ) {
3060
3061 $dbw = wfGetDB( DB_MASTER );
3062
3063 if ( wfReadOnly() ) {
3064 return [ [ 'readonlytext' ] ];
3065 }
3066
3067 // Get the last editor
3068 $current = $this->getRevision();
3069 if ( is_null( $current ) ) {
3070 // Something wrong... no page?
3071 return [ [ 'notanarticle' ] ];
3072 }
3073
3074 $from = str_replace( '_', ' ', $fromP );
3075 // User name given should match up with the top revision.
3076 // If the user was deleted then $from should be empty.
3077 if ( $from != $current->getUserText() ) {
3078 $resultDetails = [ 'current' => $current ];
3079 return [ [ 'alreadyrolled',
3080 htmlspecialchars( $this->mTitle->getPrefixedText() ),
3081 htmlspecialchars( $fromP ),
3082 htmlspecialchars( $current->getUserText() )
3083 ] ];
3084 }
3085
3086 // Get the last edit not by this person...
3087 // Note: these may not be public values
3088 $user = intval( $current->getUser( Revision::RAW ) );
3089 $user_text = $dbw->addQuotes( $current->getUserText( Revision::RAW ) );
3090 $s = $dbw->selectRow( 'revision',
3091 [ 'rev_id', 'rev_timestamp', 'rev_deleted' ],
3092 [ 'rev_page' => $current->getPage(),
3093 "rev_user != {$user} OR rev_user_text != {$user_text}"
3094 ], __METHOD__,
3095 [ 'USE INDEX' => 'page_timestamp',
3096 'ORDER BY' => 'rev_timestamp DESC' ]
3097 );
3098 if ( $s === false ) {
3099 // No one else ever edited this page
3100 return [ [ 'cantrollback' ] ];
3101 } elseif ( $s->rev_deleted & Revision::DELETED_TEXT
3102 || $s->rev_deleted & Revision::DELETED_USER
3103 ) {
3104 // Only admins can see this text
3105 return [ [ 'notvisiblerev' ] ];
3106 }
3107
3108 // Generate the edit summary if necessary
3109 $target = Revision::newFromId( $s->rev_id, Revision::READ_LATEST );
3110 if ( empty( $summary ) ) {
3111 if ( $from == '' ) { // no public user name
3112 $summary = wfMessage( 'revertpage-nouser' );
3113 } else {
3114 $summary = wfMessage( 'revertpage' );
3115 }
3116 }
3117
3118 // Allow the custom summary to use the same args as the default message
3119 $args = [
3120 $target->getUserText(), $from, $s->rev_id,
3121 $wgContLang->timeanddate( wfTimestamp( TS_MW, $s->rev_timestamp ) ),
3122 $current->getId(), $wgContLang->timeanddate( $current->getTimestamp() )
3123 ];
3124 if ( $summary instanceof Message ) {
3125 $summary = $summary->params( $args )->inContentLanguage()->text();
3126 } else {
3127 $summary = wfMsgReplaceArgs( $summary, $args );
3128 }
3129
3130 // Trim spaces on user supplied text
3131 $summary = trim( $summary );
3132
3133 // Truncate for whole multibyte characters.
3134 $summary = $wgContLang->truncate( $summary, 255 );
3135
3136 // Save
3138
3139 if ( $guser->isAllowed( 'minoredit' ) ) {
3140 $flags |= EDIT_MINOR;
3141 }
3142
3143 if ( $bot && ( $guser->isAllowedAny( 'markbotedits', 'bot' ) ) ) {
3145 }
3146
3147 $targetContent = $target->getContent();
3148 $changingContentModel = $targetContent->getModel() !== $current->getContentModel();
3149
3150 // Actually store the edit
3151 $status = $this->doEditContent(
3152 $targetContent,
3153 $summary,
3154 $flags,
3155 $target->getId(),
3156 $guser,
3157 null,
3158 $tags
3159 );
3160
3161 // Set patrolling and bot flag on the edits, which gets rollbacked.
3162 // This is done even on edit failure to have patrolling in that case (T64157).
3163 $set = [];
3164 if ( $bot && $guser->isAllowed( 'markbotedits' ) ) {
3165 // Mark all reverted edits as bot
3166 $set['rc_bot'] = 1;
3167 }
3168
3169 if ( $wgUseRCPatrol ) {
3170 // Mark all reverted edits as patrolled
3171 $set['rc_patrolled'] = 1;
3172 }
3173
3174 if ( count( $set ) ) {
3175 $dbw->update( 'recentchanges', $set,
3176 [ /* WHERE */
3177 'rc_cur_id' => $current->getPage(),
3178 'rc_user_text' => $current->getUserText(),
3179 'rc_timestamp > ' . $dbw->addQuotes( $s->rev_timestamp ),
3180 ],
3181 __METHOD__
3182 );
3183 }
3184
3185 if ( !$status->isOK() ) {
3186 return $status->getErrorsArray();
3187 }
3188
3189 // raise error, when the edit is an edit without a new version
3190 $statusRev = isset( $status->value['revision'] )
3191 ? $status->value['revision']
3192 : null;
3193 if ( !( $statusRev instanceof Revision ) ) {
3194 $resultDetails = [ 'current' => $current ];
3195 return [ [ 'alreadyrolled',
3196 htmlspecialchars( $this->mTitle->getPrefixedText() ),
3197 htmlspecialchars( $fromP ),
3198 htmlspecialchars( $current->getUserText() )
3199 ] ];
3200 }
3201
3202 if ( $changingContentModel ) {
3203 // If the content model changed during the rollback,
3204 // make sure it gets logged to Special:Log/contentmodel
3205 $log = new ManualLogEntry( 'contentmodel', 'change' );
3206 $log->setPerformer( $guser );
3207 $log->setTarget( $this->mTitle );
3208 $log->setComment( $summary );
3209 $log->setParameters( [
3210 '4::oldmodel' => $current->getContentModel(),
3211 '5::newmodel' => $targetContent->getModel(),
3212 ] );
3213
3214 $logId = $log->insert( $dbw );
3215 $log->publish( $logId );
3216 }
3217
3218 $revId = $statusRev->getId();
3219
3220 Hooks::run( 'ArticleRollbackComplete', [ $this, $guser, $target, $current ] );
3221
3222 $resultDetails = [
3223 'summary' => $summary,
3224 'current' => $current,
3225 'target' => $target,
3226 'newid' => $revId
3227 ];
3228
3229 return [];
3230 }
3231
3243 public static function onArticleCreate( Title $title ) {
3244 // Update existence markers on article/talk tabs...
3245 $other = $title->getOtherPage();
3246
3247 $other->purgeSquid();
3248
3249 $title->touchLinks();
3250 $title->purgeSquid();
3251 $title->deleteTitleProtection();
3252
3253 MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $title );
3254
3255 // Invalidate caches of articles which include this page
3256 DeferredUpdates::addUpdate( new HTMLCacheUpdate( $title, 'templatelinks' ) );
3257
3258 if ( $title->getNamespace() == NS_CATEGORY ) {
3259 // Load the Category object, which will schedule a job to create
3260 // the category table row if necessary. Checking a replica DB is ok
3261 // here, in the worst case it'll run an unnecessary recount job on
3262 // a category that probably doesn't have many members.
3263 Category::newFromTitle( $title )->getID();
3264 }
3265 }
3266
3272 public static function onArticleDelete( Title $title ) {
3273 // Update existence markers on article/talk tabs...
3274 $other = $title->getOtherPage();
3275
3276 $other->purgeSquid();
3277
3278 $title->touchLinks();
3279 $title->purgeSquid();
3280
3281 MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $title );
3282
3283 // File cache
3286
3287 // Messages
3288 if ( $title->getNamespace() == NS_MEDIAWIKI ) {
3289 MessageCache::singleton()->updateMessageOverride( $title, null );
3290 }
3291
3292 // Images
3293 if ( $title->getNamespace() == NS_FILE ) {
3294 DeferredUpdates::addUpdate( new HTMLCacheUpdate( $title, 'imagelinks' ) );
3295 }
3296
3297 // User talk pages
3298 if ( $title->getNamespace() == NS_USER_TALK ) {
3299 $user = User::newFromName( $title->getText(), false );
3300 if ( $user ) {
3301 $user->setNewtalk( false );
3302 }
3303 }
3304
3305 // Image redirects
3306 RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $title );
3307 }
3308
3315 public static function onArticleEdit( Title $title, Revision $revision = null ) {
3316 // Invalidate caches of articles which include this page
3317 DeferredUpdates::addUpdate( new HTMLCacheUpdate( $title, 'templatelinks' ) );
3318
3319 // Invalidate the caches of all pages which redirect here
3320 DeferredUpdates::addUpdate( new HTMLCacheUpdate( $title, 'redirect' ) );
3321
3322 MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $title );
3323
3324 // Purge CDN for this page only
3325 $title->purgeSquid();
3326 // Clear file cache for this page only
3328
3329 $revid = $revision ? $revision->getId() : null;
3330 DeferredUpdates::addCallableUpdate( function() use ( $title, $revid ) {
3332 } );
3333 }
3334
3343 public function getCategories() {
3344 $id = $this->getId();
3345 if ( $id == 0 ) {
3346 return TitleArray::newFromResult( new FakeResultWrapper( [] ) );
3347 }
3348
3349 $dbr = wfGetDB( DB_REPLICA );
3350 $res = $dbr->select( 'categorylinks',
3351 [ 'cl_to AS page_title, ' . NS_CATEGORY . ' AS page_namespace' ],
3352 // Have to do that since Database::fieldNamesWithAlias treats numeric indexes
3353 // as not being aliases, and NS_CATEGORY is numeric
3354 [ 'cl_from' => $id ],
3355 __METHOD__ );
3356
3358 }
3359
3366 public function getHiddenCategories() {
3367 $result = [];
3368 $id = $this->getId();
3369
3370 if ( $id == 0 ) {
3371 return [];
3372 }
3373
3374 $dbr = wfGetDB( DB_REPLICA );
3375 $res = $dbr->select( [ 'categorylinks', 'page_props', 'page' ],
3376 [ 'cl_to' ],
3377 [ 'cl_from' => $id, 'pp_page=page_id', 'pp_propname' => 'hiddencat',
3378 'page_namespace' => NS_CATEGORY, 'page_title=cl_to' ],
3379 __METHOD__ );
3380
3381 if ( $res !== false ) {
3382 foreach ( $res as $row ) {
3383 $result[] = Title::makeTitle( NS_CATEGORY, $row->cl_to );
3384 }
3385 }
3386
3387 return $result;
3388 }
3389
3397 public function getAutoDeleteReason( &$hasHistory ) {
3398 return $this->getContentHandler()->getAutoDeleteReason( $this->getTitle(), $hasHistory );
3399 }
3400
3411 public function updateCategoryCounts( array $added, array $deleted, $id = 0 ) {
3412 $id = $id ?: $this->getId();
3413 $ns = $this->getTitle()->getNamespace();
3414
3415 $addFields = [ 'cat_pages = cat_pages + 1' ];
3416 $removeFields = [ 'cat_pages = cat_pages - 1' ];
3417 if ( $ns == NS_CATEGORY ) {
3418 $addFields[] = 'cat_subcats = cat_subcats + 1';
3419 $removeFields[] = 'cat_subcats = cat_subcats - 1';
3420 } elseif ( $ns == NS_FILE ) {
3421 $addFields[] = 'cat_files = cat_files + 1';
3422 $removeFields[] = 'cat_files = cat_files - 1';
3423 }
3424
3425 $dbw = wfGetDB( DB_MASTER );
3426
3427 if ( count( $added ) ) {
3428 $existingAdded = $dbw->selectFieldValues(
3429 'category',
3430 'cat_title',
3431 [ 'cat_title' => $added ],
3432 __METHOD__
3433 );
3434
3435 // For category rows that already exist, do a plain
3436 // UPDATE instead of INSERT...ON DUPLICATE KEY UPDATE
3437 // to avoid creating gaps in the cat_id sequence.
3438 if ( count( $existingAdded ) ) {
3439 $dbw->update(
3440 'category',
3441 $addFields,
3442 [ 'cat_title' => $existingAdded ],
3443 __METHOD__
3444 );
3445 }
3446
3447 $missingAdded = array_diff( $added, $existingAdded );
3448 if ( count( $missingAdded ) ) {
3449 $insertRows = [];
3450 foreach ( $missingAdded as $cat ) {
3451 $insertRows[] = [
3452 'cat_title' => $cat,
3453 'cat_pages' => 1,
3454 'cat_subcats' => ( $ns == NS_CATEGORY ) ? 1 : 0,
3455 'cat_files' => ( $ns == NS_FILE ) ? 1 : 0,
3456 ];
3457 }
3458 $dbw->upsert(
3459 'category',
3460 $insertRows,
3461 [ 'cat_title' ],
3462 $addFields,
3463 __METHOD__
3464 );
3465 }
3466 }
3467
3468 if ( count( $deleted ) ) {
3469 $dbw->update(
3470 'category',
3471 $removeFields,
3472 [ 'cat_title' => $deleted ],
3473 __METHOD__
3474 );
3475 }
3476
3477 foreach ( $added as $catName ) {
3478 $cat = Category::newFromName( $catName );
3479 Hooks::run( 'CategoryAfterPageAdded', [ $cat, $this ] );
3480 }
3481
3482 foreach ( $deleted as $catName ) {
3483 $cat = Category::newFromName( $catName );
3484 Hooks::run( 'CategoryAfterPageRemoved', [ $cat, $this, $id ] );
3485 }
3486
3487 // Refresh counts on categories that should be empty now, to
3488 // trigger possible deletion. Check master for the most
3489 // up-to-date cat_pages.
3490 if ( count( $deleted ) ) {
3491 $rows = $dbw->select(
3492 'category',
3493 [ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ],
3494 [ 'cat_title' => $deleted, 'cat_pages <= 0' ],
3495 __METHOD__
3496 );
3497 foreach ( $rows as $row ) {
3498 $cat = Category::newFromRow( $row );
3499 // T166757: do the update after this DB commit
3500 DeferredUpdates::addCallableUpdate( function () use ( $cat ) {
3501 $cat->refreshCounts();
3502 } );
3503 }
3504 }
3505 }
3506
3514 if ( wfReadOnly() ) {
3515 return;
3516 }
3517
3518 if ( !Hooks::run( 'OpportunisticLinksUpdate',
3519 [ $this, $this->mTitle, $parserOutput ]
3520 ) ) {
3521 return;
3522 }
3523
3524 $config = RequestContext::getMain()->getConfig();
3525
3526 $params = [
3527 'isOpportunistic' => true,
3528 'rootJobTimestamp' => $parserOutput->getCacheTime()
3529 ];
3530
3531 if ( $this->mTitle->areRestrictionsCascading() ) {
3532 // If the page is cascade protecting, the links should really be up-to-date
3533 JobQueueGroup::singleton()->lazyPush(
3535 );
3536 } elseif ( !$config->get( 'MiserMode' ) && $parserOutput->hasDynamicContent() ) {
3537 // Assume the output contains "dynamic" time/random based magic words.
3538 // Only update pages that expired due to dynamic content and NOT due to edits
3539 // to referenced templates/files. When the cache expires due to dynamic content,
3540 // page_touched is unchanged. We want to avoid triggering redundant jobs due to
3541 // views of pages that were just purged via HTMLCacheUpdateJob. In that case, the
3542 // template/file edit already triggered recursive RefreshLinksJob jobs.
3543 if ( $this->getLinksTimestamp() > $this->getTouched() ) {
3544 // If a page is uncacheable, do not keep spamming a job for it.
3545 // Although it would be de-duplicated, it would still waste I/O.
3546 $cache = ObjectCache::getLocalClusterInstance();
3547 $key = $cache->makeKey( 'dynamic-linksupdate', 'last', $this->getId() );
3548 $ttl = max( $parserOutput->getCacheExpiry(), 3600 );
3549 if ( $cache->add( $key, time(), $ttl ) ) {
3550 JobQueueGroup::singleton()->lazyPush(
3551 RefreshLinksJob::newDynamic( $this->mTitle, $params )
3552 );
3553 }
3554 }
3555 }
3556 }
3557
3567 public function getDeletionUpdates( Content $content = null ) {
3568 if ( !$content ) {
3569 // load content object, which may be used to determine the necessary updates.
3570 // XXX: the content may not be needed to determine the updates.
3571 try {
3572 $content = $this->getContent( Revision::RAW );
3573 } catch ( Exception $ex ) {
3574 // If we can't load the content, something is wrong. Perhaps that's why
3575 // the user is trying to delete the page, so let's not fail in that case.
3576 // Note that doDeleteArticleReal() will already have logged an issue with
3577 // loading the content.
3578 }
3579 }
3580
3581 if ( !$content ) {
3582 $updates = [];
3583 } else {
3584 $updates = $content->getDeletionUpdates( $this );
3585 }
3586
3587 Hooks::run( 'WikiPageDeletionUpdates', [ $this, $content, &$updates ] );
3588 return $updates;
3589 }
3590
3598 public function isLocal() {
3599 return true;
3600 }
3601
3611 public function getWikiDisplayName() {
3613 return $wgSitename;
3614 }
3615
3624 public function getSourceURL() {
3625 return $this->getTitle()->getCanonicalURL();
3626 }
3627
3628 /*
3629 * @param WANObjectCache $cache
3630 * @return string[]
3631 * @since 1.28
3632 */
3634 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3635
3636 return $linkCache->getMutableCacheKeys( $cache, $this->getTitle()->getTitleValue() );
3637 }
3638}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
$wgCascadingRestrictionLevels
Restriction levels that can be used with cascading protection.
$wgUseAutomaticEditSummaries
If user doesn't specify any edit summary when making a an edit, MediaWiki will try to automatically c...
$wgSitename
Name of the site.
$wgUseRCPatrol
Use RC Patrolling to check for vandalism (from recent changes and watchlists) New pages and new files...
$wgUseNPPatrol
Use new page patrolling to check new pages on Special:Newpages.
$wgArticleCountMethod
Method used to determine if a page in a content namespace should be counted as a valid article.
$wgAjaxEditStash
Have clients send edits to be prepared when filling in edit summaries.
$wgRCWatchCategoryMembership
Treat category membership changes as a RecentChange.
$wgContentHandlerUseDB
Set to false to disable use of the database fields introduced by the ContentHandler facility.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfRandom()
Get a random decimal value between 0 and 1, in a way not likely to give duplicate values for any real...
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfIncrStats( $key, $count=1)
Increment a statistics counter.
wfGetLB( $wiki=false)
Get a load balancer object.
wfReadOnly()
Check whether the wiki is in read-only mode.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfMemcKey()
Make a cache key for the local wiki.
wfArrayDiff2( $a, $b)
Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
wfReadOnlyReason()
Check if the site is in read-only mode and return the message if so.
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
wfMsgReplaceArgs( $message, $args)
Replace message parameter keys on the given formatted output.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
$wgUser
Definition Setup.php:781
if( $line===false) $args
Definition cdb.php:63
static checkCache(Title $title, Content $content, User $user)
Check that a prepared edit is in cache and still up-to-date.
Deferrable Update for closure/callback updates via IDatabase::doAtomicSection()
Job to add recent change entries mentioning category membership changes.
Handles purging appropriate CDN URLs given a title (or titles)
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
static getLocalizedName( $name, Language $lang=null)
Returns the localized name for a given content model.
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
static getDBOptions( $bitfield)
Get an appropriate DB index, options, and fallback DB index for a query.
Class to invalidate the HTML cache of all the pages linking to a given title.
static clearFileCache(Title $title)
Clear the file caches for a page for all actions.
static invalidateCache(Title $title, $revid=null)
Clear the info cache for a given Title.
static singleton( $wiki=false)
Class the manages updates of *_link tables as well as similar extension-managed tables.
static queueRecursiveJobsForTable(Title $title, $table)
Queue a RefreshLinks job for any table.
MediaWiki exception.
Class for creating log entries manually, to inject them into the database.
Definition LogEntry.php:396
static singleton()
Get the signleton instance of this class.
The Message class provides methods which fulfil two basic services:
Definition Message.php:159
static singleton()
Get an instance of this object.
Set options of the Parser.
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
static notifyNew( $timestamp, &$title, $minor, &$user, $comment, $bot, $ip='', $size=0, $newId=0, $patrol=0, $tags=[])
Makes an entry in the database corresponding to page creation Note: the title object must be loaded w...
static notifyEdit( $timestamp, &$title, $minor, &$user, $comment, $oldId, $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0, $tags=[])
Makes an entry in the database corresponding to an edit.
static newPrioritized(Title $title, array $params)
static newDynamic(Title $title, array $params)
static singleton()
Get a RepoGroup instance.
Definition RepoGroup.php:59
static getMain()
Static methods.
static invalidateModuleCache(Title $title, Revision $old=null, Revision $new=null, $wikiId)
Clear the preloadTitleInfo() cache for all wiki modules on this wiki on page change if it was a JS or...
static newKnownCurrent(IDatabase $db, $pageId, $revId)
Load a revision based on a known page ID and current revision ID from the DB.
getId()
Get revision ID.
Definition Revision.php:735
getContentHandler()
Returns the content handler appropriate for this revision's content model.
static newFromPageId( $pageId, $revId=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given page ID.
Definition Revision.php:165
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition Revision.php:448
static loadFromTimestamp( $db, $title, $timestamp)
Load the revision for the given title with the given timestamp.
Definition Revision.php:307
static newNullRevision( $dbw, $pageId, $summary, $minor, $user=null)
Create a new null-revision for insertion into a page's history.
getContent( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
const DELETED_USER
Definition Revision.php:92
const DELETED_TEXT
Definition Revision.php:90
const FOR_PUBLIC
Definition Revision.php:98
const SUPPRESSED_ALL
Definition Revision.php:95
const RAW
Definition Revision.php:100
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition Revision.php:116
Database independant search index updater.
Class for handling updates to the site_stats table.
static newFromResult( $res)
Represents a title within MediaWiki.
Definition Title.php:39
getNamespace()
Get the namespace index, i.e.
Definition Title.php:924
getFragment()
Get the Title fragment (i.e.
Definition Title.php:1356
getDBkey()
Get the main part with underscores.
Definition Title.php:901
getInterwiki()
Get the interwiki prefix.
Definition Title.php:811
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:50
isAllowed( $action='')
Internal mechanics of testing a permission.
Definition User.php:3541
isAllowedAny()
Check if user is allowed to access a feature / make an action.
Definition User.php:3511
Multi-datacenter aware caching interface.
Special handling for category pages.
Special handling for file pages.
Class representing a MediaWiki article and history.
Definition WikiPage.php:36
static newFromID( $id, $from='fromdb')
Constructor from a page id.
Definition WikiPage.php:158
doUpdateRestrictions(array $limit, array $expiry, &$cascade, $reason, User $user, $tags=null)
Update the article's restriction field, and leave a log entry.
getContributors()
Get a list of users who have edited this article, not including the user who made the most recent rev...
Definition WikiPage.php:979
doPurge()
Perform the actions of a page purging.
followRedirect()
Get the Title object or URL this page redirects to.
Definition WikiPage.php:930
insertOn( $dbw, $pageId=null)
Insert a new empty page record for this article.
updateCategoryCounts(array $added, array $deleted, $id=0)
Update all the appropriate counts in the category table, given that we've added the categories $added...
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition WikiPage.php:120
doEditContent(Content $content, $summary, $flags=0, $baseRevId=false, User $user=null, $serialFormat=null, $tags=[], $undidRevId=0)
Change an existing article or create a new article.
pageDataFromTitle( $dbr, $title, $options=[])
Fetch a page record matching the Title object's namespace and title using a sanitized title string.
Definition WikiPage.php:345
getTimestamp()
Definition WikiPage.php:674
checkFlags( $flags)
Check flags and add EDIT_NEW or EDIT_UPDATE to them as needed.
static onArticleEdit(Title $title, Revision $revision=null)
Purge caches on page update etc.
isLocal()
Whether this content displayed on this page comes from the local database.
getRevision()
Get the latest revision.
Definition WikiPage.php:642
getLinksTimestamp()
Get the page_links_updated field.
Definition WikiPage.php:558
getMinorEdit()
Returns true if last revision was marked as "minor edit".
Definition WikiPage.php:771
getUndoContent(Revision $undo, Revision $undoafter=null)
Get the content that needs to be saved in order to undo all revisions between $undo and $undoafter.
clearCacheFields()
Clear the object cache fields.
Definition WikiPage.php:256
Revision $mLastRevision
Definition WikiPage.php:73
clearPreparedEdit()
Clear the mPreparedEdit cache field, as may be needed by mutable content types.
Definition WikiPage.php:276
getLatest()
Get the page_latest field.
Definition WikiPage.php:569
formatExpiry( $expiry)
doViewUpdates(User $user, $oldid=0)
Do standard deferred updates after page view (existing or missing page)
updateIfNewerOn( $dbw, $revision)
If the given revision is newer than the currently set page_latest, update the page record.
int $mId
Definition WikiPage.php:58
__clone()
Makes sure that the mTitle object is cloned to the newly cloned WikiPage.
Definition WikiPage.php:108
loadFromRow( $data, $from)
Load the object from a database row.
Definition WikiPage.php:415
supportsSections()
Returns true if this page's content model supports sections.
getRedirectTarget()
If this page is a redirect, get its target.
Definition WikiPage.php:832
setTimestamp( $ts)
Set the page timestamp (use only to avoid DB queries)
Definition WikiPage.php:688
protectDescriptionLog(array $limit, array $expiry)
Builds the description to serve as comment for the log entry.
getUser( $audience=Revision::FOR_PUBLIC, User $user=null)
Definition WikiPage.php:701
makeParserOptions( $context)
Get parser options suitable for rendering the primary article wikitext.
pageData( $dbr, $conditions, $options=[])
Fetch a page record with the given conditions.
Definition WikiPage.php:321
getSourceURL()
Get the source URL for the content on this page, typically the canonical URL, but may be a remote lin...
getOldestRevision()
Get the Revision object of the oldest revision.
Definition WikiPage.php:580
replaceSectionAtRev( $sectionId, Content $sectionContent, $sectionTitle='', $baseRevId=null)
string $mTouched
Definition WikiPage.php:83
setLastEdit(Revision $revision)
Set the latest revision.
Definition WikiPage.php:633
stdClass $mPreparedEdit
Map of cache fields (text, parser output, ect) for a proposed/new edit.
Definition WikiPage.php:53
updateRevisionOn( $dbw, $revision, $lastRevision=null, $lastRevIsRedirect=null)
Update the page record to point to a newly saved revision.
shouldCheckParserCache(ParserOptions $parserOptions, $oldId)
Should the parser cache be used?
loadLastEdit()
Loads everything except the text This isn't necessary for all uses, so it's only done if needed.
Definition WikiPage.php:593
Title $mTitle
Definition WikiPage.php:42
getUserText( $audience=Revision::FOR_PUBLIC, User $user=null)
Definition WikiPage.php:739
doModify(Content $content, $flags, User $user, $summary, array $meta)
getContentModel()
Returns the page's content model id (see the CONTENT_MODEL_XXX constants).
Definition WikiPage.php:507
pageDataFromId( $dbr, $id, $options=[])
Fetch a page record matching the requested ID.
Definition WikiPage.php:359
const PURGE_CDN_CACHE
Definition WikiPage.php:91
const PURGE_CLUSTER_PCACHE
Definition WikiPage.php:92
doEditUpdates(Revision $revision, User $user, array $options=[])
Do standard deferred updates after page edit.
insertRedirectEntry(Title $rt, $oldLatest=null)
Insert or update the redirect table entry for this page to indicate it redirects to $rt.
Definition WikiPage.php:897
doDeleteArticle( $reason, $suppress=false, $u1=null, $u2=null, &$error='', User $user=null)
Same as doDeleteArticleReal(), but returns a simple boolean.
getCategories()
#-
string $mTimestamp
Timestamp of the current revision or empty string if not loaded.
Definition WikiPage.php:78
getHiddenCategories()
Returns a list of hidden categories this page is a member of.
getComment( $audience=Revision::FOR_PUBLIC, User $user=null)
Definition WikiPage.php:757
static newFromRow( $row, $from='fromdb')
Constructor from a database row.
Definition WikiPage.php:185
getAutoDeleteReason(&$hasHistory)
Auto-generates a deletion reason.
lockAndGetLatest()
Lock the page row for this title+id and return page_latest (or 0)
const PURGE_GLOBAL_PCACHE
Definition WikiPage.php:93
static flattenRestrictions( $limit)
Take an array of page restrictions and flatten it to a string suitable for insertion into the page_re...
getParserOutput(ParserOptions $parserOptions, $oldid=null, $forceParse=false)
Get a ParserOutput for the given ParserOptions and revision ID.
const PURGE_ALL
Definition WikiPage.php:94
updateRedirectOn( $dbw, $redirectTitle, $lastRevIsRedirect=null)
Add row to the redirect table if this is a redirect, remove otherwise.
prepareContentForEdit(Content $content, $revision=null, User $user=null, $serialFormat=null, $useCache=true)
Prepare content which is about to be saved.
hasViewableContent()
Check if this page is something we're going to be showing some sort of sensible content for.
Definition WikiPage.php:480
triggerOpportunisticLinksUpdate(ParserOutput $parserOutput)
Opportunistically enqueue link update jobs given fresh parser output if useful.
getDeletionUpdates(Content $content=null)
Returns a list of updates to be performed when this page is deleted.
insertRedirect()
Insert an entry for this page into the redirect table if the content is a redirect.
Definition WikiPage.php:871
getContent( $audience=Revision::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
Definition WikiPage.php:663
getActionOverrides()
Definition WikiPage.php:216
int $mDataLoadedFrom
One of the READ_* constants.
Definition WikiPage.php:63
static onArticleDelete(Title $title)
Clears caches when article is deleted.
Title $mRedirectTarget
Definition WikiPage.php:68
replaceSectionContent( $sectionId, Content $sectionContent, $sectionTitle='', $edittime=null)
static selectFields()
Return the list of revision fields that should be selected to create a new page.
Definition WikiPage.php:286
insertProtectNullRevision( $revCommentMsg, array $limit, array $expiry, $cascade, $reason, $user=null)
Insert a new null revision for this page.
doDeleteUpdates( $id, Content $content=null, Revision $revision=null)
Do some database updates after deletion.
getTitle()
Get the title object of the article.
Definition WikiPage.php:237
isRedirect()
Tests if the article content represents a redirect.
Definition WikiPage.php:489
static onArticleCreate(Title $title)
The onArticle*() functions are supposed to be a kind of hooks which should be called whenever any of ...
string $mLinksUpdated
Definition WikiPage.php:88
commitRollback( $fromP, $summary, $bot, &$resultDetails, User $guser, $tags=null)
Backend implementation of doRollback(), please refer there for parameter and return value documentati...
getRedirectURL( $rt)
Get the Title object or URL to use for a redirect.
Definition WikiPage.php:941
loadPageData( $from='fromdb')
Load the object from a given source by title.
Definition WikiPage.php:375
clear()
Clear the object.
Definition WikiPage.php:245
doCreate(Content $content, $flags, User $user, $summary, array $meta)
checkTouched()
Loads page_touched and returns a value indicating if it should be used.
Definition WikiPage.php:536
getLastPurgeTimestamp()
Get the last time a user explicitly purged the page via action=purge.
isCountable( $editInfo=false)
Determine whether a page would be suitable for being counted as an article in the site_stats table ba...
Definition WikiPage.php:788
doRollback( $fromP, $summary, $token, $bot, &$resultDetails, User $user, $tags=null)
Roll back the most recent consecutive set of edits to a page from the same user; fails if there are n...
getContentHandler()
Returns the ContentHandler instance to be used to deal with the content of this WikiPage.
Definition WikiPage.php:229
getWikiDisplayName()
The display name for the site this content come from.
static convertSelectType( $type)
Convert 'fromdb', 'fromdbmaster' and 'forupdate' to READ_* constants.
Definition WikiPage.php:197
getCreator( $audience=Revision::FOR_PUBLIC, User $user=null)
Get the User object of the user who created the page.
Definition WikiPage.php:720
getMutableCacheKeys(WANObjectCache $cache)
protectDescription(array $limit, array $expiry)
Builds the description to serve as comment for the edit.
getTouched()
Get the page_touched field.
Definition WikiPage.php:547
__construct(Title $title)
Constructor and clear the article.
Definition WikiPage.php:100
doDeleteArticleReal( $reason, $suppress=false, $u1=null, $u2=null, &$error='', User $user=null, $tags=[], $logsubtype='delete')
Back-end article deletion Deletes the article with database consistency, writes logs,...
Database error base class.
Definition DBError.php:30
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
$res
Definition database.txt:21
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
when a variable name is used in a function
Definition design.txt:94
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition globals.txt:64
const EDIT_FORCE_BOT
Definition Defines.php:154
const EDIT_INTERNAL
Definition Defines.php:157
const EDIT_UPDATE
Definition Defines.php:151
const NS_FILE
Definition Defines.php:68
const NS_MEDIAWIKI
Definition Defines.php:70
const EDIT_SUPPRESS_RC
Definition Defines.php:153
const NS_MEDIA
Definition Defines.php:50
const NS_USER_TALK
Definition Defines.php:65
const EDIT_MINOR
Definition Defines.php:152
const NS_CATEGORY
Definition Defines.php:76
const EDIT_AUTOSUMMARY
Definition Defines.php:156
const EDIT_NEW
Definition Defines.php:150
the array() calling protocol came about after MediaWiki 1.4rc1.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context $parserOutput
Definition hooks.txt:1096
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:249
error also a ContextSource you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2728
do that in ParserLimitReportFormat instead $parser
Definition hooks.txt:2536
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition hooks.txt:2578
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition hooks.txt:1954
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
Definition hooks.txt:268
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Definition hooks.txt:1018
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers please use GetContentModels hook to make them known to core if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
Definition hooks.txt:1143
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition hooks.txt:1102
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition hooks.txt:1100
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt;div ...>$1&lt;/div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty & $sectionContent
Definition hooks.txt:2555
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition hooks.txt:2753
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition hooks.txt:2604
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition hooks.txt:1966
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context $revId
Definition hooks.txt:1101
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition hooks.txt:1049
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition hooks.txt:903
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition hooks.txt:1751
returning false will NOT prevent logging $e
Definition hooks.txt:2127
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Base interface for content objects.
Definition Content.php:34
Interface for database access objects.
const READ_LOCKING
Constants for object loading bitfield flags (higher => higher QoS)
Interface for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
Definition Page.php:24
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40
$cache
Definition mcc.php:33
$source
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:26
$params