SemanticMediaWiki /
SemanticCite
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SCI; |
||
| 4 | |||
| 5 | use IContextSource; |
||
|
0 ignored issues
–
show
|
|||
| 6 | use MediaWiki\MediaWikiServices; |
||
|
0 ignored issues
–
show
The type
MediaWiki\MediaWikiServices was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 7 | |||
| 8 | /** |
||
| 9 | * Helper class to avoid making objects depend on the IContextSource and instead |
||
| 10 | * provide dedicated methods to access a specific aspect of the context. |
||
| 11 | * |
||
| 12 | * @license GNU GPL v2+ |
||
| 13 | * @since 1.0 |
||
| 14 | * |
||
| 15 | * @author mwjames |
||
| 16 | * @reviewer thomas-topway-it |
||
| 17 | */ |
||
| 18 | class MediaWikiContextInteractor { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var IContextSource |
||
| 22 | */ |
||
| 23 | private $context; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var revisionLookup |
||
|
0 ignored issues
–
show
The type
SCI\revisionLookup was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 27 | */ |
||
| 28 | 14 | private $revisionLookup; |
|
| 29 | 14 | ||
| 30 | 14 | /** |
|
| 31 | * @since 1.0 |
||
| 32 | * |
||
| 33 | * @param IContextSource $context |
||
| 34 | */ |
||
| 35 | public function __construct( IContextSource $context ) { |
||
| 36 | $this->context = $context; |
||
| 37 | $this->revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup(); |
||
| 38 | } |
||
| 39 | 12 | ||
| 40 | /** |
||
| 41 | 12 | * @see RawAction::getOldId |
|
| 42 | 12 | * |
|
| 43 | * @since 1.0 |
||
| 44 | 12 | * |
|
| 45 | 12 | * @return int |
|
| 46 | */ |
||
| 47 | 1 | public function getOldId() { |
|
| 48 | 1 | $oldid = $this->context->getRequest()->getInt( 'oldid' ); |
|
| 49 | $title = $this->context->getTitle(); |
||
| 50 | |||
| 51 | 1 | switch ( $this->context->getRequest()->getText( 'direction' ) ) { |
|
| 52 | 1 | case 'next': |
|
| 53 | 11 | # output next revision, or nothing if there isn't one |
|
| 54 | $nextid = 0; |
||
| 55 | 1 | if ( $oldid ) { |
|
| 56 | $revision = $this->revisionLookup->getRevisionById( $oldid ); |
||
| 57 | 1 | $nextRevision = $this->revisionLookup->getNextRevision( $revision ); |
|
| 58 | if ( $nextRevision ) { |
||
| 59 | 1 | $nextid = $nextRevision->getId(); |
|
| 60 | 1 | } |
|
| 61 | 1 | } |
|
| 62 | 10 | $oldid = $nextid ?: -1; |
|
| 63 | 1 | break; |
|
| 64 | 1 | case 'prev': |
|
| 65 | # output previous revision, or nothing if there isn't one |
||
| 66 | $previd = 0; |
||
| 67 | 12 | if ( !$oldid ) { |
|
| 68 | # get the current revision so we can get the penultimate one |
||
| 69 | $oldid = $title->getLatestRevID(); |
||
| 70 | } |
||
| 71 | if ( $oldid ) { |
||
| 72 | $revision = $this->revisionLookup->getRevisionById( $oldid ); |
||
| 73 | $previousRevision = $this->revisionLookup->getPreviousRevision( $revision ); |
||
| 74 | if ( $previousRevision ) { |
||
| 75 | $previd = $previousRevision->getId(); |
||
| 76 | } |
||
| 77 | 9 | } |
|
| 78 | $oldid = $previd ?: -1; |
||
| 79 | 9 | break; |
|
| 80 | case 'cur': |
||
| 81 | 9 | $oldid = 0; |
|
| 82 | 1 | break; |
|
| 83 | } |
||
| 84 | |||
| 85 | 9 | return (int)$oldid; |
|
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @since 1.0 |
||
| 90 | * |
||
| 91 | * @param string $magicword |
||
| 92 | * |
||
| 93 | * @return boolean |
||
| 94 | */ |
||
| 95 | 10 | public function hasMagicWord( $magicword ) { |
|
| 96 | 10 | ||
| 97 | $outputPage = $this->context->getOutput(); |
||
| 98 | |||
| 99 | if ( isset( $outputPage->smwmagicwords ) && in_array( $magicword, $outputPage->smwmagicwords ) ) { |
||
| 100 | return true; |
||
| 101 | } |
||
| 102 | |||
| 103 | return false; |
||
| 104 | 9 | } |
|
| 105 | 9 | ||
| 106 | /** |
||
| 107 | * @since 1.0 |
||
| 108 | * |
||
| 109 | * @param string $action |
||
| 110 | * |
||
| 111 | * @return boolean |
||
| 112 | */ |
||
| 113 | 9 | public function hasAction( $action ) { |
|
| 114 | 9 | return \Action::getActionName( $this->context ) === $action; |
|
|
0 ignored issues
–
show
The type
Action was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @since 1.0 |
||
| 119 | * |
||
| 120 | * @return Title |
||
|
0 ignored issues
–
show
The type
SCI\Title was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 121 | */ |
||
| 122 | public function getTitle() { |
||
| 123 | return $this->context->getTitle(); |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @since 1.0 |
||
| 128 | * |
||
| 129 | * @return string |
||
| 130 | */ |
||
| 131 | public function getLanguageCode() { |
||
| 132 | return $this->context->getLanguage()->getCode(); |
||
| 133 | } |
||
| 134 | |||
| 135 | } |
||
| 136 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths