Rush has submitted this change and it was merged.
Change subject: Make the mediawiki userpage field searchable.
......................................................................
Make the mediawiki userpage field searchable.
Bug: T783
Change-Id: I686f4301cff09650bab19a5b86d91633b003a538
---
M MediaWikiUserpageCustomField.php
1 file changed, 101 insertions(+), 6 deletions(-)
Approvals:
Rush: Verified; Looks good to me, approved
diff --git a/MediaWikiUserpageCustomField.php b/MediaWikiUserpageCustomField.php
index 9e18d03..e37ddd7 100644
--- a/MediaWikiUserpageCustomField.php
+++ b/MediaWikiUserpageCustomField.php
@@ -1,6 +1,7 @@
<?php
final class MediaWikiUserpageCustomField extends PhabricatorUserCustomField {
+ protected $externalAccount;
public function shouldUseStorage() {
return false;
@@ -10,21 +11,51 @@
return 'mediawiki:externalaccount';
}
+ public function getFieldName() {
+ return pht("MediaWiki Userpage");
+ }
+
+ public function getFieldValue() {
+ $account = $this->getExternalAccount();
+
+ if (! $account || !strlen($account->getAccountURI())) {
+ return null;
+ }
+
+ $uri = urldecode($account->getAccountURI());
+
+ // Split on the User: part of the userpage uri
+ $name = explode('User:',$uri);
+ // grab the part after User:
+ $name = array_pop($name);
+ // decode for display:
+ $name = urldecode(rawurldecode($name));
+
+ return $name;
+ }
+
+ protected function getExternalAccount() {
+ if (!$this->externalAccount) {
+ $user = $this->getObject();
+ $this->externalAccount = id(new
PhabricatorExternalAccount())->loadOneWhere(
+ 'userPHID = %s AND accountType = %s',
+ $user->getPHID(),
+ 'mediawiki');
+ }
+ return $this->externalAccount;
+ }
+
public function shouldAppearInPropertyView() {
return true;
}
public function renderPropertyViewLabel() {
- return pht('MediaWiki Userpage');
+ return $this->getFieldName();
}
public function renderPropertyViewValue(array $handles) {
- $user = $this->getObject();
- $account = id(new PhabricatorExternalAccount())->loadOneWhere(
- 'userPHID = %s AND accountType = %s',
- $user->getPHID(),
- 'mediawiki');
+ $account = $this->getExternalAccount();
if (! $account || !strlen($account->getAccountURI())) {
return pht('Unknown');
@@ -47,4 +78,68 @@
$name);
}
+
+ public function shouldAppearInApplicationSearch() {
+ return true;
+ }
+
+
+ public function getFieldType() {
+ return 'text';
+ }
+
+ public function buildFieldIndexes() {
+ $indexes = array();
+
+ $value = $this->getFieldValue();
+ if (strlen($value)) {
+ $indexes[] = $this->newStringIndex($value);
+ $indexes[] =
$this->newStringIndex(urldecode($this->getExternalAccount()->getAccountURI()));
+ $parts = explode(' ',$value);
+ if (count($parts) > 1) {
+ foreach($parts as $part) {
+ $indexes[] = $this->newStringIndex($part);
+ }
+ }
+ }
+
+ return $indexes;
+ }
+
+ public function readApplicationSearchValueFromRequest(
+ PhabricatorApplicationSearchEngine $engine,
+ AphrontRequest $request) {
+
+ return $request->getStr($this->getFieldKey());
+ }
+
+ public function applyApplicationSearchConstraintToQuery(
+ PhabricatorApplicationSearchEngine $engine,
+ PhabricatorCursorPagedPolicyAwareQuery $query,
+ $value) {
+
+ if (strlen($value)) {
+ $query->withApplicationSearchContainsConstraint(
+ $this->newStringIndex(null),
+ $value);
+ }
+ }
+
+ public function appendToApplicationSearchForm(
+ PhabricatorApplicationSearchEngine $engine,
+ AphrontFormView $form,
+ $value,
+ array $handles) {
+
+ $form->appendChild(
+ id(new AphrontFormTextControl())
+ ->setLabel($this->getFieldName())
+ ->setName($this->getFieldKey())
+ ->setValue($value));
+ }
+
+ protected function newStringIndexStorage() {
+ return new PhabricatorUserCustomFieldStringIndex();
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/165985
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I686f4301cff09650bab19a5b86d91633b003a538
Gerrit-PatchSet: 3
Gerrit-Project: phabricator/extensions
Gerrit-Branch: master
Gerrit-Owner: 20after4 <[email protected]>
Gerrit-Reviewer: 20after4 <[email protected]>
Gerrit-Reviewer: Aklapper <[email protected]>
Gerrit-Reviewer: Qgil <[email protected]>
Gerrit-Reviewer: Rush <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits