/** * Determine ACL definition page title by protected element type and name * * @param int $peType PE type * @param string $nameOfPE PE name * @return string $defTitle Definition title text */ public static function nameOfSD($peType, $nameOfPE) { global $wgContLang, $haclgContLang; $defTitle = $wgContLang->getNsText(HACL_NS_ACL) . ':'; if ($nameOfPE instanceof Title) { // Get canonical prefixed text from a Title object $base = $nameOfPE->getText(); $ns = $nameOfPE->getNamespace(); if ($ns == NS_CATEGORY && $peType == IACL::PE_CATEGORY || $ns == HACL_NS_ACL && ($peType == IACL::PE_RIGHT || $peType == IACL::PE_GROUP) || $ns == NS_SPECIAL && $peType == IACL::PE_SPECIAL) { $ns = false; } elseif ($peType != IACL::PE_PAGE) { throw new Exception("BUG: " . __METHOD__ . " called with title object {$nameOfPE}, but peType={$peType}"); } if ($ns == NS_SPECIAL) { // Canonicalize special page titles list($base, $par) = SpecialPageFactory::resolveAlias($t->getText()); if ("{$par}" !== '') { $base = "{$base}/{$par}"; } } $nameOfPE = ($ns ? iaclfCanonicalNsText($nameOfPE->getNamespace()) . ':' : '') . $base; } if ($peType == IACL::PE_SPECIAL) { $defTitle .= $haclgContLang->getPetPrefix(IACL::PE_PAGE) . '/Special:'; } elseif ($peType != IACL::PE_RIGHT) { $prefix = $haclgContLang->getPetPrefix($peType); if ($prefix) { $defTitle .= $prefix . '/'; } } return $defTitle . $nameOfPE; }
function haclAutocomplete($t, $n, $limit = 11, $add_checkboxes = false, $item_prefix = false) { global $haclgContLang; if (!$limit) { $limit = 11; } $a = array(); $dbr = wfGetDB(DB_SLAVE); // Users if ($t == 'user') { $r = $dbr->select('user', 'user_name, user_real_name', array('user_name LIKE ' . $dbr->addQuotes('%' . $n . '%') . ' OR user_real_name LIKE ' . $dbr->addQuotes('%' . $n . '%')), __METHOD__, array('ORDER BY' => 'user_name', 'LIMIT' => $limit)); while ($row = $r->fetchRow()) { $a[] = array($row[1] ? $row[0] . ' (' . $row[1] . ')' : $row[0], $row[0]); } } elseif ($t == 'group') { $ip = 'hi_'; $n = str_replace(' ', '_', $n); $r = $dbr->select('page', '*', array('page_namespace' => HACL_NS_ACL, 'page_title LIKE ' . $dbr->addQuotes($haclgContLang->getPetPrefix(IACL::PE_GROUP) . '/%' . $n . '%')), __METHOD__, array('ORDER BY' => 'page_title', 'LIMIT' => $limit)); foreach ($r as $group) { // TODO filter unreadable? $n = str_replace('_', ' ', substr($group->page_title, 6)); $a[] = array($n, $n); } } elseif ($t == 'page') { $ip = 'ti_'; $n = str_replace(' ', '_', $n); $where = array(); // Check if namespace is specified within $n $etc = haclfDisableTitlePatch(); $tt = Title::newFromText($n . 'X'); if ($tt->getNamespace() != NS_MAIN) { $n = substr($tt->getDBkey(), 0, -1); $where['page_namespace'] = $tt->getNamespace(); } haclfRestoreTitlePatch($etc); // Select page titles // FIXME: ??? CAST(page_title AS CHAR CHARACTER SET utf8) $where[] = 'page_title LIKE ' . $dbr->addQuotes($n . '%'); $r = $dbr->select('page', 'page_title, page_namespace', $where, __METHOD__, array('ORDER BY' => 'page_namespace, page_title', 'LIMIT' => $limit)); while ($row = $r->fetchRow()) { $title = Title::newFromText($row[0], $row[1]); // Filter unreadable if ($title->userCan('read')) { // Use canonical titles $t = ($title->getNamespace() ? iaclfCanonicalNsText($title->getNamespace()) . ':' : '') . $title->getText(); $a[] = array($title->getPrefixedText(), $t); } } } elseif ($t == 'namespace') { $ip = 'ti_'; global $wgCanonicalNamespaceNames, $wgContLang, $haclgUnprotectableNamespaceIds; $ns = $wgCanonicalNamespaceNames; $ns[0] = 'Main'; ksort($ns); // Always unlimited $limit = count($ns) + 1; $n = mb_strtolower($n); $nl = mb_strlen($n); foreach ($ns as $k => $v) { $v = str_replace('_', ' ', $v); $name = str_replace('_', ' ', $wgContLang->getNsText($k)); if (!$name) { $name = $v; } if ($k >= 0 && (!$nl || mb_strtolower(mb_substr($v, 0, $nl)) == $n || mb_strtolower(mb_substr($name, 0, $nl)) == $n) && empty($haclgUnprotectableNamespaceIds[$k])) { $a[] = array($name, $v); } } } elseif ($t == 'category') { $ip = 'ti_'; $n = str_replace(' ', '_', $n); $where = array('page_namespace' => NS_CATEGORY, 'page_title LIKE ' . $dbr->addQuotes($n . '%')); $r = $dbr->select('page', 'page_title', $where, __METHOD__, array('ORDER BY' => 'page_title', 'LIMIT' => $limit)); while ($row = $r->fetchRow()) { $title = Title::newFromText($row[0], NS_CATEGORY); // Filter unreadable if ($title->userCan('read')) { $title = $title->getText(); $a[] = array($title, $title); } } } elseif ($t == 'sd') { $ip = 'ri_'; $n = str_replace(' ', '_', $n); $r = $dbr->select('page', '*', array('page_namespace' => HACL_NS_ACL, 'page_title NOT LIKE ' . $dbr->addQuotes($haclgContLang->getPetPrefix(IACL::PE_GROUP) . '/%'), 'page_title LIKE ' . $dbr->addQuotes('%' . $n . '%')), __METHOD__, array('ORDER BY' => 'page_title', 'LIMIT' => $limit)); foreach ($r as $sd) { // TODO filter unreadable? $n = str_replace('_', ' ', $sd->page_title); $a[] = array($n, $n); } } // No items if (!$a) { return '<div class="hacl_tt">' . wfMsg('hacl_autocomplete_no_' . $t . 's') . '</div>'; } // More than (limit-1) items => add '...' at the end of list $max = false; if (count($a) >= $limit) { array_pop($a); $max = true; } $i = 0; $html = ''; $ip = $item_prefix ? $item_prefix . '_' : 'item'; if ($add_checkboxes) { // This is used by Group Editor: display autocomplete list with checkboxes foreach ($a as $item) { $i++; $html .= '<div id="' . $ip . $i . '" class="hacl_ti" title="' . htmlspecialchars($item[1]) . '"><input style="cursor: pointer" type="checkbox" id="c' . $ip . $i . '" /> ' . htmlspecialchars($item[0]) . ' <span id="t' . $ip . $i . '"></span></div>'; } } else { // This is used by ACL Editor: simple autocomplete lists for editboxes foreach ($a as $item) { $i++; $html .= '<div id="' . $ip . $i . '" class="hacl_ti" title="' . htmlspecialchars($item[1]) . '">' . htmlspecialchars($item[0]) . '</div>'; } } if ($max) { $html .= '<div class="hacl_tt">...</div>'; } return $html; }