SemanticMediaWiki /
SemanticApprovedRevs
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SMW\ApprovedRevs; |
||
| 4 | |||
| 5 | use File; |
||
| 6 | use MediaWiki\MediaWikiServices; |
||
|
0 ignored issues
–
show
|
|||
| 7 | use OldLocalFile; |
||
|
0 ignored issues
–
show
The type
OldLocalFile 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...
|
|||
| 8 | use RepoGroup; |
||
|
0 ignored issues
–
show
The type
RepoGroup 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...
|
|||
| 9 | use MediaWiki\Revision\RevisionStoreRecord; |
||
|
0 ignored issues
–
show
The type
MediaWiki\Revision\RevisionStoreRecord 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...
|
|||
| 10 | use Title; |
||
|
0 ignored issues
–
show
The type
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...
|
|||
| 11 | |||
| 12 | /** |
||
| 13 | * @license GNU GPL v2+ |
||
| 14 | * @since 1.0 |
||
| 15 | * |
||
| 16 | * @author mwjames |
||
| 17 | */ |
||
| 18 | class ApprovedRevsHandler { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var ApprovedRevsFacade |
||
| 22 | */ |
||
| 23 | private $approvedRevsFacade; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var RepoGroup |
||
| 27 | */ |
||
| 28 | private $repoGroup; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @since 1.0 |
||
| 32 | * |
||
| 33 | * @param ApprovedRevsFacade $approvedRevsFacade |
||
| 34 | * @param RepoGroup|null $repoGroup |
||
| 35 | 9 | */ |
|
| 36 | 9 | public function __construct( ApprovedRevsFacade $approvedRevsFacade, RepoGroup $repoGroup = null ) { |
|
| 37 | 9 | $this->approvedRevsFacade = $approvedRevsFacade; |
|
| 38 | 9 | $this->repoGroup = $repoGroup; |
|
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @since 1.0 |
||
| 43 | * |
||
| 44 | * @param Title $title |
||
| 45 | * @param integer $latestRevID |
||
| 46 | * |
||
| 47 | * @return boolean |
||
| 48 | 4 | */ |
|
| 49 | public function isApprovedUpdate( Title $title, $latestRevID ) { |
||
| 50 | 4 | ||
| 51 | 1 | if ( !$this->approvedRevsFacade->hasApprovedRevision( $title ) ) { |
|
| 52 | return true; |
||
| 53 | } |
||
| 54 | 3 | ||
| 55 | 2 | if ( ( $approvedRevID = $this->approvedRevsFacade->getApprovedRevID( $title ) ) !== null ) { |
|
| 56 | return $approvedRevID == $latestRevID; |
||
| 57 | } |
||
| 58 | 1 | ||
| 59 | return true; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @since 1.0 |
||
| 64 | * |
||
| 65 | * @param Title $title |
||
| 66 | * @param ?RevisionStoreRecord &$revision |
||
| 67 | 1 | */ |
|
| 68 | public function doChangeRevision( Title $title, ?RevisionStoreRecord &$revision ) { |
||
| 69 | |||
| 70 | // Forcibly change the revision to match what ApprovedRevs sees as |
||
| 71 | 1 | // approved |
|
| 72 | 1 | if ( ( $approvedRevID = $this->approvedRevsFacade->getApprovedRevID( $title ) ) !== null ) { |
|
| 73 | $approvedRev = MediaWikiServices::getInstance() |
||
| 74 | 1 | ->getRevisionLookup()->getRevisionById( $approvedRevID ); |
|
| 75 | if ( $approvedRev instanceof RevisionStoreRecord ) { |
||
| 76 | $revision = $approvedRev; |
||
| 77 | } |
||
| 78 | 1 | } |
|
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @since 1.0 |
||
| 83 | * |
||
| 84 | * @param Title $title |
||
| 85 | * @param integer &$revisionID |
||
| 86 | 1 | */ |
|
| 87 | public function doChangeRevisionID( Title $title, &$revisionID ) { |
||
| 88 | 1 | ||
| 89 | 1 | if ( ( $approvedRevID = $this->approvedRevsFacade->getApprovedRevID( $title ) ) !== null ) { |
|
| 90 | $revisionID = $approvedRevID; |
||
| 91 | 1 | } |
|
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @since 1.0 |
||
| 96 | * |
||
| 97 | * @param Title $title |
||
| 98 | * @param File &$file |
||
| 99 | 2 | */ |
|
| 100 | public function doChangeFile( Title $title, &$file ) { |
||
| 101 | |||
| 102 | // It has been observed that when running `runJobs.php` with `--wait` |
||
| 103 | // the `ApprovedRevs` instance holds an outdated cache entry therefore |
||
| 104 | 2 | // clear the static before trying to get the info |
|
| 105 | $this->approvedRevsFacade->clearApprovedFileInfo( $title ); |
||
| 106 | 2 | ||
| 107 | 2 | list( $timestamp, $file_sha1 ) = $this->approvedRevsFacade->getApprovedFileInfo( |
|
| 108 | $title |
||
| 109 | ); |
||
| 110 | 2 | ||
| 111 | 1 | if ( $file_sha1 === false ) { |
|
| 112 | return true; |
||
| 113 | } |
||
| 114 | 1 | ||
| 115 | if ( $this->repoGroup === null ) { |
||
| 116 | $this->repoGroup = RepoGroup::singleton(); |
||
| 117 | } |
||
| 118 | 1 | ||
| 119 | $localRepo = $this->repoGroup->getLocalRepo(); |
||
| 120 | |||
| 121 | 1 | // Retrievalable from the archive? |
|
| 122 | $file = OldLocalFile::newFromKey( $file_sha1, $localRepo, $timestamp ); |
||
| 123 | |||
| 124 | 1 | // Try the local repo! |
|
| 125 | 1 | if ( $file === false ) { |
|
| 126 | 1 | $files = $localRepo->findBySha1( $file_sha1 ); |
|
| 127 | $file = end( $files ); |
||
| 128 | } |
||
| 129 | 1 | ||
| 130 | 1 | if ( $file instanceof File ) { |
|
| 131 | $file->file_sha1 = $file_sha1; |
||
| 132 | 1 | } |
|
| 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