In 1D, you should remember that the median $\hat{m}$ minimizes a sum of absolute values ($\ell_1$ norm):
$$ \hat{m} = \arg \min \sum_{k=1}^k |x_k-m|.$$
You can find out that the answer (in 1D only) is the center value of the $x_k$ for an odd number of samples, and any value between the two center values for an even number of samples (traditionally their average).
The weighted median, to me, boils down to:
$$ \hat{m}_w = \arg \min \sum_{k=1}^k w_i|x_k-m|,$$
just like the weighted mean $\hat{M}$ minimizes ($\ell_2$ norm):
$$ \hat{M} = \arg \min \sum_{k=1}^k w_i|x_k-M|^2.$$
In the definition I use, let $x=[1,2,3,2,4]$. The standard median is $2$, uniquely based on the rank. You can then take integer weights, like $w=[1,2,5,2,1]$. They aim at limiting the pure ranking effect of the median, and at introducing some spatialisation or "refocused location". A weighted median would consist in duplicating/triplicating/$n$-plicating the initial values with respect to the weights and their respective location: $x_w=[1,2,2,3,3,3,3,3,2,2,4]$ and take the median of the new data: $3$.
The definition extends to rational and real weights (perhaps complex).
The advantages of the weighted median in images are mostly two-fold, since you can recover the median with $w_k=1$:
- Restore some spatialisation, absent in the traditional median, which generates "moving edges", by better centering the median around the central pixel of the square window (if weights in the mask are shapes like a pyramid). That is evident from the example above: the median picks $2$, but the weighting answer $3$, as a central edge, would be a better choice,
- Allow negative weights, to better mimic not only smoothing filters (positive weights) but also "median-derivative-like" filters.
One of my sources is Nonlinear Image Processing, by Mitra & Sicuranza.
So the weighted median is always "better" as more generic, provided you can find a neat weighting. To recenter, a pyramidal shape (centered at the center pixel of the square) ought to be better than a flat mask. For instance, take a weighting based on Pascal triangle coefficients.
The concept of a true median in $n$ dimensions is more complicated than the above procedure, since there is no "natural ordering" (compatible with some operations) in 2D, and requires optimization.