/** * Callback for usort() to do title sorts by (namespace, title) * * @param LinkTarget $a * @param LinkTarget $b * * @return int Result of string comparison, or namespace comparison */ public static function compare(LinkTarget $a, LinkTarget $b) { if ($a->getNamespace() == $b->getNamespace()) { return strcmp($a->getText(), $b->getText()); } else { return $a->getNamespace() - $b->getNamespace(); } }
private function verifyCallbackJob($callback, LinkTarget $expectedTitle, $expectedUserId, callable $notificationTimestampCondition) { $this->assertInternalType('callable', $callback); $callbackReflector = new ReflectionFunction($callback); $vars = $callbackReflector->getStaticVariables(); $this->assertArrayHasKey('job', $vars); $this->assertInstanceOf(ActivityUpdateJob::class, $vars['job']); /** @var ActivityUpdateJob $job */ $job = $vars['job']; $this->assertEquals($expectedTitle->getDBkey(), $job->getTitle()->getDBkey()); $this->assertEquals($expectedTitle->getNamespace(), $job->getTitle()->getNamespace()); $jobParams = $job->getParams(); $this->assertArrayHasKey('type', $jobParams); $this->assertEquals('updateWatchlistNotification', $jobParams['type']); $this->assertArrayHasKey('userid', $jobParams); $this->assertEquals($expectedUserId, $jobParams['userid']); $this->assertArrayHasKey('notifTime', $jobParams); $this->assertTrue($notificationTimestampCondition($jobParams['notifTime'])); }
/** * @param LinkTarget $target * @param string|HtmlArmor|null $text * @param array $extraAttribs * @param array $query * @return string */ public function makeKnownLink(LinkTarget $target, $text = null, array $extraAttribs = [], array $query = []) { $classes = []; if ($target->isExternal()) { $classes[] = 'extiw'; } $colour = Linker::getLinkColour($target, $this->stubThreshold); if ($colour !== '') { $classes[] = $colour; } return $this->makePreloadedLink($target, $text, $classes ? implode(' ', $classes) : '', $extraAttribs, $query); }
/** * Return a wrapper for a series of database rows to * fetch all of a given page's revisions in turn. * Each row can be fed to the constructor to get objects. * * @param LinkTarget $title * @return ResultWrapper * @deprecated Since 1.28 */ public static function fetchRevision(LinkTarget $title) { $row = self::fetchFromConds(wfGetDB(DB_REPLICA), ['rev_id=page_latest', 'page_namespace' => $title->getNamespace(), 'page_title' => $title->getDBkey()]); return new FakeResultWrapper($row ? [$row] : []); }
/** * @see TitleFormatter::getText() * * @param LinkTarget $title * * @return string */ public function getFullText(LinkTarget $title) { return $this->formatTitle($title->getNamespace(), $title->getText(), $title->getFragment(), $title->getInterwiki()); }
/** * Check if the given title already is watched by the user, and if so * add a watch for the new title. * * To be used for page renames and such. * This must be called separately for Subject and Talk pages * * @param LinkTarget $oldTarget * @param LinkTarget $newTarget */ public function duplicateEntry(LinkTarget $oldTarget, LinkTarget $newTarget) { $dbw = $this->getConnectionRef(DB_MASTER); $result = $dbw->select('watchlist', ['wl_user', 'wl_notificationtimestamp'], ['wl_namespace' => $oldTarget->getNamespace(), 'wl_title' => $oldTarget->getDBkey()], __METHOD__, ['FOR UPDATE']); $newNamespace = $newTarget->getNamespace(); $newDBkey = $newTarget->getDBkey(); # Construct array to replace into the watchlist $values = []; foreach ($result as $row) { $values[] = ['wl_user' => $row->wl_user, 'wl_namespace' => $newNamespace, 'wl_title' => $newDBkey, 'wl_notificationtimestamp' => $row->wl_notificationtimestamp]; } if (!empty($values)) { # Perform replace # Note that multi-row replace is very efficient for MySQL but may be inefficient for # some other DBMSes, mostly due to poor simulation by us $dbw->replace('watchlist', [['wl_user', 'wl_namespace', 'wl_title']], $values, __METHOD__); } }
/** * Move a page * * @param integer $id The page_id * @param LinkTarget $newLinkTarget The new title link target * @return bool */ private function movePage($id, LinkTarget $newLinkTarget) { $this->db->update('page', ["page_namespace" => $newLinkTarget->getNamespace(), "page_title" => $newLinkTarget->getDBkey()], ["page_id" => $id], __METHOD__); // Update *_from_namespace in links tables $fromNamespaceTables = [['pagelinks', 'pl'], ['templatelinks', 'tl'], ['imagelinks', 'il']]; foreach ($fromNamespaceTables as $tableInfo) { list($table, $fieldPrefix) = $tableInfo; $this->db->update($table, ["{$fieldPrefix}_from_namespace" => $newLinkTarget->getNamespace()], ["{$fieldPrefix}_from" => $id], __METHOD__); } return true; }
/** * Creates a query condition part for getting only items before or after the given link target * (while ordering using $sort mode) * * @param IDatabase $db * @param LinkTarget $target * @param string $op comparison operator to use in the conditions * @return string */ private function getFromUntilTargetConds(IDatabase $db, LinkTarget $target, $op) { return $db->makeList(["wl_namespace {$op} " . $target->getNamespace(), $db->makeList(['wl_namespace = ' . $target->getNamespace(), "wl_title {$op}= " . $db->addQuotes($target->getDBkey())], LIST_AND)], LIST_OR); }
private function isCacheable(LinkTarget $title) { return $title->inNamespace(NS_TEMPLATE) || $title->inNamespace(NS_FILE); }
/** * @since 1.16.3 * @param LinkTarget $target * @return LinkTarget|Title You will get back the same type you passed in, or a Title object */ public static function normaliseSpecialPage(LinkTarget $target) { if ($target->getNamespace() == NS_SPECIAL) { list($name, $subpage) = SpecialPageFactory::resolveAlias($target->getDBkey()); if (!$name) { return $target; } $ret = SpecialPage::getTitleFor($name, $subpage, $target->getFragment()); return $ret; } else { return $target; } }
/** * Create a new Title from a LinkTarget * * @param LinkTarget $linkTarget Assumed to be safe. * * @return Title */ public static function newFromLinkTarget(LinkTarget $linkTarget) { if ($linkTarget instanceof Title) { // Special case if it's already a Title object return $linkTarget; } return self::makeTitle($linkTarget->getNamespace(), $linkTarget->getText(), $linkTarget->getFragment(), $linkTarget->getInterwiki()); }
/** * Load either the current, or a specified, revision * that's attached to a given link target. If not attached * to that link target, will return null. * * $flags include: * Revision::READ_LATEST : Select the data from the master * Revision::READ_LOCKING : Select & lock the data from the master * * @param LinkTarget $linkTarget * @param int $id (optional) * @param int $flags Bitfield (optional) * @return Revision|null */ public static function newFromTitle(LinkTarget $linkTarget, $id = 0, $flags = 0) { $conds = ['page_namespace' => $linkTarget->getNamespace(), 'page_title' => $linkTarget->getDBkey()]; if ($id) { // Use the specified ID $conds['rev_id'] = $id; return self::newFromConds($conds, $flags); } else { // Use a join to get the latest revision $conds[] = 'rev_id=page_latest'; $db = wfGetDB($flags & self::READ_LATEST ? DB_MASTER : DB_SLAVE); return self::loadFromConds($db, $conds, $flags); } }