| 1 | <?php |
||
| 15 | class ProjectRepository extends Repository |
||
| 16 | { |
||
| 17 | |||
| 18 | /** @var array Project metadata. */ |
||
| 19 | protected $metadata; |
||
| 20 | |||
| 21 | /** @var string[] Metadata if XTools is in single-wiki mode. */ |
||
| 22 | protected $singleMetadata; |
||
| 23 | |||
| 24 | /** @var string The cache key for the 'all project' metadata. |
||
| 25 | */ |
||
| 26 | protected $cacheKeyAllProjects = 'allprojects'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Convenience method to get a new Project object based on a given identification string. |
||
| 30 | * @param string $projectIdent The domain name, database name, or URL of a project. |
||
| 31 | * @param ContainerInterface $container Symfony's container. |
||
| 32 | * @return Project |
||
| 33 | */ |
||
| 34 | public static function getProject($projectIdent, ContainerInterface $container) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Get the XTools default project. |
||
| 51 | * @param ContainerInterface $container |
||
| 52 | * @return Project |
||
| 53 | */ |
||
| 54 | public static function getDefaultProject(ContainerInterface $container) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Get the global 'meta' project, which is either Meta (if this is Labs) or the default project. |
||
| 62 | * @return Project |
||
| 63 | */ |
||
| 64 | public function getGlobalProject() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * For single-wiki installations, you must manually set the wiki URL and database name |
||
| 75 | * (because there's no meta.wiki database to query). |
||
| 76 | * @param $metadata |
||
| 77 | * @throws \Exception |
||
| 78 | */ |
||
| 79 | public function setSingleMetadata($metadata) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Get metadata about all projects. |
||
| 90 | * @return string[] Each item has 'dbname' and 'url' keys. |
||
| 91 | */ |
||
| 92 | public function getAll() |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Get metadata about one project. |
||
| 124 | * @param string $project A project URL, domain name, or database name. |
||
| 125 | * @return string[] With 'dbname' and 'url' keys. |
||
| 126 | */ |
||
| 127 | public function getOne($project) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Get metadata about a project. |
||
| 180 | * |
||
| 181 | * @param string $projectUrl The project's URL. |
||
| 182 | * @return array With 'general' and 'namespaces' keys: the former contains 'wikiName', |
||
| 183 | * 'wikiId', 'url', 'lang', 'articlePath', 'scriptPath', 'script', 'timezone', and |
||
| 184 | * 'timezoneOffset'; the latter contains all namespace names, keyed by their IDs. |
||
| 185 | */ |
||
| 186 | public function getMetadata($projectUrl) |
||
| 187 | { |
||
| 188 | if ($this->metadata) { |
||
| 189 | return $this->metadata; |
||
| 190 | } |
||
| 191 | |||
| 192 | $api = MediawikiApi::newFromPage($projectUrl); |
||
| 193 | |||
| 194 | $params = ['meta' => 'siteinfo', 'siprop' => 'general|namespaces']; |
||
| 195 | $query = new SimpleRequest('query', $params); |
||
| 196 | |||
| 197 | $this->metadata = [ |
||
| 198 | 'general' => [], |
||
| 199 | 'namespaces' => [], |
||
| 200 | ]; |
||
| 201 | |||
| 202 | $res = $api->getRequest($query); |
||
| 203 | |||
| 204 | if (isset($res['query']['general'])) { |
||
| 205 | $info = $res['query']['general']; |
||
| 206 | $this->metadata['general'] = [ |
||
| 207 | 'wikiName' => $info['sitename'], |
||
| 208 | 'wikiId' => $info['wikiid'], |
||
| 209 | 'url' => $info['server'], |
||
| 210 | 'lang' => $info['lang'], |
||
| 211 | 'articlePath' => $info['articlepath'], |
||
| 212 | 'scriptPath' => $info['scriptpath'], |
||
| 213 | 'script' => $info['script'], |
||
| 214 | 'timezone' => $info['timezone'], |
||
| 215 | 'timeOffset' => $info['timeoffset'], |
||
| 216 | ]; |
||
| 217 | |||
| 218 | // if ($this->container->getParameter('app.is_labs') && |
||
|
1 ignored issue
–
show
|
|||
| 219 | // substr($result['general']['dbName'], -2) != '_p' |
||
| 220 | // ) { |
||
| 221 | // $result['general']['dbName'] .= '_p'; |
||
| 222 | // } |
||
| 223 | } |
||
| 224 | |||
| 225 | if (isset($res['query']['namespaces'])) { |
||
| 226 | foreach ($res['query']['namespaces'] as $namespace) { |
||
| 227 | if ($namespace['id'] < 0) { |
||
| 228 | continue; |
||
| 229 | } |
||
| 230 | |||
| 231 | if (isset($namespace['name'])) { |
||
| 232 | $name = $namespace['name']; |
||
| 233 | } elseif (isset($namespace['*'])) { |
||
| 234 | $name = $namespace['*']; |
||
| 235 | } else { |
||
| 236 | continue; |
||
| 237 | } |
||
| 238 | |||
| 239 | // FIXME: Figure out a way to i18n-ize this |
||
| 240 | if ($name === '') { |
||
| 241 | $name = 'Article'; |
||
| 242 | } |
||
| 243 | |||
| 244 | $this->metadata['namespaces'][$namespace['id']] = $name; |
||
| 245 | } |
||
| 246 | } |
||
| 247 | |||
| 248 | return $this->metadata; |
||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Get a list of projects that have opted in to having all their users' restricted statistics |
||
| 253 | * available to anyone. |
||
| 254 | * |
||
| 255 | * @return string[] |
||
| 256 | */ |
||
| 257 | public function optedIn() |
||
| 266 | |||
| 267 | /** |
||
| 268 | * The path to api.php |
||
| 269 | * |
||
| 270 | * @return string |
||
| 271 | */ |
||
| 272 | public function getApiPath() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Get a page from the given Project. |
||
| 279 | * @param Project $project The project. |
||
| 280 | * @param string $pageName The name of the page. |
||
| 281 | * @return Page |
||
| 282 | */ |
||
| 283 | public function getPage(Project $project, $pageName) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Check to see if a page exists on this project and has some content. |
||
| 294 | * @param Project $project The project. |
||
| 295 | * @param int $namespaceId The page namespace ID. |
||
| 296 | * @param string $pageTitle The page title, without namespace. |
||
| 297 | * @return bool |
||
| 298 | */ |
||
| 299 | public function pageHasContent(Project $project, $namespaceId, $pageTitle) |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Get page assessments configuration for this project |
||
| 317 | * and cache in static variable. |
||
| 318 | * @param string $projectDomain The project domain such as en.wikipedia.org |
||
| 319 | * @return string[]|bool As defined in config/assessments.yml, |
||
| 320 | * or false if none exists |
||
| 321 | */ |
||
| 322 | public function getAssessmentsConfig($projectDomain) |
||
| 339 | } |
||
| 340 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.