This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Wikibase\Repo\Specials; |
||
4 | |||
5 | use MWException; |
||
6 | use RuntimeException; |
||
7 | use Status; |
||
8 | use Title; |
||
9 | use Wikibase\DataModel\Entity\EntityDocument; |
||
10 | use Wikibase\DataModel\Entity\EntityId; |
||
11 | use Wikibase\DataModel\Entity\ItemId; |
||
12 | use Wikibase\Lib\FormatableSummary; |
||
13 | use Wikibase\Lib\Store\EntityTitleLookup; |
||
14 | use Wikibase\Lib\UserInputException; |
||
15 | use Wikibase\Repo\EditEntity\EditEntity; |
||
16 | use Wikibase\Repo\EditEntity\MediawikiEditEntityFactory; |
||
17 | use Wikibase\Repo\SummaryFormatter; |
||
18 | use Wikibase\Repo\WikibaseRepo; |
||
19 | |||
20 | /** |
||
21 | * Abstract base class for special pages of the WikibaseRepo extension. |
||
22 | * |
||
23 | * @license GPL-2.0-or-later |
||
24 | * @author Bene* < [email protected] > |
||
25 | */ |
||
26 | abstract class SpecialWikibaseRepoPage extends SpecialWikibasePage { |
||
27 | |||
28 | /** |
||
29 | * @var SpecialPageCopyrightView |
||
30 | */ |
||
31 | private $copyrightView; |
||
32 | |||
33 | /** |
||
34 | * @var SummaryFormatter |
||
35 | */ |
||
36 | protected $summaryFormatter; |
||
37 | |||
38 | /** |
||
39 | * @var EntityTitleLookup |
||
40 | */ |
||
41 | private $entityTitleLookup; |
||
42 | |||
43 | /** |
||
44 | * @var MediawikiEditEntityFactory |
||
45 | */ |
||
46 | private $editEntityFactory; |
||
47 | |||
48 | /** |
||
49 | * @var EditEntity |
||
50 | */ |
||
51 | private $editEntity = null; |
||
52 | |||
53 | /** |
||
54 | * @param string $title The title of the special page |
||
55 | * @param string $restriction The required user right |
||
56 | * @param SpecialPageCopyrightView $copyrightView |
||
57 | * @param SummaryFormatter $summaryFormatter |
||
58 | * @param EntityTitleLookup $entityTitleLookup |
||
59 | * @param MediawikiEditEntityFactory $editEntityFactory |
||
60 | */ |
||
61 | public function __construct( |
||
62 | $title, |
||
63 | $restriction, |
||
64 | SpecialPageCopyrightView $copyrightView, |
||
65 | SummaryFormatter $summaryFormatter, |
||
66 | EntityTitleLookup $entityTitleLookup, |
||
67 | MediawikiEditEntityFactory $editEntityFactory |
||
68 | ) { |
||
69 | parent::__construct( $title, $restriction ); |
||
70 | $this->copyrightView = $copyrightView; |
||
71 | $this->summaryFormatter = $summaryFormatter; |
||
72 | $this->entityTitleLookup = $entityTitleLookup; |
||
73 | $this->editEntityFactory = $editEntityFactory; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @param EntityId|null $id |
||
78 | * @param int $baseRev |
||
79 | * @return EditEntity |
||
80 | */ |
||
81 | protected function prepareEditEntity( EntityId $id = null, $baseRev = 0 ) { |
||
82 | $this->editEntity = $this->editEntityFactory->newEditEntity( |
||
83 | $this->getUser(), |
||
84 | $id, |
||
85 | $baseRev, |
||
86 | $this->getRequest()->wasPosted() |
||
87 | ); |
||
88 | |||
89 | return $this->editEntity; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Returns the EditEntity interactor. |
||
94 | * |
||
95 | * @note Call only after calling prepareEditEntity() first. |
||
96 | * |
||
97 | * @return EditEntity |
||
98 | */ |
||
99 | protected function getEditEntity() { |
||
100 | if ( !$this->editEntity ) { |
||
101 | throw new RuntimeException( 'Call prepareEditEntity() before calling getEditEntity()' ); |
||
102 | } |
||
103 | |||
104 | return $this->editEntity; |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Parses an entity id. |
||
109 | * |
||
110 | * @param string $rawId |
||
111 | * |
||
112 | * @return EntityId |
||
113 | * @throws UserInputException |
||
114 | */ |
||
115 | protected function parseEntityId( $rawId ) { |
||
116 | $idParser = WikibaseRepo::getDefaultInstance()->getEntityIdParser(); |
||
117 | |||
118 | try { |
||
119 | $id = $idParser->parse( $rawId ); |
||
120 | } catch ( RuntimeException $ex ) { |
||
121 | throw new UserInputException( |
||
122 | 'wikibase-wikibaserepopage-invalid-id', |
||
123 | [ $rawId ], |
||
124 | "Entity ID \"$rawId\" is not valid" |
||
125 | ); |
||
126 | } |
||
127 | |||
128 | return $id; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Parses an item id. |
||
133 | * |
||
134 | * @param string $rawId |
||
135 | * |
||
136 | * @return ItemId |
||
137 | * @throws UserInputException |
||
138 | */ |
||
139 | protected function parseItemId( $rawId ) { |
||
140 | $id = $this->parseEntityId( $rawId ); |
||
141 | |||
142 | if ( !( $id instanceof ItemId ) ) { |
||
143 | throw new UserInputException( |
||
144 | 'wikibase-wikibaserepopage-not-itemid', |
||
145 | [ $rawId ], |
||
146 | "Entity ID \"$rawId\" does not refer to an Item" |
||
147 | ); |
||
148 | } |
||
149 | |||
150 | return $id; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * @param EntityId $id |
||
155 | * |
||
156 | * @throws MWException |
||
157 | * @return null|Title |
||
158 | */ |
||
159 | protected function getEntityTitle( EntityId $id ) { |
||
160 | return $this->entityTitleLookup->getTitleForId( $id ); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Saves the entity using the given summary. |
||
165 | * |
||
166 | * @note Call prepareEditEntity() first. |
||
167 | * |
||
168 | * @param EntityDocument $entity |
||
169 | * @param FormatableSummary $summary |
||
170 | * @param string $token |
||
171 | * @param int $flags The edit flags (see WikiPage::doEditContent) |
||
172 | * |
||
173 | * @return Status |
||
174 | */ |
||
175 | protected function saveEntity( |
||
176 | EntityDocument $entity, |
||
177 | FormatableSummary $summary, |
||
178 | $token, |
||
179 | $flags = EDIT_UPDATE |
||
180 | ) { |
||
181 | $status = $this->getEditEntity()->attemptSave( |
||
182 | $entity, |
||
183 | $this->summaryFormatter->formatSummary( $summary ), |
||
184 | $flags, |
||
185 | $token |
||
186 | ); |
||
187 | |||
188 | return $status; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @param string|null $saveMessageKey Defaults to "wikibase-<special page name>-submit". |
||
193 | * |
||
194 | * @return string HTML |
||
195 | */ |
||
196 | protected function getCopyrightHTML( $saveMessageKey = null ) { |
||
197 | if ( $saveMessageKey === null ) { |
||
198 | $saveMessageKey = 'wikibase-' . strtolower( $this->getName() ) . '-submit'; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
199 | } |
||
200 | |||
201 | return $this->copyrightView->getHtml( $this->getLanguage(), $saveMessageKey ); |
||
202 | } |
||
203 | |||
204 | } |
||
205 |