Code Duplication    Length = 13-16 lines in 9 locations

includes/api/ApiQueryInfo.php 9 locations

@@ 137-152 (lines=16) @@
134
	/**
135
	 * @deprecated since 1.24
136
	 */
137
	public static function getEditToken( $pageid, $title ) {
138
		// We could check for $title->userCan('edit') here,
139
		// but that's too expensive for this purpose
140
		// and would break caching
141
		global $wgUser;
142
		if ( !$wgUser->isAllowed( 'edit' ) ) {
143
			return false;
144
		}
145
146
		// The token is always the same, let's exploit that
147
		if ( !isset( ApiQueryInfo::$cachedTokens['edit'] ) ) {
148
			ApiQueryInfo::$cachedTokens['edit'] = $wgUser->getEditToken();
149
		}
150
151
		return ApiQueryInfo::$cachedTokens['edit'];
152
	}
153
154
	/**
155
	 * @deprecated since 1.24
@@ 157-169 (lines=13) @@
154
	/**
155
	 * @deprecated since 1.24
156
	 */
157
	public static function getDeleteToken( $pageid, $title ) {
158
		global $wgUser;
159
		if ( !$wgUser->isAllowed( 'delete' ) ) {
160
			return false;
161
		}
162
163
		// The token is always the same, let's exploit that
164
		if ( !isset( ApiQueryInfo::$cachedTokens['delete'] ) ) {
165
			ApiQueryInfo::$cachedTokens['delete'] = $wgUser->getEditToken();
166
		}
167
168
		return ApiQueryInfo::$cachedTokens['delete'];
169
	}
170
171
	/**
172
	 * @deprecated since 1.24
@@ 174-186 (lines=13) @@
171
	/**
172
	 * @deprecated since 1.24
173
	 */
174
	public static function getProtectToken( $pageid, $title ) {
175
		global $wgUser;
176
		if ( !$wgUser->isAllowed( 'protect' ) ) {
177
			return false;
178
		}
179
180
		// The token is always the same, let's exploit that
181
		if ( !isset( ApiQueryInfo::$cachedTokens['protect'] ) ) {
182
			ApiQueryInfo::$cachedTokens['protect'] = $wgUser->getEditToken();
183
		}
184
185
		return ApiQueryInfo::$cachedTokens['protect'];
186
	}
187
188
	/**
189
	 * @deprecated since 1.24
@@ 191-203 (lines=13) @@
188
	/**
189
	 * @deprecated since 1.24
190
	 */
191
	public static function getMoveToken( $pageid, $title ) {
192
		global $wgUser;
193
		if ( !$wgUser->isAllowed( 'move' ) ) {
194
			return false;
195
		}
196
197
		// The token is always the same, let's exploit that
198
		if ( !isset( ApiQueryInfo::$cachedTokens['move'] ) ) {
199
			ApiQueryInfo::$cachedTokens['move'] = $wgUser->getEditToken();
200
		}
201
202
		return ApiQueryInfo::$cachedTokens['move'];
203
	}
204
205
	/**
206
	 * @deprecated since 1.24
@@ 208-220 (lines=13) @@
205
	/**
206
	 * @deprecated since 1.24
207
	 */
208
	public static function getBlockToken( $pageid, $title ) {
209
		global $wgUser;
210
		if ( !$wgUser->isAllowed( 'block' ) ) {
211
			return false;
212
		}
213
214
		// The token is always the same, let's exploit that
215
		if ( !isset( ApiQueryInfo::$cachedTokens['block'] ) ) {
216
			ApiQueryInfo::$cachedTokens['block'] = $wgUser->getEditToken();
217
		}
218
219
		return ApiQueryInfo::$cachedTokens['block'];
220
	}
221
222
	/**
223
	 * @deprecated since 1.24
@@ 233-245 (lines=13) @@
230
	/**
231
	 * @deprecated since 1.24
232
	 */
233
	public static function getEmailToken( $pageid, $title ) {
234
		global $wgUser;
235
		if ( !$wgUser->canSendEmail() || $wgUser->isBlockedFromEmailuser() ) {
236
			return false;
237
		}
238
239
		// The token is always the same, let's exploit that
240
		if ( !isset( ApiQueryInfo::$cachedTokens['email'] ) ) {
241
			ApiQueryInfo::$cachedTokens['email'] = $wgUser->getEditToken();
242
		}
243
244
		return ApiQueryInfo::$cachedTokens['email'];
245
	}
246
247
	/**
248
	 * @deprecated since 1.24
@@ 250-262 (lines=13) @@
247
	/**
248
	 * @deprecated since 1.24
249
	 */
250
	public static function getImportToken( $pageid, $title ) {
251
		global $wgUser;
252
		if ( !$wgUser->isAllowedAny( 'import', 'importupload' ) ) {
253
			return false;
254
		}
255
256
		// The token is always the same, let's exploit that
257
		if ( !isset( ApiQueryInfo::$cachedTokens['import'] ) ) {
258
			ApiQueryInfo::$cachedTokens['import'] = $wgUser->getEditToken();
259
		}
260
261
		return ApiQueryInfo::$cachedTokens['import'];
262
	}
263
264
	/**
265
	 * @deprecated since 1.24
@@ 267-279 (lines=13) @@
264
	/**
265
	 * @deprecated since 1.24
266
	 */
267
	public static function getWatchToken( $pageid, $title ) {
268
		global $wgUser;
269
		if ( !$wgUser->isLoggedIn() ) {
270
			return false;
271
		}
272
273
		// The token is always the same, let's exploit that
274
		if ( !isset( ApiQueryInfo::$cachedTokens['watch'] ) ) {
275
			ApiQueryInfo::$cachedTokens['watch'] = $wgUser->getEditToken( 'watch' );
276
		}
277
278
		return ApiQueryInfo::$cachedTokens['watch'];
279
	}
280
281
	/**
282
	 * @deprecated since 1.24
@@ 284-296 (lines=13) @@
281
	/**
282
	 * @deprecated since 1.24
283
	 */
284
	public static function getOptionsToken( $pageid, $title ) {
285
		global $wgUser;
286
		if ( !$wgUser->isLoggedIn() ) {
287
			return false;
288
		}
289
290
		// The token is always the same, let's exploit that
291
		if ( !isset( ApiQueryInfo::$cachedTokens['options'] ) ) {
292
			ApiQueryInfo::$cachedTokens['options'] = $wgUser->getEditToken();
293
		}
294
295
		return ApiQueryInfo::$cachedTokens['options'];
296
	}
297
298
	public function execute() {
299
		$this->params = $this->extractRequestParams();