1<?php 2 3namespace dokuwiki\Remote; 4 5use dokuwiki\Utf8\PhpString; 6use IXR\DataType\Date; 7 8/** 9 * Provides wrappers for the API calls as they existed in API Version 11 10 * 11 * No guarantees are made about the exact compatibility of the return values. 12 * 13 * @deprecated 14 */ 15class LegacyApiCore extends ApiCore 16{ 17 /** @inheritdoc */ 18 public function getMethods() 19 { 20 $methods = parent::getMethods(); 21 22 return array_merge( 23 $methods, 24 [ 25 'dokuwiki.getVersion' => new ApiCall([$this, 'legacyGetVersion'], 'legacy'), 26 'dokuwiki.login' => (new ApiCall([$this, 'legacyLogin'], 'legacy'))->setPublic(), 27 'dokuwiki.logoff' => new ApiCall([$this, 'legacyLogoff'], 'legacy'), 28 'dokuwiki.getPagelist' => new ApiCall([$this, 'legacyGetPagelist'], 'legacy'), 29 'dokuwiki.search' => new ApiCall([$this, 'legacySearch'], 'legacy'), 30 'dokuwiki.getTime' => new ApiCall([$this, 'legacyGetTime'], 'legacy'), 31 'dokuwiki.setLocks' => new ApiCall([$this, 'legacySetLocks'], 'legacy'), 32 'dokuwiki.getTitle' => (new ApiCall([$this, 'legacyGetTitle'], 'legacy'))->setPublic(), 33 'dokuwiki.appendPage' => new ApiCall([$this, 'legacyAppendPage'], 'legacy'), 34 'dokuwiki.createUser' => new ApiCall([$this, 'legacyCreateUser'], 'legacy'), 35 'dokuwiki.deleteUsers' => new ApiCall([$this, 'legacyDeleteUsers'], 'legacy'), 36 'wiki.getPage' => new ApiCall([$this, 'legacyGetPage'], 'legacy'), 37 'wiki.getPageVersion' => new ApiCall([$this, 'legacyGetPageVersion'], 'legacy'), 38 'wiki.getPageHTML' => new ApiCall([$this, 'legacyGetPageHTML'], 'legacy'), 39 'wiki.getPageHTMLVersion' => new ApiCall([$this, 'legacyGetPageHTMLVersion'], 'legacy'), 40 'wiki.getAllPages' => new ApiCall([$this, 'legacyGetAllPages'], 'legacy'), 41 'wiki.getAttachments' => new ApiCall([$this, 'legacyGetAttachments'], 'legacy'), 42 'wiki.getBackLinks' => new ApiCall([$this, 'legacyGetBackLinks'], 'legacy'), 43 'wiki.getPageInfo' => new ApiCall([$this, 'legacyGetPageInfo'], 'legacy'), 44 'wiki.getPageInfoVersion' => new ApiCall([$this, 'legacyGetPageInfoVersion'], 'legacy'), 45 'wiki.getPageVersions' => new ApiCall([$this, 'legacyGetPageVersions'], 'legacy'), 46 'wiki.putPage' => new ApiCall([$this, 'legacyPutPage'], 'legacy'), 47 'wiki.listLinks' => new ApiCall([$this, 'legacyListLinks'], 'legacy'), 48 'wiki.getRecentChanges' => new ApiCall([$this, 'legacyGetRecentChanges'], 'legacy'), 49 'wiki.getRecentMediaChanges' => new ApiCall([$this, 'legacyGetRecentMediaChanges'], 'legacy'), 50 'wiki.aclCheck' => new ApiCall([$this, 'legacyAclCheck'], 'legacy'), 51 'wiki.putAttachment' => new ApiCall([$this, 'legacyPutAttachment'], 'legacy'), 52 'wiki.deleteAttachment' => new ApiCall([$this, 'legacyDeleteAttachment'], 'legacy'), 53 'wiki.getAttachment' => new ApiCall([$this, 'legacyGetAttachment'], 'legacy'), 54 'wiki.getAttachmentInfo' => new ApiCall([$this, 'legacyGetAttachmentInfo'], 'legacy'), 55 'dokuwiki.getXMLRPCAPIVersion' => (new ApiCall([$this, 'legacyGetXMLRPCAPIVersion'], 'legacy')) 56 ->setPublic(), 57 'wiki.getRPCVersionSupported' => (new ApiCall([$this, 'legacyGetRPCVersionSupported'], 'legacy')) 58 ->setPublic(), 59 ] 60 ); 61 } 62 63 /** 64 * This returns a XMLRPC object that will not work for the new JSONRPC API 65 * 66 * @param int $ts 67 * @return Date 68 */ 69 protected function toDate($ts) 70 { 71 return new Date($ts); 72 } 73 74 75 /** 76 * @deprecated use core.getWikiVersion instead 77 */ 78 public function legacyGetVersion() 79 { 80 return getVersion(); 81 } 82 83 /** 84 * @deprecated use core.getWikiTime instead 85 */ 86 public function legacyGetTime() 87 { 88 return $this->getWikiTime(); 89 } 90 91 92 /** 93 * @deprecated use core.getPage instead 94 */ 95 public function legacyGetPage($id) 96 { 97 return $this->getPage($id); 98 } 99 100 /** 101 * @deprecated use core.getPage instead 102 */ 103 public function legacyGetPageVersion($id, $rev = '') 104 { 105 return $this->getPage($id, $rev); 106 } 107 108 /** 109 * @deprecated use core.getMedia instead 110 */ 111 public function legacyGetAttachment($id) 112 { 113 return $this->getMedia($id); 114 } 115 116 /** 117 * @deprecated use core.getMediaInfo instead 118 */ 119 public function legacygetAttachmentInfo($id) 120 { 121 $info = $this->getMediaInfo($id); 122 return [ 123 'lastModified' => $this->toDate($info->revision), 124 'size' => $info->size, 125 ]; 126 } 127 128 /** 129 * @deprecated use core.getPageHTML instead 130 */ 131 public function legacyGetPageHTML($id) 132 { 133 return $this->getPageHTML($id); 134 } 135 136 /** 137 * @deprecated use core.getPageHTML instead 138 */ 139 public function legacyGetPageHTMLVersion($id, $rev = '') 140 { 141 return $this->getPageHTML($id, (int)$rev); 142 } 143 144 /** 145 * @deprecated use core.listPages instead 146 */ 147 public function legacyGetAllPages() 148 { 149 $pages = $this->listPages('', 0); 150 151 $result = []; 152 foreach ($pages as $page) { 153 $result[] = [ 154 'id' => $page->id, 155 'perms' => $page->permission, 156 'size' => $page->size, 157 'lastModified' => $this->toDate($page->revision), 158 ]; 159 } 160 return $result; 161 } 162 163 /** 164 * @deprecated use core.listPages instead 165 */ 166 public function legacyGetPagelist($ns, $opts = []) 167 { 168 $data = $this->listPages($ns, $opts['depth'] ?? 0, $opts['hash'] ?? false); 169 $result = []; 170 171 foreach ($data as $page) { 172 $result[] = [ 173 'id' => $page->id, 174 'perms' => $page->permission, 175 'size' => $page->size, 176 'rev' => $page->revision, 177 'lastModified' => $this->toDate($page->revision), 178 'hash' => $page->hash, 179 180 ]; 181 } 182 183 return $result; 184 } 185 186 /** 187 * @deprecated use core.searchPages instead 188 */ 189 public function legacySearch($query) 190 { 191 $this->searchPages($query); 192 $pages = []; 193 194 foreach ($this->searchPages($query) as $page) { 195 $pages[] = [ 196 'id' => $page->id, 197 'score' => $page->score, 198 'rev' => $page->revision, 199 'lastModified' => $this->toDate($page->revision), 200 'size' => $page->size, 201 'snippet' => $page->snippet, 202 'title' => $page->title 203 ]; 204 } 205 206 return $pages; 207 } 208 209 /** 210 * @deprecated use core.getWikiTitle instead 211 */ 212 public function legacyGetTitle() 213 { 214 return $this->getWikiTitle(); 215 } 216 217 /** 218 * @deprecated use core.listMedia instead 219 */ 220 public function legacyGetAttachments($ns, $options = []) 221 { 222 $files = $this->listMedia($ns, $options['pattern'] ?? '', $options['depth'] ?? 0, $options['hash'] ?? false); 223 $result = []; 224 foreach ($files as $file) { 225 $result[] = [ 226 'id' => $file->id, 227 'perms' => $file->permission, 228 'size' => $file->size, 229 'rev' => $file->revision, 230 'lastModified' => $this->toDate($file->revision), 231 'mtime' => $this->toDate($file->revision), 232 'hash' => $file->hash, 233 'file' => PhpString::basename(mediaFN($file->id)), 234 'writable' => is_writable(mediaFN($file->id)), 235 'isimg' => $file->isimage, 236 237 ]; 238 } 239 return $result; 240 } 241 242 /** 243 * @deprecated use core.getPageBackLinks instead 244 */ 245 public function legacyGetBackLinks($id) 246 { 247 return $this->getPageBackLinks($id); 248 } 249 250 /** 251 * @deprecated use core.getPageInfo instead 252 */ 253 public function legacyGetPageInfo($id) 254 { 255 $info = $this->getPageInfo($id, 0); 256 return [ 257 'name' => $info->id, 258 'lastModified' => $this->toDate($info->revision), 259 'author' => $info->author, 260 'version' => $info->revision, 261 ]; 262 } 263 264 /** 265 * @deprecated use core.getPageInfo instead 266 */ 267 public function legacyGetPageInfoVersion($id, $rev = '') 268 { 269 $info = $this->getPageInfo($id, $rev); 270 return [ 271 'name' => $info->id, 272 'lastModified' => $this->toDate($info->revision), 273 'author' => $info->author, 274 'version' => $info->revision, 275 ]; 276 } 277 278 /** 279 * @deprecated use core.savePage instead 280 */ 281 public function legacyPutPage($id, $text, $params = []) 282 { 283 return $this->savePage($id, $text, $params['sum'] ?? '', $params['minor'] ?? false); 284 } 285 286 /** 287 * @deprecated use core.appendPage instead 288 */ 289 public function legacyAppendPage($id, $text, $params = []) 290 { 291 $ok = $this->appendPage($id, $text, $params['summary'] ?? '', $params['minor'] ?? false); 292 if ($ok === true) { 293 return cleanID($id); 294 } else { 295 return $ok; 296 } 297 } 298 299 /** 300 * @deprecated use plugin.usermanager.createUser instead 301 */ 302 public function legacyCreateUser($userStruct) 303 { 304 if (!auth_isadmin()) { 305 throw new AccessDeniedException('Only admins are allowed to create users', 114); 306 } 307 308 /** @var AuthPlugin $auth */ 309 global $auth; 310 311 if (!$auth->canDo('addUser')) { 312 throw new AccessDeniedException( 313 sprintf('Authentication backend %s can\'t do addUser', $auth->getPluginName()), 314 114 315 ); 316 } 317 318 $user = trim($auth->cleanUser($userStruct['user'] ?? '')); 319 $password = $userStruct['password'] ?? ''; 320 $name = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $userStruct['name'] ?? '')); 321 $mail = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/', '', $userStruct['mail'] ?? '')); 322 $groups = $userStruct['groups'] ?? []; 323 324 $notify = (bool)$userStruct['notify'] ?? false; 325 326 if ($user === '') throw new RemoteException('empty or invalid user', 401); 327 if ($name === '') throw new RemoteException('empty or invalid user name', 402); 328 if (!mail_isvalid($mail)) throw new RemoteException('empty or invalid mail address', 403); 329 330 if ((string)$password === '') { 331 $password = auth_pwgen($user); 332 } 333 334 if (!is_array($groups) || $groups === []) { 335 $groups = null; 336 } 337 338 $ok = $auth->triggerUserMod('create', [$user, $password, $name, $mail, $groups]); 339 340 if ($ok !== false && $ok !== null) { 341 $ok = true; 342 } 343 344 if ($ok) { 345 if ($notify) { 346 auth_sendPassword($user, $password); 347 } 348 } 349 350 return $ok; 351 } 352 353 354 /** 355 * @deprecated use plugin.usermanager.deleteUser instead 356 */ 357 public function legacyDeleteUsers($usernames) 358 { 359 if (!auth_isadmin()) { 360 throw new AccessDeniedException('Only admins are allowed to delete users', 114); 361 } 362 /** @var AuthPlugin $auth */ 363 global $auth; 364 return (bool)$auth->triggerUserMod('delete', [$usernames]); 365 } 366 367 /** 368 * @deprecated use core.saveMedia instead 369 */ 370 public function legacyPutAttachment($id, $file, $params = []) 371 { 372 $ok = $this->saveMedia($id, $file, $params['ow'] ?? false); 373 if ($ok === true) { 374 return cleanID($id); 375 } else { 376 return $ok; 377 } 378 } 379 380 /** 381 * @deprecated use core.deleteMedia instead 382 */ 383 public function legacyDeleteAttachment($id) 384 { 385 $ok = $this->deleteMedia($id); 386 if ($ok === true) { 387 return 0; 388 } else { 389 return $ok; 390 } 391 } 392 393 /** 394 * @deprecated use core.aclCheck instead 395 */ 396 public function legacyAclCheck($id, $user = null, $groups = null) 397 { 398 return $this->aclCheck($id, (string)$user, (string)$groups); 399 } 400 401 /** 402 * @deprecated use core.listLinks instead 403 */ 404 public function legacyListLinks($id) 405 { 406 $links = $this->getPageLinks($id); 407 $result = []; 408 foreach ($links as $link) { 409 $result[] = [ 410 'type' => $link['type'], 411 'page' => $link['page'], 412 'href' => $link['href'], 413 ]; 414 } 415 return $result; 416 } 417 418 /** 419 * @deprecated use core.getRecentChanges instead 420 */ 421 public function legacyGetRecentChanges($timestamp) 422 { 423 $recents = $this->getRecentPageChanges($timestamp); 424 $result = []; 425 foreach ($recents as $recent) { 426 $result[] = [ 427 'name' => $recent->id, 428 'lastModified' => $this->toDate($recent->revision), 429 'author' => $recent->author, 430 'version' => $recent->revision, 431 'perms' => auth_quickaclcheck($recent->id), 432 'size' => @filesize(wikiFN($recent->id)), 433 ]; 434 } 435 return $result; 436 } 437 438 /** 439 * @deprecated use core.getRecentMediaChanges instead 440 */ 441 public function legacyGetRecentMediaChanges($timestamp) 442 { 443 $recents = $this->getRecentMediaChanges($timestamp); 444 $result = []; 445 foreach ($recents as $recent) { 446 $result[] = [ 447 'name' => $recent->id, 448 'lastModified' => $this->toDate($recent->revision), 449 'author' => $recent->author, 450 'version' => $recent->revision, 451 'perms' => auth_quickaclcheck($recent->id), 452 'size' => @filesize(mediaFN($recent->id)), 453 ]; 454 } 455 return $result; 456 } 457 458 /** 459 * @deprecated use core.getPageHistory instead 460 */ 461 public function legacyGetPageVersions($id, $first = 0) 462 { 463 $revisions = $this->getPageHistory($id, $first); 464 $result = []; 465 466 foreach ($revisions as $revision) { 467 $result[] = [ 468 'user' => $revision->author, 469 'ip' => $revision->ip, 470 'type' => $revision->type, 471 'sum' => $revision->summary, 472 'modified' => $this->toDate($revision->revision), 473 'version' => $revision->revision, 474 ]; 475 } 476 return $result; 477 } 478 479 /** 480 * @deprecated Wiki RPC spec is no longer supported 481 */ 482 public function legacyGetRPCVersionSupported() 483 { 484 return 2; 485 } 486 487 /** 488 * @deprecated use core.lockPages and core.unlockPages instead 489 */ 490 public function legacySetLocks($set) 491 { 492 $locked = $this->lockPages($set['lock']); 493 $lockfail = array_diff($set['lock'], $locked); 494 495 $unlocked = $this->unlockPages($set['unlock']); 496 $unlockfail = array_diff($set['unlock'], $unlocked); 497 498 return [ 499 'locked' => $locked, 500 'lockfail' => $lockfail, 501 'unlocked' => $unlocked, 502 'unlockfail' => $unlockfail 503 ]; 504 } 505 506 /** 507 * @deprecated use core.getAPIVersion instead 508 */ 509 public function legacyGetXMLRPCAPIVersion() 510 { 511 return $this->getAPIVersion(); 512 } 513 514 /** 515 * @deprecated use core.login instead 516 */ 517 public function legacyLogin($user, $pass) 518 { 519 return parent::login($user, $pass); 520 } 521 522 /** 523 * @deprecated use core.logoff instead 524 */ 525 public function legacyLogoff() 526 { 527 return parent::logoff(); 528 } 529} 530