Index: branches/uploadwizard-deployment/includes/api/ApiBase.php |
— | — | @@ -548,6 +548,44 @@ |
549 | 549 | } |
550 | 550 | |
551 | 551 | /** |
| 552 | + * Return true if we're to watch the page, false if not, null if no change. |
| 553 | + * @param $watchlist String Valid values: 'watch', 'unwatch', 'preferences', 'nochange' |
| 554 | + * @param $titleObj Title the page under consideration |
| 555 | + * @param $userOption String The user option to consider when $watchlist=preferences. |
| 556 | + * If not set will magically default to either watchdefault or watchcreations |
| 557 | + * @returns mixed |
| 558 | + */ |
| 559 | + protected function getWatchlistValue ( $watchlist, $titleObj, $userOption = null ) { |
| 560 | + global $wgUser; |
| 561 | + switch ( $watchlist ) { |
| 562 | + case 'watch': |
| 563 | + return true; |
| 564 | + |
| 565 | + case 'unwatch': |
| 566 | + return false; |
| 567 | + |
| 568 | + case 'preferences': |
| 569 | + # If the user is already watching, don't bother checking |
| 570 | + if ( $titleObj->userIsWatching() ) { |
| 571 | + return null; |
| 572 | + } |
| 573 | + # If no user option was passed, use watchdefault or watchcreation |
| 574 | + if ( is_null( $userOption ) ) { |
| 575 | + $userOption = $titleObj->exists() |
| 576 | + ? 'watchdefault' : 'watchcreations'; |
| 577 | + } |
| 578 | + # If the corresponding user option is true, watch, else no change |
| 579 | + return $wgUser->getOption( $userOption ) ? true : null; |
| 580 | + |
| 581 | + case 'nochange': |
| 582 | + return null; |
| 583 | + |
| 584 | + default: |
| 585 | + return null; |
| 586 | + } |
| 587 | + } |
| 588 | + |
| 589 | + /** |
552 | 590 | * Using the settings determine the value for the given parameter |
553 | 591 | * |
554 | 592 | * @param $paramName String: parameter name |