MaxSem has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/339766 )
Change subject: Cleanup ...................................................................... Cleanup * Fix method name case * Fix PHPDoc * Add parameter types * Remove `return true` from hook handlers Change-Id: Ic993572d64f873f1c0262d7e695298f755268b7f --- M includes/ApiQueryGlobalUsage.php M includes/GlobalUsage.php M includes/GlobalUsageCachePurgeJob.php M includes/GlobalUsageHooks.php M includes/GlobalUsageImagePageHooks.php M includes/GlobalUsageQuery.php M includes/SpecialGlobalUsage.php M includes/SpecialGloballyWantedFiles.php M includes/SpecialMostGloballyLinkedFiles.php 9 files changed, 104 insertions(+), 110 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GlobalUsage refs/changes/66/339766/1 diff --git a/includes/ApiQueryGlobalUsage.php b/includes/ApiQueryGlobalUsage.php index 1361d87..6870b51 100644 --- a/includes/ApiQueryGlobalUsage.php +++ b/includes/ApiQueryGlobalUsage.php @@ -68,7 +68,7 @@ ]; if ( isset( $prop['url'] ) ) { /* We expand the url because we don't want protocol relative urls in API results */ - $result['url'] = wfExpandUrl( WikiMap::getForeignUrl( $item['wiki'], $title ), PROTO_CURRENT ); + $result['url'] = wfExpandUrl( WikiMap::getForeignURL( $item['wiki'], $title ), PROTO_CURRENT ); } if ( isset( $prop['pageid'] ) ) { $result['pageid'] = $item['id']; diff --git a/includes/GlobalUsage.php b/includes/GlobalUsage.php index 9524221..6233678 100644 --- a/includes/GlobalUsage.php +++ b/includes/GlobalUsage.php @@ -23,8 +23,8 @@ /** * Construct a GlobalUsage instance for a certain wiki. * - * @param $interwiki string Interwiki prefix of the wiki - * @param $db IDatabase Database object + * @param string $interwiki Interwiki prefix of the wiki + * @param IDatabase $db Database object */ public function __construct( $interwiki, IDatabase $db ) { $this->interwiki = $interwiki; @@ -34,10 +34,10 @@ /** * Sets the images used by a certain page * - * @param $title Title Title of the page - * @param $images array Array of db keys of images used - * @param $pageIdFlags int - * @param $ticket int|null + * @param Title $title Page title + * @param array $images Array of db keys of images used + * @param int $pageIdFlags + * @param int|null $ticket */ public function insertLinks( Title $title, array $images, $pageIdFlags = Title::GAID_FOR_UPDATE, $ticket = null @@ -66,7 +66,7 @@ /** * Get all global images from a certain page - * @param $id int + * @param int $id * @return array */ public function getLinksFromPage( $id ) { @@ -91,9 +91,9 @@ /** * Deletes all entries from a certain page to certain files * - * @param $id int Page id of the page - * @param $to mixed File name(s) - * @param $ticket int|null + * @param int $id Page id of the page + * @param array|null $to File name(s) + * @param int|null $ticket */ public function deleteLinksFromPage( $id, array $to = null, $ticket = null ) { global $wgUpdateRowsPerQuery; @@ -118,9 +118,9 @@ /** * Deletes all entries to a certain image * - * @param $title Title Title of the file + * @param Title $title File title */ - public function deleteLinksToFile( $title ) { + public function deleteLinksToFile( Title $title ) { $this->db->delete( 'globalimagelinks', [ @@ -134,7 +134,7 @@ /** * Copy local links to global table * - * @param $title Title Title of the file to copy entries from. + * @param Title $title File to copy entries from */ public function copyLocalImagelinks( Title $title ) { global $wgContLang; @@ -158,19 +158,18 @@ ]; } - $fname = __METHOD__; - DeferredUpdates::addCallableUpdate( function () use ( $insert, $fname ) { - $this->db->insert( 'globalimagelinks', $insert, $fname, [ 'IGNORE' ] ); + DeferredUpdates::addCallableUpdate( function () use ( $insert ) { + $this->db->insert( 'globalimagelinks', $insert, __METHOD__, [ 'IGNORE' ] ); } ); } /** * Changes the page title * - * @param $id int Page id of the page - * @param $title Title New title of the page + * @param int $id Page id + * @param Title $title New page title */ - public function moveTo( $id, $title ) { + public function moveTo( $id, Title $title ) { $this->db->update( 'globalimagelinks', [ @@ -228,7 +227,7 @@ * @note This assumes the user has a single shared repo. If the user has * multiple/nested foreign repos, then its unclear what it means to * be on the "shared repo". See discussion on bug 23136. - * @return boolean + * @return bool */ public static function onSharedRepo() { global $wgGlobalUsageSharedRepoWiki, $wgGlobalUsageDatabase; @@ -297,7 +296,7 @@ } /** - * @param integer $index DB_MASTER/DB_REPLICA + * @param int $index DB_MASTER/DB_REPLICA * @param array $groups * @return IDatabase */ diff --git a/includes/GlobalUsageCachePurgeJob.php b/includes/GlobalUsageCachePurgeJob.php index 9d90edf..015f9da 100644 --- a/includes/GlobalUsageCachePurgeJob.php +++ b/includes/GlobalUsageCachePurgeJob.php @@ -13,6 +13,11 @@ * to be in sync, so the later can be used for the local jobs. */ class GlobalUsageCachePurgeJob extends Job { + /** + * @param Title $title + * @param array $params + * @param int $id + */ function __construct( $title, $params, $id = 0 ) { parent::__construct( 'globalUsageCachePurge', $title, $params, $id ); $this->removeDuplicates = true; // expensive @@ -27,12 +32,13 @@ $rootParams = Job::newRootJobParams( // "overall" purge job info "GlobalUsage:htmlCacheUpdate:imagelinks:{$title->getPrefixedText()}" ); - $filesForPurge = [ $title->getDbKey() ]; // title to purge backlinks to + $filesForPurge = [ $title->getDBkey() ]; // title to purge backlinks to // All File pages that redirect this one may have backlinks that need purging. // These backlinks are probably broken now (missing files or double redirects). + /** @var Title $redirTitle */ foreach ( $title->getBacklinkCache()->getLinks( 'redirect' ) as $redirTitle ) { if ( $redirTitle->getNamespace() == NS_FILE ) { - $filesForPurge[] = $redirTitle->getDbKey(); + $filesForPurge[] = $redirTitle->getDBkey(); } } // Remove any duplicates in case titles link to themselves diff --git a/includes/GlobalUsageHooks.php b/includes/GlobalUsageHooks.php index 5b89047..f9b8550 100644 --- a/includes/GlobalUsageHooks.php +++ b/includes/GlobalUsageHooks.php @@ -21,7 +21,8 @@ /** * Hook to LinksUpdateComplete * Deletes old links from usage table and insert new ones. - * @param $linksUpdater LinksUpdate + * + * @param LinksUpdate $linksUpdater * @param int|null $ticket * @return bool */ @@ -57,22 +58,19 @@ if ( $removed ) { $gu->deleteLinksFromPage( $articleId, $removed, $ticket ); } - - return true; } /** * Hook to TitleMoveComplete * Sets the page title in usage table to the new name. * For shared file moves, purges all pages in the wiki farm that use the files. - * @param $ot Title - * @param $nt Title - * @param $user User - * @param $pageid int - * @param $redirid - * @return bool + * @param Title $ot + * @param Title $nt + * @param User $user + * @param int $pageid + * @param int $redirid */ - public static function onTitleMoveComplete( $ot, $nt, $user, $pageid, $redirid ) { + public static function onTitleMoveComplete( Title $ot, Title $nt, User $user, $pageid, $redirid ) { $gu = self::getGlobalUsage(); $gu->moveTo( $pageid, $nt ); @@ -89,39 +87,35 @@ JobQueueGroup::singleton()->lazyPush( $jobs ); } ); } - - return true; } /** * Hook to ArticleDeleteComplete * Deletes entries from usage table. - * @param $article Article - * @param $user User - * @param $reason string - * @param $id int - * @return bool + * + * @param Article $article + * @param User $user + * @param string $reason + * @param int $id */ - public static function onArticleDeleteComplete( $article, $user, $reason, $id ) { + public static function onArticleDeleteComplete( Article $article, User $user, $reason, $id ) { $gu = self::getGlobalUsage(); // @FIXME: avoid making DB replication lag $gu->deleteLinksFromPage( $id ); - - return true; } /** * Hook to FileDeleteComplete * Copies the local link table to the global. * Purges all pages in the wiki farm that use the file if it is a shared repo file. - * @param $file File + * + * @param File $file * @param $oldimage - * @param $article Article - * @param $user User - * @param $reason string - * @return bool + * @param Article $article + * @param User $user + * @param string $reason */ - public static function onFileDeleteComplete( $file, $oldimage, $article, $user, $reason ) { + public static function onFileDeleteComplete( File $file, $oldimage, $article, $user, $reason ) { if ( !$oldimage ) { $gu = self::getGlobalUsage(); $gu->copyLocalImagelinks( $file->getTitle() ); @@ -131,19 +125,17 @@ JobQueueGroup::singleton()->push( $job ); } } - - return true; } /** * Hook to FileUndeleteComplete * Deletes the file from the global link table. * Purges all pages in the wiki farm that use the file if it is a shared repo file. - * @param $title Title + * + * @param Title $title * @param $versions - * @param $user User - * @param $reason string - * @return bool + * @param User $user + * @param string $reason */ public static function onFileUndeleteComplete( $title, $versions, $user, $reason ) { $gu = self::getGlobalUsage(); @@ -153,16 +145,14 @@ $job = new GlobalUsageCachePurgeJob( $title, [] ); JobQueueGroup::singleton()->push( $job ); } - - return true; } /** * Hook to UploadComplete * Deletes the file from the global link table. + * * Purges all pages in the wiki farm that use the file if it is a shared repo file. - * @param $upload File - * @return bool + * @param File $upload */ public static function onUploadComplete( $upload ) { $gu = self::getGlobalUsage(); @@ -172,8 +162,6 @@ $job = new GlobalUsageCachePurgeJob( $upload->getTitle(), [] ); JobQueueGroup::singleton()->push( $job ); } - - return true; } /** @@ -185,7 +173,7 @@ private static function fileUpdatesCreatePurgeJobs() { global $wgGlobalUsageSharedRepoWiki, $wgGlobalUsagePurgeBacklinks; - return ( $wgGlobalUsagePurgeBacklinks && wfWikiId() === $wgGlobalUsageSharedRepoWiki ); + return ( $wgGlobalUsagePurgeBacklinks && wfWikiID() === $wgGlobalUsageSharedRepoWiki ); } /** @@ -199,19 +187,17 @@ /** * Hook to make sure globalimagelinks table gets duplicated for parsertests - * @param $tables array - * @return bool + * + * @param array $tables */ public static function onParserTestTables( &$tables ) { $tables[] = 'globalimagelinks'; - return true; } /** * Hook to apply schema changes * * @param $updater DatabaseUpdater - * @return bool */ public static function onLoadExtensionSchemaUpdates( $updater = null ) { $dir = dirname( __DIR__ ) . '/patches'; @@ -227,12 +213,10 @@ $updater->addExtensionUpdate( [ 'addIndex', 'globalimagelinks', 'globalimagelinks_wiki_nsid_title', "$dir/patch-globalimagelinks_wiki_nsid_title.pg.sql", true ] ); } - return true; } public static function onwgQueryPages( &$queryPages ) { $queryPages[] = [ 'GlobalUsage\MostGloballyLinkedFilesPage', 'MostGloballyLinkedFiles' ]; $queryPages[] = [ 'GlobalUsage\SpecialGloballyWantedFiles', 'GloballyWantedFiles' ]; - return true; } } diff --git a/includes/GlobalUsageImagePageHooks.php b/includes/GlobalUsageImagePageHooks.php index 341fe8d..f790906 100644 --- a/includes/GlobalUsageImagePageHooks.php +++ b/includes/GlobalUsageImagePageHooks.php @@ -37,13 +37,12 @@ /** * Show a global usage section on the image page * - * @param $imagePage ImagePage + * @param ImagePage $imagePage * @param string $html HTML to add to the image page as global usage section - * @return bool */ - public static function onImagePageAfterImageLinks( $imagePage, &$html ) { + public static function onImagePageAfterImageLinks( ImagePage $imagePage, &$html ) { if ( !self::hasResults( $imagePage ) ) { - return true; + return; } $context = $imagePage->getContext(); @@ -74,33 +73,30 @@ } $html .= '</div>'; } - - return true; } /** * Show a link to the global image links in the TOC if there are any results available. - * @param $imagePage ImagePage - * @param $toc array - * @return bool + * + * @param ImagePage $imagePage + * @param array $toc */ - public static function onImagePageShowTOC( $imagePage, &$toc ) { + public static function onImagePageShowTOC( ImagePage $imagePage, array &$toc ) { if ( self::hasResults( $imagePage ) ) { # Insert a link after the 3rd entry in the TOC array_splice( $toc, 3, 0, '<li><a href="#globalusage">' . $imagePage->getContext()->msg( 'globalusage' )->escaped() . '</a></li>' ); } - return true; } /** * Check whether there are results for an image page. Checks whether the * file exists and is not local. * - * @param $imagePage ImagePage + * @param ImagePage $imagePage * @return bool */ - protected static function hasResults( $imagePage ) { + protected static function hasResults( ImagePage $imagePage ) { # Don't display links if the target file does not exist $file = $imagePage->getFile(); if ( !$file->exists() ) { diff --git a/includes/GlobalUsageQuery.php b/includes/GlobalUsageQuery.php index cc2808f..f230628 100644 --- a/includes/GlobalUsageQuery.php +++ b/includes/GlobalUsageQuery.php @@ -1,6 +1,7 @@ <?php namespace GlobalUsage; + use IDatabase; use Title; @@ -29,8 +30,8 @@ private $lastRow; /** - * @param $target mixed Title or array of db keys of target(s). - * If a title, can be a category or a file + * @param mixed $target Title or array of db keys of target(s). + * If a title, can be a category or a file */ public function __construct( $target ) { $this->db = GlobalUsage::getGlobalDB( DB_REPLICA ); @@ -48,8 +49,8 @@ /** * Set the offset parameter * - * @param $offset string offset - * @param $reversed bool True if this is the upper offset + * @param string $offset offset + * @param bool $reversed True if this is the upper offset * @return bool */ public function setOffset( $offset, $reversed = null ) { @@ -112,6 +113,7 @@ /** * Returns the user set limit + * * @return int */ public function getLimit() { @@ -120,7 +122,8 @@ /** * Set whether to filter out the local usage - * @param $value bool + * + * @param bool $value */ public function filterLocal( $value = true ) { $this->filterLocal = $value; @@ -139,7 +142,7 @@ $queryIn = $this->target; } else { // a Title object $namespace = $this->target->getNamespace(); - $queryIn = $this->target->getDbKey(); + $queryIn = $this->target->getDBkey(); } switch ( $namespace ) { case NS_FILE: @@ -161,7 +164,7 @@ if ( $this->filterLocal ) { // Don't show local file usage - $where[] = 'gil_wiki != ' . $this->db->addQuotes( wfWikiId() ); + $where[] = 'gil_wiki != ' . $this->db->addQuotes( wfWikiID() ); } $options = [ diff --git a/includes/SpecialGlobalUsage.php b/includes/SpecialGlobalUsage.php index 10c70c8..4561a78 100644 --- a/includes/SpecialGlobalUsage.php +++ b/includes/SpecialGlobalUsage.php @@ -37,7 +37,8 @@ /** * Entry point - * @param $par String + * + * @param string $par */ public function execute( $par ) { $target = $par ? $par : $this->getRequest()->getVal( 'target' ); @@ -150,7 +151,7 @@ /* $handlerParams */ [], /* $framed */ false, /* $manualThumb */ false ); - $this->getOutput()->addHtml( $html ); + $this->getOutput()->addHTML( $html ); } } @@ -184,30 +185,31 @@ $out = $this->getOutput(); // Top navbar - $out->addHtml( $navbar ); + $out->addHTML( $navbar ); - $out->addHtml( '<div id="mw-globalusage-result">' ); + $out->addHTML( '<div id="mw-globalusage-result">' ); foreach ( $query->getSingleImageResult() as $wiki => $result ) { - $out->addHtml( + $out->addHTML( '<h2>' . $this->msg( 'globalusage-on-wiki', $targetName, WikiMap::getWikiName( $wiki ) )->parse() . "</h2><ul>\n" ); foreach ( $result as $item ) { - $out->addHtml( "\t<li>" . self::formatItem( $item ) . "</li>\n" ); + $out->addHTML( "\t<li>" . self::formatItem( $item ) . "</li>\n" ); } - $out->addHtml( "</ul>\n" ); + $out->addHTML( "</ul>\n" ); } - $out->addHtml( '</div>' ); + $out->addHTML( '</div>' ); // Bottom navbar - $out->addHtml( $navbar ); + $out->addHTML( $navbar ); } /** * Helper to format a specific item - * @param $item array - * @return String + * + * @param array $item + * @return string */ public static function formatItem( $item ) { if ( !$item['namespace'] ) { @@ -225,10 +227,10 @@ /** * Helper function to create the navbar, stolen from wfViewPrevNext * - * @param $query GlobalUsageQuery An executed GlobalUsageQuery object + * @param GlobalUsageQuery $query An executed GlobalUsageQuery object * @return string Navbar HTML */ - protected function getNavBar( $query ) { + protected function getNavBar( GlobalUsageQuery $query ) { $target = $this->target->getText(); $limit = $query->getLimit(); diff --git a/includes/SpecialGloballyWantedFiles.php b/includes/SpecialGloballyWantedFiles.php index 020d905..8083387 100644 --- a/includes/SpecialGloballyWantedFiles.php +++ b/includes/SpecialGloballyWantedFiles.php @@ -29,6 +29,8 @@ /** * Main execution function. Use the parent if we're on the right wiki. * If we're not on a shared repo, try to redirect there. + * + * @param string $par */ function execute( $par ) { global $wgGlobalUsageSharedRepoWiki; @@ -42,7 +44,7 @@ /** * Output an extra header * - * @return String html to output + * @return string html to output */ function getPageHeader() { if ( RepoGroup::singleton()->hasForeignRepos() ) { @@ -60,7 +62,8 @@ * Also make sure that GlobalUsage db same as shared repo. * (To catch the unlikely case where GlobalUsage db is different db from the * shared repo db). - * @return boolean + * + * @return bool */ function isCacheable() { global $wgGlobalUsageDatabase; @@ -71,7 +74,7 @@ /** * Only list this special page on the wiki that is the shared repo. * - * @return boolean Should this be listed in Special:SpecialPages + * @return bool Should this be listed in Special:SpecialPages */ function isListed() { return GlobalUsage::onSharedRepo(); @@ -87,9 +90,9 @@ * We need to override this in order to link to Special:GlobalUsage * instead of Special:WhatLinksHere. * - * @param $skin Skin - * @param $result stdClass A row from the database - * @return String HTML to output + * @param Skin $skin + * @param stdClass $result A row from the database + * @return string HTML to output */ public function formatResult( $skin, $result ) { // If some of the client wikis are $wgCapitalLinks = false diff --git a/includes/SpecialMostGloballyLinkedFiles.php b/includes/SpecialMostGloballyLinkedFiles.php index aeeeb6c..97ce0d5 100644 --- a/includes/SpecialMostGloballyLinkedFiles.php +++ b/includes/SpecialMostGloballyLinkedFiles.php @@ -35,7 +35,8 @@ /** * Don't want to do cached handling on non-shared repo, since we only redirect. - * @return boolean + * + * @return bool */ function isCacheable() { return GlobalUsage::onSharedRepo(); @@ -76,7 +77,7 @@ /** * Only list this special page on the wiki that is the shared repo. * - * @return boolean Should this be listed in Special:SpecialPages + * @return bool Should this be listed in Special:SpecialPages */ function isListed() { return GlobalUsage::onSharedRepo(); -- To view, visit https://gerrit.wikimedia.org/r/339766 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic993572d64f873f1c0262d7e695298f755268b7f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/GlobalUsage Gerrit-Branch: master Gerrit-Owner: MaxSem <maxsem.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits