Debian Codegraph @

includes/Storage/PageUpdateStatus.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Storage;
22
23 use MediaWiki\Revision\RevisionRecord;
24 use MediaWiki\Status\Status;
25
26 /**
27 * Status object representing the outcome of a page update.
28 *
29 * @see PageUpdater
30 *
31 * @since 1.40
32 * @ingroup Page
33 * @author Daniel Kinzler
34 */
35 class PageUpdateStatus extends Status {
36
37 /**
38 * @internal for use by PageUpdater only
39 * @param bool $newPage
40 *
41 * @return PageUpdateStatus
42 */
43 public static function newEmpty( bool $newPage ): PageUpdateStatus {
44 return static::newGood( [
45 'new' => $newPage,
46 'revision-record' => null
47 ] );
48 }
49
50 /**
51 * @internal for use by PageUpdater only
52 * @param RevisionRecord $rev
53 */
54 public function setNewRevision( RevisionRecord $rev ) {
55 $this->value['revision-record'] = $rev;
56 }
57
58 /**
59 * The revision created by PageUpdater::saveRevision().
60 *
61 * Will return null if no revision was created because there was an error,
62 * or because the content didn't change (null edit or derived slot update).
63 *
64 * Call isOK() to distinguish these cases.
65 *
66 * @return ?RevisionRecord
67 */
68 public function getNewRevision(): ?RevisionRecord {
69 if ( !$this->isOK() ) {
70 return null;
71 }
72
73 return $this->value['revision-record'] ?? null;
74 }
75
76 /**
77 * Whether the update created a revision.
78 * If this returns false even though isOK() returns true, this means that
79 * no new revision was created because the content didn't change,
80 * including updates to derived slots.
81 *
82 * @return bool
83 */
84 public function wasRevisionCreated(): bool {
85 return $this->getNewRevision() !== null;
86 }
87
88 /**
89 * Whether the update created the page.
90 * @return bool
91 */
92 public function wasPageCreated(): bool {
93 return $this->wasRevisionCreated()
94 && ( $this->value['new'] ?? false );
95 }
96
97 /**
98 * Whether the update failed because page creation was required, but the page already exists.
99 * @return bool
100 */
101 public function failedBecausePageExists(): bool {
102 return !$this->isOK() && $this->hasMessage( 'edit-already-exists' );
103 }
104
105 /**
106 * Whether the update failed because page modification was required, but the page does not exist.
107 * @return bool
108 */
109 public function failedBecausePageMissing(): bool {
110 return !$this->isOK() && $this->hasMessage( 'edit-gone-missing' );
111 }
112
113 /**
114 * Whether the update failed because a conflicting update happened concurrently.
115 * @return bool
116 */
117 public function failedBecauseOfConflict(): bool {
118 return !$this->isOK() && $this->hasMessage( 'edit-conflict' );
119 }
120
121 }